静态成员函数
b
对于s
的默认构造函数的requires子句是否应该可见? C++20 标准对所提供示例的合法性有何规定?
template<auto...>
struct s {
s() requires (s::b()) = default; // clang nope, gcc ok, msvc ok
static constexpr bool b()
{ return true; }
};
static_assert((s<>{}, true));
来自 Clang 的错误消息:
<source>:3:22: error: no member named 'b' in 's<...>'
3 | s() requires (s::b()) = default;
| ~~~^
<source>:7:15: error: static assertion expression is not an integral constant
expression
7 | static_assert((s<>{}, true));
| ^~~~~~~~~~~~~
<source>:7:16: note: non-constexpr constructor 's' cannot be used in a constant
expression
7 | static_assert((s<>{}, true));
| ^
<source>:3:5: note: declared here
3 | s() requires (s::b()) = default;
| ^