public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] PR 66007
@ 2015-05-04 18:17 Paolo Carlini
  2015-05-04 20:29 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Carlini @ 2015-05-04 18:17 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill, Jakub Jelinek

[-- Attachment #1: Type: text/plain, Size: 506 bytes --]

Hi,

unfortunately we have to return to these few lines of code :(

This regression is a more subtle variant of c++/65858: if the user 
passes -Wno-error=narrowing the pedwarn didn't result in an actual error 
(even if we are forcing -pedantic-errors around it) but produces anyway 
a warning, thus returns true, and ok isn't set to true, thus we have a 
miscompilation in this case too. Jakub suggested simply checking by hand 
errorcount, which passes all my tests.

Thanks,
Paolo.

////////////////////

[-- Attachment #2: CL_66007 --]
[-- Type: text/plain, Size: 366 bytes --]

/cp
2015-05-04  Paolo Carlini  <paolo.carlini@oracle.com>
	    Jakub Jelinek  <jakub@redhat.com>

	PR c++/66007
	* typeck2.c (check_narrowing): Check by-hand that the pedwarn didn't
	result in an actual error.

/testsuite
2015-05-04  Paolo Carlini  <paolo.carlini@oracle.com>
	    Jakub Jelinek  <jakub@redhat.com>

	PR c++/66007
	* g++.dg/cpp0x/Wnarrowing4.C: New.

[-- Attachment #3: patch_66007 --]
[-- Type: text/plain, Size: 1334 bytes --]

Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c	(revision 222767)
+++ cp/typeck2.c	(working copy)
@@ -958,10 +958,12 @@ check_narrowing (tree type, tree init, tsubst_flag
 	}
       else if (complain & tf_error)
 	{
+	  int savederrorcount = errorcount;
 	  global_dc->pedantic_errors = 1;
-	  if (!pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
-			"narrowing conversion of %qE from %qT to %qT "
-			"inside { }", init, ftype, type))
+	  pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
+		   "narrowing conversion of %qE from %qT to %qT "
+		   "inside { }", init, ftype, type);
+	  if (errorcount == savederrorcount)
 	    ok = true;
 	  global_dc->pedantic_errors = flag_pedantic_errors;
 	}
Index: testsuite/g++.dg/cpp0x/Wnarrowing4.C
===================================================================
--- testsuite/g++.dg/cpp0x/Wnarrowing4.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/Wnarrowing4.C	(working copy)
@@ -0,0 +1,14 @@
+// PR c++/66007
+// { dg-do run { target c++11 } }
+// { dg-options "-Wno-error=narrowing" }
+
+extern "C" void abort();
+
+int main()
+{
+  unsigned foo[] = { 1, -1, 3 };
+  if (foo[0] != 1 || foo[1] != __INT_MAX__ * 2U + 1 || foo[2] != 3)
+    abort();
+}
+
+// { dg-prune-output "narrowing conversion" }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C++ Patch] PR 66007
  2015-05-04 18:17 [C++ Patch] PR 66007 Paolo Carlini
@ 2015-05-04 20:29 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2015-05-04 20:29 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches; +Cc: Jakub Jelinek

On 05/04/2015 01:17 PM, Paolo Carlini wrote:
> This regression is a more subtle variant of c++/65858: if the user
> passes -Wno-error=narrowing the pedwarn didn't result in an actual error
> (even if we are forcing -pedantic-errors around it) but produces anyway
> a warning, thus returns true, and ok isn't set to true, thus we have a
> miscompilation in this case too. Jakub suggested simply checking by hand
> errorcount, which passes all my tests.

OK.

Jason


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-05-04 20:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-04 18:17 [C++ Patch] PR 66007 Paolo Carlini
2015-05-04 20:29 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).