小编wha*_*ned的帖子

当使用始终正确的概念来实现概念时,GCC 不同意 Clang 和 MSVC

以下代码无法使用 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( ) …

c++ language-lawyer c++20

16
推荐指数
1
解决办法
561
查看次数

标签 统计

c++ ×1

c++20 ×1

language-lawyer ×1