re PR c++/50011 ([C++0x] warning: narrowing conversion of 'i' from 'short unsigned...
authorJason Merrill <jason@redhat.com>
Mon, 8 Aug 2011 14:36:22 +0000 (10:36 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 8 Aug 2011 14:36:22 +0000 (10:36 -0400)
PR c++/50011
* typeck2.c (check_narrowing): Fix integer logic.

From-SVN: r177565

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

index 8c74b2ddff89c792e54a727371a8cd7af0a3ef6a..8c1ecba038b9d839c004938f781e0cc068a7c429 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 c6b8c443757b5c76af5b4da683d16340b9fa604c..07881387eba8089f3719aa25833eee9bcc6ae29e 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 afd84c5d701db2c5b087cc72bb5fa7992fee8753..33832179d8f6d867ba8a1984f549b0a766ef80b6 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 c5ba87d55f1eb0102cf6590c4fd204180b29da73..51345c73fc17c2f7d6a73144f802a25542ae2478 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 };