danmar / simplecpp

C++ preprocessor
BSD Zero Clause License
209 stars 83 forks source link

Fail to expand macro #295

Open danmar opened 1 year ago

danmar commented 1 year ago

Reported here: https://sourceforge.net/p/cppcheck/discussion/general/thread/5f665265d7/

Example code:

#define IS_ENABLED(config_macro) Z_IS_ENABLED1(config_macro)
#define Z_IS_ENABLED1(config_macro) Z_IS_ENABLED2(_XXXX##config_macro)
#define _XXXX1 _YYYY,
#define Z_IS_ENABLED2(one_or_two_args) Z_IS_ENABLED3(one_or_two_args 1, 0)
#define Z_IS_ENABLED3(ignore_this, val, ...) val

#define FOO 1

int main() {
    return IS_ENABLED(FOO);
}

simplecpp writes this error:

1.c:2: syntax error: failed to expand 'IS_ENABLED', Wrong number of parameters for macro 'Z_IS_ENABLED2'.

gcc preprocesses this code fine.