__cplusplus对于C ++ 17的价值是什么? [英] What is the value of __cplusplus for C++17?
问题描述
我们正在尝试在C ++ 17及其更改为std::uncaught_exception
的情况下测试一些代码.我似乎无法让GCC提供__cplusplus
的值:
We are trying to test some code under C++17 and its change to std::uncaught_exception
. I can't seem to get GCC to provide the value of __cplusplus
:
$ /opt/local/bin/g++ -std=c++17 -dM -E - </dev/null | grep __cplusplus
cc1: warning: command line option '-std=c++1z' is valid for C++/ObjC++ but not for C
$
并且:
$ /opt/local/bin/g++ --version
g++-mp-6 (MacPorts gcc6 6.1.0_0) 6.1.0
Copyright (C) 2016 Free Software Foundation, Inc.
使用C ++ 17时__cplusplus
的值是什么?
What is the value of __cplusplus
when using C++17?
推荐答案
使用C ++ 17时
__cplusplus
的值是什么?
根据标准草案 N4594 §16.8/p1预定义的宏名称[cpp.predefined] (重点矿):
以下宏名称应由实现定义:
__cplusplus
名称__cplusplus
定义为值 201402L ,当编译C ++转换单元时. 156
The following macro names shall be defined by the implementation:
__cplusplus
The name__cplusplus
is defined to the value 201402L when compiling a C++ translation unit.156
156)本标准的未来版本旨在 用更大的值替换此宏的值.不合格 编译器应使用最多包含五个十进制数字的值.
156) It is intended that future versions of this standard will replace the value of this macro with a greater value. Non-conforming compilers should use a value with at most five decimal digits.
但是,为C ++ 14标准指定了相同的值.显然,C ++ 17标准尚未设置官方/标准__cplusplus
值.
However the same value is appointed for the C++14 standard. Apparently it seems so, that there's no official/standard __cplusplus
value set yet for the C++17 standard.
在GCC版本6.1和7.0中,值更改为 201500
In GCC versions 6.1 and 7.0 the value is changed to 201500
在Clang 3.8版和3.9版中,该值保持不变 201406 .
In Clang version 3.8 and 3.9 the value is unchanged 201406.
因此,您需要稍等一会儿才能看到标准值.
Consequently, you'll have to wait a little bit for the standard value to come out.
根据C ++标准§19.8/p1预定义的宏名称[cpp.predefined] (强调矿井):
According to the C++ standard §19.8/p1 Predefined macro names [cpp.predefined] (Emphasis Mine):
1 以下宏名称应由 实施:
1 The following macro names shall be defined by the implementation:
__cplusplus
整数常量 201703L .
因此,使用C ++ 17时__cplusplus
的值应为 201703L .
Thus, the value of __cplusplus
when using C++17 shall be 201703L.
这篇关于__cplusplus对于C ++ 17的价值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!