re PR c++/35909 (ICE with bit-field and const references)
authorAlexandre Oliva <aoliva@redhat.com>
Tue, 27 May 2008 05:48:02 +0000 (05:48 +0000)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Tue, 27 May 2008 05:48:02 +0000 (05:48 +0000)
gcc/cp/ChangeLog:
PR c++/35909
* call.c (convert_like_real): Convert bitfield to desired type
before creating temporary.
gcc/testsuite/ChangeLog:
PR c++/35909
* g++.dg/conversion/bitfield9.C: New.

From-SVN: r135969

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/conversion/bitfield9.C [new file with mode: 0644]

index 4b1c7dbc32c866491af11ae1136cb75b7df49c63..3c54503608bd075062b012900f91a151d9cff26b 100644 (file)
@@ -1,3 +1,9 @@
+2008-05-27  Alexandre Oliva  <aoliva@redhat.com>
+
+       PR c++/35909
+       * call.c (convert_like_real): Convert bitfield to desired type
+       before creating temporary.
+
 2008-05-26  Daniel Franke  <franke.daniel@gmail.com>
 
        * Makefile.in: Adjusted dependencies on c-incpath.o.
index b83ad3a2eef41270954378bd4e533ee340238746..fe78f9cdf296ee78729406534f260b52dad9607c 100644 (file)
@@ -4580,7 +4580,10 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
                return error_mark_node;
              }
            if (lvalue & clk_bitfield)
-             expr = convert_bitfield_to_declared_type (expr);
+             {
+               expr = convert_bitfield_to_declared_type (expr);
+               expr = fold_convert (type, expr);
+             }
            expr = build_target_expr_with_type (expr, type);
          }
 
index 8a5e58fd96996279338662576820173f1a6f8110..bf57f50ddd3cd692e89e33753af3a438d58f20a3 100644 (file)
@@ -1,3 +1,8 @@
+2008-05-27  Alexandre Oliva  <aoliva@redhat.com>
+
+       PR c++/35909
+       * g++.dg/conversion/bitfield9.C: New.
+
 2008-05-26  Arnaud Charlet  <charlet@adacore.com>
 
        * gnat.dg/specs/array_no_def_init.ads: New test.
diff --git a/gcc/testsuite/g++.dg/conversion/bitfield9.C b/gcc/testsuite/g++.dg/conversion/bitfield9.C
new file mode 100644 (file)
index 0000000..998dd48
--- /dev/null
@@ -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);
+}
+