simplecpp icon indicating copy to clipboard operation
simplecpp copied to clipboard

Preprocessing failure with comma in macro

Open danmar opened this issue 9 years ago • 1 comments

Input:

#define COUNTER_NAME(NAME, ...) NAME##Count
#define COMMA ,

#define DECLARE_COUNTERS(LIST) unsigned long LIST(COUNTER_NAME, COMMA);

#define ACTUAL_LIST(FUNCTION, SEPARATOR) \
    FUNCTION(event1, int, foo) SEPARATOR \
    FUNCTION(event2, char, bar)

DECLARE_COUNTERS(ACTUAL_LIST)

Output of gcc -E:

#1 "cppcheck-issue-xxxx.cpp"
#1 "<built-in>"
#1 "<command-line>"
#1 "cppcheck-issue-xxxx.cpp"
#10 "cppcheck-issue-xxxx.cpp"
unsigned long event1Count , event2Count;

simplecpp output:

test.c:4: syntax error: failed to expand 'DECLARE_COUNTERS', Wrong number of parameters for macro 'ACTUAL_LIST'.

danmar avatar Sep 06 '16 20:09 danmar

Here is a simpler test case:

#define COMMA ,
#define MULTI(SEPARATOR) A SEPARATOR B

#define VARS MULTI(COMMA)
unsigned VARS;

gives a similar error: issues/simpleComma.c:4: syntax error: failed to expand 'VARS', Wrong number of parameters for macro 'MULTI'.

hexcoder- avatar Sep 29 '17 15:09 hexcoder-