Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 362148

Summary: Recognize __COUNTER__ macro
Product: [Tools] CDT Reporter: vagran <vagran.ast>
Component: cdt-parserAssignee: Markus Schorn <mschorn.eclipse>
Status: RESOLVED FIXED QA Contact: Markus Schorn <mschorn.eclipse>
Severity: enhancement    
Priority: P3 CC: cdtdoug, vagran.ast
Version: 8.0   
Target Milestone: 8.1.0   
Hardware: PC   
OS: Linux   
Whiteboard:

Description vagran CLA 2011-10-27 01:23:58 EDT
Build Identifier: 20110916-0149

In most modern compilers (GCC, msvc) there is a __COUNTER__ macro which is expanded to integer 0 and is incremented by one on every next expansion in scope of one compilation unit. It would be nice to support this behavior in Eclipse. Otherwise there are error highlighted by code analyzer, like "invalid redefinition" etc, if this macro is used for identifiers generation.

Reproducible: Always

Steps to Reproduce:
Type this code:

#define CONCAT2(x, y)      x##y
#define CONCAT(x, y)       CONCAT2(x, y)
#define MYVAR class CONCAT(A, __LINE__) { } CONCAT(myvar, __COUNTER__);
MYVAR;
MYVAR;
MYVAR;

Last two lines will be marked with error "Invalid redeclaration of 'MYVAR'".
Comment 1 Markus Schorn CLA 2011-11-03 04:26:48 EDT
Added testcase and implementation.
Comment 2 CDT Genie CLA 2011-11-03 05:23:03 EDT
*** cdt git genie on behalf of Markus Schorn ***

    Bug 362148: Support for __COUNTER__ macro.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=058e14d32c4674b0a81c504e74b970b5783798cf