【发布时间】:2018-08-25 06:50:43
【问题描述】:
在 Visual Studio 中测试功能时,我发现了这种奇怪的行为:
#ifndef __cpp_constexpr
#error Opposite day! //Compiler error
#endif
#define test_macro
#ifndef test_macro
#error But only for feature macros? //No compiler error
#endif
int main() {}
__cpp_constexpr 是明确定义的,我在实际程序中使用它。
根据我的测试,似乎使用功能宏 #ifndef 的行为类似于 #ifdef
反之亦然。
这是 Visual Studio 的错误,还是我遗漏了什么?
在 VS 2017、Visual C++14 或更高版本中编译,启用了 C++17 标准。
附: Intellisense 正在按预期工作,它只是编译器。
【问题讨论】:
-
FWIW 功能测试宏似乎也没有被其他编译器正确支持;例如,虽然 GCC 可以很好地处理
__cpp_constexpr,但它无法处理其他问题,例如__cpp_lib_make_unique。实际上,它们似乎不可靠,因此并不适用于所有意图和目的。
标签: c++ visual-studio visual-c++ macros