aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2011-08-02 17:09:17 -0400
committerJason Merrill <jason@gcc.gnu.org>2011-08-02 17:09:17 -0400
commit54e7d7f5e9e226024737b41ce6feabf1522d13df (patch)
tree849cdd5ffbc844e11ab6b9a0166cb5799909bace
parent326a64554b0ebf03a33a6a55b4467e5d77e62199 (diff)
downloadgcc-54e7d7f5e9e226024737b41ce6feabf1522d13df.zip
gcc-54e7d7f5e9e226024737b41ce6feabf1522d13df.tar.gz
gcc-54e7d7f5e9e226024737b41ce6feabf1522d13df.tar.bz2
re PR c++/49577 ([C++0x] narrowing conversion not rejected)
PR c++/49577 * typeck2.c (check_narrowing): Check unsigned mismatch. * semantics.c (finish_compound_literal): check_narrowing. From-SVN: r177215
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/semantics.c3
-rw-r--r--gcc/cp/typeck2.c3
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist5.C4
-rw-r--r--gcc/testsuite/g++.dg/opt/range-test-1.C2
6 files changed, 17 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 28900c8..4e64f1b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2011-08-02 Jason Merrill <jason@redhat.com>
+ PR c++/49577
+ * typeck2.c (check_narrowing): Check unsigned mismatch.
+ * semantics.c (finish_compound_literal): check_narrowing.
+
PR c++/49593
* pt.c (find_parameter_packs_r): Handle CONSTRUCTOR.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index a528477..ac24b77 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2379,6 +2379,9 @@ finish_compound_literal (tree type, tree compound_literal,
&& check_array_initializer (NULL_TREE, type, compound_literal))
return error_mark_node;
compound_literal = reshape_init (type, compound_literal, complain);
+ if (cxx_dialect >= cxx0x && SCALAR_TYPE_P (type)
+ && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal))
+ check_narrowing (type, compound_literal);
if (TREE_CODE (type) == ARRAY_TYPE
&& TYPE_DOMAIN (type) == NULL_TREE)
{
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 727a88b..c6b8c44 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -740,7 +740,8 @@ 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)
+ if ((TYPE_PRECISION (type) < TYPE_PRECISION (ftype)
+ || TYPE_UNSIGNED (type) != TYPE_UNSIGNED (ftype))
&& (TREE_CODE (init) != INTEGER_CST
|| !int_fits_type_p (init, type)))
ok = false;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 884162d..6e91668 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
2011-08-02 Jason Merrill <jason@redhat.com>
+ PR c++/49577
+ * g++.dg/cpp0x/initlist5.C: Add additional cases.
+
PR c++/49593
* g++.dg/cpp0x/variadic115.C: New.
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist5.C b/gcc/testsuite/g++.dg/cpp0x/initlist5.C
index dbd17ec..c5ba87d 100644
--- a/gcc/testsuite/g++.dg/cpp0x/initlist5.C
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist5.C
@@ -25,3 +25,7 @@ double d = 1.1;
float fa[] = { d, 1.1 }; // { dg-error "narrowing conversion of 'd'" }
constexpr double d2 = 1.1;
float fa2[] = { d2, 1.1 };
+
+// PR c++/49577
+unsigned u{ -1 }; // { dg-error "narrowing" }
+char c = char{ u }; // { dg-error "narrowing" }
diff --git a/gcc/testsuite/g++.dg/opt/range-test-1.C b/gcc/testsuite/g++.dg/opt/range-test-1.C
index cc5ba66..9015147 100644
--- a/gcc/testsuite/g++.dg/opt/range-test-1.C
+++ b/gcc/testsuite/g++.dg/opt/range-test-1.C
@@ -156,7 +156,7 @@ T(16, int, x == -3 || x == -4 || x == -5,
{ -3 C -4 C -5 }, { -6 C -7 C -8 C -2 C -1 C 1 C 2 C INT_MAX C INT_MIN })
T(17, unsigned int, (x >= -8U && x <= -3U) || x == -2U || x == -1U || x == 0 || x == 1 || x == 2,
{ -8U C -7U C -6U C -5U C -4U C -3U C -2U C -1U C 0 C 1 C 2 },
- { -9U C -10U C 3 C 4 C 12 C -54U C INT_MAX C INT_MIN })
+ { -9U C -10U C 3 C 4 C 12 C -54U C INT_MAX C (unsigned int)INT_MIN })
T(18, int, (x >= -8 && x <= -3) || x == -2 || x == -1 || x == 0 || x == 1 || x == 2,
{ -8 C -7 C -6 C -5 C -4 C -3 C -2 C -1 C 0 C 1 C 2 },
{ -9 C -10 C 3 C 4 C 12 C -54 C INT_MAX C INT_MIN })