【问题标题】:why is "cc1plus: warning: unrecognized command line option" for "no-" options only flagged by g++ when there is another warning?为什么当有另一个警告时,“no-”选项的“cc1plus:警告:无法识别的命令行选项”仅由 g++ 标记?
【发布时间】:2013-12-02 07:28:40
【问题描述】:
> cat warning.cpp
#pragma foobar
> cat no_warning.cpp
#pragma message "foobar"
> g++ -Wall -Wno-foobar -c warning.cpp
warning.cpp:1:0: warning: ignoring #pragma foobar  [-Wunknown-pragmas]
cc1plus: warning: unrecognized command line option "-Wno-foobar" [enabled by default]
> g++ -Wall -Wno-foobar -c no_warning.cpp
no_warning.cpp:1:17: note: #pragma message: foobar

【问题讨论】:

  • 你真的在输入命令行吗?或者你正在使用某种 make 实用程序?如果是make,它们中的大多数都有一个标志来在运行之前打印命令。这将为我们提供一个失败的示例命令行。
  • 我当然是用 make 开始的,但是为了隔离问题,我现在在命令行上手动使用 g++。我只是切换文件名,瞧,问题就消失了。对于较大的文件,问题就在那里,对于较小的文件,则不是。有什么区别,目前还没有任何线索。
  • 请添加失败的命令示例(完整的),gcc --versiong++ --version
  • 给你。我已经完全隔离了,还是没有头绪。
  • Note that in general we do not recommend the use of pragmas - gcc 手册。不知道这东西应该做什么。可以在gcc.gnu.org/onlinedocs/gcc/Pragmas.html 找到支持的编译指示的完整列表

标签: c++ g++


【解决方案1】:

这是设计使然,解释here

When an unrecognized warning option is requested (e.g., -Wunknown-warning),
GCC emits a diagnostic stating that the option is not recognized.

However, if the -Wno- form is used, the behavior is slightly different:
no diagnostic is produced for -Wno-unknown-warning unless other diagnostics
are being produced.

This allows the use of new -Wno- options with old compilers, but if something
goes wrong, the compiler warns that an unrecognized option is present.

换句话说,假设您有foo.cc,并且 GCC-4.9 会警告其中的某些内容(我们称之为foobar),但您认为使用foobar 是安全的。

由于您想将所有警告都视为错误(使用-Werror),因此您尽职尽责地将-Wno-foobar 添加到您的Makefile

现在其他人尝试使用 GCC-4.8 构建您的代码。如上所述,这会产生 no 警告并且他成功了。

如果这确实产生了警告,您将无法同时使用 foobar 构造并拥有一个可用于 GCC-4.8 和 GCC-4.9 的 Makefile

【讨论】:

    猜你喜欢
    • 2016-12-11
    • 1970-01-01
    • 2013-01-18
    • 2011-05-22
    • 2011-12-27
    • 2015-02-05
    • 2016-02-10
    • 2016-08-09
    • 1970-01-01
    相关资源
    最近更新 更多