Given:
decltype(auto) f1()
{
int x = 0;
return x; // decltype(x) is int, so f1 returns int
}
decltype(auto) f2()
{
int x = 0;
return (x); // decltype((x)) is int&, so f2 returns int&
}
(Taken from Scott Meyer's Effective Modern C++).
Now, if I have found the correct paragraph, Section 7.1.5.2 Simple type specifiers [dcl.type.simple] of the C++ standard says:
If e is an id-expression or a class member access (5.2.5 [expr.ref]), decltype(e) is defined as the type of the entity named by e
and the example from that section is:
struct A { double x; }
const A* a = new A();
decltype((a->x)); // type is const double&
Now, I wonder why is the decltype((x))
is deduced to be int&
in the book.