What Does the Fpermissive Flag Do

What does the fpermissive flag do?

Right from the docs:

-fpermissive
Downgrade some diagnostics about nonconformant code from errors to warnings.
Thus, using -fpermissive will allow some nonconforming code to compile.

Bottom line: don't use it unless you know what you are doing!

Why do I get an -fpermissive error with this code?

You need to declare the function Get() to be const:

const std::string Get() const { return s; }

Even though Get() doesn't change any member values, the compiler is instructed to only let you call functions that are explicitly labeled const.

gcc is instructing you that you can override it's complaint by using the argument -fpermissive; however, it's generally better not to do this (or else why declare anything const at all?). Generally, it's better to make sure every member function called on a const parameter is a const member function.

This article concerning Const Correctness is very interesting.

Why does g++ require -fpermissive flag for printing iterator value in c++?

You likely have an error in your for loop.

You probably terminated your for loop with a semicolon, which ends the scope of "it".

It is a variable local to the for loop. You are trying to use it outside the loop.

In GCC, how can I mute the '-fpermissive' warning?

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.



Related Topics



Leave a reply



Submit