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.
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)