https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64892
Harald van Dijk harald at gigawatt dot nl changed:
What|Removed |Added
CC||harald at gigawatt dot nl
--- Comment #2 from Harald van Dijk harald at gigawatt dot nl ---
decltype(declvalpairint,int().first) is int because
declvalpairint,int().first is an unparenthesized class member access,
which just reports how the member first is declared.
decltype((declvalpairint,int().first)) is int because
(declvalpairint,int().first) is an lvalue, just like any other named
rvalue reference.
It's just like when you have intr;, decltype(r) is int, decltype((r)) is
int.
But as far as I can tell, the return type should be deduced as int, not as
int, because the expression in the return statement is not parenthesised.
N4140 says The type deduced for the variable or return type is determined as
described in 7.1.6.2, as though the initializer had been the operand of the
decltype. ([dcl.spec.auto]p7), without anything about adding parentheses like
you suggest. That should then cause an error, because an lvalue cannot be used
in a function returning an rvalue reference. And that's what clang does.
Reduced:
int i = 0;
decltype(auto) j = i;
or
decltype(auto) f(intr) { return r; }
should both give an error, and do with clang, but are silently accepted by gcc.