diff options
author | Patrick Palka <ppalka@redhat.com> | 2020-12-15 12:10:26 -0500 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2020-12-15 12:10:26 -0500 |
commit | 35317db051b9ce3eff7d4ad6d31de026447314f3 (patch) | |
tree | 60dd6e0c48a0a5dca0beb342108ce25762841bce /gcc/cp | |
parent | 30c41abc41b1b415ebb42444ced6087c79b70f3a (diff) | |
download | gcc-35317db051b9ce3eff7d4ad6d31de026447314f3.zip gcc-35317db051b9ce3eff7d4ad6d31de026447314f3.tar.gz gcc-35317db051b9ce3eff7d4ad6d31de026447314f3.tar.bz2 |
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.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/pt.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e5f18d2..5100954 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10805,14 +10805,16 @@ uses_template_parms (tree t) return dependent_p; } -/* Returns true iff current_function_decl is an incompletely instantiated +/* Returns true iff we're processing an incompletely instantiated function template. Useful instead of processing_template_decl because the latter is set to 0 during instantiate_non_dependent_expr. */ bool in_template_function (void) { - tree fn = current_function_decl; + /* Inspect the less volatile cfun->decl instead of current_function_decl; + the latter might get set for e.g. access checking during satisfaction. */ + tree fn = cfun ? cfun->decl : NULL_TREE; bool ret; ++processing_template_decl; ret = (fn && DECL_LANG_SPECIFIC (fn) |