diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2003-07-22 09:53:34 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2003-07-22 09:53:34 +0000 |
commit | e0d1297c4320ae158fbba12f8d2a0ec2970462ba (patch) | |
tree | 6679a92cc9d1ed37f7676b33077730a559a92f24 /gcc/cp/call.c | |
parent | c6e4cc53e53de0f671b715bfb83f37dbf73aaf2f (diff) | |
download | gcc-e0d1297c4320ae158fbba12f8d2a0ec2970462ba.zip gcc-e0d1297c4320ae158fbba12f8d2a0ec2970462ba.tar.gz gcc-e0d1297c4320ae158fbba12f8d2a0ec2970462ba.tar.bz2 |
cp-tree.h (enum cp_lvalue_kind): Add clk_packed.
cp:
* cp-tree.h (enum cp_lvalue_kind): Add clk_packed.
* tree.c (lvalue_p_1): Set it.
* class.c (check_field): Don't allow non-packed non-POD fields to
be packed.
* call.c (reference_binding): Need a temporary for all bitfield
and packed fields.
(convert_like_real): Check it is ok to make a temporary here.
testsuite:
* g++.dg/ext/packed3.C: New test.
* g++.dg/ext/packed4.C: New test.
From-SVN: r69669
Diffstat (limited to 'gcc/cp/call.c')
-rw-r--r-- | gcc/cp/call.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 013d600..022ac78 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -1054,10 +1054,10 @@ reference_binding (tree rto, tree rfrom, tree expr, int flags) lvalue. */ conv = build1 (IDENTITY_CONV, from, expr); conv = direct_reference_binding (rto, conv); - if ((lvalue_p & clk_bitfield) != 0 - && CP_TYPE_CONST_NON_VOLATILE_P (to)) + if ((lvalue_p & clk_bitfield) != 0 + || ((lvalue_p & clk_packed) != 0 && !TYPE_PACKED (to))) /* For the purposes of overload resolution, we ignore the fact - this expression is a bitfield. (In particular, + this expression is a bitfield or packed field. (In particular, [over.ics.ref] says specifically that a function with a non-const reference parameter is viable even if the argument is a bitfield.) @@ -1068,6 +1068,7 @@ reference_binding (tree rto, tree rfrom, tree expr, int flags) a temporary, so we just issue an error when the conversion actually occurs. */ NEED_TEMPORARY_P (conv) = 1; + return conv; } else if (CLASS_TYPE_P (from) && !(flags & LOOKUP_NO_CONVERSION)) @@ -4172,6 +4173,23 @@ convert_like_real (tree convs, tree expr, tree fn, int argnum, int inner, if (NEED_TEMPORARY_P (convs) || !non_cast_lvalue_p (expr)) { tree type = TREE_TYPE (TREE_OPERAND (convs, 0)); + + if (!CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (ref_type))) + { + /* If the reference is volatile or non-const, we + cannot create a temporary. */ + cp_lvalue_kind lvalue = real_lvalue_p (expr); + + if (lvalue & clk_bitfield) + error ("cannot bind bitfield `%E' to `%T'", + expr, ref_type); + else if (lvalue & clk_packed) + error ("cannot bind packed field `%E' to `%T'", + expr, ref_type); + else + my_friendly_assert (0, 20030715); + return error_mark_node; + } expr = build_target_expr_with_type (expr, type); } |