c++: extend lookup_template_class shortcut [PR110122]
commit682d401a6ba723b2bf98779d056efc8ff2640178
authorPatrick Palka <ppalka@redhat.com>
Sun, 11 Jun 2023 15:09:16 +0000 (11 11:09 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sun, 11 Jun 2023 15:09:16 +0000 (11 11:09 -0400)
tree695beeda14eae14e0c91e4950fc366a15443c86a
parentecc96eb5d2a0e5dd93365ef76a58d7f754273934
c++: extend lookup_template_class shortcut [PR110122]

Here when substituting the injected class name A during regeneration of
the lambda, we find ourselves in lookup_template_class for A<V> with
V=_ZTAXtl3BarEE (i.e. the template parameter object for Foo{}).  The call
to coerce_template_parms within then undesirably tries to make a copy of
this class NTTP argument, which fails because Foo is not copyable.  But it
seems clear that this testcase shouldn't require copyability of Foo.

lookup_template_class has a shortcut for looking up the current class
scope, which would avoid the problematic coerce_template_parms call, but
the shortcut doesn't trigger because it only considers the innermost
class scope which in this case in the lambda type.  So this patch fixes
this by extending the lookup_template_class shortcut to consider outer
class scopes too (and skipping over lambda types since they are never
specialized from lookup_template_class).  We also need to avoid calling
coerce_template_parms when specializing a templated non-template nested
class for the first time (such as A::B in the testcase).  Coercion should
be unnecessary there because the innermost arguments belong to the context
and so should have already been coerced.

PR c++/110122

gcc/cp/ChangeLog:

* pt.cc (lookup_template_class): Extend shortcut for looking up the
current class scope to consider outer class scopes too, and use
current_nonlambda_class_type instead of current_class_type.  Only
call coerce_template_parms when specializing a primary template.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/nontype-class57.C: New test.
* g++.dg/cpp2a/nontype-class58.C: New test.
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp2a/nontype-class57.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/nontype-class58.C [new file with mode: 0644]