]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/33984 (bit-fields, references and overloads)
authorJakub Jelinek <jakub@redhat.com>
Wed, 23 Jan 2008 01:50:45 +0000 (02:50 +0100)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Wed, 23 Jan 2008 01:50:45 +0000 (01:50 +0000)
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

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

index 45297deda4310dadc6034fb9d597ab6eb79b74c6..f9971d4943d6f896ef0a388d45574f4ee0316bbd 100644 (file)
@@ -1,3 +1,12 @@
+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>
 
        PR c++/34912
index f15550d7fda0a7f359ee63bf9f3b74410b549545..1e591a61ac10f8974e7767a41ac1155e47e46189 100644 (file)
@@ -1,6 +1,6 @@
 /* Functions related to invoking methods and overloaded functions.
    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.
    Contributed by Michael Tiemann (tiemann@cygnus.com) and
    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)
   conversion *conv = NULL;
   tree to = TREE_TYPE (rto);
   tree from = rfrom;
+  tree tfrom;
   bool related_p;
   bool compatible_p;
   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)
   else if (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
      reference compatible.  We have do do this after stripping
      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
      type, so that we can later do a const_cast to the desired type.  */
   if (related_p && c_cast_p
-      && !at_least_as_qualified_p (to, from))
-    to = build_qualified_type (to, cp_type_quals (from));
-  compatible_p = reference_compatible_p (to, from);
+      && !at_least_as_qualified_p (to, tfrom))
+    to = build_qualified_type (to, cp_type_quals (tfrom));
+  compatible_p = reference_compatible_p (to, tfrom);
 
   /* Directly bind reference when target expression's type is compatible with
      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)
         is bound to the object represented by the rvalue or to a sub-object
         within that object.  */
 
-      conv = build_identity_conv (from, expr);
+      conv = build_identity_conv (tfrom, expr);
       conv = direct_reference_binding (rto, conv);
 
       if (flags & LOOKUP_PREFER_RVALUE)
@@ -2084,7 +2089,7 @@ add_builtin_candidates (struct z_candidate **candidates, enum tree_code code,
   for (i = 0; i < 3; ++i)
     {
       if (args[i])
-       argtypes[i]  = lvalue_type (args[i]);
+       argtypes[i] = unlowered_expr_type (args[i]);
       else
        argtypes[i] = NULL_TREE;
     }
index 6e67157a290a3c881a9f5533f735bdec7108650a..65e7144bfd7d9d100785b29c32d158408f2acd97 100644 (file)
@@ -4795,14 +4795,18 @@ layout_class_type (tree t, tree *virtuals_p)
         must be converted to the type given the bitfield here.  */
       if (DECL_C_BIT_FIELD (field))
        {
-         tree ftype;
          unsigned HOST_WIDE_INT width;
-         ftype = TREE_TYPE (field);
+         tree ftype = TREE_TYPE (field);
          width = tree_low_cst (DECL_SIZE (field), /*unsignedp=*/1);
          if (width != TYPE_PRECISION (ftype))
-           TREE_TYPE (field)
-             = c_build_bitfield_integer_type (width,
-                                              TYPE_UNSIGNED (ftype));
+           {
+             TREE_TYPE (field)
+               = 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
index ec42934bc9ca36d9cd93d7b3f92d7eb7f1c3103a..e0e47abbffc1d4eb279cc6868572281a7d681c20 100644 (file)
@@ -1,3 +1,9 @@
+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>
 
        From Michael Frysinger  <michael.frysinger@analog.com>
diff --git a/gcc/testsuite/g++.dg/conversion/bitfield7.C b/gcc/testsuite/g++.dg/conversion/bitfield7.C
new file mode 100644 (file)
index 0000000..1080168
--- /dev/null
@@ -0,0 +1,16 @@
+// 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" }
+}
index 18f2734681195cdc736c8aeb3b9aa3f1f6456804..23a34344e171a1a6a2eec8535090c488e722ea03 100644 (file)
@@ -70,7 +70,7 @@ struct B {
     CHECK_DECLTYPE(decltype(bit), int);
     CHECK_DECLTYPE(decltype((bit)), 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&);
   }
 };