simplecpp icon indicating copy to clipboard operation
simplecpp copied to clipboard

Do not abort when there is #ifdef in macro expansion list

Open danmar opened this issue 2 months ago • 0 comments

Example code:

#define dostuff(X) X

dostuff(
#ifdef A
    1
#endif
    -1
)

simplecpp writes an error message and aborts:

1.c:5: syntax error: failed to expand 'dostuff', it is invalid to use a preprocessor directive as macro parameter

This error message is correct and it's great that simplecpp warns for this.

But customers don't like that simplecpp aborts. Compilers will typically preprocess it without warnings. gcc preprocess it to 1-1 if A is defined, and -1 if A is not defined.

danmar avatar Oct 16 '25 15:10 danmar