【发布时间】:2021-12-17 17:38:48
【问题描述】:
以下代码使用 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>);
Clang 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&>;
^
MSVC v19.29 VS16.11:
<source>(9): error C2607: static assertion failed
GCC 错了吗?我希望 refable<void> 评估为 false,因为它在直接上下文中形成无效类型 (void&)。
【问题讨论】:
标签: c++ language-lawyer c++20