【问题标题】:__cplusplus apparently not set correctly in Visual Studio 2022 when building for C++17?在为 C++17 构建时,__cplusplus 显然没有在 Visual Studio 2022 中正确设置?
【发布时间】:2022-11-09 05:30:40
【问题描述】:

我的代码进行了以下测试,以保护仅适用于 C++11 或更高版本的代码。

尽管使用 /std:c++17 调用了 cl,但它的评估结果为 0。

#if __cplusplus >= 201103

我在 Windows 11 上的 Microsoft Visual Studio Community 2022(64 位)中看到了这一点。

【问题讨论】:

    标签: visual-c++


    【解决方案1】:

    右键单击有问题的项目,然后设置 Properties-->C/C++-->Command Line-->Additional Options with /Zc:__cplusplus

    我最好的猜测是,他们制定了这个奇怪的错误功能来服务“错误报告”,即使用== 测试原始值的代码一旦增加版本号就会失败。

    https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170 有更多信息

    【讨论】:

      猜你喜欢
      • 2019-11-27
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 1970-01-01
      • 2021-03-01
      • 2020-11-13
      • 1970-01-01
      相关资源
      最近更新 更多