OSDN Git Service

PR c++/53661
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 17 Sep 2012 16:41:41 +0000 (16:41 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 17 Sep 2012 16:41:41 +0000 (16:41 +0000)
* typeck2.c (check_narrowing): Avoid false positives on conversion
from enumeral type.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@191398 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 96cdf57..2300f04 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-13  Jason Merrill  <jason@redhat.com>
 
        PR c++/53839
 2012-09-13  Jason Merrill  <jason@redhat.com>
 
        PR c++/53839
index 7793744..f9ac28b 100644 (file)
@@ -786,6 +786,9 @@ check_narrowing (tree type, tree init)
   else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype)
           && CP_INTEGRAL_TYPE_P (type))
     {
   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),
       if ((tree_int_cst_lt (TYPE_MAX_VALUE (type),
                            TYPE_MAX_VALUE (ftype))
           || tree_int_cst_lt (TYPE_MIN_VALUE (ftype),
index 7b332cb..9ac0e32 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-13  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/54556
 2012-09-13  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/54556
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};