diff mbox

[C++,committed] PR 65801

Message ID 553610B3.4050901@oracle.com
State New
Headers show

Commit Message

Paolo Carlini April 21, 2015, 8:56 a.m. UTC
Hi,

I committed the below to trunk as approved by Jason on the audit trail. 
Will go in gcc-5 branch too for 5.2. Tested x86_64-linux.

Thanks,
Paolo.

//////////////////////
/cp
2015-04-20  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/65801
	* typeck2.c (check_narrowing): In C++11 mode too, -Wno-narrowing
	suppresses the diagnostic.

2015-04-20  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/65801
	* doc/invoke.texi ([-Wnarrowing]): Update.

/testsuite
2015-04-20  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/65801
	* g++.dg/cpp0x/Wnarrowing2.C: New.
diff mbox

Patch

Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c	(revision 222240)
+++ cp/typeck2.c	(working copy)
@@ -957,9 +957,13 @@  check_narrowing (tree type, tree init, tsubst_flag
 	    }
 	}
       else if (complain & tf_error)
-	error_at (EXPR_LOC_OR_LOC (init, input_location),
-		  "narrowing conversion of %qE from %qT to %qT inside { }",
-		  init, ftype, type);
+	{
+	  global_dc->pedantic_errors = 1;
+	  pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
+		   "narrowing conversion of %qE from %qT to %qT inside { }",
+		   init, ftype, type);
+	  global_dc->pedantic_errors = flag_pedantic_errors;
+	}
     }
 
   return cxx_dialect == cxx98 || ok; 
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi	(revision 222240)
+++ doc/invoke.texi	(working copy)
@@ -2706,10 +2706,10 @@  int i = @{ 2.2 @}; // error: narrowing from double
 
 This flag is included in @option{-Wall} and @option{-Wc++11-compat}.
 
-With @option{-std=c++11}, @option{-Wno-narrowing} suppresses for
-non-constants 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.
+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.
 
 @item -Wnoexcept @r{(C++ and Objective-C++ only)}
 @opindex Wnoexcept
Index: testsuite/g++.dg/cpp0x/Wnarrowing2.C
===================================================================
--- testsuite/g++.dg/cpp0x/Wnarrowing2.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/Wnarrowing2.C	(working copy)
@@ -0,0 +1,5 @@ 
+// PR c++/65801
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wno-narrowing" }
+
+static struct zai { unsigned int x; } x = {-1};