<html>
    <head>
      <base href="https://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 --- - cast-expression from lvalue to rvalue reference fails while reinterpret_cast for the same conversion works" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23802&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=nb5Vdgs6K51-TlURXvUKx2LfSpzHuOjM1t0I5a3hVyk&s=MCF43ku8COqfE8bpYZXxJm_gmSZveya6noEH6vLXJg0&e=">23802</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>cast-expression from lvalue to rvalue reference fails while reinterpret_cast for the same conversion works
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.6
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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++11
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>andrey.vul@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider the following example:

// begin a.cc
struct S {};
int x;
S&& y1 = (S&&)x;
S&& y2 = reinterpret_cast<S&&>(x);
S& z1 = (S&)x;
//end a.cc


The casts initializing y1 and y2 should behave the same but the cast-expression
gives the diagnostic:
    "error: cannot cast from lvalue of type 'int' to rvalue reference type 'S
&&'; types are not compatible"

The expression initializing z1 works as intended.

I conclude that reinterpret_cast is neglected as a candidate in a
cast-expression when the target is a rvalue reference, violating 5.4p4.4.

clang++ -v output:
clang version 3.6.1 (tags/RELEASE_361/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2
 "/usr/bin/x86_64-pc-linux-gnu-clang-3.6.1" -cc1 -triple x86_64-pc-linux-gnu
-emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name a.cc
-mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno
-masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array
-target-cpu x86-64 -target-linker-version 2.25 -v -dwarf-column-info
-resource-dir /usr/bin/../lib/clang/3.6.1 -internal-isystem
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/include/g++-v4 -internal-isystem
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/include/g++-v4/x86_64-pc-linux-gnu
-internal-isystem
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/include/g++-v4/backward
-internal-isystem /usr/local/include -internal-isystem
/usr/bin/../lib/clang/3.6.1/include -internal-externc-isystem /include
-internal-externc-isystem /usr/include -Wall -Wextra -std=c++11
-fdeprecated-macro -fdebug-compilation-dir /tmp -ferror-limit 19
-fmessage-length 132 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions
-fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/a-85edcb.o
-x c++ a.cc
clang -cc1 version 3.6.1 based upon LLVM 3.6.1 default target
x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/include/g++-v4
 /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/include/g++-v4/x86_64-pc-linux-gnu
 /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/include/g++-v4/backward
 /usr/bin/../lib/clang/3.6.1/include
 /usr/include
End of search list.
a.cc:3:10: error: cannot cast from lvalue of type 'int' to rvalue reference
type 'S &&'; types are not compatible
S&& y1 = (S&&)x;
         ^~~~~~
1 error generated.</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>