Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 354553 - Problematic CDT macro expansion for non-standard token pasting
Summary: Problematic CDT macro expansion for non-standard token pasting
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 8.0.1   Edit
Assignee: Markus Schorn CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-11 17:00 EDT by renegat.nospam CLA
Modified: 2013-08-27 13:28 EDT (History)
2 users (show)

See Also:


Attachments
fix (1.06 KB, patch)
2011-08-12 04:08 EDT, renegat.nospam CLA
cdtdoug: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description renegat.nospam CLA 2011-08-11 17:00:13 EDT
Build Identifier: 20110615-0604

Description:

CDT macro expansion for non-standard token pasting incompatible with MS Windows WDK headers

Example:

  #define foo(x) (## x)
  void test foo(void);

The CDT parser generates the annotation 'Invalid use of macro pasting in macro: foo' for the expression "foo(void)" and expands the 
expression to ")". The annotation is ok, but the result of the expansion should be "(x)" for compatibility reasons:

The 'Windows Driver Kit 7.1.0' uses this non-standard token pasting in file "inc/api/DriverSpecs.h" (function annotations for static code analysis). Except those non-standard macro expansions the CDT parser is 100% compatible with the driver kit headers.

Behaviour of some compilers for this 'non-standard' macro pasting:

  - GNU gcc generates an error: pasting "(" and "void" does not give a valid
    preprocessing token

  - Intel icc emits a warning and expands "foo(void)" to "(void)"

  - Microsoft cl does not complain about it and expands it either to "(void)"

Bugfix: the CDT parser should expand the expression "(## x)" in a macro expansion to "(x)" instead of ")"

Reproducible: Always
Comment 1 renegat.nospam CLA 2011-08-12 04:08:22 EDT
Created attachment 201374 [details]
fix

Fix makes the parsing result compatible with Microsoft cl compiler extension, annotation as 'Invalid use of macro pasting in macro ...' will be kept.
Comment 2 Markus Schorn CLA 2011-08-17 05:59:12 EDT
Added testcase and (slightly different) fix.
Comment 3 CDT Genie CLA 2011-08-17 06:23:01 EDT
*** cdt git genie on behalf of Markus Schorn ***

    Bug 354553: Handling of invalid token paste

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=c17176f43ce1a8e10fb6f3a13101262256bd9f95
Comment 4 CDT Genie CLA 2011-08-17 06:23:02 EDT
*** cdt git genie on behalf of Markus Schorn ***

    Bug 354553: Handling of invalid token paste

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=0f0f7172316d6a768e11e00ec7b8404b68919d73
Comment 5 Derrick Gibelyou CLA 2013-08-27 10:26:12 EDT
I am still seeing this problem in CDT 8.1.201209170703 and 8.2.0.201306112328.

The indexer gives the error: "Invalid use of macro pasting in macro: foo".

The compiler in this case is TI's cl6x.
Comment 6 CDT Genie CLA 2013-08-27 12:22:24 EDT
*** cdt git genie on behalf of Andrew Gvozdev ***

    bug 354553: keep only language settings tests to speed up troubleshooting

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=66aa54cf0c3ac526156bcb9c839c74fac8faee96
Comment 7 Andrew Gvozdev CLA 2013-08-27 13:28:23 EDT
(In reply to comment #6)
> *** cdt git genie on behalf of Andrew Gvozdev ***
> bug 354553: keep only language settings tests to speed up troubleshooting
> http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=66aa54cf0c3ac526156bcb9c839c74fac8faee96
Err, wrong bug. Meant to be bug 415841. This commit went to a test branch.