MSVC build failure with /Zc:__cplusplus and C++17 #1883
Labels
kind: bug
state: stale
the issue has not been updated in a while and will be closed automatically soon unless it is updated
On develop branch (commit bde5712), MSVC will fail to compile if C++17 is disabled and the /Zc:__cplusplus is set.
The compile error seems reasonable:
Here, the "deprecated" attribute is begin applied to a "friend" declaration. There are free operators after the friend declaration (which presumably is what the attribute is supposed to bind to). But since this is technically a friend declaration and not really an operation declaration, MSVC doesn't seem to like it.
In a couple of other places, for static methods, JSON_HEDLEY_DEPRECATED() is compiled correctly.
Hedley seems to be hiding this issue somewhat, due to the behaviour of the __cplusplus define in MSVC. Quite oddly, __cplusplus is set to 199711L by default in MSVC, even when C++17 compilation is enabled. Hedley only reads the __cplusplus macro and interprets that as meaning that the compiler only supports C++98, and so disables the deprecated attribute entirely.
However, we can enable the /Zc:__cplusplus compiler option to make the __cplusplus macro behave in a more standard (or at least more clang/GCC-compatible) way. This causes Hedley to apply the attribute, and the error appears.
There's more info about this oddity in the compiler here: https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=vs-2019
I've worked around it with this block:
Also, when not using the /Zc:__cplusplus option it compiles fine (even when C++17 is enabled). That's not convenient for me to do, though, because it would have to apply for every source file that includes json.hpp
The text was updated successfully, but these errors were encountered: