From patchwork Thu Nov 29 20:12:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 202820 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 0BBA62C0081 for ; Fri, 30 Nov 2012 07:12:34 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1354824756; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=hX1QemR NgtQ9XEgWs5RK+GXlvWw=; b=drRYMKkLZeNtZLb3AvFRsR4jmXo+36/r8cI/+OU hi9xhqQNP1AjHCfxpNHR1LaSuCNqxw/RgyE5O6hTjkm4YMKzYsjb8uLW6DN+skeP j3AUejIPxifBGJvz4cCGZjLzCkX37L/vlL5JQaW6I/cYXkuLLTImRVhcUNmhzu6H dlNU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=quUw6avYD9n9F0weneR7Vf023b1QWRcYrs1oSE4hVTeUwoDiQdVg6UNXOSfNQb eoE+0pda8L20QqdDakHurU30hlKdPp9ZtDuzr6qxPeof9d8UW0WNsRxjis7GQtWp VIs+1hI6xcwxUdHZKV4Lq00nXBiJ1H9LGyuiIgRUX8//I=; Received: (qmail 2726 invoked by alias); 29 Nov 2012 20:12:27 -0000 Received: (qmail 2712 invoked by uid 22791); 29 Nov 2012 20:12:26 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS 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, 29 Nov 2012 20:12:20 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qATKCK5Q005399 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 29 Nov 2012 15:12:20 -0500 Received: from [10.3.113.86] (ovpn-113-86.phx2.redhat.com [10.3.113.86]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qATKCJXp010082 for ; Thu, 29 Nov 2012 15:12:20 -0500 Message-ID: <50B7C1A3.8040204@redhat.com> Date: Thu, 29 Nov 2012 15:12:19 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121029 Thunderbird/16.0.2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/53137 ('this' capture in templates) 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 My earlier semi-fix for this issue failed to update LAMBDA_EXPR_THIS_CAPTURE to point to the proxy variable, so uses ended up with an unattached FIELD_DECL. Fixed thus. Tested x86_64-pc-linux-gnu, applying to trunk and 4.7. commit 73e140fd81aa10994184bb8edfe9cfafdc1499a9 Author: Jason Merrill Date: Thu Nov 29 11:37:05 2012 -0500 PR c++/53137 * pt.c (tsubst_expr) [DECL_EXPR]: Set LAMBDA_EXPR_THIS_CAPTURE here. (tsubst_copy_and_build) [LAMBDA_EXPR]: And clear it here. (instantiate_class_template_1): Not here. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 85c8e7c..ceac093 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -659,8 +659,9 @@ enum cp_lambda_default_capture_mode_type { #define LAMBDA_EXPR_CAPTURE_LIST(NODE) \ (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->capture_list) -/* During parsing of the lambda, the node in the capture-list that holds - the 'this' capture. */ +/* During parsing of the lambda-introducer, the node in the capture-list + that holds the 'this' capture. During parsing of the body, the + capture proxy for that node. */ #define LAMBDA_EXPR_THIS_CAPTURE(NODE) \ (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->this_capture) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index ecb013e..3bc0d64 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -8956,14 +8956,8 @@ instantiate_class_template_1 (tree type) tree decl = lambda_function (type); if (decl) { - tree lam = CLASSTYPE_LAMBDA_EXPR (type); - LAMBDA_EXPR_THIS_CAPTURE (lam) - = lookup_field_1 (type, get_identifier ("__this"), false); - instantiate_decl (decl, false, false); maybe_add_lambda_conv_op (type); - - LAMBDA_EXPR_THIS_CAPTURE (lam) = NULL_TREE; } else gcc_assert (errorcount); @@ -12728,6 +12722,12 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, else if (is_capture_proxy (DECL_EXPR_DECL (t))) { DECL_CONTEXT (decl) = current_function_decl; + if (DECL_NAME (decl) == this_identifier) + { + tree lam = DECL_CONTEXT (current_function_decl); + lam = CLASSTYPE_LAMBDA_EXPR (lam); + LAMBDA_EXPR_THIS_CAPTURE (lam) = decl; + } insert_capture_proxy (decl); } else if (DECL_IMPLICIT_TYPEDEF_P (t)) @@ -14313,6 +14313,7 @@ tsubst_copy_and_build (tree t, wait until after we finish instantiating the type. */ LAMBDA_EXPR_CAPTURE_LIST (r) = RECUR (LAMBDA_EXPR_CAPTURE_LIST (t)); + LAMBDA_EXPR_THIS_CAPTURE (r) = NULL_TREE; RETURN (build_lambda_object (r)); } diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this6.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this6.C new file mode 100644 index 0000000..acf4eaa --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this6.C @@ -0,0 +1,32 @@ +// PR c++/53137 +// { dg-options -std=c++11 } + +template +void getParent(STORE& tStore) +{ +} + +struct Store +{ + template + void updateChildCommon(CheckParentFunc c) + { + c(); + } + + template + int& getStore(); + + template + void updateChild(const T& obj) + { + updateChildCommon([this] () { getParent(getStore()); }); + } + + void update(int obj); +}; + +void Store::update(int obj) +{ + updateChild(obj); +}