https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102728
Bug ID: 102728 Summary: requires statement fails to recognize lambda in unevaluated context Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: nickhuang99 at hotmail dot com Target Milestone: --- Consider that this snippet of code gives error of no matching specialization which is not rooted from lambda in function parameter, instead it is rooted from "requires" statement violation of lambda in unevaluated-context. The warning about no-return-statement in lambda within requirement exposes this is "requires" issue. #include <concepts> template<class T> concept IsLambda=requires(T t){ {t}->std::convertible_to<decltype(+[]{})>; }; template<IsLambda T> // OK if replace IsLambda with "class" void foo(T t){ t();} template<> void foo<decltype(+[]{})>(decltype(+[]{}) t){ t(); } Also, a proof that this is not lambda-in-function-parameter issue is that you can replace template parameter "IsLambda" in template function declaration with "class" and GCC works fine. Both clang and MSVC++ accepts above code. (https://www.godbolt.org/z/xhW7Tofao) <source>: In substitution of 'template<class T> requires IsLambda<T> void foo(T) [with T = void (*)()]': <source>:12:44: required from here <source>:5:40: warning: no return statement in function returning non-void [-Wreturn-type] 5 | {t}->std::convertible_to<decltype(+[]{})>; | ^~~~ <source>:12:6: error: template-id 'foo<void (*)()>' for 'void foo(void (*)())' does not match any template declaration 12 | void foo<decltype(+[]{})>(decltype(+[]{}) t){ | ^~~~~~~~~~~~~~~~~~~~ <source>:9:6: note: candidate is: 'template<class T> requires IsLambda<T> void foo(T)' 9 | void foo(T t){ t();} | ^~~