【问题标题】:Suppressing the g++ warning "-Wliteral-suffix" for specific include headers抑制特定包含标头的 g++ 警告“-Wliteral-suffix”
【发布时间】:2014-08-19 21:42:32
【问题描述】:

我正在做一个项目,我在其中使用新的 c++11 标准。 因此,现在很少有来自库的包含头会生成警告 -Wliteral-suffix,我会禁止包含该警告。

我找到了一个使用编译指示的简单解决方案,但它对我不起作用

How to suppress GCC warnings from library headers?

这是我当前的代码:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wliteral-suffix"

#include <pylon/PylonBase.h>
#include <pylon/InstantCamera.h>
#include <pylon/TlFactory.h>

#pragma GCC diagnostic pop

该库生成的所有当前警告如下所示:

/opt/pylon3/genicam/library/CPP/include/Base/GCException.h:272:105: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]

我正在使用gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)

【问题讨论】:

  • 使用-fdiagnostics-show-option 运行 GCC 以查看是否可以禁用该警告;可能只是 GCC 阻止您禁用它。
  • 看起来像bug

标签: c++ c++11 g++ compiler-warnings suppress-warnings


【解决方案1】:

关闭警告/错误的选项是特定于编译器的。假设你必须支持 GCC 和 Clang,选项是

  • GCC:-Wno-literal-suffix
  • Clang:-Wno-reserved-user-defined-literal(或 -Wno-error=reserved-user-defined-literal,如果您想继续看到警告消息)
  • MSVC:???

来源:https://sourcecodeartisan.com/2021/03/06/invalid-suffix-on-literal.html

【讨论】:

    【解决方案2】:

    如果您收到来自 system 标头的警告,则应将它们包括在内:

    # Makefile
    
    CPPFLAGS += -isystem/path/to/python/prefix
    

    参考资料:

    【讨论】:

      【解决方案3】:

      我认为你必须使用相反的:-Wno-literal-suffix。与旧的 4.7.2(最好)相比,这个版本的问题也更多。

      【讨论】:

        猜你喜欢
        • 2010-10-03
        • 2015-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-04
        • 2013-05-20
        相关资源
        最近更新 更多