From patchwork Tue Jan 31 18:07:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 722131 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 3vCZ412rJfz9s65 for ; Wed, 1 Feb 2017 05:07:44 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="dFas16an"; 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=B88YBSjaJzKAUFRS8 NyGhQ6gAW/a5SvX5K7hzBK5nzJJEuCbLbKKMiPzPSCVF5CQaYQAfBdwtJkJ6f3Bh GM+pbh26K3EaE9gtV5VEidt3KgsOT84fd2Us/Xc2/glLX8unthfRYuDZkz/dm4rA zD1BC+q6myWCTdubx6a5r1F3Eg= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=AgHvFG9bi21wNL+4WqHVx+2 /owc=; b=dFas16an0rpFS2c3b3FCq2jZOUVS4UWiusO6urLv/tp24JHxJTzANvn GFNUxUKnwZ9zdFZqAKQCssYhKUCBzPZ1KIWFJeQ+APgf+lfP0Y/T6naDwpVKwKw9 sw5wnRTzuka/lahsibrag9YhkUB8zh0VFzR5vgjR/VDNFFuz1KbQ= Received: (qmail 45392 invoked by alias); 31 Jan 2017 18:07:35 -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 45378 invoked by uid 89); 31 Jan 2017 18:07:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.1 required=5.0 tests=BAYES_50, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=Foo, adams, Adams, nathanacmorg X-HELO: mail-yb0-f193.google.com Received: from mail-yb0-f193.google.com (HELO mail-yb0-f193.google.com) (209.85.213.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 31 Jan 2017 18:07:24 +0000 Received: by mail-yb0-f193.google.com with SMTP id w194so30750659ybe.1 for ; Tue, 31 Jan 2017 10:07:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:cc:from:message-id :date:user-agent:mime-version:in-reply-to; bh=iF+TEYFeTbOCIw0UBrKZZ17RkoyhW5YG/QKqQVcJ6Iw=; b=Si6MRwsZrvw2/37c2xaBjQsHvgxoqUafFzvSldL7utJgkU+sLdtX9G2z8XLpiK3PUx UtAYN9p075SCevNeBoMG45WzZYFyNp0jM0sQeOXsWbv3efZZdQ41OJLRujRYL0Yraohc Xt6vnm1/f304abblnJplcv5weQ6Y8FDAzlkl6ov8R68XONLnCstgMPoLaA9R1mCzXlR/ 1FLWRTIC42hynMGcE/bP9K1hY5n1zr24PvxUJ5fX6odbmj2oflGn7kkP0Del1q19rmsI GKIyiU8TXQ5f5cDnL/P0UPBkoqoa2Zb/afqrp8LWWIdCc1sZnv6BJblFg3J91YFoNI/f wDew== X-Gm-Message-State: AIkVDXI2sRSpQrq7T1UfhDfbdNqIhOTBNK/U64fnjPXHCZC+LDJf55nIBZwhTac3RArgAQ== X-Received: by 10.129.97.10 with SMTP id v10mr21197247ywb.216.1485886042357; Tue, 31 Jan 2017 10:07:22 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::9:5fde]) by smtp.googlemail.com with ESMTPSA id x26sm9325573ywj.42.2017.01.31.10.07.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Jan 2017 10:07:21 -0800 (PST) Subject: Re: [C++ PATCH] pr 67273 & 79253 lambdas, warnings & ICEs To: Jason Merrill References: <6b669076-bc73-4ddb-f4fa-0647906a6965@acm.org> Cc: GCC Patches From: Nathan Sidwell Message-ID: <72e48af9-5af0-506e-3598-27e39ba38e2e@acm.org> Date: Tue, 31 Jan 2017 13:07:20 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: On 01/31/2017 10:04 AM, Jason Merrill wrote: > Agreed. As I was suggesting in response to one of Adam's patches, I > think we need to defer creating the closure until f is instantiated; > at that point we can resolve all names from f and so we should be able > to always push to top when instantiating the lambda. Yup. > Perhaps > > if (!fn_context || fn_context != current_function_decl) That works fine, thanks. It also makes it clearer that 'nested' must be true if !push_to_top (but not vice-versa), which allowed a little more simplification. Committed the attached to trunk. nathan 2017-01-31 Nathan Sidwell PR c++/67273 PR c++/79253 * pt.c: (instantiate_decl): Push to top level when current function scope doesn't match. Only push lmabda scope stack when pushing to top. PR c++/67273 PR c++/79253 * g++.dg/cpp1y/pr67273.C: New. * g++.dg/cpp1y/pr79253.C: New. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 245066) +++ cp/pt.c (working copy) @@ -22666,20 +22666,21 @@ instantiate_decl (tree d, bool defer_ok, goto out; } - bool nested; + bool push_to_top, nested; tree fn_context; fn_context = decl_function_context (d); - nested = (current_function_decl != NULL_TREE); + nested = current_function_decl != NULL_TREE; + push_to_top = !(nested && fn_context == current_function_decl); + vec omp_privatization_save; if (nested) save_omp_privatization_clauses (omp_privatization_save); - if (!fn_context) + if (push_to_top) push_to_top_level (); else { - if (nested) - push_function_context (); + push_function_context (); cp_unevaluated_operand = 0; c_inhibit_evaluation_warnings = 0; } @@ -22756,7 +22757,7 @@ instantiate_decl (tree d, bool defer_ok, block = push_stmt_list (); else { - if (LAMBDA_FUNCTION_P (d)) + if (push_to_top && LAMBDA_FUNCTION_P (d)) { /* When instantiating a lambda's templated function operator, we need to push the non-lambda class scope @@ -22849,9 +22850,9 @@ instantiate_decl (tree d, bool defer_ok, /* We're not deferring instantiation any more. */ TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (d)) = 0; - if (!fn_context) + if (push_to_top) pop_from_top_level (); - else if (nested) + else pop_function_context (); if (nested) Index: testsuite/g++.dg/cpp1y/pr67273.C =================================================================== --- testsuite/g++.dg/cpp1y/pr67273.C (revision 0) +++ testsuite/g++.dg/cpp1y/pr67273.C (working copy) @@ -0,0 +1,16 @@ +// { dg-do compile { target c++14 } } +// { dg-additional-options "-Wshadow" } + +// pr67273 bogus warning about shadowing. + + +template void Foo (T &&lambda) +{ + int ARG = 2; + lambda (1); +} + +void Baz () +{ + Foo ([] (auto &&ARG) {}); +} Index: testsuite/g++.dg/cpp1y/pr79253.C =================================================================== --- testsuite/g++.dg/cpp1y/pr79253.C (revision 0) +++ testsuite/g++.dg/cpp1y/pr79253.C (working copy) @@ -0,0 +1,33 @@ +// { dg-do compile { target c++14 } } +// PR 79253 ICE instantiating lambda body. + +template struct A; +template > class B {}; +template void foo (U, V) { T (0, 0); } +struct C {}; +template