simplecpp icon indicating copy to clipboard operation
simplecpp copied to clipboard

token pasting and empty tokens

Open matlo opened this issue 2 years ago • 1 comments

// test.h

#define SIMPLE(T, NAME) \
   T NAME;

#define ADVANCED(T, PREFIX, NAME, EXTENSION) \
   SIMPLE(T, PREFIX##NAME##EXTENSION)

ADVANCED(int, , foo, )
cppcheck -E test.h
Checking test.h ...
[test.h:6]: (error) failed to expand 'ADVANCED', Invalid ## usage when expanding 'ADVANCED'.
cpp test.h 
# 1 "test.h"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "test.h"
# 9 "test.h"
int foo;

matlo avatar Apr 12 '22 18:04 matlo

Same result with 0fe0ab6:

./simplecpp test.h

test.h:6: syntax error: failed to expand 'ADVANCED', Invalid ## usage when expanding 'ADVANCED': Unexpected token ',foo'

matlo avatar Apr 12 '22 19:04 matlo