Includes of system headers are never implicitly relative to the source file#282
Conversation
|
is it possible to write some test for this? Something similar to this maybe: |
Sorry, something went wrong.
8be5251 to
2b73c45
Compare
December 21, 2022 14:20
|
Hope this will do - the test detects the difference between the old and new simplecpp behaviour. I found I had to create an empty |
Sorry, something went wrong.
|
This is scary. I finally got around to checking why the issue I introduced in #276 and fixed in #281 did not trigger any test failures. And it turns out it is caused by the same code you just fixed. simplecpp is completely void of tests with additional files at the moment. That has been a source of discussion in #261. There's also tests lacking in cppcheck which I have partially added locally. |
Sorry, something went wrong.
|
hmm.. I feel I can merge this. However when I try it locally it does not seem to work. I have this code in my file 1.c: And 1.h contains: when I run simplecpp with command It works as it should for you? |
Sorry, something went wrong.
That's why we need unit tests with headers/includes... |
Sorry, something went wrong.
|
The title of this PR says that "system headers are never relative to the source file". That is not true. See: |
Sorry, something went wrong.
…e file Sometimes, #include directives with angle-bracket filespec delimiters are used (or abused) to defeat the preprocessor's behaviour where it tries to find a header file at a path relative to the file containing the directive. Without this fix, any non-root header file, foo/bar.h, which does #include <bar.h> while intending to include a root-level header file, will instead enter an infinite inclusion loop, terminating when the inclusion stack overflows with a "#include nested too deeply" error.
2b73c45 to
81808f8
Compare
January 10, 2023 16:04
That looks to have been caused by
OK, I have added the word "implicitly" into the commit summary, hope this is sufficient. For what it's worth, I found the following description in the gcc man page (I realise this isn't unversal to all compilers): |
Sorry, something went wrong.
I will add such tests to Cppcheck soon with the referenced PR. |
Sorry, something went wrong.
|
Thanks I think this looks good. If CI is happy I'll merge it. Let's consider the testing later separately. I also think we could explore using pytest in simplecpp. |
Sorry, something went wrong.
Sometimes,
#includedirectives with angle-bracket filespec delimiters are used (or abused) to defeat the preprocessor's behaviour where it tries to find a header file at a path relative to the file containing the directive.Without this fix, any non-root header file,
foo/bar.h, which doeswhile intending to include a root-level header file, will instead enter an infinite inclusion loop, terminating when the inclusion stack overflows with a
#include nested too deeplyerror.See also this cppcheck issue.