c++: excessive instantiation during CTAD [PR101174]
authorPatrick Palka <ppalka@redhat.com>
Wed, 23 Jun 2021 21:23:39 +0000 (17:23 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 23 Jun 2021 21:23:39 +0000 (17:23 -0400)
commit7da4eae3dcef6fd5d955eb2c80c453aa52368004
tree050c717c3758571ee7bf7c088325ef08291139d6
parentf72f71c52e0d48551c2a8d6a28c349a551fef905
c++: excessive instantiation during CTAD [PR101174]

We set DECL_CONTEXT on implicitly generated deduction guides so that
their access is consistent with that of the constructor.  But this
apparently leads to excessive instantiation in some cases, ultimately
because instantiation of a deduction guide should be independent of
instantiation of the resulting class specialization, but setting the
DECL_CONTEXT of the former to the latter breaks this independence.

To fix this, this patch makes push_access_scope handle artificial
deduction guides specifically rather than setting their DECL_CONTEXT
in build_deduction_guide.  We could alternatively make the class
befriend the guide via DECL_BEFRIENDING_CLASSES, but that wouldn't
be a complete fix and would break class-deduction-access3.C below
since friendship isn't transitive.

PR c++/101174

gcc/cp/ChangeLog:

* pt.c (push_access_scope): For artificial deduction guides,
set the access scope to that of the constructor.
(pop_access_scope): Likewise.
(build_deduction_guide): Don't set DECL_CONTEXT on the guide.

libstdc++-v3/ChangeLog:

* testsuite/23_containers/multiset/cons/deduction.cc:
Uncomment CTAD example that was rejected by this bug.
* testsuite/23_containers/set/cons/deduction.cc: Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/class-deduction-access3.C: New test.
* g++.dg/cpp1z/class-deduction91.C: New test.
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp1z/class-deduction-access3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1z/class-deduction91.C [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/multiset/cons/deduction.cc
libstdc++-v3/testsuite/23_containers/set/cons/deduction.cc