ned14 / pcpp

A C99 preprocessor written in pure Python
Other
220 stars 41 forks source link

Token-pasting-related problem processing BOOST_WORKAROUND #42

Closed joaquintides closed 4 years ago

joaquintides commented 4 years ago

If I process the following with the pcpp command line tool:

#define BOOST_WORKAROUND(symbol, test)                \
       ((symbol ## _WORKAROUND_GUARD + 0 == 0) &&     \
       (symbol != 0) && (1 % (( (symbol test) ) + 1)))

#define BOOST_MSVC 1916
#define BOOST_MSVC_WORKAROUND_GUARD 0
BOOST_WORKAROUND(BOOST_MSVC,==1916)

the output is:

((1916_WORKAROUND_GUARD + 0 == 0) &&            (1916 != 0) && (1 % (( (1916 ==1916) ) + 1)))

while g++ -E produces:

((0 + 0 == 0) && (1916 != 0) && (1 % (( (1916 ==1916) ) + 1)))
ned14 commented 4 years ago

Nice catch, thanks.

ned14 commented 4 years ago

Finally got to fixing this, mainly due to me being sick of writing WG21 normative wording and I really, really wanted a break. pcpp now has a proper yacc based expression evaluator so complex #if expressions will now work properly. Apart from occasional whitespace differences, the edition in trunk ought to be much more capable of parsing most of Boost than before. Thanks for reporting this bug.

joaquintides commented 4 years ago

Thanks for fixing this! Best regards,