From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 73BC93858D1E; Mon, 19 Dec 2022 20:39:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 73BC93858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671482383; bh=jbFA9y2paqQ6LALTGwMy3YZ4Q4rJyGPY4QSS0aJWpHo=; h=From:To:Subject:Date:From; b=oPBCckVHYa51medrAhQF6H1hfkGWyL2vSm4RCUq4FlLBVDNbwNIKwpMThpC5fW9H5 wtDCbxSmcuCpsT+xmK9BLbsFJ6hQXTpe1igKUiH1Rcwx4A4Wsz47s2Aymjp7Ej5cvj kimxlDMduN2E7vO6wNgAGuhqIBmaG5UQJP86cwMc= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4799] c++: ICE with concepts TS multiple auto deduction [PR101886] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: a39f454f0faf0734c7d040c9d8523f71be821000 X-Git-Newrev: a7c8036b26082d8da001e05596777c5f911590e1 Message-Id: <20221219203943.73BC93858D1E@sourceware.org> Date: Mon, 19 Dec 2022 20:39:43 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a7c8036b26082d8da001e05596777c5f911590e1 commit r13-4799-ga7c8036b26082d8da001e05596777c5f911590e1 Author: Patrick Palka Date: Mon Dec 19 14:59:43 2022 -0500 c++: ICE with concepts TS multiple auto deduction [PR101886] In extract_autos_r, we need to recompute TYPE_CANONICAL for the template type parameter after adjusting its index, otherwise we end up with a comptypes ICE for the below testcase. Note that such in-place type adjustment isn't generally safe to do since the type could be the TYPE_CANONICAL of another (unadjusted) type, but in this case the canonical auto (of some level and 0 index) is the first auto (of that level) that's created, and so any auto that we do end up adjusting can't be the canonical one. PR c++/101886 gcc/cp/ChangeLog: * pt.cc (extract_autos_r): Recompute TYPE_CANONICAL after adjusting the template type parameter's index. Simplify by using TEMPLATE_TYPE_IDX. Add some sanity checks. gcc/testsuite/ChangeLog: * g++.dg/concepts/auto5.C: New test. Diff: --- gcc/cp/pt.cc | 12 +++++++++--- gcc/testsuite/g++.dg/concepts/auto5.C | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 2516cca590e..2b7b3756b68 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -29243,18 +29243,24 @@ extract_autos_r (tree t, void *data) { /* All the autos were built with index 0; fix that up now. */ tree *p = hash.find_slot (t, INSERT); - unsigned idx; + int idx; if (*p) /* If this is a repeated constrained-type-specifier, use the index we chose before. */ - idx = TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (*p)); + idx = TEMPLATE_TYPE_IDX (*p); else { /* Otherwise this is new, so use the current count. */ *p = t; idx = hash.elements () - 1; } - TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (t)) = idx; + if (idx != TEMPLATE_TYPE_IDX (t)) + { + gcc_checking_assert (TEMPLATE_TYPE_IDX (t) == 0); + gcc_checking_assert (TYPE_CANONICAL (t) != t); + TEMPLATE_TYPE_IDX (t) = idx; + TYPE_CANONICAL (t) = canonical_type_parameter (t); + } } /* Always keep walking. */ diff --git a/gcc/testsuite/g++.dg/concepts/auto5.C b/gcc/testsuite/g++.dg/concepts/auto5.C new file mode 100644 index 00000000000..f1d653efd87 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/auto5.C @@ -0,0 +1,9 @@ +// PR c++/101886 +// { dg-do compile { target c++17_only } } +// { dg-options "-fconcepts-ts" } + +template struct A { }; + +A a; +A b1 = a; +A b2 = a;