[Bug c/55976] -Werror=return-type should error on returning a value from a void function
egallager at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Jul 26 18:04:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55976
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2017-07-26
CC| |egallager at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #1 from Eric Gallager <egallager at gcc dot gnu.org> ---
-Werror=return-type might not work but -Werror -Wreturn-type does:
$ /usr/local/bin/gcc -c -Werror=return-type 55976.c
55976.c: In function ‘t’:
55976.c:3:20: warning: ‘return’ with a value, in function returning void
void t () { return 1; } // does not error
^
55976.c:3:6: note: declared here
void t () { return 1; } // does not error
^
55976.c: In function ‘b’:
55976.c:4:12: warning: ‘return’ with no value, in function returning non-void
int b () { return; } // does
^~~~~~
55976.c:4:5: note: declared here
int b () { return; } // does
^
$ /usr/local/bin/gcc -c -Werror -Wreturn-type 55976.c
55976.c: In function ‘t’:
55976.c:3:20: error: ‘return’ with a value, in function returning void
[-Werror]
void t () { return 1; } // does not error
^
55976.c:3:6: note: declared here
void t () { return 1; } // does not error
^
55976.c: In function ‘b’:
55976.c:4:12: error: ‘return’ with no value, in function returning non-void
[-Werror]
int b () { return; } // does
^~~~~~
55976.c:4:5: note: declared here
int b () { return; } // does
^
cc1: all warnings being treated as errors
$
Confirming on the basis that -Werror=return-type should work just as well as
-Werror -Wreturn-type.
More information about the Gcc-bugs
mailing list