Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__has_include with angle-bracketed argument breaks preprocessing #229

Closed
dummyunit opened this issue Jan 17, 2022 · 13 comments
Closed

__has_include with angle-bracketed argument breaks preprocessing #229

dummyunit opened this issue Jan 17, 2022 · 13 comments

Comments

@dummyunit
Copy link
Contributor

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.

@danmar
Copy link
Owner

danmar commented Jan 18, 2022

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

@jamesharris-garmin
Copy link

jamesharris-garmin commented May 2, 2022

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 ?

@danmar
Copy link
Owner

danmar commented May 8, 2022

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..

@aremmell
Copy link

No movement? Does someone externally need to PR this to get it done? It's pretty bad! This is a super common construct to use these days

@danmar
Copy link
Owner

danmar commented Sep 12, 2023

No movement? Does someone externally need to PR this to get it done? It's pretty bad! This is a super common construct to use these days

This is an open source project. The development team is just a group of volounteers that helps out for free in their spare time.

I am hoping that Cppcheck Premium will grow and that we can someday pay some developer to work on Simplecpp and Cppcheck..

@aremmell
Copy link

Sorry, didn't mean to come off the wrong way. I was just surprised about this one. I would try to fix it myself if I thought I could without breaking 8 other things.

I imagine the learning curve is quite steep if you've never done something similar before. I can give it a go though if you want :)

@danmar
Copy link
Owner

danmar commented Sep 18, 2023

Sorry, didn't mean to come off the wrong way.

ok.

I imagine the learning curve is quite steep if you've never done something similar before. I can give it a go though if you want :)

This code is not super trivial but imho this is probably a relatively nice task to start working with compared to some other tasks. Feel free to take a look I would appreciate a PR!

@aremmell
Copy link

Where would one start looking?

@danmar
Copy link
Owner

danmar commented Sep 21, 2023

spontanously I wonder what happens here:

if (hasInclude && tok->str() == HAS_INCLUDE) {

at a quick glance it looks as if <> is handled.

@danmar
Copy link
Owner

danmar commented Sep 21, 2023

in this test case it looks like <> are handled:

" #if __has_include(<realFileName1.cpp>)\n"

@danmar
Copy link
Owner

danmar commented Oct 4, 2023

can somebody create a test case that fails? I don't get a syntax error here:

$ cat 229.cpp 
#if __has_include(<any>)
#endif
$ ./simplecpp 229.cpp 

$

@yut23
Copy link

yut23 commented Nov 29, 2023

The issues I was seeing with this seem to have been fixed by #271 (first included in cppcheck 2.10).

@danmar
Copy link
Owner

danmar commented Dec 1, 2023

ok thanks.. I will close this.. if anybody still see problems feel free to reopen this issue or open a new issue..

@danmar danmar closed this as completed Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants