From d7cfa3145fc72f621ab2747df2f7bf046c0ee4db Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 8 Aug 2011 10:36:22 -0400 Subject: [PATCH] re PR c++/50011 ([C++0x] warning: narrowing conversion of 'i' from 'short unsigned int' to 'int' inside { } [-Wnarrowing]) PR c++/50011 * typeck2.c (check_narrowing): Fix integer logic. From-SVN: r177565 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/typeck2.c | 6 ++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/cpp0x/initlist5.C | 4 ++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8c74b2ddff8..8c1ecba038b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2011-08-08 Jason Merrill + + PR c++/50011 + * typeck2.c (check_narrowing): Fix integer logic. + 2011-08-08 Rainer Orth * Make-lang.in (g++$(exeext)): Add $(EXTRA_GCC_LIBS). diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index c6b8c443757..07881387eba 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index afd84c5d701..33832179d8f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-08-08 Jason Merrill + + * g++.dg/cpp0x/initlist5.C: Add 50011 test. + 2011-08-07 Janus Weil PR fortran/49638 diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist5.C b/gcc/testsuite/g++.dg/cpp0x/initlist5.C index c5ba87d55f1..51345c73fc1 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist5.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist5.C @@ -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 }; -- 2.30.2