From patchwork Fri Apr 10 03:31:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Butcher X-Patchwork-Id: 460963 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 56934140276 for ; Tue, 14 Apr 2015 08:37:50 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=hmVW+AMN; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=J2Lc1ID1j/fuSv5sXLuUuke2MhBTo4nN+8UOqs4bd4UbEy6CzAYUE aMxSsb+26USYbHz+TyYLArBQ5wX2hEX4CYned5n/5y2ievHoh+Yr/beQqXY7+RGD dsnml+LbbBp/iaLb/N1T0rxjjOb1nw5sDJ8VYOmAVn3lF59tT2jWEg= 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:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=0VlyFnMKqWNUo8rILC2gdwIYL4E=; b=hmVW+AMNcr8GwN7Y19dU hNqDsENyJBLJIpzHYNQKPIbkpWmQdNIak81D7cpwsQ4v78Sk+SobSUhpY4m5rMN/ NTE9rgsgUUL2xCgXIv4929ku+xUgUTvgyqcypFcJT5wC/To2z7SvQ18YN5RnBBCY 1pCDX/gFphWgTgOt9qxVXnM= 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-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 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: Fri, 10 Apr 2015 04:31:33 +0100 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> 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); +}