diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index e5f18d23ea06c26898dce76ad3b16ad0d785e98c..5100954dfdec7e16665b3555959e3a5d94511aae 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)
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires23.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires23.C
new file mode 100644
index 0000000000000000000000000000000000000000..e109beaac4f730ed6389f367f1e0bd2d2c2a22a4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires23.C
@@ -0,0 +1,9 @@
+// { dg-do compile { target c++20 } }
+
+// Verify f<A>'s associated constraints evaluate to false due
+// to return type deduction failure for A::foo().
+
+template <class T> concept fooable = requires { T::foo(0); };
+template <fooable T> int f ();
+struct A { static auto *foo(auto); };
+int a = f<A>(); // { dg-error "no match" }