simplecpp icon indicating copy to clipboard operation
simplecpp copied to clipboard

__has_include with angle-bracketed argument breaks preprocessing

Open dummyunit opened this issue 3 years ago • 3 comments

Preprocessing (in C++17 mode) of code like this:

#if __has_include(<any>)
#endif

results in an error:

/tmp/fail.cpp:1: syntax error: failed to evaluate #if condition

This happens regardless of whether the mentioned header file exists or not.

Debugging shows that <any> is split in 3 tokens: <, any, >, but the code for handling __has_include expects one token as argument: https://github.com/danmar/simplecpp/blob/ab680f96ea9aa0fc7ed241f6dc51954d7a8d6735/simplecpp.cpp
As a result the check to matching closing parenthesis fails (as any is not )) and a fatal syntax error is reported: https://github.com/danmar/simplecpp/blob/ab680f96ea9aa0fc7ed241f6dc51954d7a8d6735/simplecpp.cpp

This also affects Cppcheck - it reports preprocessorErrorDirective on that line and stops.

dummyunit avatar Jan 17 '22 17:01 dummyunit

ouch I thought this __has_include was fixed by now. Thanks for reporting!

danmar avatar Jan 18 '22 19:01 danmar

have we been able to fix this? or should someone submit a pull request?

Follow up: are we actually finding the correct file? in that code is it actually searching for < when we are searching the file? does it actually try to open any ?

jamesharris-garmin avatar May 02 '22 16:05 jamesharris-garmin

I didn't have time to look at this yet. A PR would be appreciated.

Follow up:

not sure I'd have to look in the code and/or debug..

danmar avatar May 08 '22 12:05 danmar