Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++20 set for intellisense in vscode but __cplusplus does not

I'm using VSCode as an IDE. On windows, with cl compiler available, intellisense does not evaluate correctly the __cplusplus macro. I set intellisense to use C++20 (basically like in: How can I change the version of the C++ language standard used in VS Code?). But I've got a section of code between:

#if __cplusplus >= 202002L
...
#endif

and it is grayed (not parsed by intellisense, which seems to use 199711L).

How can I fix that?

NB On the other hand my compilation setting works just fine and evaluate correctly the macro.

like image 382
Oersted Avatar asked Dec 08 '25 16:12

Oersted


1 Answers

By finding lots of discussions on the subject of intellisense and __cplusplus macro it seemed to be related to /Zc:__cplusplus compiler option.

It is not assumed by intellisense and must be added explicitly. In vscode settings UI: Extension/C/C++/Intellisense/C_Cpp › Default: Compiler Args just add /Zc:__cplusplus.


update: adding /permissive- is also a good idea, though not required for the __cplusplus issue. (Thanks to @Eljay for his comment)

like image 191
Oersted Avatar answered Dec 12 '25 09:12

Oersted



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!