[LLVMbugs] [Bug 22426] New: generic lambdas, decltype(auto), and rvalue references, oh my!

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Jan 31 17:00:36 PST 2015


            Bug ID: 22426
           Summary: generic lambdas, decltype(auto), and rvalue
                    references, oh my!
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: eniebler at boost.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Clang (trunk) rejects the following code (with -std=c++1y):

#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&&>>()));

The error I get is:

main.cpp:13:16: error: rvalue reference to type 'int' cannot
      bind to lvalue of type 'int'
        return ((decltype(p)&&)p).first;

There should *never* be an error when using decltype(auto). The compiler should
use the actual type of the return expression as the return type. It seems clang
is getting confused about the value category here.

I observe that X is an alias for int&& in the above code, and I feel that the
generic lambda is doing the same thing. Both the type of the expression in the
lambda and the return type of the lambda should also be int&&.

I also observe that if I replace decltype(auto) with
decltype(((decltype(p)&&)p).first), then the code compiles and Y is an alias
for int&&, which seems right to me.

For the record, gcc also gets this code wrong, but in a different way.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150201/3791ecce/attachment.html>

More information about the llvm-bugs mailing list