https://bugs.llvm.org/show_bug.cgi?id=49585
Bug ID: 49585
Summary: shared_ptr is released when used in for loop's
condition statement and continue is used in loop's
body
Product: clang
Version: 11.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected],
[email protected], [email protected]
Created attachment 24646
--> https://bugs.llvm.org/attachment.cgi?id=24646&action=edit
example program
Exactly as the title states, assuming that getData(i) returns a shared_ptr<foo>
that is stored in an underlying vector, el gets destroyed, effectively leaving
the vector in a corrupted state.
This occurs only in the presence of the continue, without it (e.g. when
printing inside the condition), everything works fine. Same if el in not
created in the condition check.
Reporting against v.11, but when fiddling with godbolt the bug seems to have
been there since forever and is replicable for C++11 and any newer standard.
void testLoop()
{
std::cout << __FUNCTION__ << " start" << '\n';
Holder h;
for (auto i = 0u; auto el = h.getData(i); ++i) {
if (i %2)
continue;
h.getData(i)->print();
}
std::cout << __FUNCTION__ << " end" << '\n';
}
It has initially been found for MSVC, if it is related:
https://stackoverflow.com/questions/66382186/possible-msvc-compiler-bug#
https://godbolt.org/z/T43n4e
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs