From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id BBC113858D37 for ; Thu, 27 Apr 2023 20:46:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BBC113858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682628376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RF7Vj9ao9CyxDhqaXKtBtU6m1mLGwzoVY1eGK/X7efo=; b=PVHYhb18K42k6R7jsBtmdXs4vMjBYzlFgYC2vxIkfWmf0howgcsJs+Sq+0YKxVKzblyCaL aJ9jmxdz7ytBiiiERieWwELWLmZNmPZq/2xLa/T19Gr/3KT8/SGWsfqC2HJ+5CZAUoXgdW uJFthhCkhP/v3ogcIYEwcCJmbCKk3K8= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-HbiLsGHhPZSYEM6GYbA9NQ-1; Thu, 27 Apr 2023 16:46:14 -0400 X-MC-Unique: HbiLsGHhPZSYEM6GYbA9NQ-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-751319bd93cso555263585a.0 for ; Thu, 27 Apr 2023 13:46:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682628374; x=1685220374; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RF7Vj9ao9CyxDhqaXKtBtU6m1mLGwzoVY1eGK/X7efo=; b=hGXiCX2r7ztwLx1qNuWyr4VYk+jFuN9gKpXmMvVKfJccmF7Bkv+nnpHk3YAyu0IHRn 6fcmwr7yOZ4YUhA+xdj/dQHpFV936b+1VstLZk0PjPMskkR5fum2PdCn8sQRiCqy9kFo 7omzU+O9hLDk/ZhWtOl69/iXHuLQTpR3MQfiJ0PPmalerdMrtj9MZTXICv1nz48QK4ix bhQd7fLIP//FqH7Of0K+/9aXhkichFOd0f4MLgc0o645WAPceG1CvMZU5P2pXznCgxZd Zi/et6lVwjZY87RAfP1aDVQgwNJiiw9F8r1oBmAgZp4BsH0AXBsI/Y3POeVXmNWBFboM 9GPw== X-Gm-Message-State: AC+VfDyXZsNpmHcsQf/vZ50+XcjyTTRnXMpjEfPFQHiLyW13aQ6343Zy lCq2ODgnmioXWvYws3TzmUh17P7H1/mis//t/C4wpwmdo9QYkMRjfl8IX8qpuGBjpvdB4hkK6yf VBNVPVy3t29wLf2b7RfxKg32H/HmIS0zZftdygGUGCHGXwo/YtqXNy8CuO6TaVkSqyTW66/DOdN s= X-Received: by 2002:a05:6214:48c:b0:5e9:48da:9938 with SMTP id pt12-20020a056214048c00b005e948da9938mr14102249qvb.11.1682628373996; Thu, 27 Apr 2023 13:46:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Ka1n/jIZfcBl5uPmTk8fB+bieinCYwJ2a2BDHqmcV8N5q29flBak6lg0MFXqHo11/iPDHJQ== X-Received: by 2002:a05:6214:48c:b0:5e9:48da:9938 with SMTP id pt12-20020a056214048c00b005e948da9938mr14102219qvb.11.1682628373639; Thu, 27 Apr 2023 13:46:13 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id i3-20020a0c9c83000000b005fe4a301350sm5650029qvf.48.2023.04.27.13.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 13:46:13 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: outer args for level-lowered ttp [PR109651] Date: Thu, 27 Apr 2023 16:46:10 -0400 Message-ID: <20230427204610.3403840-1-ppalka@redhat.com> X-Mailer: git-send-email 2.40.1.423.g2807bd2c10 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Now that with r14-11-g2245459c85a3f4 made us coerce the template arguments of a bound ttp again after level-lowering, this unfortunately causes a crash from coerce_template_args_for_ttp in the below testcase. During the level-lowering substitution T=int into the bound ttp TT as part of substitution into the lambda signature, current_template_parms is just U=U rather than the ideal TT=TT, U=U. And because we don't consistently set DECL_CONTEXT for level-lowered ttps (it's kind of a chicken of the egg problem in this case), we attempt to use current_template_parms to obtain the outer arguments during coerce_template_args_for_ttp. But the depth 1 of c_t_p current_template_parms is less than the depth 2 of the level-lowered TT, and we end up segfaulting from there. So for level-lowered ttps it seems we need to get the outer arguments a different way -- namely, we can look at the trailing parms of its DECL_TEMPLATE_PARMS. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/13? PR c++/109651 gcc/cp/ChangeLog: * pt.cc (coerce_template_args_for_ttp): For level-lowered ttps with DECL_CONTEXT not set, obtain the outer template arguments via its DECL_TEMPLATE_PARMS. gcc/testsuite/ChangeLog: * g++.dg/template/ttp37.C: New test. --- gcc/cp/pt.cc | 5 +++++ gcc/testsuite/g++.dg/template/ttp37.C | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/ttp37.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 678cb7930e3..bbde61061f6 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -7872,6 +7872,11 @@ coerce_template_args_for_ttp (tree templ, tree arglist, tree outer = DECL_CONTEXT (templ); if (outer) outer = generic_targs_for (outer); + else if (TEMPLATE_TYPE_LEVEL (TREE_TYPE (templ)) + != TEMPLATE_TYPE_ORIG_LEVEL (TREE_TYPE (templ))) + /* This is a level-lowered template template parameter, for which + we don't consistently set DECL_CONTEXT (FIXME). */ + outer = template_parms_to_args (TREE_CHAIN (DECL_TEMPLATE_PARMS (templ))); else if (current_template_parms) { /* This is an argument of the current template, so we haven't set diff --git a/gcc/testsuite/g++.dg/template/ttp37.C b/gcc/testsuite/g++.dg/template/ttp37.C new file mode 100644 index 00000000000..876e5b6232a --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ttp37.C @@ -0,0 +1,11 @@ +// PR c++/109651 +// { dg-do compile { target c++20 } } + +template +void f() { + []() { + [] class TT>(TT) { }; + }; +} + +template void f(); -- 2.40.1.423.g2807bd2c10