diff mbox

Clarify interaction of -Wnarrowing with -std

Message ID 20160219124235.GF3171@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely Feb. 19, 2016, 12:42 p.m. UTC
In PR69864 Manu suggests improving the docs to explain that
-Wnarrowing sometimes produces errors not warnings.

I think the right way to do that is clarify how it interacts with
-std. Specifically that the effect of -Wnarrowing listed first in the
manual *only* applies to C++98 modes, For all later modes (not just
with -std=c++11 as it says now), narrowing conversions produce errors
or warnings by default.

OK for trunk?

Comments

Jason Merrill Feb. 19, 2016, 7:01 p.m. UTC | #1
On 02/19/2016 07:42 AM, Jonathan Wakely wrote:
> In PR69864 Manu suggests improving the docs to explain that
> -Wnarrowing sometimes produces errors not warnings.
>
> I think the right way to do that is clarify how it interacts with
> -std. Specifically that the effect of -Wnarrowing listed first in the
> manual *only* applies to C++98 modes, For all later modes (not just
> with -std=c++11 as it says now), narrowing conversions produce errors
> or warnings by default.
>
> OK for trunk?

OK, thanks.

Jason
Sandra Loosemore Feb. 19, 2016, 8:17 p.m. UTC | #2
On 02/19/2016 12:01 PM, Jason Merrill wrote:
> On 02/19/2016 07:42 AM, Jonathan Wakely wrote:
>> In PR69864 Manu suggests improving the docs to explain that
>> -Wnarrowing sometimes produces errors not warnings.
>>
>> I think the right way to do that is clarify how it interacts with
>> -std. Specifically that the effect of -Wnarrowing listed first in the
>> manual *only* applies to C++98 modes, For all later modes (not just
>> with -std=c++11 as it says now), narrowing conversions produce errors
>> or warnings by default.
>>
>> OK for trunk?
>
> OK, thanks.

I suppose the patch is OK as it stands, but I was going to suggest 
restructuring it so that it talks about the default behavior first and 
what it does with non-default -std= options after that, instead of 
vice-versa.  Unfortunately I am backlogged on other things right now and 
it might take me a day or two before I have time to come up with some 
alternate wording.  If we are in a rush, go ahead and commit the 
existing patch meanwhile, I guess.

-Sandra
Jonathan Wakely Feb. 19, 2016, 8:33 p.m. UTC | #3
On 19/02/16 13:17 -0700, Sandra Loosemore wrote:
>On 02/19/2016 12:01 PM, Jason Merrill wrote:
>>On 02/19/2016 07:42 AM, Jonathan Wakely wrote:
>>>In PR69864 Manu suggests improving the docs to explain that
>>>-Wnarrowing sometimes produces errors not warnings.
>>>
>>>I think the right way to do that is clarify how it interacts with
>>>-std. Specifically that the effect of -Wnarrowing listed first in the
>>>manual *only* applies to C++98 modes, For all later modes (not just
>>>with -std=c++11 as it says now), narrowing conversions produce errors
>>>or warnings by default.
>>>
>>>OK for trunk?
>>
>>OK, thanks.
>
>I suppose the patch is OK as it stands, but I was going to suggest 
>restructuring it so that it talks about the default behavior first and 
>what it does with non-default -std= options after that, instead of 
>vice-versa.  Unfortunately I am backlogged on other things right now 
>and it might take me a day or two before I have time to come up with 
>some alternate wording.  If we are in a rush, go ahead and commit the 
>existing patch meanwhile, I guess.

I did wonder about that but couldn't come up with wording I liked.

I went ahead and committed it after Jason's OK, but I can take another
look at it next week.
diff mbox

Patch

commit b78b2728d8d946bd92843f6155cdd2415682da09
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Feb 19 12:14:33 2016 +0000

    	* doc/invoke.texi (C++ Dialect Options): Clarify interaction of
    	-Wnarrowing with -std.

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 2bd793d..c1ab788 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2756,7 +2756,8 @@  Requires @option{-flto} to be enabled.  Enabled by default.
 @item -Wnarrowing @r{(C++ and Objective-C++ only)}
 @opindex Wnarrowing
 @opindex Wno-narrowing
-Warn when a narrowing conversion prohibited by C++11 occurs within
+With @option{-std=gnu++98} or @option{-std=c++98}, warn when a narrowing
+conversion prohibited by C++11 occurs within
 @samp{@{ @}}, e.g.
 
 @smallexample
@@ -2765,10 +2766,13 @@  int i = @{ 2.2 @}; // error: narrowing from double to int
 
 This flag is included in @option{-Wall} and @option{-Wc++11-compat}.
 
-With @option{-std=c++11}, @option{-Wno-narrowing} suppresses the diagnostic
-required by the standard.  Note that this does not affect the meaning
-of well-formed code; narrowing conversions are still considered
-ill-formed in SFINAE context.
+When a later standard is in effect, e.g. when using @option{-std=c++11},
+narrowing conversions are diagnosed by default, as required by the standard.
+A narrowing conversion from a constant produces an error,
+and a narrowing conversion from a non-constant produces a warning,
+but @option{-Wno-narrowing} suppresses the diagnostic.
+Note that this does not affect the meaning of well-formed code;
+narrowing conversions are still considered ill-formed in SFINAE contexts.
 
 @item -Wnoexcept @r{(C++ and Objective-C++ only)}
 @opindex Wnoexcept