https://bugs.llvm.org/show_bug.cgi?id=47861
Bug ID: 47861
Summary: Lifetime of temporaries inconsistently extending when
optiimzations are enabled
Product: clang
Version: 11.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangb...@nondot.org
Reporter: ch...@chrissavoie.com
CC: blitzrak...@gmail.com, dgre...@apple.com,
erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
richard-l...@metafoo.co.uk
Godbolt example: https://godbolt.org/z/fssed1
The following code:
struct A {
__attribute__((noinline))
A(int i) : data(i) {}
A& operator+=(int i) { data += i; return *this; }
int data;
};
int main() {
A const& b = A(5) += 5;
A c(6);
return b.data + c.data; // 16 expected
}
Will return 16 when compiled without optimizations, 11 when compiled with
optimizations (-O2 or greater).
Browsing versions on godbolt it looks like the difference appeared between
versions 6.0.0 and 7.0.0.
I realize that this is generally undefined behavior, but the differences
between optimization levels caught me off guard. I'm not sure if there's either
a way to return to the pre-7 behavior or to make the non-optimized version more
obviously incorrect.
--
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