2

I am using Visual Studio 2015 Update 3 and my _MSVC_LANG is defined as 201402L, regardless of whether I supply /std:c++14 as compiler parameter or not.

Does _MSVC_LANG have other values in later or earlier versions of visual-c++?

WolfgangS
  • 154
  • 5
  • 11
  • [This](https://blogs.msdn.microsoft.com/vcblog/2016/08/12/stl-fixes-in-vs-2015-update-3/) is probably what you are looking for. – selbie Apr 26 '17 at 16:01
  • 1
    /std:c++14 is the default for Update 3, so adding the option does not change anything. There are no earlier versions that have the macro, we don't have a time machine to guess at later versions. Just try it. – Hans Passant Apr 26 '17 at 17:06

2 Answers2

7

Prior to Visual Studio 2015, the _MSVC_LANG macro didn't exist (internally they relied on the __cplusplus macro containing the equivalent version number).

In Visual Studio's yvals.h header, you can see the logic for C++ version macros (this is from Visual Studio 2017 15.3.3):

 #ifndef _HAS_CXX17
  #if defined(_MSVC_LANG) && !(defined(__EDG__) && defined(__clang__))  // TRANSITION, VSO#273681
   #if _MSVC_LANG > 201402
    #define _HAS_CXX17  1
   #else /* _MSVC_LANG > 201402 */
    #define _HAS_CXX17  0
   #endif /* _MSVC_LANG > 201402 */
  #else /* _MSVC_LANG etc. */
   #if __cplusplus > 201402
    #define _HAS_CXX17  1
   #else /* __cplusplus > 201402 */
    #define _HAS_CXX17  0
   #endif /* __cplusplus > 201402 */
  #endif /* _MSVC_LANG etc. */
 #endif /* _HAS_CXX17 */

The preprocessor definitions _HAS_CXX17 & _HAS_CXX14 control the inclusion of STL features.

Mark Ingram
  • 71,849
  • 51
  • 176
  • 230
0

Another resource lists the possible values for _MSVC_LANG as 201402L, 201703L, 202002L, or a higher unspecified value, depending on the /std switch being used during compilation:

_MSVC_LANG Defined as an integer literal that specifies the C++ language standard targeted by the compiler. It's set only in code compiled as C++. The macro is the integer literal value 201402L by default, or when the /std:c++14 compiler option is specified. The macro is set to 201703L if the /std:c++17 compiler option is specified. The macro is set to 202002L if the /std:c++20 compiler option is specified. It's set to a higher, unspecified value when the /std:c++latest option is specified. Otherwise, the macro is undefined. The _MSVC_LANG macro and /std (Specify language standard version) compiler options are available beginning in Visual Studio 2015 Update 3.

W1M0R
  • 3,367
  • 3
  • 30
  • 32