[LLVMbugs] [Bug 21386] New: An rvalue-rerefence to a bit-field should be bound to a prvalue.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Oct 26 09:43:17 PDT 2014


            Bug ID: 21386
           Summary: An rvalue-rerefence to a bit-field should be bound to
                    a prvalue.
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kariya_mitsuru at hotmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The sample code below should output "1, 5, 6" but it outputs "2, 5, 42" (from
clang 3.3).

#include <iostream>

struct S {
    int i:3;
    int j:5;

int main()
    S s{1, 5};
    int&& rrj = static_cast<int&&>(s.j);
    std::cout << s.i << ", " << s.j << ", " << rrj << std::endl;
cf. http://melpon.org/wandbox/permlink/flLfdof281ToOQCL

Latest C++ standard (N4140) [expr.static.cast]/p.3 says that

If the value is not a bit-field, the result refers to the object or the
specified base class subobject thereof; otherwise, the lvalue-to-rvalue
conversion (4.1) is applied to the bit-field and the resulting prvalue is used
as the expression of the static_cast for the remainder of this section.

So, the rvalue-reference rrj should be initialized to a prvalue 5, s.i should
output 1, and rrj should output 6(even though "the answer to life the universe
and everything" is 42 ;)).

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/20141026/ba6946e4/attachment.html>

More information about the llvm-bugs mailing list