Commit 54e7d7f5 by Jason Merrill Committed by Jason Merrill

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
parent 326a6455
2011-08-02 Jason Merrill <jason@redhat.com> 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 PR c++/49593
* pt.c (find_parameter_packs_r): Handle CONSTRUCTOR. * pt.c (find_parameter_packs_r): Handle CONSTRUCTOR.
......
...@@ -2379,6 +2379,9 @@ finish_compound_literal (tree type, tree compound_literal, ...@@ -2379,6 +2379,9 @@ finish_compound_literal (tree type, tree compound_literal,
&& check_array_initializer (NULL_TREE, type, compound_literal)) && check_array_initializer (NULL_TREE, type, compound_literal))
return error_mark_node; return error_mark_node;
compound_literal = reshape_init (type, compound_literal, complain); 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 if (TREE_CODE (type) == ARRAY_TYPE
&& TYPE_DOMAIN (type) == NULL_TREE) && TYPE_DOMAIN (type) == NULL_TREE)
{ {
......
...@@ -740,7 +740,8 @@ check_narrowing (tree type, tree init) ...@@ -740,7 +740,8 @@ check_narrowing (tree type, tree init)
else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype) else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype)
&& CP_INTEGRAL_TYPE_P (type)) && 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 && (TREE_CODE (init) != INTEGER_CST
|| !int_fits_type_p (init, type))) || !int_fits_type_p (init, type)))
ok = false; ok = false;
......
2011-08-02 Jason Merrill <jason@redhat.com> 2011-08-02 Jason Merrill <jason@redhat.com>
PR c++/49577
* g++.dg/cpp0x/initlist5.C: Add additional cases.
PR c++/49593 PR c++/49593
* g++.dg/cpp0x/variadic115.C: New. * g++.dg/cpp0x/variadic115.C: New.
......
...@@ -25,3 +25,7 @@ double d = 1.1; ...@@ -25,3 +25,7 @@ double d = 1.1;
float fa[] = { d, 1.1 }; // { dg-error "narrowing conversion of 'd'" } float fa[] = { d, 1.1 }; // { dg-error "narrowing conversion of 'd'" }
constexpr double d2 = 1.1; constexpr double d2 = 1.1;
float fa2[] = { d2, 1.1 }; float fa2[] = { d2, 1.1 };
// PR c++/49577
unsigned u{ -1 }; // { dg-error "narrowing" }
char c = char{ u }; // { dg-error "narrowing" }
...@@ -156,7 +156,7 @@ T(16, int, x == -3 || x == -4 || x == -5, ...@@ -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 }) { -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, 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 }, { -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, 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 }, { -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 }) { -9 C -10 C 3 C 4 C 12 C -54 C INT_MAX C INT_MIN })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment