diff mbox

Warn about return with a void expression with -Wreturn-type.

Message ID CALvMQwSA-TCerSYPTp02gWYzDSyPypfHkeqdL9+MiyXupO8AgQ@mail.gmail.com
State New
Headers show

Commit Message

Marcin Baczyński June 2, 2016, 10:03 a.m. UTC
2016-06-02 4:51 GMT+02:00 Martin Sebor <msebor@gmail.com>:
>> So here's my shot at fixing this in the documentation. Does that look
>> okay?
>>
>
> It looks good to me.  Just one minor point below.
>
>> @@ -4055,8 +4055,12 @@ Warn whenever a function is defined with a
>> return type that defaults
>> to @code{int}.  Also warn about any @code{return} statement with no
>> return value in a function whose return type is not @code{void}
>> (falling off the end of the function body is considered returning
>> -without a value), and about a @code{return} statement with an
>> -expression in a function whose return type is @code{void}.
>> +without a value).
>> +
>> +For a @code{return} statement with an expression in a function whose
>> +return type is @code{void}, warn unless the expression type is also
>> +@code{void}.  As a GNU extension, the latter case is accepted without a
>> +warning unless @option{-Wpedantic} is used.
>
>
> I would suggest to add that this only applies to C.  Otherwise
> it's valid C++ so G++ accepts it without a pedantic warning.

Done.

>
> As a disclaimer, someone else endowed with those special powers
> will need to approve your final patch.  If you don't get a timely
> approval please ping the patch weekly.
>
> Martin
>


gcc/ChangeLog:

  PR c/48116.

  * doc/invoke.texi (-Wreturn-type): Mention not warning on return with
   a void expression in a void function.
---
gcc/doc/invoke.texi | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

message, even when @option{-Wno-return-type} is specified.  The only
--
2.8.3

Comments

Bernd Schmidt June 3, 2016, 9:36 a.m. UTC | #1
On 06/02/2016 12:03 PM, Marcin Baczyński wrote:
> 2016-06-02 4:51 GMT+02:00 Martin Sebor <msebor@gmail.com>:
>> As a disclaimer, someone else endowed with those special powers
>> will need to approve your final patch.  If you don't get a timely
>> approval please ping the patch weekly.

>    * doc/invoke.texi (-Wreturn-type): Mention not warning on return with
>     a void expression in a void function.

If Martin is happy with this then OK.


Bernd
Marcin Baczyński June 3, 2016, 10:12 a.m. UTC | #2
2016-06-03 11:36 GMT+02:00 Bernd Schmidt <bschmidt@redhat.com>:
> On 06/02/2016 12:03 PM, Marcin Baczyński wrote:
>>
>> 2016-06-02 4:51 GMT+02:00 Martin Sebor <msebor@gmail.com>:
>>>
>>> As a disclaimer, someone else endowed with those special powers
>>> will need to approve your final patch.  If you don't get a timely
>>> approval please ping the patch weekly.
>
>
>>    * doc/invoke.texi (-Wreturn-type): Mention not warning on return with
>>     a void expression in a void function.
>
>
> If Martin is happy with this then OK.

Thanks!
Could someone with repository write access commit the patch, please?
>
>
> Bernd
>
Martin Sebor June 4, 2016, 8:51 p.m. UTC | #3
On 06/03/2016 04:12 AM, Marcin Baczyński wrote:
> 2016-06-03 11:36 GMT+02:00 Bernd Schmidt <bschmidt@redhat.com>:
>> On 06/02/2016 12:03 PM, Marcin Baczyński wrote:
>>>
>>> 2016-06-02 4:51 GMT+02:00 Martin Sebor <msebor@gmail.com>:
>>>>
>>>> As a disclaimer, someone else endowed with those special powers
>>>> will need to approve your final patch.  If you don't get a timely
>>>> approval please ping the patch weekly.
>>
>>
>>>     * doc/invoke.texi (-Wreturn-type): Mention not warning on return with
>>>      a void expression in a void function.
>>
>>
>> If Martin is happy with this then OK.
>
> Thanks!
> Could someone with repository write access commit the patch, please?

I committed it in r237093.

Thanks
Martin
diff mbox

Patch

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index ce162a0..1747d1b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -4055,8 +4055,12 @@  Warn whenever a function is defined with a
return type that defaults
to @code{int}.  Also warn about any @code{return} statement with no
return value in a function whose return type is not @code{void}
(falling off the end of the function body is considered returning
-without a value), and about a @code{return} statement with an
-expression in a function whose return type is @code{void}.
+without a value).
+
+For C only, warn about a @code{return} statement with an expression in a
+function whose return type is @code{void}, unless the expression type is
+also @code{void}.  As a GNU extension, the latter case is accepted
+without a warning unless @option{-Wpedantic} is used.

For C++, a function without return type always produces a diagnostic