From patchwork Thu Apr 25 16:22:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 239562 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id A37D52C00D1 for ; Fri, 26 Apr 2013 02:22:23 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=fAi7SpSmHEX3rJwbAXWfXOSRJIOJJP77o45NaQccoSY2WH qcY9zshMZAhrXed1xRjOTM3uUHaWKuMP4P0QC64OOtXTo0jRt7nJTsuxyU2k75e3 lnw+tq0mxmXXHmJfbYZU/Wgz/3gtUprhf52mPBMsfaMbCFg/L77vWsE1Y1DfY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=tlqgdpjGlJhrKR8LU70oRXb+alU=; b=A9Y6/pUqL9M5nbn9D6CH kDqR3oiQvFJ3IRN8AKcyjcbWmbA+DOoBog7bLvR2O5a3swx21eZPxw8+kgAz+OL3 etKr7/rpW4gCcwBISSwYQkkMsMlo+Pc2Mpr6OwNx2BGrWAxFvz0nRU/B8MbW4tOx v6lX5ppdxVYHVNaoW3QfZ5I= Received: (qmail 22817 invoked by alias); 25 Apr 2013 16:22:17 -0000 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 Received: (qmail 22807 invoked by uid 89); 25 Apr 2013 16:22:16 -0000 X-Spam-SWARE-Status: No, score=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 25 Apr 2013 16:22:16 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3PGMEuK023909 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 25 Apr 2013 12:22:15 -0400 Received: from [10.3.113.66] (ovpn-113-66.phx2.redhat.com [10.3.113.66]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3PGMEWk026517 for ; Thu, 25 Apr 2013 12:22:14 -0400 Message-ID: <51795835.2060601@redhat.com> Date: Thu, 25 Apr 2013 12:22:13 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:22.0) Gecko/20100101 Thunderbird/22.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/57064 (ref-qualifier and function returning rvalue ref) X-Virus-Found: No In the patch adding ref-qualifiers, I initially turned the 'this' argument back into a glvalue for the object with build_fold_indirect_ref. I was nervous about this being able to reliably reconstruct the original glvalue argument, so on the trunk I switched things to wait and take the address later. But that seemed risky for the branch, since it would affect the C++98 code path, so I left it off. This PR demonstrates that my initial nervousness was justified, so I've added a bit more code on the branch to handle this case. Tested x86_64-pc-linux-gnu, applying to 4.8. commit 5742904a95f4daaa0752bea6e1599e82197419b0 Author: Jason Merrill Date: Thu Apr 25 10:38:47 2013 -0400 PR c++/57064 * call.c (add_function_candidate): Strip ref-to-ptr conversion. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index f575dae..72c1dac 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -1959,6 +1959,10 @@ add_function_candidate (struct z_candidate **candidates, object parameter has reference type. */ bool rv = FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn)); parmtype = cp_build_reference_type (parmtype, rv); + if (TREE_CODE (arg) == CONVERT_EXPR + && TYPE_PTR_P (TREE_TYPE (arg))) + /* Strip conversion from reference to pointer. */ + arg = TREE_OPERAND (arg, 0); arg = build_fold_indirect_ref (arg); argtype = lvalue_type (arg); } diff --git a/gcc/testsuite/g++.dg/cpp0x/ref-qual9.C b/gcc/testsuite/g++.dg/cpp0x/ref-qual9.C new file mode 100644 index 0000000..cdb8d68 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/ref-qual9.C @@ -0,0 +1,14 @@ +// PR c++/57064 +// { dg-require-effective-target c++11 } + +template T&& move(T& t); + +struct A { + void p() &; + int p() &&; +}; + +void g(A &&a) +{ + int i = move(a).p(); +}