From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 55055 invoked by alias); 13 Apr 2015 22:37:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 55032 invoked by uid 89); 13 Apr 2015 22:37:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KAM_COUK,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-wi0-f173.google.com Received: from mail-wi0-f173.google.com (HELO mail-wi0-f173.google.com) (209.85.212.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 13 Apr 2015 22:37:26 +0000 Received: by widdi4 with SMTP id di4so91230784wid.0 for ; Mon, 13 Apr 2015 15:37:23 -0700 (PDT) X-Received: by 10.180.96.196 with SMTP id du4mr25651615wib.77.1428964643652; Mon, 13 Apr 2015 15:37:23 -0700 (PDT) Received: from xtorus.lan (munkyhouse.force9.co.uk. [84.92.42.80]) by mx.google.com with ESMTPSA id vq9sm13322284wjc.6.2015.04.13.15.37.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Apr 2015 15:37:22 -0700 (PDT) From: Adam Butcher To: Jason Merrill Cc: gcc-patches , Adam Butcher Subject: [PATCH 1/2] PR c++/61636 * cp/parser.c (cp_parser_postfix_expression): Resolve default captured 'this' early for generic lambdas. Date: Mon, 13 Apr 2015 22:37:00 -0000 Message-Id: <1428636694-6767-2-git-send-email-adam@jessamine.co.uk> In-Reply-To: <1428636694-6767-1-git-send-email-adam@jessamine.co.uk> References: <1428636694-6767-1-git-send-email-adam@jessamine.co.uk> X-SW-Source: 2015-04/txt/msg00619.txt.bz2 PR c++/61636 * g++.dg/cpp1y/pr61636.C: New test. --- gcc/cp/parser.c | 16 ++++++++++++++++ gcc/testsuite/g++.dg/cpp1y/pr61636.C | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1y/pr61636.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 4d6b479..ac91976 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -6321,6 +6321,22 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p, tree instance = TREE_OPERAND (postfix_expression, 0); tree fn = TREE_OPERAND (postfix_expression, 1); + /* For generic lambdas, resolve default captured 'this' now. */ + if (processing_template_decl + && is_dummy_object (instance) + && current_class_type + && CLASSTYPE_LAMBDA_EXPR (current_class_type)) + if (tree callop = lambda_function (current_class_type)) + if (DECL_TEMPLATE_INFO (callop) + && (DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (callop)) + == callop) + && TREE_TYPE (instance) != current_class_type + && DERIVED_FROM_P (TREE_TYPE (instance), + current_nonlambda_class_type ())) + TREE_OPERAND (postfix_expression, 0) + = instance + = maybe_resolve_dummy (instance, true); + if (processing_template_decl && (type_dependent_expression_p (instance) || (!BASELINK_P (fn) diff --git a/gcc/testsuite/g++.dg/cpp1y/pr61636.C b/gcc/testsuite/g++.dg/cpp1y/pr61636.C new file mode 100644 index 0000000..5694675 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/pr61636.C @@ -0,0 +1,19 @@ +// PR c++/61636 +// { dg-do compile { target c++1y } } + +struct X +{ + void f(int) {} + + auto defer_f() + { + return [&] (auto x) { + return f(x); + }; + } +}; + +int main() +{ + X().defer_f()(2); +} -- 2.3.5