c++: Fix return type deduction during satisfaction
authorPatrick Palka <ppalka@redhat.com>
Tue, 15 Dec 2020 17:10:26 +0000 (12:10 -0500)
committerPatrick Palka <ppalka@redhat.com>
Tue, 15 Dec 2020 17:10:26 +0000 (12:10 -0500)
commit35317db051b9ce3eff7d4ad6d31de026447314f3
tree60dd6e0c48a0a5dca0beb342108ce25762841bce
parent30c41abc41b1b415ebb42444ced6087c79b70f3a
c++: Fix return type deduction during satisfaction

During satisfaction that's entered through the three-parameter version
of satisfy_declaration_constraints, current_function_decl gets set to
the dependent DECL_TEMPLATE_RESULT for sake of access checking.  This
makes the predicate in_template_function return true during satisfaction
from this entrypoint, which in turn makes calls to mark_used exit early
before it does its full processing.  This leads to us accepting the
invalid testcase below due to mark_used never attempting to deduce the
return type of A::foo() and detecting failure thereof.

It seems wrong for in_template_function to be true during instantiation
or during satisfaction, so this patch makes in_template_function inspect
the less volatile cfun->decl instead of current_function_decl.

gcc/cp/ChangeLog:

* pt.c (in_template_function): Inspect cfun->decl instead of
current_function_decl.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-requires23.C: New test.
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp2a/concepts-requires23.C [new file with mode: 0644]