-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
clangd gets confused by -U...
in command line
#97759
Comments
@llvm/issue-subscribers-clangd Author: Jan Palus (jpalus)
For input file `test.c`:
```c
#include <stdio.h>
#ifndef MSG void hello() {
clangd reports false positive: $ clangd --check=test.c
...
I[21:05:56.452] Indexing headers...
I[21:05:56.472] Building AST...
E[21:05:56.491] [undeclared_var_use] Line 8: use of undeclared identifier 'MSG'
I[21:05:56.491] Indexing AST...
I[21:05:56.492] Building inlay hints
I[21:05:56.492] Building semantic highlighting
I[21:05:56.492] Testing features at each token (may be slow in large files)
I[21:05:56.493] Found definition heuristically using nearby identifier MSG
I[21:05:56.493] Found definition heuristically using nearby identifier MSG
I[21:05:56.501] All checks completed, 1 errors |
I believe this has the same underlying cause as clangd/clangd#1396: "clang first loads the preamble and then applies the builtin buffer". Here, the A workaround is to add a non-preprocessor declaration between the includes and the #include <stdio.h>
struct EndPreamble {}; // dummy declaration to force the end of the preamble
#ifndef MSG
#define MSG "hello world"
#endif
void hello() {
printf(MSG);
} |
Duplicate of clangd/clangd#1396 |
For input file
test.c
:and
compile_commands.json
:clangd reports false positive:
The text was updated successfully, but these errors were encountered: