27

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

Can I mimic this behavior?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
piwi
  • 5,136
  • 2
  • 24
  • 48
  • 3
    `-fno-permissive` is the default. `-fpermissive` and nothing are the "negative" and "positive" versions of the flag. That said, you should not use this. Fix the code! Even if it's not yours. – rubenvb Jun 07 '12 at 13:13
  • 3
    -fno-permissive is not the default, since the option does not exists. The behavior it would have if it did exist would be the default though. I could fix the code, but it seems more like a workaround... Anyway, fixing the entire set of included headers is not really an option. – piwi Jun 07 '12 at 13:21
  • 1
    that's exactly what I meant. `-fpermissive` is the hack/workaround here. What code are we talking about anyways. Maybe there's a better alternative. – rubenvb Jun 07 '12 at 13:26
  • I know I should not use the flag, but I must use the library; it's already deeply used: switching to an alternative is not an option. I guess that fixing the headers is ok then, given the context. – piwi Jun 07 '12 at 13:53
  • 3
    I've filed a regression bug in GCC for this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81787 – o11c Aug 09 '17 at 21:48

2 Answers2

20

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:

Bug 81787. [5/6/7/8 Regression] #pragma GCC diagnostic warning "-fpermissive" no longer

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
firebush
  • 5,180
  • 4
  • 34
  • 45
  • 3
    Hmmph. I'm not impressed with the argument for not making this possible to turn this off. "Changes the meaning of the C++ language", "downgrades diagnostics about nonconformant code to warnings", bonnet blanc, blanc bonnet. – zwol Feb 27 '20 at 21:17
14

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.

zwol
  • 135,547
  • 38
  • 252
  • 361
  • 1
    Thanks for your reply! Do you know where I can be find mentions about `-pedantic` being the inverse of `-fpermissive`? – piwi May 15 '13 at 12:08
  • 1
    Unfortunately it's not clearly documented. You can read about `-fpermissive` here: http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/C_002b_002b-Dialect-Options.html#index-fpermissive-154 and `-pedantic` here: http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Warning-Options.html#index-pedantic-257 And if you read between the lines you might come to understand that what's going on is that the C++ compiler has `-pedantic-errors` as its default state. But I can't prove that to you without pointing at the actual code... – zwol May 15 '13 at 13:42
  • ... and they don't have an online crossreference index for their VCS so I can't find the relevant bit of actual code without downloading it all and running a bunch of `grep`s, which I don't have time for this morning. Sorry. – zwol May 15 '13 at 13:55
  • no problem, thanks anyway! I'll eventually try your solution see if it helps solve my problem. – piwi May 15 '13 at 14:51
  • What's the opposite of 'ignored'? (how to reinstate since I only want to do it for a section of code?) – clearlight Jul 23 '19 at 10:47
  • @clearlight I don't know, sorry. You should probably ask a new question. – zwol Jul 23 '19 at 14:02
  • @clearlight: you can wrap it like so: #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-pedantic" // code that's generating the warning here #pragma GCC diagnostic pop (each of those statements on its own line obviously, sorry about the formatting) – gg99 Feb 27 '20 at 20:44