]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/53661 (Wrong narrowing conversion warning with -std=c++11)
authorJason Merrill <jason@redhat.com>
Mon, 17 Sep 2012 16:06:03 +0000 (12:06 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 17 Sep 2012 16:06:03 +0000 (12:06 -0400)
PR c++/53661
* typeck2.c (check_narrowing): Avoid false positives on conversion
from enumeral type.

From-SVN: r191395

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

index f70b46673b3159102bacbf5cc02cf928ac7fc42d..c11a8c20c6b5e2aebab231730a7c5f790b9e5c38 100644 (file)
@@ -1,3 +1,9 @@
+2012-09-14  Jason Merrill  <jason@redhat.com>
+
+       PR c++/53661
+       * typeck2.c (check_narrowing): Avoid false positives on conversion
+       from enumeral type.
+
 2012-09-14  Marc Glisse  <marc.glisse@inria.fr>
 
        PR c++/54427
index 6faebb5d8644d984377c21c742166678e5e39a93..58b2db679a39466e2f8c2ec2d175504509ac0837 100644 (file)
@@ -787,6 +787,9 @@ check_narrowing (tree type, tree init)
   else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype)
           && CP_INTEGRAL_TYPE_P (type))
     {
+      if (TREE_CODE (ftype) == ENUMERAL_TYPE)
+       /* Check for narrowing based on the values of the enumeration. */
+       ftype = ENUM_UNDERLYING_TYPE (ftype);
       if ((tree_int_cst_lt (TYPE_MAX_VALUE (type),
                            TYPE_MAX_VALUE (ftype))
           || tree_int_cst_lt (TYPE_MIN_VALUE (ftype),
index 7581988f70150b9072ff0d3de79dace5a498dbc1..f97869398fbcbcc01c244268483880a42e29fd00 100644 (file)
@@ -1,3 +1,8 @@
+2012-09-14  Jason Merrill  <jason@redhat.com>
+
+       PR c++/53661
+       * g++.dg/init/aggr9.C: New.
+
 2012-09-17  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/loop_optimization12.ad[sb]: New test.
diff --git a/gcc/testsuite/g++.dg/init/aggr9.C b/gcc/testsuite/g++.dg/init/aggr9.C
new file mode 100644 (file)
index 0000000..67d8299
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/53661
+
+enum Code {
+  SUCCESS = 0
+};
+
+Code a;
+
+int r[] = {a};