From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 6D2D73858D3C; Wed, 3 May 2023 04:30:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D2D73858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683088234; bh=pjC6Dkn1Uw6rIqACtW3qWtlS27DzZlAYE7LIoepmiXY=; h=From:To:Subject:Date:From; b=I3nYIiTwoao346OD/nD2SsgaYeJDx0rYHPLJredOU3ejbLOZg7u7itMZfhcuHpI19 h3ZblNH8Ujap+IWCtYXCjngfSymMzdoUQKywZrQbT8KfoI0JCngbnlF3fLJQaWkQM1 ih0AEebHusC9t7Hx/UQGaeLb8880Qv+uOPAiuu3g= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-418] c++: fix TTP level reduction cache X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/trunk X-Git-Oldrev: d7cb9720ed54687bd1135c5e6ef90776a9db0bd5 X-Git-Newrev: 0bc2a1dc327af9817163cc8df78b9f9be2ad0f90 Message-Id: <20230503043034.6D2D73858D3C@sourceware.org> Date: Wed, 3 May 2023 04:30:34 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0bc2a1dc327af9817163cc8df78b9f9be2ad0f90 commit r14-418-g0bc2a1dc327af9817163cc8df78b9f9be2ad0f90 Author: Jason Merrill Date: Tue Mar 14 15:16:46 2023 -0400 c++: fix TTP level reduction cache We try to cache the result of reduce_template_parm_level so that when we reduce the same parm multiple times we get the same result, but this wasn't working for template template parms because in that case TYPE is a TEMPLATE_TEMPLATE_PARM, and so same_type_p was false because of the same level mismatch that we're trying to adjust for. So in that case compare the template parms of the template template parms instead. The result can be seen in nontype12.C, where we previously gave three duplicate errors on line 7 and now give only one because subsequent substitutions use the cache. gcc/cp/ChangeLog: * pt.cc (reduce_template_parm_level): Fix comparison of template template parm to cached version. gcc/testsuite/ChangeLog: * g++.dg/template/nontype12.C: Check for duplicate error. Diff: --- gcc/cp/pt.cc | 7 ++++++- gcc/testsuite/g++.dg/template/nontype12.C | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 471fc20bc5b..5446b5058b7 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -4550,7 +4550,12 @@ reduce_template_parm_level (tree index, tree type, int levels, tree args, if (TEMPLATE_PARM_DESCENDANTS (index) == NULL_TREE || (TEMPLATE_PARM_LEVEL (TEMPLATE_PARM_DESCENDANTS (index)) != TEMPLATE_PARM_LEVEL (index) - levels) - || !same_type_p (type, TREE_TYPE (TEMPLATE_PARM_DESCENDANTS (index)))) + || !(TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM + ? (comp_template_parms + (DECL_TEMPLATE_PARMS (TYPE_NAME (type)), + DECL_TEMPLATE_PARMS (TEMPLATE_PARM_DECL + (TEMPLATE_PARM_DESCENDANTS (index))))) + : same_type_p (type, TREE_TYPE (TEMPLATE_PARM_DESCENDANTS (index))))) { tree orig_decl = TEMPLATE_PARM_DECL (index); diff --git a/gcc/testsuite/g++.dg/template/nontype12.C b/gcc/testsuite/g++.dg/template/nontype12.C index e37cf8f7646..6642ffd0a13 100644 --- a/gcc/testsuite/g++.dg/template/nontype12.C +++ b/gcc/testsuite/g++.dg/template/nontype12.C @@ -4,7 +4,8 @@ template struct A { template int foo(); // { dg-error "double" "" { target c++17_down } } - template class> int bar(); // { dg-error "double" "" { target c++17_down } } + template class> int bar(); // { dg-bogus {double.*C:7:[^\n]*double} } + // { dg-error "double" "" { target c++17_down } .-1 } template struct X; // { dg-error "double" "" { target c++17_down } } };