* C++ PATCH for c++/50011 (wrong narrowing error)
@ 2011-08-08 14:57 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2011-08-08 14:57 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 151 bytes --]
Oops, my last fix was still wrong. This patch just compares min/max
values, which should be safe. :)
Tested x86_64-pc-linux-gnu, applied to trunk.
[-- Attachment #2: 50011.patch --]
[-- Type: text/x-patch, Size: 1286 bytes --]
commit 5efa9cf21a329bba89748ddbc8e3bf3c8ea4329e
Author: Jason Merrill <jason@redhat.com>
Date: Sun Aug 7 17:10:26 2011 -0400
PR c++/50011
* typeck2.c (check_narrowing): Fix integer logic.
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index c6b8c44..0788138 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/g++.dg/cpp0x/initlist5.C b/gcc/testsuite/g++.dg/cpp0x/initlist5.C
index c5ba87d..51345c7 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 };
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-08-08 14:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-08 14:57 C++ PATCH for c++/50011 (wrong narrowing error) Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).