This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PR c++/35909] fix const ref binding to demoted bitfield
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 24 Apr 2008 03:57:41 -0300
- Subject: [PR c++/35909] fix const ref binding to demoted bitfield
The testcase in the patch shows a situation in which we don't want to
use the original bitfield type for reference binding. The patch for PR
35056 assumed this type would always be correct, but there may be an
integral promotion or conversion before creating the integral temporary
that is bound to the reference to const. This patch converts the
integral expression to the type of the temporary if needed.
Tested on trunk x86_64-linux-gnu. Ok to install?
Ok for 4.3 branch if it passes there as well?
for gcc/cp/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR c++/35909
* call.c (convert_like_real): Convert bitfield to desired type
before creating temporary.
for gcc/testsuite/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR c++/35909
* g++.dg/conversion/bitfield9.C: New.
Index: gcc/cp/call.c
===================================================================
--- gcc/cp/call.c.orig 2008-04-22 03:26:25.000000000 -0300
+++ gcc/cp/call.c 2008-04-22 03:26:27.000000000 -0300
@@ -4580,7 +4580,11 @@ convert_like_real (conversion *convs, tr
return error_mark_node;
}
if (lvalue & clk_bitfield)
- expr = convert_bitfield_to_declared_type (expr);
+ {
+ expr = convert_bitfield_to_declared_type (expr);
+ if (type != TREE_TYPE (expr))
+ expr = fold (build_nop (type, expr));
+ }
expr = build_target_expr_with_type (expr, type);
}
Index: gcc/testsuite/g++.dg/conversion/bitfield9.C
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/g++.dg/conversion/bitfield9.C 2008-04-22 03:26:27.000000000 -0300
@@ -0,0 +1,17 @@
+// PR c++/35909
+// { dg-do compile }
+
+struct MidiCommand
+{
+ unsigned data1 : 8;
+};
+
+void g(const unsigned char &);
+void h(const unsigned int &);
+
+void f(MidiCommand mc)
+{
+ g(mc.data1);
+ h(mc.data1);
+}
+
--
Alexandre Oliva http://www.lsd.ic.unicamp.br/~oliva/
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}
FSFLA Board Member ÂSÃ Libre! => http://www.fsfla.org/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}