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

C++: support the search order of header files used by clang/gcc #16648

Open
qwerty472123 opened this issue Jun 3, 2024 · 1 comment
Open
Labels
C++ question Further information is requested

Comments

@qwerty472123
Copy link

As a example:

  • a/a.h
#include "b.h"
  • a/c.h
hi_c c;
  • b/b.h
#include "c.h"
  • c/c.h
hello_c c;
  • test.cpp
#include "a/a.h"
# clang++ -I b -I c -c test.cpp -otest
In file included from test.cpp:1:
In file included from ./a/a.h:1:
In file included from b/b.h:1:
c/c.h:1:1: error: unknown type name 'hello_c'
hello_c c;
^
1 error generated.
# g++ -I b -I c -c test.cpp -otest
In file included from b/b.h:1:0,
                 from a/a.h:1,
                 from test.cpp:1:
c/c.h:1:1: error: ‘hello_c’ does not name a type
 hello_c c;
 ^~~~~~~

however, when use codeql extractor by /usr/local/bin/codeql/cpp/tools/linux64/extractor --mimic clang++ -I b -I c -c test.cpp -otest, it shows

"a/c.h", line 1: error: identifier "hi_c" is undefined
  hi_c c;
  ^

[E 09:26:49 145792] Warning[extractor-c++]: In construct_text_message: "a/c.h", line 1: error: identifier "hi_c" is undefined
  hi_c c;
  ^

It includes a/c.h, which is the same with MSVC, but gcc/clang includes c/c.h.

Clang and GCC using a static context for search directory, but MSVC use a dynamic context, which caused the problem.

I wanna CodeQL extractor to support the behavior of Clang and GCC for more consistent result with the clang compiled ELF.

@qwerty472123 qwerty472123 added the question Further information is requested label Jun 3, 2024
@qwerty472123 qwerty472123 changed the title support the search order of header files used by clang/gcc C++: support the search order of header files used by clang/gcc Jun 3, 2024
@jketema
Copy link
Contributor

jketema commented Jun 3, 2024

Hi @qwerty472123,

Thanks for your report. This indeed seems incorrect. I've opened an internal issue to track this.

@jketema jketema added the C++ label Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants