Bug 481948 - Quoted macro definition leads to syntax error
Summary: Quoted macro definition leads to syntax error
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 9.0.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-11 13:04 EST by Marc-André Laperle CLA
Modified: 2020-09-04 15:26 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc-André Laperle CLA 2015-11-11 13:04:07 EST
Using CDT master as of today.

1. Create an executable, hello world C++ project with this code:
#include <iostream>

using namespace std;

int main() {
  cout << "!!!Hello World!!!" << endl; // prints
  MACRO   // this will be a syntax error
}

2. Open the project properties, C/C++ General, Settings.
3. Under (GCC) C++ Compiler, Preprocessor, add the symbol MACRO='return 0;'
4. Click OK.

In the file, the MACRO line is marked as a syntax error, but this compiles properly (with GCC at least).




I kept the title of the bug as a specific case because I don't actually know at what stage this should be handled. What I mean is that the macro could be unquoted before being passed to the preprocessor or the preprocessor could do the unquoting. Here are a few flows that the macros go through:

1) managed build settings -> managed build language settings -> CDT preprocessor
2) managed build settings -> build (invocke gcc -D...)
3) build output parser -> output parser language settings -> CDT preprocessor

For #2 to work, as of today, you have to keep the quotes. As part of bug 463723, I was working on a specific problem of #3, where a quoted macro was not being read correctly by the output parser. But then passing this to the preprocessor as-is doesn't work properly and this is also the case for #1 (as shown in the steps). So there needs to be a common place where to handle removing the quotes, either at the preprocessor stage, or somewhere before that.