Bug 321356 - Inconsistent empty preprocessor define handling by build / core / parser
Summary: Inconsistent empty preprocessor define handling by build / core / parser
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 7.0   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 275779
  Show dependency tree
 
Reported: 2010-07-30 10:56 EDT by James Blackburn CLA
Modified: 2020-09-04 15:24 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description James Blackburn CLA 2010-07-30 10:56:57 EDT
There seems to be an issue in the way -Ds in quotes are passed to the parser.

Steps to reproduce:
1) Create HelloWorld program

int main(void) DEFINED {
	puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
	return EXIT_SUCCESS;
}

2) Add define (in build settings, or paths and symbols)
   DEFINED -> ""

3) Build the app

make all 
Building file: ../src/parser_issue.c
Invoking: GCC C Compiler
gcc -DDEFINED="" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/parser_issue.d" -MT"src/parser_issue.d" -o"src/parser_issue.o" "../src/parser_issue.c"
Finished building: ../src/parser_issue.c

Syntax error shown in the UI.

Adding "#define DEFINED" to the source file resolves the issue local to the file.
Comment 1 James Blackburn CLA 2010-07-30 11:25:03 EDT
Interestingly if I change the -D to just
-DDEFINED 

the parser no longer complains but the compiler does:

Building file: ../src/parser_issue.c
Invoking: GCC C Compiler
gcc -DDEFINED -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/parser_issue.d" -MT"src/parser_issue.d" -o"src/parser_issue.o" "../src/parser_issue.c"
../src/parser_issue.c: In function 'main':
../src/parser_issue.c:14: error: expected declaration specifiers before numeric constant
../src/parser_issue.c:17: error: expected '{' at end of input
make: *** [src/parser_issue.o] Error 1

with --save-temps I see that 
-DDEFINED:
 gcc => #define DEFINED 1
 CDT Parse log => DEFINED=

-DDEFINED="":
 gcc => #define DEFINED
 CDT Parse log => DEFINED=""
Comment 2 James Blackburn CLA 2010-07-30 11:34:28 EDT
Presumably make / the shell is resolving an empty quotes to nothing, so the compiler isn't seeing this -DDEFINED=. 
The workaround is to set DEFINED= in the build settings page.

Unfortunately the Paths & Symbols page has two boxes: Name + Value. If you leave Value blank it just does -DDEFINED which is interpreted as -DDEFINED=1.

Even with -DDEFINED=, exporting this setting doesn't seem to work right. You end up with -DDEFINED again.
Comment 3 Alex Burr CLA 2010-07-30 11:52:29 EDT
FWIW, I managed to work round the problem by setting DEFINED to ${env_var:NULL}
(NULL is not set to anything). This gets propagated through the project references okay, and I end up with 'DDEFINED= on the command line rather than just -DDEFINED.
Comment 4 Andrew Gvozdev CLA 2010-07-30 14:13:20 EDT
(In reply to comment #0)
> There seems to be an issue in the way -Ds in quotes are passed to the parser.
See also more issues related to quoting in bug 309158

(In reply to comment #3)
> FWIW, I managed to work round the problem by setting DEFINED to ${env_var:NULL}
That's a good one