diff mbox

[C++] PR 69872 ("[6/7 Regression] -Wnarrowing note without warning/errror")

Message ID 574449D2.2070305@oracle.com
State New
Headers show

Commit Message

Paolo Carlini May 24, 2016, 12:32 p.m. UTC
Hi,

in this small diagnostic regression we emit an inform without a 
preceding warning/error: checking the return value of the pedwarn, as we 
normally want to do, fixes the problem. Tested x86_64-linux.

Thanks,
Paolo.

/////////////////////
/cp
2016-05-24  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/69872
	* typeck2.c (check_narrowing): Check pedwarn return value.

/testsuite
2016-05-24  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/69872
	* g++.dg/warn/Wno-narrowing1.C: New.

Comments

Jason Merrill May 24, 2016, 3:48 p.m. UTC | #1
OK.

Jason


On Tue, May 24, 2016 at 8:32 AM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> Hi,
>
> in this small diagnostic regression we emit an inform without a preceding
> warning/error: checking the return value of the pedwarn, as we normally want
> to do, fixes the problem. Tested x86_64-linux.
>
> Thanks,
> Paolo.
>
> /////////////////////
diff mbox

Patch

Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c	(revision 236630)
+++ cp/typeck2.c	(working copy)
@@ -950,10 +950,12 @@  check_narrowing (tree type, tree init, tsubst_flag
 	{
 	  if (complain & tf_warning_or_error)
 	    {
-	      if (!almost_ok || pedantic)
-		pedwarn (loc, OPT_Wnarrowing, "narrowing conversion of %qE "
-			 "from %qT to %qT inside { }", init, ftype, type);
-	      if (pedantic && almost_ok)
+	      if ((!almost_ok || pedantic)
+		  && pedwarn (loc, OPT_Wnarrowing,
+			      "narrowing conversion of %qE "
+			      "from %qT to %qT inside { }",
+			      init, ftype, type)
+		  && almost_ok)
 		inform (loc, " the expression has a constant value but is not "
 			"a C++ constant-expression");
 	      ok = true;
Index: testsuite/g++.dg/warn/Wno-narrowing1.C
===================================================================
--- testsuite/g++.dg/warn/Wno-narrowing1.C	(revision 0)
+++ testsuite/g++.dg/warn/Wno-narrowing1.C	(working copy)
@@ -0,0 +1,7 @@ 
+// PR c++/69872
+// { dg-options "-Wall -Wextra -pedantic -Wno-narrowing" }
+
+struct s { int x, y; };
+short offsets[1] = {
+  ((char*) &(((struct s*)16)->y) - (char *)16),  // { dg-bogus "note" }
+};