Regarding function f
, is the substituted constraint expression of the non-type template argument
of templated variable b
a valid constant expression? Which specific wording of the C++20 standard
either allows or forbids this?
struct s { static constexpr bool v = true; };
template<auto> inline constexpr bool b = true;
constexpr bool f(auto x) requires b<x.v> { return true; }
static_assert(f(s{})); // clang ok, gcc nope, msvc ok
The error message from GCC:
<source>:3:36: error: missing template arguments before '<' token
3 | constexpr bool f(auto x) requires b<x.v> { return true; }
| ^
<source>:3:36: error: expected initializer before '<' token
<source>:4:15: error: 'f' was not declared in this scope
4 | static_assert(f(s{}));
| ^
constexpr bool f(auto x) requires b<decltype(x)::v> { return true; }
is fine with all of them. And I don't understand why yours is ok for clang / msvc, but thats probably just my ignorance about c++20 – Dextrosinistral