bitweeder / lucenaBAL

C++ utility library providing build platform, compiler, and Standard Library feature detection
https://bitweeder.github.io/lucenaBAL
Other
4 stars 1 forks source link

Microsoft Visual Studio doesn't set `__cplusplus` correctly by default #1

Closed bitweeder closed 5 years ago

bitweeder commented 5 years ago

Currently, there is a global C++ dialect check performed during feature testing to ensure the client is running at least the baseline requirement. Ironically, this test is broken, providing a pointed reminder of why simple global checks are a bad idea. MSVS 2019 always reports that it's C++98, regardless of how /std is set, unless /Zc:__cplusplus is also set. This raises the following questions:

A few potential solutions suggest themselves:

This will remain open for the time being.

bitweeder commented 5 years ago

Some further research has shown that there is a proprietary macro, _MSVC_LANG, which fulfills the usual role of __cplusplus, tracking how /std is set. Unlike __cplusplus, it defaults to 201402L rather than 199711L, reflecting the default (and minimum) standard available through /std. The value returned when /std:c++latest is set is “a higher, unspecified value” than that of the latest supported Standard (currently 201703L). The downside is that it’s only available in MSVS 2015 Update 3 and later—admittedly, not much of a downside. One of the upsides is that it avoids the complicated situation of determining whether the currently-used C++ dialect doesn’t support a given feature even if the compiler version indicates that it can, in the absence of SD_6 macros and reliable __cplusplus checks. Pending some testing, this will probably be sufficient to close the bug.

bitweeder commented 5 years ago

This has been fixed as part of the post-Cologne SD-6 update.