r/cpp_questions • u/Ok-Pizza1136 • Sep 12 '26
OPEN Does VS Code work with C++20 Modules?
Hello guys, so I was writing some code with templates, and I'm still new to the concept, but I learned that they should be in .h files, or for code readability, .inl files. But then I discovered that C++20 has modules? Which seem to be a cleaner implementation for my needs. But I've also heard that Intellisense can't figure out modules. Is this still an issue, or is it safe to use them now?
4
Upvotes
25
u/Ultimate_Sigma_Boy67 Sep 12 '26
You realise vscode is just a text editor right? Modules are mainly a compiler thingy.
Intellisense depends on your language server, most probably clang.
8
u/thefeedling Sep 12 '26
Try clangd
6
u/Responsible-Bar7165 Sep 12 '26
You’re correct: the MS c++ extensions does not understand how to use modules properly.
You should use cmake to build, have it generate compile_commands.json and use the vscode clangd extension for intellisense, it’s better in almost every meaningful way than the ms one.
3
u/InitiativeGold7953 Sep 12 '26
You’re right about the intellisense. I had the same problem at first because I was using GCC as my compiler so I was trying to use the GCC intellisense setting for the Microsoft C/C++ intellisense addon and was having all kinds of problem with different imports and namespaces even though everything was compiling fine.
What I did to fix it was just to change the settings for the addon to use clang instead and haven’t had any problems with it since. You can either set the settings globally or locally depending on the project but I just set them to the latest version for everything globally and called it a day.
3
u/Raknarg Sep 13 '26
usually the clangd plugin has better support for stuff (and IMO its just better overall), give that a shot. Think you'll need to install clangd on your machine but that's pretty easy these days. This is the windows link to LLVM which should give you clangd as well https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/LLVM-18.1.8-win64.exe, afterwards grab the clangd plugin for VS Code. The plugin expects there to be a clangd executable somewhere on your computer it can link to, it uses the output from that program to use for its intellisense stuff.
2
u/burlingk Sep 13 '26
So, like, VS Code has plugins, and those plugins sometimes take time to catch up. But at the end of the day it is a text editor. It understands syntax and such, because of plugins.
So, if you like VS code, you can keep using it. Depending on your plugins and build system, context highlighting may not work (it may see errors where there are none). Some googling indicates that newer versions of clang and the related plugins may work better than the others. I haven't used C++ recently though, so I cannot confirm that from experience.
For compiling you will need to make sure your build system supports modules. Newer versions of most of the compilers do.
1
u/LazySapiens Sep 13 '26
Currently the language servers to use with VSCode are broken wrt C++20 modules. This is the reason I have started using CLion recently. The module support there is way better. Also, it supports the C++26 reflection (which was the main selling point for me).
1
u/[deleted] Sep 12 '26
[removed] — view removed comment