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.carl...@oracle.com>

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

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

        PR c++/69872
        * g++.dg/warn/Wno-narrowing1.C: New.
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" }
+};

Reply via email to