OSDN Git Service

PR c++/50011
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Aug 2011 14:36:22 +0000 (14:36 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Aug 2011 14:36:22 +0000 (14:36 +0000)
* typeck2.c (check_narrowing): Fix integer logic.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@177565 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/initlist5.C

index 8c74b2d..8c1ecba 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-08  Jason Merrill  <jason@redhat.com>
+
+       PR c++/50011
+       * typeck2.c (check_narrowing): Fix integer logic.
+
 2011-08-08  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        * Make-lang.in (g++$(exeext)): Add $(EXTRA_GCC_LIBS).
index c6b8c44..0788138 100644 (file)
@@ -740,8 +740,10 @@ check_narrowing (tree type, tree init)
   else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype)
           && CP_INTEGRAL_TYPE_P (type))
     {
-      if ((TYPE_PRECISION (type) < TYPE_PRECISION (ftype)
-          || TYPE_UNSIGNED (type) != TYPE_UNSIGNED (ftype))
+      if ((tree_int_cst_lt (TYPE_MAX_VALUE (type),
+                           TYPE_MAX_VALUE (ftype))
+          || tree_int_cst_lt (TYPE_MIN_VALUE (ftype),
+                              TYPE_MIN_VALUE (type)))
          && (TREE_CODE (init) != INTEGER_CST
              || !int_fits_type_p (init, type)))
        ok = false;
index afd84c5..3383217 100644 (file)
@@ -1,3 +1,7 @@
+2011-08-08  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/cpp0x/initlist5.C: Add 50011 test.
+
 2011-08-07  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/49638
index c5ba87d..51345c7 100644 (file)
@@ -29,3 +29,7 @@ float fa2[] = { d2, 1.1 };
 // PR c++/49577
 unsigned u{ -1 };              // { dg-error "narrowing" }
 char c = char{ u };            // { dg-error "narrowing" }
+
+// PR c++/50011
+short unsigned su;
+int i { su };