Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC always compiles in C++11 mode #105

Open
Ahajha opened this issue Feb 18, 2022 · 0 comments
Open

MSVC always compiles in C++11 mode #105

Ahajha opened this issue Feb 18, 2022 · 0 comments

Comments

@Ahajha
Copy link

Ahajha commented Feb 18, 2022

MSVC's implementation of __cplusplus was broken (always being 199711L) until 2018. Thus, the following code does not set TL_EXPECTED_CXX14:

#if __cplusplus > 201103L
#define TL_EXPECTED_CXX14
#endif

A workaround for the end user is to add /Zc:__cplusplus at the command line, which is available in VS 15.7 onwards.

As far as I can tell, MSVC always compiles in C++14 mode, so the check could just be:

#if __cplusplus > 201103L || defined _MSC_VER
#define TL_EXPECTED_CXX14
#endif

In case you want to be extra sure, according to this documentation, the _MSVC_LANG macro does give the intended language version. So this could be updated to something like:

#ifdef _MSVC_LANG // Or equivalently, _MSC_VER
#if _MSVC_LANG > 201103L
#define TL_EXPECTED_CXX14
#endif // _MSVC_LANG > 201103L
#else // _MSVC_LANG
#if __cplusplus > 201103L
#define TL_EXPECTED_CXX14
#endif // __cplusplus > 201103L
#endif // _MSVC_LANG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant