Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 362148 - Recognize __COUNTER__ macro
Summary: Recognize __COUNTER__ macro
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 8.0   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: 8.1.0   Edit
Assignee: Markus Schorn CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-27 01:23 EDT by vagran CLA
Modified: 2012-02-23 11:33 EST (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 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