http://llvm.org/bugs/show_bug.cgi?id=22426

            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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to