This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/55976] -Werror=return-type should error on returning a value from a void function
- From: "egallager at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 26 Jul 2017 18:04:11 +0000
- Subject: [Bug c/55976] -Werror=return-type should error on returning a value from a void function
- Auto-submitted: auto-generated
- References: <bug-55976-4@http.gcc.gnu.org/bugzilla/>
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.