[Bug c++/64892] C++1y: generic lambdas, decltype(auto), and rvalue references, oh my!

2015-02-01 Thread harald at gigawatt dot nl
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.


[Bug c++/64892] C++1y: generic lambdas, decltype(auto), and rvalue references, oh my!

2015-01-31 Thread eric.niebler at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64892

--- Comment #1 from Eric Niebler eric.niebler at gmail dot com ---
I think this is user error. I was confused between the difference between
decltype(x.y) and decltype((x.y)). It seems the decltype(auto) is semantically
the same as decltype((x.y)) in this case. From that perspective, gcc is begin
consistent.

As for why decltype((declvalpairint,int().first)) is int instead of
int, I'm guessing it's because of some subtlety of rvalue references that I
don't yet grasp. I'll leave this open on the off-chance that this really is a
bug, and on the off-change that someone will explain to me why it is the way it
is.

Sorry in advance if this is just noise.