[llvm-bugs] [Bug 42220] New: rvalue bound to aggregate with base class fails to bind base reference member to temporary
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jun 10 16:37:08 PDT 2019
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: unassignedclangbugs at nondot.org
Reporter: davidfink314 at gmail.com
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190610/3d66b305/attachment.html>
More information about the llvm-bugs
mailing list