Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-17915

Incorrect handling of value less add_definitions from cmake projects

    XMLWordPrintable

Details

    Description

      When using cmake based projects with add_definitions(-DFOO) where no value is defined, Qt Creator seems to add "#define FOO" instead of "define FOO 1" into macro definitions used for code highlighting.

      "-D" is documented here
      https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#Preprocessor-Options
      and here:
      https://msdn.microsoft.com/en-us/library/hhzbb5c8.aspx

      This breaks code highlighting for cases like this:
      #if FOO
      (...)
      #endif

      Statically analyzing the code I think bug is in cmakecbpparser.cpp:void CMakeCbpParser::parseAdd()

      Now (taken from latest git, not 4.2.0):
      if (macroNameIndex != 1)

      { int assignIndex = compilerOption.indexOf('=', macroNameIndex); if (assignIndex != -1) compilerOption[assignIndex] = ' '; m_buildTarget.defines.append("#define "); m_buildTarget.defines.append(compilerOption.mid(macroNameIndex).toUtf8()); m_buildTarget.defines.append('\n'); }

      I think it should be:
      if (macroNameIndex != 1)

      { int assignIndex = compilerOption.indexOf('=', macroNameIndex); if (assignIndex != -1) compilerOption[assignIndex] = ' '; m_buildTarget.defines.append("#define "); m_buildTarget.defines.append(compilerOption.mid(macroNameIndex).toUtf8()); if (assignIndex == -1) m_buildTarget.defines.append(" 1"); m_buildTarget.defines.append('\n'); }

      Attachments

        For Gerrit Dashboard: QTCREATORBUG-17915
        # Subject Branch Project Status CR V

        Activity

          People

            hunger Tobias Hunger
            domin144 Dominik Wójt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes