This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Enable -Wreturn-type by default ?
- From: Sylvestre Ledru <sylvestre at debian dot org>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: Dodji Seketeli <dodji at seketeli 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: Sun, 17 Nov 2013 16:40:37 +0100
- 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> <CAH6eHdRUrCrSsEV9ckq73QhTb0O-XREjN58Lv7xJfgk_0bH2eQ at mail dot gmail dot com>
On 14/11/2013 12:48, Jonathan Wakely wrote:
> 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".
I wrote a patch for this. I am updating the tests (many of them have now
warnings because of -Wreturn-type).
I updated 410 of them and I am still doing the work. Hopefully, I will
send a patch in the next few days...
For "control reaches end of non-void function", I haven't activated by
default and I called the option -Wfalloff-nonvoid-function
Of course, that is just a proposal! :) Better names are welcome.
Sylvestre