* Florian Weimer:

> It turns out that permerror_opt is not directly usable for
> -fpermissive in the C front end.  The front end uses pedwarn
> extensively, and pedwarns are not overridable by -Wno-* options,
> yet permerrors are.  Add new pedpermerror helpers that turn into
> pedwarns if -pedantic-errors is active.
>
> Due to the dependency on flag_pedantic_errors, the new helpers
> are specific to the C-family front ends.  For implementing the
> rich location variant, export emit_diagnostic_valist from
> gcc/diagnostic.cc in parallel to its location_t variant.
>
> gcc/
>
>       * diagnostic-core.h (emit_diagnostic_valist): Declare function.
>       * diagnostic.cc (emit_diagnostic_valist): Define it.
>
> gcc/c-family/
>
>       * c-common.h (pedpermerror): Declare functions.
>       * c-warn.cc (pedpermerror): Define them.

Jason suggested off-list that this shouldn't be necessary, and the
description of -pedantic-errors is wrong (it is possible to undo
-pedantic-errors effects with -Wno-error=…).  The permerror_opt
interface should already do what I need.

It turns out that I was very unlucky and picked -Wreturn-type for my
tests.

This:

long i = "abc";
volatile j;
int f (void) { return; }

Gives, with GCC 13:

$ gcc -pedantic-errors -Wno-error=implicit-int -Wno-error=int-conversion 
-Wno-error=return-type test.c
test.c:1:10: warning: initialization of ‘long int’ from ‘char *’ makes integer 
from pointer without a cast [-Wint-conversion]
    1 | long i = "abc";
      |          ^~~~~
test.c:2:10: warning: type defaults to ‘int’ in declaration of ‘j’ 
[-Wimplicit-int]
    2 | volatile j;
      |          ^
test.c: In function ‘f’:
test.c:3:16: error: ‘return’ with no value, in function returning non-void
    3 | int f (void) { return; }
      |                ^~~~~~
test.c:3:5: note: declared here
    3 | int f (void) { return; }
      |     ^

This happens because we drop the OPT_Wreturn_type in some cases:

          if (flag_isoc99)
            warned_here = pedwarn
              (loc, warn_return_type >= 0 ? OPT_Wreturn_type : 0,
               "%<return%> with no value, in function returning non-void");
          else
            warned_here = warning_at
              (loc, OPT_Wreturn_type,
               "%<return%> with no value, in function returning non-void");

And for the other direction:

      if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
        warned_here = pedwarn
          (xloc, warn_return_type >= 0 ? OPT_Wreturn_type : 0,
           "%<return%> with a value, in function returning void");

I think with the -Wreturn-mismatch split, we can drop the
warn_return_type >= 0 condition, and then permerror_opt should indeed
do the right thing.

I'll write the kitchen sink test now, use that to verify this theory,
and repost as appropriate.

Thanks,
Florian

Reply via email to