decltype(1, t) 应该是左值引用吗? (编译器不同意)

Should decltype(1, t) be an l-value reference? (Compilers disagree)

最小代码:

int t;
static_assert(is_same_v<decltype(1, t), int&>);

以上代码在 g++ 和 clang++ 中编译但在 MSVC 中失败。 MSVC 似乎认为:

int t;
static_assert(is_same_v<decltype(1, t), int>);

标准规定了哪一项?对于 SFINAE,我非常依赖这种模式。

Gcc 和 Clang 是正确的。 1, tcomma expression,

The type, value, and value category of the result of the comma expression are exactly the type, value, and value category of the second operand, E2.

第二个操作数,即t是一个左值,那么decltype将导致T&

If the argument is any other expression of type T, and

  • if the value category of expression is lvalue, then decltype yields T&;

根据标准,[expr.comma]/1

(强调我的)

The type and value of the result are the type and value of the right operand; the result is of the same value category as its right operand,

[dcl.type.decltype]/1.5

otherwise, if e is an lvalue, decltype(e) is T&, where T is the type of e;

顺便说一句:我尝试使用 MSVC here 并使用 Gcc 和 Clang 得到了相同的结果。