public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64892] New: C++1y: generic lambdas, decltype(auto), and rvalue references, oh my!
@ 2015-02-01  1:10 eric.niebler at gmail dot com
  2015-02-01  5:37 ` [Bug c++/64892] " eric.niebler at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: eric.niebler at gmail dot com @ 2015-02-01  1:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64892

            Bug ID: 64892
           Summary: C++1y: generic lambdas, decltype(auto), and rvalue
                    references, oh my!
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eric.niebler at gmail dot com

In the following code, gcc seems to be getting the value category wrong for the
return type of the generic lambda:

#include <utility>

int main()
{
    using std::pair;
    using std::declval;
    using X = decltype(declval<pair<int&&,int&&>>().first);
    auto f = [](auto && p) -> decltype(auto) //((decltype(p)&&)p).first)
    {
        return ((decltype(p)&&)p).first;
    };
    using Y = decltype(f(declval<pair<int&&,int&&>>()));
}

In this code, Y becomes an alias for int&. I believe it should be int&&. X is
an alias for int&&, and I think it's doing the same thing. Also, if I replace
the decltype(auto) with decltype(((decltype(p)&&)p).first) -- which is
*exactly* the return expression -- Y becomes an alias for int&&. Seems fishy to
me.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/64892] C++1y: generic lambdas, decltype(auto), and rvalue references, oh my!
  2015-02-01  1:10 [Bug c++/64892] New: C++1y: generic lambdas, decltype(auto), and rvalue references, oh my! eric.niebler at gmail dot com
@ 2015-02-01  5:37 ` eric.niebler at gmail dot com
  2015-02-01 22:37 ` harald at gigawatt dot nl
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: eric.niebler at gmail dot com @ 2015-02-01  5:37 UTC (permalink / raw)
  To: gcc-bugs

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((declval<pair<int&&,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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/64892] C++1y: generic lambdas, decltype(auto), and rvalue references, oh my!
  2015-02-01  1:10 [Bug c++/64892] New: C++1y: generic lambdas, decltype(auto), and rvalue references, oh my! eric.niebler at gmail dot com
  2015-02-01  5:37 ` [Bug c++/64892] " eric.niebler at gmail dot com
@ 2015-02-01 22:37 ` harald at gigawatt dot nl
  2015-03-05 12:19 ` [Bug c++/64892] [C++14] " redi at gcc dot gnu.org
  2020-11-05 21:38 ` mpolacek at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: harald at gigawatt dot nl @ 2015-02-01 22:37 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/64892] [C++14] generic lambdas, decltype(auto), and rvalue references, oh my!
  2015-02-01  1:10 [Bug c++/64892] New: C++1y: generic lambdas, decltype(auto), and rvalue references, oh my! eric.niebler at gmail dot com
  2015-02-01  5:37 ` [Bug c++/64892] " eric.niebler at gmail dot com
  2015-02-01 22:37 ` harald at gigawatt dot nl
@ 2015-03-05 12:19 ` redi at gcc dot gnu.org
  2020-11-05 21:38 ` mpolacek at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2015-03-05 12:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64892

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-03-05
            Summary|C++1y: generic lambdas,     |[C++14] generic lambdas,
                   |decltype(auto), and rvalue  |decltype(auto), and rvalue
                   |references, oh my!          |references, oh my!
     Ever confirmed|0                           |1

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Harald van Dijk from comment #2)
> 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.

Confirmed. EDG rejects them both too.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/64892] [C++14] generic lambdas, decltype(auto), and rvalue references, oh my!
  2015-02-01  1:10 [Bug c++/64892] New: C++1y: generic lambdas, decltype(auto), and rvalue references, oh my! eric.niebler at gmail dot com
                   ` (2 preceding siblings ...)
  2015-03-05 12:19 ` [Bug c++/64892] [C++14] " redi at gcc dot gnu.org
@ 2020-11-05 21:38 ` mpolacek at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-11-05 21:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64892

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Now fixed via PR78209.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-05 21:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-01  1:10 [Bug c++/64892] New: C++1y: generic lambdas, decltype(auto), and rvalue references, oh my! eric.niebler at gmail dot com
2015-02-01  5:37 ` [Bug c++/64892] " eric.niebler at gmail dot com
2015-02-01 22:37 ` harald at gigawatt dot nl
2015-03-05 12:19 ` [Bug c++/64892] [C++14] " redi at gcc dot gnu.org
2020-11-05 21:38 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).