admin管理员组

文章数量:1303496

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.

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.

Share Improve this question edited Feb 28 at 9:52 Oersted asked Feb 10 at 12:38 OerstedOersted 2,7766 silver badges28 bronze badges 5
  • @sweenish you're right, question edited. – Oersted Commented Feb 10 at 14:57
  • NB IMHO, my question is not a dup as the proposed duplicate are about cl setting, not intellisense configuration for vscode (though both subject are linked). I personally use the option given in the answer through cmake, for actual compilation. It didn't occurred to me that they were also needed for intellisense. – Oersted Commented Feb 10 at 16:20
  • Its been edited beyond repair – wahwahwah Commented Feb 23 at 19:42
  • This has little to do with VS Code, and more to do with MSVC, Microsoft's compiler. But I say just use cmake at this point. Very few people should be bothering with compiler/linker flags directly anymore. – sweenish Commented Feb 27 at 17:50
  • @sweenish my edit was unclear also though the title actually points to vscode. I'm editing again. – Oersted Commented Feb 28 at 9:49
Add a comment  | 

1 Answer 1

Reset to default 2

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)

本文标签: cC20 set for intellisense in vscode but cplusplus does notStack Overflow