public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Patrick Palka <patrick@parcs.ath.cx>
To: Jason Merrill <jason@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix PR c++/66786 (ICE with nested lambdas in variable template)
Date: Sun, 06 Mar 2016 14:30:00 -0000	[thread overview]
Message-ID: <CA+C-WL9B1Be6NdmAXXbzhsY4Zu=o_6yz-qpiM-NFbdQ+yBdRKw@mail.gmail.com> (raw)
In-Reply-To: <56DBD161.3010507@redhat.com>

On Sun, Mar 6, 2016 at 1:42 AM, Jason Merrill <jason@redhat.com> wrote:
> On 02/08/2016 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?
>
>
> This is breaking several lambda testcases with -fconcepts on;
> LAMBDA_TYPE_EXTRA_SCOPE can also be a FIELD_DECL or PARM_DECL.  Let's just
> check DECL_P.

Sorry about that.

In the case of LAMBDA_TYPE_EXTRA_SCOPE being a PARM_DECL, could there
be a chance that this PARM_DECL has a non-null DECL_LANG_SPECIFIC? If
so it looks like we could still later ICE in get_template_info (called
from template_class_depth) when we try to get at its
DECL_TEMPLATE_INFO, an accessor that cannot be used on PARM_DECLs.  So
I wonder if maybe get_template_info() should also be adjusted to
handle the case of being given a PARM_DECL which may have a non-null
DECL_LANG_SPECIFIC:

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 823e2f0..f68b1f6 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -330,7 +330,8 @@ get_template_info (const_tree t)
   if (!t || t == error_mark_node)
     return NULL;

-  if (TREE_CODE (t) == NAMESPACE_DECL)
+  if (TREE_CODE (t) == NAMESPACE_DECL
+      || TREE_CODE (t) == PARM_DECL)
     return NULL;

   if (DECL_P (t) && DECL_LANG_SPECIFIC (t))
@@ -378,7 +379,7 @@ template_class_depth (tree type)
          && uses_template_parms (INNERMOST_TEMPLATE_ARGS (TI_ARGS (tinfo))))
        ++depth;

-      if (VAR_OR_FUNCTION_DECL_P (type))
+      if (DECL_P (type))
        type = CP_DECL_CONTEXT (type);
       else if (LAMBDA_TYPE_P (type))
        type = LAMBDA_TYPE_EXTRA_SCOPE (type);

  reply	other threads:[~2016-03-06 14:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-08  5:19 Patrick Palka
2016-02-15 14:43 ` Patrick Palka
2016-03-02 17:52   ` Patrick Palka
2016-03-04 23:38 ` Jason Merrill
2016-03-06  6:42 ` Jason Merrill
2016-03-06 14:30   ` Patrick Palka [this message]
2016-03-07 14:08     ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+C-WL9B1Be6NdmAXXbzhsY4Zu=o_6yz-qpiM-NFbdQ+yBdRKw@mail.gmail.com' \
    --to=patrick@parcs.ath.cx \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).