[PATCH] c/55976 -Werror=return-type should error on returning a value from a void function

Jakub Jelinek jakub@redhat.com
Wed Apr 4 17:35:00 GMT 2018


On Tue, Apr 03, 2018 at 01:36:13PM -0600, Martin Sebor wrote:
> On 04/03/2018 10:26 AM, dave.pagan@oracle.com wrote:
> > This patch fixes handlng of -Werror=return-type. Currently, even with
> > the flag specified, return type errors remain warnings.
> > 
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55976
> > 
> > Function c_finish_return (), when calling pedwarn, should specifiy
> > OPT_Wreturn_type as the diagnostic index if warn_return_type is set so
> > that the given diagnostic is generated as an error, not a warning.
> > 
> > Patch was successfully bootstrapped and tested on x86_64-linux.
> 
> I would expect the option to control the warning consistently so
> that when the test case is compiled with just -Wno-return-type
> (and no other options) the warning is not issued.  But that's not
> what happens because pedwarn() is called with a zero argument as
> the option.

I think we need to make sure we error out even with -Wno-return-type
when -pedantic-errors.  Especially when issues this pedwarn warns about are
very hard to debug show stoppers for anybody calling such functions in GCC 8
(because we turn such spots into __builtin_unreachable () and thus randomly
can execute completely unrelated code).  So, I think consistency isn't that
important here.

	Jakub



More information about the Gcc-patches mailing list