From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 53315 invoked by alias); 2 Mar 2016 17:52:45 -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 53296 invoked by uid 89); 2 Mar 2016 17:52:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=Hx-languages-length:3622, 36920 X-HELO: mail-ob0-f181.google.com Received: from mail-ob0-f181.google.com (HELO mail-ob0-f181.google.com) (209.85.214.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 02 Mar 2016 17:52:41 +0000 Received: by mail-ob0-f181.google.com with SMTP id xx9so92373893obc.2 for ; Wed, 02 Mar 2016 09:52:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=wyXxVGXBxwRCY7PZdjfw94MoovdNtOGRrnaBFdOgJg8=; b=XtcZyETEt0JQaw5f8CdKqWmoIZhMqVUh+bw2JdR2w5mPB3TDtYjEBJ0jSR/PeLIZFc TAWf6xf/TO443Dlr9oTJ+HCNOBSme1GdWQX7UnyuCX4YpMIg0K9hq1XIRaZo9T3+xKV+ PEG3+F576ovbFmOXu5sxEuIBiEJwU41ZBuFHcPfy07zQvHveAvgWy3XLofs/qEb/VNCH 4T5+2209QwQAFXykyRCB9WJleT5k5MOqPyj6jy0e9C+eB4XPm4w5un0LUxDDd4cjf8aU qAj5Ou+zpcAYbSO1NNPLAR8OA9sCzsqZR3QVaJ7B2KByrRuBgm0KthjFZcBcL2ZATHYw adWA== X-Gm-Message-State: AD7BkJLp9MMRcUAfMFAoXga/IUdVqzi2akcMGR4t06Uun0W+GH4aQzVGjUWwhOaKigYcoNj0/IiJrYYZpby4kg== X-Received: by 10.60.80.70 with SMTP id p6mr22967942oex.75.1456941159652; Wed, 02 Mar 2016 09:52:39 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.29.226 with HTTP; Wed, 2 Mar 2016 09:52:19 -0800 (PST) In-Reply-To: References: <1454908753-15468-1-git-send-email-patrick@parcs.ath.cx> From: Patrick Palka Date: Wed, 02 Mar 2016 17:52:00 -0000 Message-ID: Subject: Re: [PATCH] Fix PR c++/66786 (ICE with nested lambdas in variable template) To: GCC Patches Cc: Jason Merrill , Patrick Palka Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2016-03/txt/msg00185.txt.bz2 On Mon, Feb 15, 2016 at 9:42 AM, Patrick Palka wrote: > On Mon, Feb 8, 2016 at 12:19 AM, Patrick Palka wrote: >> Here, we are calling template_class_depth on a FIELD_DECL corresponding >> to a lambda that is used inside variable template. template_class_depth >> however does not see that this FIELD_DECL is used inside a variable >> template binding because its chain of DECL_CONTEXTs does not include the >> corresponding VAR_DECL. So template_class_depth returns the wrong >> template nesting level which causes its callers to malfunction. In >> particular we strip a template argument level in >> tsubst_copy [FIELD_DECL] when we shouldn't have. >> >> This patch makes template_class_depth look at a lambda type's >> LAMBDA_TYPE_EXTRA_SCOPE field instead of its TYPE_CONTEXT, so that it >> can iterate into an enclosing variable template, if applicable. >> >> Tested on x86_64-pc-linux gnu, no new regressions. Also tested against >> Boost. Is this OK to commit? >> >> gcc/cp/ChangeLog: >> >> PR c++/66786 >> * pt.c (template_class_depth): Given a lambda type, iterate >> into its LAMBDA_TYPE_EXTRA_SCOPE field instead of its >> TYPE_CONTEXT. Given a VAR_DECL, iterate into its >> CP_DECL_CONTEXT. >> >> gcc/testsuite/ChangeLog: >> >> PR c++/66786 >> * g++.dg/cpp1y/var-templ48.C: New test. >> * g++.dg/cpp1y/var-templ49.C: New test. >> --- >> gcc/cp/pt.c | 12 ++++++++---- >> gcc/testsuite/g++.dg/cpp1y/var-templ48.C | 5 +++++ >> gcc/testsuite/g++.dg/cpp1y/var-templ49.C | 9 +++++++++ >> 3 files changed, 22 insertions(+), 4 deletions(-) >> create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ48.C >> create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ49.C >> >> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c >> index 4d405cf..5c344c1 100644 >> --- a/gcc/cp/pt.c >> +++ b/gcc/cp/pt.c >> @@ -369,16 +369,20 @@ template_class_depth (tree type) >> { >> int depth; >> >> - for (depth = 0; >> - type && TREE_CODE (type) != NAMESPACE_DECL; >> - type = (TREE_CODE (type) == FUNCTION_DECL) >> - ? CP_DECL_CONTEXT (type) : CP_TYPE_CONTEXT (type)) >> + for (depth = 0; type && TREE_CODE (type) != NAMESPACE_DECL; ) >> { >> tree tinfo = get_template_info (type); >> >> if (tinfo && PRIMARY_TEMPLATE_P (TI_TEMPLATE (tinfo)) >> && uses_template_parms (INNERMOST_TEMPLATE_ARGS (TI_ARGS (tinfo)))) >> ++depth; >> + >> + if (VAR_OR_FUNCTION_DECL_P (type)) >> + type = CP_DECL_CONTEXT (type); >> + else if (LAMBDA_TYPE_P (type)) >> + type = LAMBDA_TYPE_EXTRA_SCOPE (type); >> + else >> + type = CP_TYPE_CONTEXT (type); >> } >> >> return depth; >> diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ48.C b/gcc/testsuite/g++.dg/cpp1y/var-templ48.C >> new file mode 100644 >> index 0000000..f0c7693 >> --- /dev/null >> +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ48.C >> @@ -0,0 +1,5 @@ >> +// PR c++/66786 >> +// { dg-do compile { target c++14 } } >> + >> +template auto list = [](T... xs) { [=](auto f) { f(xs...); }; }; >> +int main() { list(0); } >> diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ49.C b/gcc/testsuite/g++.dg/cpp1y/var-templ49.C >> new file mode 100644 >> index 0000000..cd3f230 >> --- /dev/null >> +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ49.C >> @@ -0,0 +1,9 @@ >> +// PR c++/66786 >> +// { dg-do compile { target c++14 } } >> + >> +int f (int, bool); >> + >> +template >> +auto list = [](auto... xs) { return [=](auto f, auto... ys) { return f(xs..., ys...); }; }; >> + >> +const int &a = list(0, true)(f); >> -- >> 2.7.1.257.g925a48d >> > > Ping. Ping