From patchwork Thu Mar 28 18:14:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 232159 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 646A92C00A9 for ; Fri, 29 Mar 2013 05:14:38 +1100 (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=tJ76ckYbOYMmS9PaMWeN8gFboyQ7DU8MywvCDJLMcmW6ER uCeyZFDqHdVhaIK8NCwtfJvuWUWAmUcS8R+1teIkozxeIAp3QKH4dQxTuVM9Y1p3 5ekJzuJbtF+w/FPg4u5Oh/+zxVjtzhZrze+RdwiNHu565yAaj5g4Ea3b2b1MU= 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=qN9EsOKTf2Mdo84jkrenLlesR5U=; b=qokE+H2qKqHepldBEPoM yTAsd5ijS/g95VphyNe/xC+tVbikcanL4336yfGDDdVm7ygINu1h9IcImMynHlGc lVj1oPE3BfC5TG40xOEE64FM9rsB+u22huxmkm6cXV58UST4ggRCn2iFCiY24kNf tGVeS/A3z9Fk00YU3oumYrE= Received: (qmail 20244 invoked by alias); 28 Mar 2013 18:14:27 -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 20222 invoked by uid 89); 28 Mar 2013 18:14:20 -0000 X-Spam-SWARE-Status: No, score=-7.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_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, 28 Mar 2013 18:14:17 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2SIEGED003411 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 28 Mar 2013 14:14:16 -0400 Received: from [10.16.196.202] (wlan-196-202.bos.redhat.com [10.16.196.202]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2SIEEDF016145 for ; Thu, 28 Mar 2013 14:14:15 -0400 Message-ID: <51548876.4040006@redhat.com> Date: Thu, 28 Mar 2013 14:14:14 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/56701 (treating 'this' as an rvalue) X-Virus-Found: No When 'this' appears in an expression, it should be an rvalue rather than a const lvalue; in C++11, the distinction matters. The cp_build_indirect_ref change is to avoid building extra copies of *this due to this change. Tested x86_64-pc-linux-gnu, applying to trunk. commit a668cad5042d5e499b4d3c78e40505d22f061e3a Author: Jason Merrill Date: Wed Mar 27 16:04:00 2013 -0400 PR c++/56701 * semantics.c (finish_this_expr): 'this' is an rvalue. * typeck.c (cp_build_indirect_ref): Handle NOP_EXPR of 'this'. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index ad1c209..2fe2908 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2297,7 +2297,6 @@ finish_this_expr (void) result = lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type)); else result = current_class_ptr; - } else if (current_function_decl && DECL_STATIC_FUNCTION_P (current_function_decl)) @@ -2314,6 +2313,9 @@ finish_this_expr (void) result = error_mark_node; } + /* The keyword 'this' is a prvalue expression. */ + result = rvalue (result); + return result; } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index a0caa30..fedcc6d 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2843,7 +2843,11 @@ cp_build_indirect_ref (tree ptr, ref_operator errorstring, { tree pointer, type; - if (ptr == current_class_ptr) + if (ptr == current_class_ptr + || (TREE_CODE (ptr) == NOP_EXPR + && TREE_OPERAND (ptr, 0) == current_class_ptr + && (same_type_ignoring_top_level_qualifiers_p + (TREE_TYPE (ptr), TREE_TYPE (current_class_ptr))))) return current_class_ref; pointer = (TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-this.C b/gcc/testsuite/g++.dg/cpp0x/rv-this.C new file mode 100644 index 0000000..8064a51 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/rv-this.C @@ -0,0 +1,7 @@ +// PR c++/56701 +// { dg-require-effective-target c++11 } + +struct A +{ + void f(){ A*&& a = this; } +};