给定类型A的定义:
struct A { int i; };
根据规范[expr.ref](我用n4618):
(if
E2
is non-reference,) …IfE1
is an lvalue,thenE1.E2
is an lvalue; otherwiseE1.E2
is an xvalue…
显然A {}.我是x值;
也给了[dcl.type.simple]:
(for
decltype(e)
,) — … ife
is an unparenthesized id-expression or an unparenthesized class member access…
— otherwise,ife
is an xvalue,decltype(e) is T&&,where T is the type ofe
因此,decltype((A {}.i))将产生int&&
然而,我尝试过GCC5.1和Clang3.9,它们产生int,而vs2015u3产生int&&哪个是对的?