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

            Bug ID: 42220
           Summary: rvalue bound to aggregate with base class fails to
                    bind base reference member to temporary
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++17
          Assignee: unassignedclangb...@nondot.org
          Reporter: davidfink...@gmail.com
                CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
                    llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk

The following code should bind to the two temporary Obj() and extend their
lifetimes to the lifetimes of the enclosing aggregate.

While the first case (a plain aggregate) succeeds,
the second case (a child aggregate) fails to bind to the temporary Obj(), and
DDDDDDDDDDDDDDDDDDDDDDDDDD is called too early.

The line that fails to bind in the second case is:
DerivedAgg&& x = DerivedAgg{Obj()};



void AAAAAAAAAAAAAAAAAAAAAAAAAA();
void BBBBBBBBBBBBBBBBBBBBBBBB();
void CCCCCCCCCCCCCCCCCCCCCCCCCC();
void DDDDDDDDDDDDDDDDDDDDDDDDDD();

void SEPERATOR();

struct Obj {
    inline ~Obj() {
        DDDDDDDDDDDDDDDDDDDDDDDDDD();
    }
};
struct Agg {
    Obj&& obj;
    ~Agg() {
        CCCCCCCCCCCCCCCCCCCCCCCCCC();
    }
};
struct DerivedAgg : Agg {
    ~DerivedAgg() {
        BBBBBBBBBBBBBBBBBBBBBBBB();
    }
};

int main() {
    {
        // works, Agg.obj ref binds to Obj(), x binds to Agg
        Agg&& x = Agg{Obj()};
        AAAAAAAAAAAAAAAAAAAAAAAAAA();
    }
    SEPERATOR();
    {
        // fails in clang
        // DerivedAgg.Agg.obj should bind to Obj()
        // x should bind to DerivedAgg
        DerivedAgg&& x = DerivedAgg{Obj()};
        AAAAAAAAAAAAAAAAAAAAAAAAAA();
    }
}





>From godbolt, clang (trunk), identical to output for clang 8.0.0:
main:                                   # @main
        push    rbx
        sub     rsp, 16
        call    AAAAAAAAAAAAAAAAAAAAAAAAAA()
        call    CCCCCCCCCCCCCCCCCCCCCCCCCC()
        call    DDDDDDDDDDDDDDDDDDDDDDDDDD()
        call    SEPERATOR()
        mov     rax, rsp
        mov     qword ptr [rsp + 8], rax
        call    DDDDDDDDDDDDDDDDDDDDDDDDDD()
        call    AAAAAAAAAAAAAAAAAAAAAAAAAA()
        call    BBBBBBBBBBBBBBBBBBBBBBBB()
        call    CCCCCCCCCCCCCCCCCCCCCCCCCC()
        xor     eax, eax
        add     rsp, 16
        pop     rbx
        ret


Compare to gcc 9.1, which gets it right (and MSVC even gets it right too)
main:
        push    rbp
        call    AAAAAAAAAAAAAAAAAAAAAAAAAA()
        call    CCCCCCCCCCCCCCCCCCCCCCCCCC()
        call    DDDDDDDDDDDDDDDDDDDDDDDDDD()
        call    SEPERATOR()
        call    AAAAAAAAAAAAAAAAAAAAAAAAAA()
        call    BBBBBBBBBBBBBBBBBBBBBBBB()
        call    CCCCCCCCCCCCCCCCCCCCCCCCCC()
        call    DDDDDDDDDDDDDDDDDDDDDDDDDD()
        xor     eax, eax
        pop     rbp
        ret

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to