Language Service: Unable to resolve type when managing namespaces via header and preprocessor
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Reproduce the behavior using main.cpp and namespace.hpp from the issue, then compare resolution for b::Foo with a:🅱️:Foo and Foo. Investigate the language service's handling of preprocessor-managed nested namespaces and verify that main.cpp has no error squiggles and that b::Foo resolves to its declaration.
Written by the indexing model from the issue text.
Description
Bug type: Language Service
Describe the bug
- OS and Version: Windows 10 Pro 21H1 19043.1288
- VS Code Version: 1.61.2 (user setup)
- C/C++ Extension Version: v1.7.1
- Other extensions you installed (and if the issue persists after disabling them):
- Local
- jeff-hykin.better-cpp-syntax (disabled)
- usernamehw.errorlens (disabled)
- ms-vscode-remote.remote-ssh
- ms-vscode-remote.remote-ssh-edit (disabled)
- ms-vscode-remote.remote-wsl (disabled)
- SSH
- ms-vscode.cpptools
- twxs.cmake (disabled)
- ms-vscode.cmake-tools (disabled)
- mhutchie.git-graph (disabled)
- eamodio.gitlens (disabled)
- ms-python.vscode-pylance (disabled)
- ms-python.python (disabled)
- Local
- If using SSH remote, specify OS of remote machine: Ubuntu 20.04.3 LTS
- When managing a nested namespace with the preprocessor via a header file, a type inside the nested namespace is not recognized from inside the namespace when specifying the inner namespace explicitly. See Steps to reproduce for clarification.
Steps to reproduce
-
Open a folder with the following two files:
// main.cpp #include "namespace.hpp" class Foo {}; b::Foo *foo; #include "namespace.hpp" int main() {}// namespace.hpp #ifndef NAMESPACE_A_B_OPEN #define NAMESPACE_A_B_OPEN namespace a { namespace b { #else } } #endif -
See the following errors:
b::has error squiggles with the following two problems:
this declaration has no storage class or type specifier C/C++(77)expected a ';'C/C++(65)-
b::Foodoes not correctly link to its declaration above when pressingCTRL+CLICKand shows no information when hovering the mouse over it. -
endifhas error squiggles with the following two problems (this one might be unrelated to the other errors - I don't really care about this one):
PCH warning: header stop not at file scope. An IntelliSense PCH file was not generated. C/C++(2923)expected a '}' C/C++(67)
Expected behavior
No error squiggles in main.cpp and correctly resolving b::Foo.
Additional context
The following changes to the code circumvent the problem:
-
Specify the outer namespace as well:
-b::Foo *foo; +a::b::Foo *foo; -
Don't specify the inner namespace:
-b::Foo *foo; +Foo *foo; -
Manually including
namespace.hppby copying the content ofnamespace.hppto the two lines with#include "namespace.hpp".
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/vscode-cpptools
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
microsoft/vscode-cpptools#14787 ·
-
[Bug] cpptools fails to start on Ubuntu ARM64 due to missing execute permissions on shared libraries Openbug fixed Language Service regression
microsoft/vscode-cpptools#14779 · 1 assignee ·
-
Language Service more info needed
microsoft/vscode-cpptools#14778 · 1 comment · 1 assignee ·
-
Difficulty 4/5 3-5 days Newbie friendliness 64/100
microsoft/vscode-cpptools#14769 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
microsoft/vscode-cpptools#14768 · 1 comment ·
All issues in microsoft/vscode-cpptools
Similar issues
-
Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OpenNSW/nsw-srilanka#497 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
0xMiden/bridge-portal#132 ·
-
react-doctor severity:warning tech-debt
Difficulty 1/5 Under an hour Newbie friendliness 88/100
digidem/comapeo-cloud-app#403 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100