microsoft / microsoft/vscode-cmake-tools
Intellisense not recognizing predefined macros with CMake, Clang and -nostdinc
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.7k
- Forks
- 546
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 32
Description
Bug type: Language Service
Describe the bug
- OS and Version: Ubuntu 21.10
- VS Code Version:
Version: 1.63.2
Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3
Date: 2021-12-15T09:39:46.686Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.13.0-39-generic - C/C++ Extension Version: 1.9.7
- Other extensions you installed (and if the issue persists after disabling them):
ms-vscode.cmake-tools - Workspace: Single project, trivial project with just one trivial source.
C++ compilers provide some predefined macros, like __INT_FAST32_TYPE__ and Intellisense should be able to know that definition. I don't know how Intellisense gets to know the predefined macros; the cmake-tools extension may provide them, the cmake-tools extension may provide the compiler path and the list of arguments used to invoke it, it may even have nothing to do with the cmake-tools extension and Intellisense just does something to get them. One way to get predefined macros is to invoke the compiler, like c++ -dM -E foo.h with a dummy foo.h.
I tested and found out that both Clang 13.0.0 and GCC 11.2.0 provide the same predefined macros for types (except a couple exceptions). Passing the flags -nostdinc and -nostdlib had no effect on this.
However, passing the flag -nostdinc for some target, on the CMakeLists.txt, when using clang, resulted in the predefined macros not being recognized by Intellisense.
The offending CMakeLists.txt:
cmake_minimum_required(VERSION 3.20.0)
project(scratch VERSION 0.1.0)
add_executable(scratch main.cpp)
target_compile_features(scratch PRIVATE cxx_std_20)
target_compile_options(scratch PRIVATE -nostdinc)
# target_link_options(scratch PRIVATE -nostdlib)
main.cpp is a trivial source.
Steps to reproduce
- Create a new project, maybe with command
Cmake: Quick Start - Add compile option
-nostdincinCMakeLists.txt(like in the code snippet above) - Run vscode command
Cmake: Delete Cache and Reconfigure(not sure if necessary) - Run vscode command
Developer: Reload Window(not sure if necessary) - On reload, the predefined macros will be highlighted as undefined on the source
Expected behavior
Predefined macros should be recognized, despite passing the -nostdinc option
NOTE: Not sure if this is a bug with this extension or with the cmake-tools extension.
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.
Research direction
Reproduce the report using the shown CMakeLists.txt and trivial main.cpp, with Clang and the -nostdinc option, then run the listed CMake Tools cache/reload commands. Trace how the CMake configuration reaches IntelliSense and determine whether the behavior belongs to CMake Tools or the C/C++ extension. Done means predefined macros remain recognized under this configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp, vscode
- Domain
- build-system, developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100