From patchwork Thu May 26 00:16:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 97474 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6200BB6F94 for ; Thu, 26 May 2011 10:16:41 +1000 (EST) Received: (qmail 22572 invoked by alias); 26 May 2011 00:16:32 -0000 Received: (qmail 22547 invoked by uid 22791); 26 May 2011 00:16:21 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 26 May 2011 00:16:01 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4Q0G1rx030991 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 25 May 2011 20:16:01 -0400 Received: from [127.0.0.1] (ovpn-113-23.phx2.redhat.com [10.3.113.23]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4Q0G09T013413 for ; Wed, 25 May 2011 20:16:01 -0400 Message-ID: <4DDD9BC0.9060702@redhat.com> Date: Wed, 25 May 2011 20:16:00 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/45401 (losing __restrict on reference squashing) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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. commit abb9429bb160d33b268bb45b9538ba83d920b0f2 Author: Jason Merrill 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;