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
This commit is contained in:
Jason Merrill 2011-08-08 10:36:22 -04:00 committed by Jason Merrill
parent cca2207a2d
commit d7cfa3145f
4 changed files with 17 additions and 2 deletions

View 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).

View 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;

View 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

View 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 };