Description
Environment
- OS and Version: Ubuntu 16.04 | Linux x64 4.15.0-142-generic
- VS Code Version: 1.76.2
- C/C++ Extension Version: v1.14.4
Bug Summary and Steps to Reproduce
Bug Summary:
It's about go to definition (F12)
for competing definitions. For example, there are two functions with the same prototype but linked to different executables, one for true program, the other for testing. If there is a dummy macro definition to indicate HAS_UT
in the true function. Then, invoking go to definition
under client / caller will bring us to the definition inside the test file.
Steps to reproduce:
main.c:
#include "foo.h"
int main(int argc, char const *argv[])
{
foo_func();
return 0;
}
foo.h:
#ifndef FOO_H_
#define FOO_H_
#define HAS_UT
void foo_func();
#endif // FOO_H_
foo.c as file for true definition
#include "foo.h"
#include <stdio.h>
void HAS_UT foo_func()
{
printf("True foo_func\n");
}
test.c as the file for test (a fake here):
#include "foo.h"
#include <stdio.h>
void foo_func()
{
printf("test foo_func\n");
}
You may not need to compile, just invoke go to definition
with the cursor under foo_func
in the main.c
.
Expected behavior: If there was no HAS_UT
in the definition of foo_func
in foo.c
, go to definition
will work right, showing a peek window with 2 definitions waiting for selection.
Configuration and Logs
Logs from C/C++: Log Diagnostics
-------- Diagnostics - 3/20/2023, 11:01:52 AM
Version: 1.14.4
Current Configuration:
{
"name": "Linux",
"includePath": [
"/home/wang/workspace/trial_error/vscode_bug/**"
],
"defines": [],
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64",
"intelliSenseModeIsExplicit": false,
"cStandardIsExplicit": false,
"cppStandardIsExplicit": false,
"mergeConfigurations": false,
"compilerPath": "/usr/bin/clang",
"compilerPathIsExplicit": false,
"browse": {
"limitSymbolsToIncludedHeaders": true,
"path": [
"${workspaceFolder}/**"
]
}
}
Translation Unit Mappings:
[ /home/wang/workspace/trial_error/vscode_bug/foo.c ]:
/home/wang/workspace/trial_error/vscode_bug/foo.c
/home/wang/workspace/trial_error/vscode_bug/foo.h *
[ /home/wang/workspace/trial_error/vscode_bug/test.c ]:
/home/wang/workspace/trial_error/vscode_bug/test.c
/home/wang/workspace/trial_error/vscode_bug/foo.h
[ /home/wang/workspace/trial_error/vscode_bug/main.c ]:
/home/wang/workspace/trial_error/vscode_bug/main.c
/home/wang/workspace/trial_error/vscode_bug/foo.h
Translation Unit Configurations:
[ /home/wang/workspace/trial_error/vscode_bug/foo.c ]:
Process ID: 21763
Memory Usage: 35 MB
Compiler Path: /usr/bin/clang
Includes:
/usr/local/include
/usr/lib/llvm-8/lib/clang/8.0.0/include
/usr/include/x86_64-linux-gnu
/usr/include
Standard Version: c17
IntelliSense Mode: linux-clang-x64
Other Flags:
--clang
--clang_version=80000
[ /home/wang/workspace/trial_error/vscode_bug/test.c ]:
Process ID: 22094
Memory Usage: 35 MB
Compiler Path: /usr/bin/clang
Includes:
/usr/local/include
/usr/lib/llvm-8/lib/clang/8.0.0/include
/usr/include/x86_64-linux-gnu
/usr/include
Standard Version: c17
IntelliSense Mode: linux-clang-x64
Other Flags:
--clang
--clang_version=80000
[ /home/wang/workspace/trial_error/vscode_bug/main.c ]:
Process ID: 22571
Memory Usage: 35 MB
Compiler Path: /usr/bin/clang
Includes:
/usr/local/include
/usr/lib/llvm-8/lib/clang/8.0.0/include
/usr/include/x86_64-linux-gnu
/usr/include
Standard Version: c17
IntelliSense Mode: linux-clang-x64
Other Flags:
--clang
--clang_version=80000
Total Memory Usage: 105 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 22234
Number of files parsed: 1
Logs from Debug
level
loggingLevel: Debug
loggingLevel has changed to: Debug
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/activeDocumentChange: file:///home/wang/workspace/trial_error/vscode_bug/main.c
LSP: cpptools/getCodeActions: file:///home/wang/workspace/trial_error/vscode_bug/main.c (id: 638)
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/getInlayHints: file:///home/wang/workspace/trial_error/vscode_bug/main.c (id: 639)
LSP: cpptools/getFoldingRanges: file:///home/wang/workspace/trial_error/vscode_bug/main.c (id: 640)
LSP: textDocument/hover: file:///home/wang/workspace/trial_error/vscode_bug/main.c (id: 641)
LSP: textDocument/documentHighlight: file:///home/wang/workspace/trial_error/vscode_bug/main.c (id: 642)
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/getCodeActions: file:///home/wang/workspace/trial_error/vscode_bug/main.c (id: 643)
LSP: textDocument/hover: file:///home/wang/workspace/trial_error/vscode_bug/main.c (id: 644)
LSP: textDocument/definition: file:///home/wang/workspace/trial_error/vscode_bug/main.c (id: 645)
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/activeDocumentChange: file:///home/wang/workspace/trial_error/vscode_bug/test.c
LSP: cpptools/getCodeActions: file:///home/wang/workspace/trial_error/vscode_bug/test.c (id: 646)
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/getInlayHints: file:///home/wang/workspace/trial_error/vscode_bug/test.c (id: 647)
LSP: textDocument/documentHighlight: file:///home/wang/workspace/trial_error/vscode_bug/test.c (id: 648)
LSP: cpptools/getFoldingRanges: file:///home/wang/workspace/trial_error/vscode_bug/test.c (id: 649)
LSP: cpptools/getCodeActions: file:///home/wang/workspace/trial_error/vscode_bug/test.c (id: 650)
idle loop: reparsing the active document
Checking for syntax errors: /home/wang/workspace/trial_error/vscode_bug/test.c
Queueing IntelliSense update for files in translation unit of: /home/wang/workspace/trial_error/vscode_bug/test.c
Error squiggle count: 0
Update IntelliSense time (sec): 0.275
LSP: cpptools/getSemanticTokens: file:///home/wang/workspace/trial_error/vscode_bug/test.c (id: 651)
LSP: cpptools/getFoldingRanges: file:///home/wang/workspace/trial_error/vscode_bug/test.c (id: 652)
Other Extensions
No response
Additional context
No response