re PR c++/69872 (-Wnarrowing note without warning/errror)
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 24 May 2016 16:41:39 +0000 (16:41 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 24 May 2016 16:41:39 +0000 (16:41 +0000)
/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.

From-SVN: r236651

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wno-narrowing1.C [new file with mode: 0644]

index c77dee6dfb7c43606c75819a81a8d8c0cb8e4a06..4e06a71e7ca4d414c0b168eaab3423403067a1ef 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-24  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/69872
+       * typeck2.c (check_narrowing): Check pedwarn return value.
+
 2016-05-24  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/71257
index 833be20f7fed43b2a8bf35bac38e3f1e9d490526..835a44f1cf6188fe9d4d5ad11a89f4ef8cf4a61c 100644 (file)
@@ -950,10 +950,12 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain)
        {
          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 e2b2466903c8b50d39964a2360aad9ff69e5c4af..d27369c87f53e93df609c9820dcb255c0256bf74 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-24  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/69872
+       * g++.dg/warn/Wno-narrowing1.C: New.
+
 2016-05-24  Marek Polacek  <polacek@redhat.com>
 
        PR c/71249
diff --git a/gcc/testsuite/g++.dg/warn/Wno-narrowing1.C b/gcc/testsuite/g++.dg/warn/Wno-narrowing1.C
new file mode 100644 (file)
index 0000000..285f05a
--- /dev/null
@@ -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" }
+};