2

I am trying to compile some nonconforming code in c++17 but am stuck at the with the following issue.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-fpermissive"

Some code that compiles only when with -fpermissive flag is set

#pragma GCC diagnostic pop

compiles fine on gcc version 4.6.4 through 4.7.4, but all later versions of gcc are giving me the following warning and don't suppress the error.

warning: ‘-fpermissive’ is not an option that controls warnings [-Wpragmas]
#pragma GCC diagnostic ignored "-fpermissive"

When I write (out of desperation)

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-fpermissive"

Some code that compiles only when with -fpermissive flag is set

#pragma GCC diagnostic pop

I am back at square one. Currently I'd like to continue using gcc 7.1 for the project. I can compile the entire project with -fpermissive flag set as a compile option but this means that some other section of code causing a -fpermissive error could compile.

Condensed example https://godbolt.org/g/KFd5Ke

This question is not a duplicate of In gcc, how to mute the -fpermissive warning? as this is directed toward newer versions of gcc where the solution provided in the aformentioned So question does not work. I even included an example.

Andreas
  • 167
  • 1
  • 7
  • Possible duplicate of [In gcc, how to mute the -fpermissive warning?](https://stackoverflow.com/questions/10932479/in-gcc-how-to-mute-the-fpermissive-warning) – o11c Aug 09 '17 at 21:41
  • 2
    This question is specifically directed towards newer versions of gcc where the solution provided in the aformentioned SO question does not work. I even included an example. – Andreas Aug 09 '17 at 21:45
  • It's still the same question, especially since the other one mentions that these problems apply. I've filed a bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81787 – o11c Aug 09 '17 at 21:49
  • So this is a bug and not a change in gcc? – Andreas Aug 09 '17 at 21:51
  • Well, it's a change (as a side effect of an important revamping of the diagnostics system), but an unexpected one. There are plenty of other bugs from that error, but `-fpermissive` is rarely useful anymore, so it slipped through the cracks. – o11c Aug 09 '17 at 21:56
  • @o11c No, it's *very much* an expected change. It was changed as a result of [PR 49655](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49655). –  Aug 09 '17 at 22:01
  • 1
    @hvd Except that `-fpermissive` *is* a warning option, just like `-pedantic` (which got an alias to a new name to fix it with this change) – o11c Aug 09 '17 at 22:03
  • @o11c Unless it's changed in recent versions, I seem to recall `-fpermissive` changing the language and by design causing valid C++ code to be rejected or to be compiled in ways that the standard doesn't allow. It doesn't control the diagnostics (or at least does more than that). It mutates the language in such a way that (some of) the diagnostics no longer apply. –  Aug 09 '17 at 22:05
  • To me it still seems safer to be able to use -fpermissive on a smaller section of code rather than be forced to compile the whole project with the flag. – Andreas Aug 09 '17 at 22:19
  • @hvd the fact that the compiler continues emitting diagnostics after a `-fpermissive` error proves that it is just a diagnostic. – o11c Aug 09 '17 at 22:39
  • 1
    @o11c That makes no sense. –  Aug 09 '17 at 22:47

0 Answers0