Swiss Frank
Swiss Frank

Reputation: 2422

__cplusplus apparently not set correctly in Visual Studio 2022 when building for C++17?

My code has the following test, to protect code that only works in C++11 or newer.

It is evaluating to 0 despite cl being invoked with /std:c++17 .

#if __cplusplus >= 201103

I am seeing this in Microsoft Visual Studio Community 2022 (64-bit) on Windows 11.

Upvotes: 5

Views: 2468

Answers (1)

Swiss Frank
Swiss Frank

Reputation: 2422

Right click on the project in question, and set Properties-->C/C++-->Command Line-->Additional Options with /Zc:__cplusplus

My best guess is that they instituted this bizarre mis-feature to service a "bug report" that code that was testing for the original value with == was failing once they increased the version number.

There is more information at https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170

Upvotes: 9

Related Questions