* C++ PATCH for c++/45401 (losing __restrict on reference squashing)
@ 2011-05-26 1:50 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2011-05-26 1:50 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 237 bytes --]
There are no standardized semantics for __restrict on references, but it
seems reasonable to do as the submitter requests and return the original
reference type unchanged when adding &&.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 45401.patch --]
[-- Type: text/x-patch, Size: 1669 bytes --]
commit abb9429bb160d33b268bb45b9538ba83d920b0f2
Author: Jason Merrill <jason@redhat.com>
Date: Wed May 25 16:19:21 2011 -0400
PR c++/45401
* decl.c (grokdeclarator): Don't change type when adding rvalue ref
to another reference type.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 7fc1945..d53fa26 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-restrict.C b/gcc/testsuite/g++.dg/cpp0x/rv-restrict.C
new file mode 100644
index 0000000..569ee5b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/rv-restrict.C
@@ -0,0 +1,6 @@
+// PR c++/45401
+// { dg-options -std=c++0x }
+
+typedef int &__restrict restrictLvref;
+typedef restrictLvref &&rvrefToRestrictLvref;
+typedef restrictLvref rvrefToRestrictLvref;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-05-26 0:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-26 1:50 C++ PATCH for c++/45401 (losing __restrict on reference squashing) Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).