C++ 在 gcc 中,如何静音 -fpermissive 警告?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10932479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In gcc, how to mute the -fpermissive warning?
提问by piwi
I am including a file from a third-party library that raises an error that can be downgraded to a warning with -fpermissive
. But because I do not want to "pollute" my compilation log with these warnings, I want to completely disable this messages.
我包含了一个来自第三方库的文件,该文件引发了一个错误,可以将其降级为警告-fpermissive
。但是因为我不想用这些警告“污染”我的编译日志,所以我想完全禁用这些消息。
So far, I set the -fpermissive
option with a diagnostic pragmawhen including the file; something like:
到目前为止,我在包含文件时设置了-fpermissive
带有诊断编译指示的选项;就像是:
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-fpermissive"
#include <third-party-file.h>
#pragma GCC diagnostic pop
Since gcc usually provide both a "positive" and "negative" version of the -f
flags, I thought about ignoring the "no-permissive" feature:
由于 gcc 通常同时提供“正面”和“负面”版本的-f
标志,因此我考虑忽略“不允许”功能:
#pragma GCC diagnostic ignored "-fno-permissive"
#include <third-party-file.h>
But there does not seem to be a "negative" version of the -fpermissive
flag (I am using gcc 4.6.3; but even the version 4.7.0 does not have it).
但是似乎没有-fpermissive
标志的“否定”版本(我使用的是 gcc 4.6.3;但即使是 4.7.0 版也没有)。
Any chance I can mimic this behavior? Thanks!
我有机会模仿这种行为吗?谢谢!
采纳答案by firebush
tldr: You cannot turn off the fpermissive output after GCC 4.7.
tldr:您不能在 GCC 4.7 之后关闭 fpermissive 输出。
Just posting this here so it has more visibility: unfortunately, zwol's answer (while well-intentioned, and potentially helpful to those with older GCC versions) does not work for more recent versions of GCC. From GCC 4.8 and beyond, you cannot turn off the fpermissive output. o11c in his comment to the OP helpfully provides the following bug which tracks this:
只是在这里发布它以便它具有更多的可见性:不幸的是,zwol 的答案(虽然是善意的,并且可能对那些使用旧 GCC 版本的人有帮助)不适用于更新版本的 GCC。从 GCC 4.8 及更高版本开始,您无法关闭 fpermissive 输出。o11c 在他对 OP 的评论中提供了以下跟踪此错误的错误:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81787
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81787
Note that it is in the state "RESOLVED INVALID", so the inability to turn it off is the expected behavior and there are no plans to change it.
请注意,它处于“已解决无效”状态,因此无法将其关闭是预期行为,并且没有计划更改它。
回答by zwol
It's maybe a bit late for this, but one of these ought to do what you wanted:
这可能有点晚了,但其中一个应该做你想做的:
#pragma GCC diagnostic ignored "-fpermissive"
or
或者
#pragma GCC diagnostic ignored "-pedantic"
"ignored" is how you squelch a diagnostic entirely, and the inverse of -fpermissive
is -pedantic
, for historical reasons.
由于历史原因,“忽略”是您完全压制诊断的方式,反之则-fpermissive
是-pedantic
。