<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - generic lambdas, decltype(auto), and rvalue references, oh my!"
   href="http://llvm.org/bugs/show_bug.cgi?id=22426">22426</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>generic lambdas, decltype(auto), and rvalue references, oh my!
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++14
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>eniebler@boost.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>