【发布时间】:2016-11-22 04:57:36
【问题描述】:
我们正在尝试在 C++17 及其 change to std::uncaught_exception 下测试一些代码。我似乎无法让 GCC 提供 __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的值是多少?
【问题讨论】:
-
添加开关
-xc++(虽然它仍然可能不正确) -
我认为最新的标准草案仍然具有旧的 C++14 值,因此还没有正式的值。
-
如果你只想测试
std::uncaught_exceptions是否可用,你应该使用feature testing macro__cpp_lib_uncaught_exceptions。 -
感谢 Galik。 GCC 应该调用 cc1plus 而不是 cc1...现在在 GCC 错误跟踪器上打开:Issue 71930: g++ invokes the wrong preprocessor。
-
感谢 cpplearner。我猜(这只是一个猜测)一些编译器不会使用
__cpp_lib_uncaught_exceptions。我想到了微软的 VC++ 和 SunCC。我发现__cplusplus是一个更好的测试,因为它使用宽刷子进行绘画。然后我可以一次性使用那些做自己的事情的编译器,通常是 VC++。