vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

IntelliSense complains about standard types when using precompiled headers

Open OleksandrKvl opened this issue 4 years ago • 4 comments

Brief Issue Summary

IntelliSense starts to complain about all standard things when I'm using target_precompile_headers(), e.g. std::size_t: "namespace "std" has no member "size_t"". The project itself builds just fine. Code structure:

//./project/src/common.h
#include <vector>
//etc.

//./project/src/main.cpp
#include "common.h"
//use std::vector...

CMake structure:

# ./project/CMakeLists.txt:
# some global settings like project(), etc.
add_subdirectory(src)

# ./project/src/CMakeLists.txt
add_executable(project)
target_sources(project
	PRIVATE
	main.cpp
	common.h)
target_precompile_headers(project
	PRIVATE
	"common.h"
)

Without target_precompile_headers() everything is OK.

Platform and Versions

  • Operating System: Ubuntu 18.04
  • CMake Version: 3.16
  • VSCode Version: 1.43.2
  • CMake Tools Extension Version: 1.3.1
  • Compiler/Toolchain: GCC 9.2.1

OleksandrKvl avatar Mar 25 '20 16:03 OleksandrKvl

I do not reproduce this and I made sure I installed recent cmake and gcc. It could help if you can share a standalone small repro and its settings.

andreeis avatar Mar 31 '20 16:03 andreeis

Here it is: https://github.com/OleksandrKvl/vscode_pch_test Don't pay attention to key shortcuts at the bottom of the main.cpp, that's my local bindings. The only thing I changed in global CMake settings is "cmake.buildDirectory": "${workspaceFolder}/build_${buildType}", I put it into the local settings.json file to preserve this small detail. The strange thing is that even if I remove common.h from main.cpp and include iostream and vector directly, error is still there. It's gone only when I remove target_precompile_headers(). And error occurs only after build, for example: no pch -> no errors -> enable pch -> still no errors -> rebuild -> errors appear now. Sometimes they don't appear immediately, only after several seconds after build.

OleksandrKvl avatar Apr 01 '20 11:04 OleksandrKvl

I reproduce now, thanks for the small project.

andreeis avatar Apr 01 '20 15:04 andreeis

Hi all, Meanwhile are there any work-arounds to this issue?

ItsSunnyMonster avatar Jul 26 '22 05:07 ItsSunnyMonster

@andreeis While you guys are fixing it, are there any workarounds in the meantime? The extension is pretty much unusable for me because of this. Thanks in advance.

ItsSunnyMonster avatar Oct 30 '22 03:10 ItsSunnyMonster

@ItsSunnyMonster, I don't reproduce this anymore and the project linked above is no longer accessible. Can you share more information about your project and also share the result of running CMake: Log Diagnostics and C/C++: Log Diagnostics when the file with the red squiggles is open?

bobbrow avatar Oct 31 '22 16:10 bobbrow

I believe it was fixed in 1.11.25 with this PR where we started forwarding the compiler options to cpptools for parsing instead of doing it ourselves: https://github.com/microsoft/vscode-cmake-tools/pull/2563

bobbrow avatar Oct 31 '22 17:10 bobbrow

This issue has been closed automatically because it needs more information and has not had recent activity.

github-actions[bot] avatar Dec 31 '22 11:12 github-actions[bot]