[LLVMbugs] [Bug 23802] New: cast-expression from lvalue to rvalue reference fails while reinterpret_cast for the same conversion works

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jun 9 12:41:27 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=23802

            Bug ID: 23802
           Summary: cast-expression from lvalue to rvalue reference fails
                    while reinterpret_cast for the same conversion works
           Product: clang
           Version: 3.6
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: andrey.vul at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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.

-- 
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/20150609/6bad44c2/attachment.html>


More information about the llvm-bugs mailing list