On 6/1/23 17:42, Patrick Palka wrote:
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 cache the overall TEMPLATE_TEMPLATE_PARM
instead of just the corresponding 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-lowerd 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 is
not "simple" so caching of the (erroneous) lowered ttp doesn't happen.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?  This reduces memory usage of range-v3's zip.cpp by 1%.

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: Expect a duplicate error again.
---
  gcc/cp/cp-tree.h                          | 10 +++++-
  gcc/cp/pt.cc                              | 37 +++++++++++++----------
  gcc/testsuite/g++.dg/template/nontype12.C |  3 +-
  3 files changed, 31 insertions(+), 19 deletions(-)

+++ b/gcc/testsuite/g++.dg/template/nontype12.C
@@ -4,8 +4,7 @@
  template<typename T> struct A
  {
    template<T> int foo();                        // { dg-error "double" "" { 
target c++17_down } }
-  template<template<T> class> int bar();        // { dg-bogus 
{double.*C:7:[^\n]*double} }

Let's xfail the duplicate error rather than remove the dg-bogus. OK with that change.

Jason

Reply via email to