Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

c++ - In gcc, how to mute the -fpermissive warning?

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.

So far, I set the -fpermissive option with a diagnostic pragma when including the file; something like:

#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:

#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).

Any chance I can mimic this behavior? Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

tldr: You cannot turn off the fpermissive output after GCC 4.7.


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:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...