以下代码无法使用 Clang 13 和 MSVC v19.29 VS16.11 编译,但可以使用 GCC 11.2 成功编译。
template <typename...>
concept always_true = true;
template <typename T>
concept refable = always_true<T&>;
static_assert(refable<void>);
Run Code Online (Sandbox Code Playgroud)
铿锵13:
<source>:9:1: error: static_assert failed
static_assert(refable<void>);
^ ~~~~~~~~~~~~~
<source>:9:15: note: because 'void' does not satisfy 'refable'
static_assert(refable<void>);
^
<source>:7:32: note: because substituted constraint expression is ill-formed: cannot form a reference to 'void'
concept refable = always_true<T&>;
^
Run Code Online (Sandbox Code Playgroud)
MSVC v19.29 VS16.11:
<source>(9): error C2607: static assertion failed
Run Code Online (Sandbox Code Playgroud)
GCC这里错了吗?我期望refable<void>评估结果为 false,因为它void&在直接上下文中形成无效的 type( ) …