This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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(declval<pair<int&&,int&&>>().first) is int&& because
declval<pair<int&&,int&&>>().first is "an unparenthesized class member access",
which just reports how the member "first" is declared.

decltype((declval<pair<int&&,int&&>>().first)) is int& because
(declval<pair<int&&,int&&>>().first) is an lvalue, just like any other named
rvalue reference.

It's just like when you have int&&r;, 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(int&&r) { return r; }

should both give an error, and do with clang, but are silently accepted by gcc.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]