re PR c++/66007 (Narrowing conversion inside { } results in all zero elements in...
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 4 May 2015 20:58:33 +0000 (20:58 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 4 May 2015 20:58:33 +0000 (20:58 +0000)
/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.

Co-Authored-By: Jakub Jelinek <jakub@redhat.com>
From-SVN: r222778

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/Wnarrowing4.C [new file with mode: 0644]

index 65cb5bee27b6d47b8576700e17cb73f2e6b2e221..bd9f2f32776c13021ee0711331490b000e2fe01a 100644 (file)
@@ -1,3 +1,10 @@
+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.
+
 2015-05-01  Paolo Carlini  <paolo.carlini@oracle.com>
            Prathamesh Kulharni  <prathamesh.kulkarni@linaro.org>
 
index 9a491aa71f23f351534b561fdbdc63ab48778ddb..c0df8237a1264692cc3f93703e89b6a33e9f0aca 100644 (file)
@@ -958,10 +958,12 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain)
        }
       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 3673938aab0858af01fe1ca70ce1ce791a5272c2..a73ad283490d6fb71aabcce1a55ad00874573549 100644 (file)
@@ -1,3 +1,9 @@
+2015-05-04  Paolo Carlini  <paolo.carlini@oracle.com>
+           Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/66007
+       * g++.dg/cpp0x/Wnarrowing4.C: New.
+
 2015-05-04  Sandra Loosemore  <sandra@codesourcery.com>
 
        * lib/target-supports.exp
diff --git a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing4.C b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing4.C
new file mode 100644 (file)
index 0000000..7defce3
--- /dev/null
@@ -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" }