]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: bad pending_template recursion
authorJason Merrill <jason@redhat.com>
Fri, 18 Apr 2025 22:00:34 +0000 (18:00 -0400)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 25 Apr 2025 10:47:47 +0000 (11:47 +0100)
commit8acea9ffa82ed84bbf15d75b9dd034b2bb82724e
treefe340a61f4b9b3f7eb594440fc21ba7ab42ca765
parent901900bc37566c59b4eb62c1427f3150b800d8a0
c++: bad pending_template recursion

limit_bad_template_recursion currently avoids immediate instantiation of
templates from uses in an already ill-formed instantiation, but we still can
get unnecessary recursive instantiation in pending_templates if the
instantiation was queued before the error.

Initially this regressed several libstdc++ tests which seemed to rely on a
static_assert in a function called from another that is separately ill-formed.
For instance, in the 48101_neg.cc tests, we first got an error in find(), then
later instantiate _S_key() (called from find) and got the static_assert error
from there. r16-131-g876d1a22dfaf87 and r16-132-g901900bc37566c changed
the library code (and tests) to make the expected static_assert errors
happen earlier.

gcc/cp/ChangeLog:

* cp-tree.h (struct tinst_level): Add had_errors bit.
* pt.cc (push_tinst_level_loc): Clear it.
(pop_tinst_level): Set it.
(reopen_tinst_level): Check it.
(instantiate_pending_templates): Call limit_bad_template_recursion.

gcc/testsuite/ChangeLog:

* g++.dg/template/recurse5.C: New test.
gcc/cp/cp-tree.h
gcc/cp/pt.cc
gcc/testsuite/g++.dg/template/recurse5.C [new file with mode: 0644]