re PR c++/45401 ([C++0x] reference collapsing and reference qualifiers)
authorJason Merrill <jason@redhat.com>
Thu, 26 May 2011 02:22:39 +0000 (22:22 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 26 May 2011 02:22:39 +0000 (22:22 -0400)
PR c++/45401
* decl.c (grokdeclarator): Don't change type when adding rvalue ref
to another reference type.

From-SVN: r174255

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/rv-restrict.C [new file with mode: 0644]

index 1b611936af486c53cfb11b2746d26ee80d591d58..1d0aa92e81c56a6bf4fb11b89a2679ca3ea9edda 100644 (file)
@@ -1,5 +1,9 @@
 2011-05-25  Jason Merrill  <jason@redhat.com>
 
+       PR c++/45401
+       * decl.c (grokdeclarator): Don't change type when adding rvalue ref
+       to another reference type.
+
        PR c++/44311
        * decl.c (case_conversion): New.
        (finish_case_label): Use it.
index 7fc194554b9dce5f8fad57f7a3d9e02c7ea21077..d53fa26c68a2e1e34a77977c7bee52529f61a4d7 100644 (file)
@@ -9200,13 +9200,18 @@ grokdeclarator (const cp_declarator *declarator,
                 to create the type "rvalue reference to cv TD' creates the
                 type TD."
               */
-             if (!VOID_TYPE_P (type))
+             if (VOID_TYPE_P (type))
+               /* We already gave an error.  */;
+             else if (TREE_CODE (type) == REFERENCE_TYPE)
+               {
+                 if (declarator->u.reference.rvalue_ref)
+                   /* Leave type alone.  */;
+                 else
+                   type = cp_build_reference_type (TREE_TYPE (type), false);
+               }
+             else
                type = cp_build_reference_type
-                      ((TREE_CODE (type) == REFERENCE_TYPE
-                        ? TREE_TYPE (type) : type),
-                       (declarator->u.reference.rvalue_ref
-                        && (TREE_CODE(type) != REFERENCE_TYPE
-                            || TYPE_REF_IS_RVALUE (type))));
+                 (type, declarator->u.reference.rvalue_ref);
 
              /* In C++0x, we need this check for direct reference to
                 reference declarations, which are forbidden by
index e8a335ff81351fa790d0e1467b2e33bd0722c58b..e302c74527b832b18f10e0c8a4dc682d8286b786 100644 (file)
@@ -1,5 +1,7 @@
 2011-05-25  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/cpp0x/rv-restrict.C: New.
+
        * g++.dg/cpp0x/enum15.C: New.
        * g++.dg/cpp0x/constexpr-switch2.C: New.
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-restrict.C b/gcc/testsuite/g++.dg/cpp0x/rv-restrict.C
new file mode 100644 (file)
index 0000000..569ee5b
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/45401
+// { dg-options -std=c++0x }
+
+typedef int &__restrict restrictLvref;
+typedef restrictLvref &&rvrefToRestrictLvref;
+typedef restrictLvref rvrefToRestrictLvref;