* typeck.c (decay_conversion): Don't adjust bitfield types.
(perform_integral_promotions): Treat bitfield enums as enums, not
as short integer types.
* tree.c (rvalue): Convert bitfields to their correct types.
PR c++/27292
* g++.dg/conversion/bitfield1.C: New test.
* g++.dg/conversion/bitfield2.C: Likewise.
* g++.dg/conversion/bitfield3.C: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@113240
138bc75d-0d04-0410-961f-
82ee72b054a4
+2006-04-24 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/27292
+ * typeck.c (decay_conversion): Don't adjust bitfield types.
+ (perform_integral_promotions): Treat bitfield enums as enums, not
+ as short integer types.
+ * tree.c (rvalue): Convert bitfields to their correct types.
+
2006-04-24 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/19963
tree type;
if (real_lvalue_p (expr))
{
- type = TREE_TYPE (expr);
+ type = is_bitfield_expr_with_lowered_type (expr);
+ if (!type)
+ type = TREE_TYPE (expr);
/* [basic.lval]
Non-class rvalues always have cv-unqualified types. */
decay_conversion (tree exp)
{
tree type;
- tree bitfield_type;
enum tree_code code;
type = TREE_TYPE (exp);
return error_mark_node;
}
- bitfield_type = is_bitfield_expr_with_lowered_type (exp);
- if (bitfield_type)
- exp = build_nop (bitfield_type, exp);
-
exp = decl_constant_value (exp);
/* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
tree type;
tree promoted_type;
- type = TREE_TYPE (expr);
+ /* [conv.prom]
+
+ If the bitfield has an enumerated type, it is treated as any
+ other value of that type for promotion purposes. */
+ type = is_bitfield_expr_with_lowered_type (expr);
+ if (!type || TREE_CODE (type) != ENUMERAL_TYPE)
+ type = TREE_TYPE (expr);
gcc_assert (INTEGRAL_OR_ENUMERATION_TYPE_P (type));
promoted_type = type_promotes_to (type);
if (type != promoted_type)
+2006-04-24 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/27292
+ * g++.dg/conversion/bitfield1.C: New test.
+ * g++.dg/conversion/bitfield2.C: Likewise.
+ * g++.dg/conversion/bitfield3.C: Likewise.
+
2006-04-24 Andrew Pinski <pinskia@gcc.gnu.org>
Richard Guenther <rguenther@suse.de>
--- /dev/null
+// { dg-do run }
+// { dg-options "-w" }
+
+enum E { a, b = 1LL << 48 };
+
+struct S {
+ E e : 3;
+};
+
+S s;
+
+int main () {
+ if (sizeof (E) != sizeof (long long))
+ return 1;
+ if (sizeof (s.e + 3) != sizeof (long long))
+ return 2;
+}
--- /dev/null
+// PR c++/27292
+
+struct A
+{
+ int i : 8;
+};
+
+bool foo(A a)
+{
+ return int(a.i);
+}
--- /dev/null
+// PR c++/16376
+// { dg-do run }
+
+int main(void){
+ struct bits {
+ unsigned int ui3 : 3;
+ } bits;
+ int i = -1; /* is a very large positive number as unsigned */
+
+ bits.ui3 = 1u;
+ if( bits.ui3 < i )
+ return 1;
+ return 0;
+}