Out of class definition of constrained member function

1 week ago 12
ARTICLE AD BOX

Having issues finding a syntax for hoisting constrained member function outside of its class that GCC is happy with. At this point I'm starting to think it's a GCC bug.

struct S { template<typename Idx> static constexpr bool some_check = true; template<typename Idx> requires some_check<Idx> void foo(Idx); }; template<typename Idx> requires S::template some_check<Idx> void S::foo(Idx idx) {}

Clang accepts it but not GCC:

$ g++ -std=c++20 test.cpp test.cpp:12:6: error: no declaration matches ‘void S::foo(Idx)’ 12 | void S::foo(Idx idx) {} | ^ test.cpp:7:10: note: candidate is: ‘template<class Idx> requires some_check<Idx> void S::foo(Idx)’ 7 | void foo(Idx); | ^~~ test.cpp:1:8: note: ‘struct S’ defined here 1 | struct S { | ^

Is this program well-formed?

Read Entire Article