Commit 645c7a55 by Jason Merrill Committed by Jason Merrill

re PR c++/51868 (Crash when generating the move constructor for a class with a bit field)

	PR c++/51868
	* typeck.c (build_static_cast_1): Handle bit-fields properly.

From-SVN: r183218
parent f4347334
2012-01-16 Jason Merrill <jason@redhat.com>
PR c++/51868
* typeck.c (build_static_cast_1): Handle bit-fields properly.
2012-01-13 Ian Lance Taylor <iant@google.com> 2012-01-13 Ian Lance Taylor <iant@google.com>
PR c++/50012 PR c++/50012
......
...@@ -5812,11 +5812,12 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, ...@@ -5812,11 +5812,12 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
{ {
tree intype; tree intype;
tree result; tree result;
cp_lvalue_kind clk;
/* Assume the cast is valid. */ /* Assume the cast is valid. */
*valid_p = true; *valid_p = true;
intype = TREE_TYPE (expr); intype = unlowered_expr_type (expr);
/* Save casted types in the function's used types hash table. */ /* Save casted types in the function's used types hash table. */
used_types_insert (type); used_types_insert (type);
...@@ -5882,13 +5883,16 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, ...@@ -5882,13 +5883,16 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
cv2 T2 if cv2 T2 is reference-compatible with cv1 T1 (8.5.3)." */ cv2 T2 if cv2 T2 is reference-compatible with cv1 T1 (8.5.3)." */
if (TREE_CODE (type) == REFERENCE_TYPE if (TREE_CODE (type) == REFERENCE_TYPE
&& TYPE_REF_IS_RVALUE (type) && TYPE_REF_IS_RVALUE (type)
&& real_lvalue_p (expr) && (clk = real_lvalue_p (expr))
&& reference_related_p (TREE_TYPE (type), intype) && reference_related_p (TREE_TYPE (type), intype)
&& (c_cast_p || at_least_as_qualified_p (TREE_TYPE (type), intype))) && (c_cast_p || at_least_as_qualified_p (TREE_TYPE (type), intype)))
{ {
/* Handle the lvalue case here by casting to lvalue reference and if (clk == clk_ordinary)
then changing it to an rvalue reference. Casting an xvalue to {
rvalue reference will be handled by the main code path. */ /* Handle the (non-bit-field) lvalue case here by casting to
lvalue reference and then changing it to an rvalue reference.
Casting an xvalue to rvalue reference will be handled by the
main code path. */
tree lref = cp_build_reference_type (TREE_TYPE (type), false); tree lref = cp_build_reference_type (TREE_TYPE (type), false);
result = (perform_direct_initialization_if_possible result = (perform_direct_initialization_if_possible
(lref, expr, c_cast_p, complain)); (lref, expr, c_cast_p, complain));
...@@ -5899,6 +5903,10 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, ...@@ -5899,6 +5903,10 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
result = build1 (NON_LVALUE_EXPR, type, result); result = build1 (NON_LVALUE_EXPR, type, result);
return convert_from_reference (result); return convert_from_reference (result);
} }
else
/* For a bit-field or packed field, bind to a temporary. */
expr = rvalue (expr);
}
/* Resolve overloaded address here rather than once in /* Resolve overloaded address here rather than once in
implicit_conversion and again in the inverse code below. */ implicit_conversion and again in the inverse code below. */
......
2012-01-16 Jason Merrill <jason@redhat.com>
PR c++/51868
* g++.dg/cpp0x/rv-bitfield.C: New.
* g++.dg/cpp0x/rv-bitfield2.C: New.
2012-01-16 Paul Thomas <pault@gcc.gnu.org> 2012-01-16 Paul Thomas <pault@gcc.gnu.org>
* gfortran.dg/class_array_3.f03: Remove the explicit loop in * gfortran.dg/class_array_3.f03: Remove the explicit loop in
......
// { dg-options -std=c++0x }
struct A
{
int i : 1;
};
int main()
{
A a;
static_cast<int&&>(a.i);
}
// PR c++/51868
// { dg-options -std=c++0x }
struct A {
A() {}
A(const A&) {}
A(A&&) {}
};
struct B {
A a;
int f : 1;
};
B func() {
return B();
}
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