aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2023-03-14 15:16:46 -0400
committerJason Merrill <jason@redhat.com>2023-05-03 00:29:28 -0400
commit0bc2a1dc327af9817163cc8df78b9f9be2ad0f90 (patch)
tree0c048e90fa3b8164e13610be8ec36181e2203207 /gcc
parentd7cb9720ed54687bd1135c5e6ef90776a9db0bd5 (diff)
downloadgcc-0bc2a1dc327af9817163cc8df78b9f9be2ad0f90.zip
gcc-0bc2a1dc327af9817163cc8df78b9f9be2ad0f90.tar.gz
gcc-0bc2a1dc327af9817163cc8df78b9f9be2ad0f90.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/pt.cc7
-rw-r--r--gcc/testsuite/g++.dg/template/nontype12.C3
2 files changed, 8 insertions, 2 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 471fc20..5446b50 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 e37cf8f..6642ffd 100644
--- a/gcc/testsuite/g++.dg/template/nontype12.C
+++ b/gcc/testsuite/g++.dg/template/nontype12.C
@@ -4,7 +4,8 @@
template<typename T> struct A
{
template<T> int foo(); // { dg-error "double" "" { target c++17_down } }
- template<template<T> class> int bar(); // { dg-error "double" "" { target c++17_down } }
+ template<template<T> class> int bar(); // { dg-bogus {double.*C:7:[^\n]*double} }
+ // { dg-error "double" "" { target c++17_down } .-1 }
template<T> struct X; // { dg-error "double" "" { target c++17_down } }
};