diff options
author | Patrick Palka <ppalka@redhat.com> | 2023-06-30 15:05:22 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2023-06-30 15:05:22 -0400 |
commit | db38b285ba61c5b888adc0d117177bfd774c1153 (patch) | |
tree | 2251b9186d95bde80480d2d1f5722e27f28c17bd /gcc/cp/cp-tree.h | |
parent | e050ce7c3adf71eedd5482c29cf54b827e026642 (diff) | |
download | gcc-db38b285ba61c5b888adc0d117177bfd774c1153.zip gcc-db38b285ba61c5b888adc0d117177bfd774c1153.tar.gz gcc-db38b285ba61c5b888adc0d117177bfd774c1153.tar.bz2 |
c++: fix up caching of level lowered ttps
Due to level/depth mismatches between the template parameters of a level
lowered ttp and the original ttp, the ttp comparison check added by
r14-418-g0bc2a1dc327af9 never actually holds outside of erroneous cases.
Moreover, it'd be good to also cache the overall TEMPLATE_TEMPLATE_PARM
instead of only the TEMPLATE_PARM_INDEX.
It's tricky to cache all level lowered ttps since the result of level
lowering may depend on more than just the depth of the arguments, e.g.
for TT in
template<class T>
struct A {
template<template<T> class TT> void f();
}
the substitution T=int yields a different level-lowered ttp than T=char.
But these kinds of ttps seem to be rare in practice, and "simple" ttps
that don't depend on outer template parameters are easy enough to cache
like so. Unfortunately, this means we're back to expecting a duplicate
error in nontype12.C again since the ttp in question isn't "simple" so
caching of the (erroneous) lowered ttp doesn't happen.
gcc/cp/ChangeLog:
* cp-tree.h (TEMPLATE_PARM_DESCENDANTS): Harden.
(TEMPLATE_TYPE_DESCENDANTS): Define.
(TEMPLATE_TEMPLATE_PARM_SIMPLE_P): Define.
* pt.cc (reduce_template_parm_level): Revert
r14-418-g0bc2a1dc327af9 change.
(process_template_parm): Set TEMPLATE_TEMPLATE_PARM_SIMPLE_P
appropriately.
(uses_outer_template_parms): Determine the outer depth of
a template template parm without relying on DECL_CONTEXT.
(tsubst) <case TEMPLATE_TEMPLATE_PARM>: Cache lowering a
simple template template parm. Consistently use 'code'.
gcc/testsuite/ChangeLog:
* g++.dg/template/nontype12.C: Refine and XFAIL the dg-bogus
duplicate diagnostic check.
Diffstat (limited to 'gcc/cp/cp-tree.h')
-rw-r--r-- | gcc/cp/cp-tree.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 2faf6fa..3de0e15 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -528,6 +528,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; 5: CLASS_TYPE_P (in RECORD_TYPE and UNION_TYPE) ENUM_FIXED_UNDERLYING_TYPE_P (in ENUMERAL_TYPE) AUTO_IS_DECLTYPE (in TEMPLATE_TYPE_PARM) + TEMPLATE_TEMPLATE_PARM_SIMPLE_P (in TEMPLATE_TEMPLATE_PARM) 6: TYPE_DEPENDENT_P_VALID Usage of DECL_LANG_FLAG_?: @@ -6013,7 +6014,7 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, TYPENAME_FLAG }; ((template_parm_index*)TEMPLATE_PARM_INDEX_CHECK (NODE)) #define TEMPLATE_PARM_IDX(NODE) (TEMPLATE_PARM_INDEX_CAST (NODE)->index) #define TEMPLATE_PARM_LEVEL(NODE) (TEMPLATE_PARM_INDEX_CAST (NODE)->level) -#define TEMPLATE_PARM_DESCENDANTS(NODE) (TREE_CHAIN (NODE)) +#define TEMPLATE_PARM_DESCENDANTS(NODE) (TREE_CHAIN (TEMPLATE_PARM_INDEX_CHECK (NODE))) #define TEMPLATE_PARM_ORIG_LEVEL(NODE) (TEMPLATE_PARM_INDEX_CAST (NODE)->orig_level) #define TEMPLATE_PARM_DECL(NODE) (TEMPLATE_PARM_INDEX_CAST (NODE)->decl) #define TEMPLATE_PARM_PARAMETER_PACK(NODE) \ @@ -6031,6 +6032,8 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, TYPENAME_FLAG }; (TEMPLATE_PARM_LEVEL (TEMPLATE_TYPE_PARM_INDEX (NODE))) #define TEMPLATE_TYPE_ORIG_LEVEL(NODE) \ (TEMPLATE_PARM_ORIG_LEVEL (TEMPLATE_TYPE_PARM_INDEX (NODE))) +#define TEMPLATE_TYPE_DESCENDANTS(NODE) \ + (TEMPLATE_PARM_DESCENDANTS (TEMPLATE_TYPE_PARM_INDEX (NODE))) #define TEMPLATE_TYPE_DECL(NODE) \ (TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (NODE))) #define TEMPLATE_TYPE_PARAMETER_PACK(NODE) \ @@ -6040,6 +6043,11 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, TYPENAME_FLAG }; #define CLASS_PLACEHOLDER_TEMPLATE(NODE) \ (DECL_INITIAL (TYPE_NAME (TEMPLATE_TYPE_PARM_CHECK (NODE)))) +/* True iff the template parameters of this TEMPLATE_TEMPLATE_PARM don't + use any outer template parameters. */ +#define TEMPLATE_TEMPLATE_PARM_SIMPLE_P(NODE) \ + (TYPE_LANG_FLAG_5 (TEMPLATE_TEMPLATE_PARM_CHECK (NODE))) + /* Contexts in which auto deduction occurs. These flags are used to control diagnostics in do_auto_deduction. */ |