This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Enable -Wreturn-type by default ?
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Dodji Seketeli <dodji at seketeli dot org>
- Cc: Sylvestre Ledru <sylvestre at debian dot org>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Thu, 14 Nov 2013 11:48:15 +0000
- Subject: Re: Enable -Wreturn-type by default ?
- Authentication-results: sourceware.org; auth=none
- References: <5283ABF2 dot 5010209 at debian dot org> <871u2jw776 dot fsf at seketeli dot org>
On 14 November 2013 11:31, Dodji Seketeli wrote:
>
> For C, I am not sure about, but I'd find it useful to have that warning
> enabled there too, so I guess I'd like to hear why the warning wasn't
> enabled there by default there as well.
A return statement with no operand is always wrong, but -Wreturn-type
also warns about this, which is valid:
int f(int c)
{
if (c)
return 0;
function_that_never_returns();
}
The noreturn attribute is not portable, and can't necessarily be added
to library functions not controlled by the user.
So maybe it makes sense to split -Wreturn-type to separately handle
"return with no value in function returning non-void" and "control
reaches end of non-void function".