我使用的是VisualStudio2015Update 3,我的_MSVC_LANG被定义为201402L,不管我是否提供/std:c++14作为编译器参数。
_MSVC_LANG在visual-c++的后期版本或早期版本中还有其他值吗?
发布于 2017-09-15 15:30:44
在Visual Studio 2015之前,_MSVC_LANG宏并不存在(在内部,它们依赖包含等效版本号的__cplusplus宏)。
在Visual的yvals.h头中,您可以看到C++版本宏的逻辑(来自VisualStudio2017 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 */预处理器定义_HAS_CXX17和_HAS_CXX14控制STL特性的包含。
发布于 2022-10-25 11:00:18
另一种资源将_MSVC_LANG的可能值列出为201402L、201703L、202002L或higher unspecified value,具体取决于编译期间使用的/std开关:
_MSVC_LANG定义为一个整数文本,它指定编译器所针对的C++语言标准。它只在编译为C++的代码中设置。在默认情况下,宏是整数文本值201402L,或者在指定/std:c++14编译器选项时。如果指定了/std:c++17编译器选项,则宏设置为201703L。如果指定了/std:c++20编译器选项,则宏设置为202002L。当指定/std:c++latest选项时,它被设置为更高的、未指定的值。否则,则未定义宏。_MSVC_LANG宏和/std (指定语言标准版本)编译器选项可在VisualStudio2015Update 3中开始使用。
https://stackoverflow.com/questions/43639122
复制相似问题