<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - shared_ptr is released when used in for loop's condition statement and continue is used in loop's body"
href="https://bugs.llvm.org/show_bug.cgi?id=49585">49585</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>shared_ptr is released when used in for loop's condition statement and continue is used in loop's body
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>11.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ammiera@hotmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=24646" name="attach_24646" title="example program">attachment 24646</a> <a href="attachment.cgi?id=24646&action=edit" title="example program">[details]</a></span>
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:
<a href="https://stackoverflow.com/questions/66382186/possible-msvc-compiler-bug">https://stackoverflow.com/questions/66382186/possible-msvc-compiler-bug</a>#
<a href="https://godbolt.org/z/T43n4e">https://godbolt.org/z/T43n4e</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>