Commit 24030e4c by Jakub Jelinek Committed by Alexandre Oliva

re PR c++/33984 (bit-fields, references and overloads)

gcc/cp/ChangeLog:
PR c++/33984
* call.c (reference_binding): For bitfields use the declared bitfield
type.
(add_builtin_candidates): Likewise.
* class.c (layout_class_type): For bitfields copy over the
original type quals.
gcc/testsuite/ChangeLog:
PR c++/33984
* g++.dg/conversion/bitfield7.C: New test.
* g++.dg/cpp0x/decltype4.C: Fixed xfail.

From-SVN: r131751
parent 3573f8da
2008-01-22 Jakub Jelinek <jakub@redhat.com>, Alexandre Oliva <aoliva@redhat.com>
PR c++/33984
* call.c (reference_binding): For bitfields use the declared bitfield
type.
(add_builtin_candidates): Likewise.
* class.c (layout_class_type): For bitfields copy over the
original type quals.
2008-01-22 Jason Merrill <jason@redhat.com> 2008-01-22 Jason Merrill <jason@redhat.com>
PR c++/34912 PR c++/34912
......
/* Functions related to invoking methods and overloaded functions. /* Functions related to invoking methods and overloaded functions.
Copyright (C) 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, Copyright (C) 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
Free Software Foundation, Inc. Free Software Foundation, Inc.
Contributed by Michael Tiemann (tiemann@cygnus.com) and Contributed by Michael Tiemann (tiemann@cygnus.com) and
modified by Brendan Kehoe (brendan@cygnus.com). modified by Brendan Kehoe (brendan@cygnus.com).
...@@ -1114,6 +1114,7 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags) ...@@ -1114,6 +1114,7 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags)
conversion *conv = NULL; conversion *conv = NULL;
tree to = TREE_TYPE (rto); tree to = TREE_TYPE (rto);
tree from = rfrom; tree from = rfrom;
tree tfrom;
bool related_p; bool related_p;
bool compatible_p; bool compatible_p;
cp_lvalue_kind lvalue_p = clk_none; cp_lvalue_kind lvalue_p = clk_none;
...@@ -1135,16 +1136,20 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags) ...@@ -1135,16 +1136,20 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags)
else if (expr) else if (expr)
lvalue_p = real_lvalue_p (expr); lvalue_p = real_lvalue_p (expr);
tfrom = from;
if ((lvalue_p & clk_bitfield) != 0)
tfrom = unlowered_expr_type (expr);
/* Figure out whether or not the types are reference-related and /* Figure out whether or not the types are reference-related and
reference compatible. We have do do this after stripping reference compatible. We have do do this after stripping
references from FROM. */ references from FROM. */
related_p = reference_related_p (to, from); related_p = reference_related_p (to, tfrom);
/* If this is a C cast, first convert to an appropriately qualified /* If this is a C cast, first convert to an appropriately qualified
type, so that we can later do a const_cast to the desired type. */ type, so that we can later do a const_cast to the desired type. */
if (related_p && c_cast_p if (related_p && c_cast_p
&& !at_least_as_qualified_p (to, from)) && !at_least_as_qualified_p (to, tfrom))
to = build_qualified_type (to, cp_type_quals (from)); to = build_qualified_type (to, cp_type_quals (tfrom));
compatible_p = reference_compatible_p (to, from); compatible_p = reference_compatible_p (to, tfrom);
/* Directly bind reference when target expression's type is compatible with /* Directly bind reference when target expression's type is compatible with
the reference and expression is an lvalue. In DR391, the wording in the reference and expression is an lvalue. In DR391, the wording in
...@@ -1171,7 +1176,7 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags) ...@@ -1171,7 +1176,7 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags)
is bound to the object represented by the rvalue or to a sub-object is bound to the object represented by the rvalue or to a sub-object
within that object. */ within that object. */
conv = build_identity_conv (from, expr); conv = build_identity_conv (tfrom, expr);
conv = direct_reference_binding (rto, conv); conv = direct_reference_binding (rto, conv);
if (flags & LOOKUP_PREFER_RVALUE) if (flags & LOOKUP_PREFER_RVALUE)
...@@ -2084,7 +2089,7 @@ add_builtin_candidates (struct z_candidate **candidates, enum tree_code code, ...@@ -2084,7 +2089,7 @@ add_builtin_candidates (struct z_candidate **candidates, enum tree_code code,
for (i = 0; i < 3; ++i) for (i = 0; i < 3; ++i)
{ {
if (args[i]) if (args[i])
argtypes[i] = lvalue_type (args[i]); argtypes[i] = unlowered_expr_type (args[i]);
else else
argtypes[i] = NULL_TREE; argtypes[i] = NULL_TREE;
} }
......
...@@ -4795,14 +4795,18 @@ layout_class_type (tree t, tree *virtuals_p) ...@@ -4795,14 +4795,18 @@ layout_class_type (tree t, tree *virtuals_p)
must be converted to the type given the bitfield here. */ must be converted to the type given the bitfield here. */
if (DECL_C_BIT_FIELD (field)) if (DECL_C_BIT_FIELD (field))
{ {
tree ftype;
unsigned HOST_WIDE_INT width; unsigned HOST_WIDE_INT width;
ftype = TREE_TYPE (field); tree ftype = TREE_TYPE (field);
width = tree_low_cst (DECL_SIZE (field), /*unsignedp=*/1); width = tree_low_cst (DECL_SIZE (field), /*unsignedp=*/1);
if (width != TYPE_PRECISION (ftype)) if (width != TYPE_PRECISION (ftype))
TREE_TYPE (field) {
= c_build_bitfield_integer_type (width, TREE_TYPE (field)
TYPE_UNSIGNED (ftype)); = c_build_bitfield_integer_type (width,
TYPE_UNSIGNED (ftype));
TREE_TYPE (field)
= cp_build_qualified_type (TREE_TYPE (field),
TYPE_QUALS (ftype));
}
} }
/* If we needed additional padding after this field, add it /* If we needed additional padding after this field, add it
......
2008-01-22 Jakub Jelinek <jakub@redhat.com>
PR c++/33984
* g++.dg/conversion/bitfield7.C: New test.
* g++.dg/cpp0x/decltype4.C: Fixed xfail.
2008-01-23 Bernd Schmidt <bernd.schmidt@analog.com> 2008-01-23 Bernd Schmidt <bernd.schmidt@analog.com>
From Michael Frysinger <michael.frysinger@analog.com> From Michael Frysinger <michael.frysinger@analog.com>
// PR c++/33984
// { dg-do compile }
struct S
{
unsigned int bar : 3;
} s;
int foo (unsigned int &);
int foo (double);
int
main ()
{
return foo (s.bar); // { dg-error "cannot bind bitfield" }
}
...@@ -70,7 +70,7 @@ struct B { ...@@ -70,7 +70,7 @@ struct B {
CHECK_DECLTYPE(decltype(bit), int); CHECK_DECLTYPE(decltype(bit), int);
CHECK_DECLTYPE(decltype((bit)), int&); CHECK_DECLTYPE(decltype((bit)), int&);
CHECK_DECLTYPE(decltype(cbit), const int); CHECK_DECLTYPE(decltype(cbit), const int);
CHECK_DECLTYPE(decltype((cbit)), const int&); // { dg-bogus "static assertion failed" "GCC gets the actual type of this expression wrong" { xfail *-*-* } 73 } CHECK_DECLTYPE(decltype((cbit)), const int&);
} }
}; };
......
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