<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><span class="vcard"><a class="email" href="mailto:denik@google.com" title="Denis Nikitin <denik@google.com>"> <span class="fn">Denis Nikitin</span></a>
</span> changed
<a class="bz_bug_link
bz_status_REOPENED "
title="REOPENED - Warn about accidental coping of data in range based for"
href="https://bugs.llvm.org/show_bug.cgi?id=32823">bug 32823</a>
<br>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>What</th>
<th>Removed</th>
<th>Added</th>
</tr>
<tr>
<td style="text-align:right;">CC</td>
<td>
</td>
<td>denik@google.com
</td>
</tr>
<tr>
<td style="text-align:right;">Status</td>
<td>RESOLVED
</td>
<td>REOPENED
</td>
</tr>
<tr>
<td style="text-align:right;">Resolution</td>
<td>FIXED
</td>
<td>---
</td>
</tr></table>
<p>
<div>
<b><a class="bz_bug_link
bz_status_REOPENED "
title="REOPENED - Warn about accidental coping of data in range based for"
href="https://bugs.llvm.org/show_bug.cgi?id=32823#c4">Comment # 4</a>
on <a class="bz_bug_link
bz_status_REOPENED "
title="REOPENED - Warn about accidental coping of data in range based for"
href="https://bugs.llvm.org/show_bug.cgi?id=32823">bug 32823</a>
from <span class="vcard"><a class="email" href="mailto:denik@google.com" title="Denis Nikitin <denik@google.com>"> <span class="fn">Denis Nikitin</span></a>
</span></b>
<pre>We are hitting the warning in template code with bool and loop like this: "for
(const auto& element : value)" where element is bool from template. But not
always.
When it is bool the warning triggers:
error: loop variable 'element' is always a copy because the range of type
'const std::vector<bool, allocator<bool> >' does not return a reference
[-Werror,-Wrange-loop-analysis]
However, the template type can also use non-bools and if I remove the reference
I hit alternative case where the warning complains about copy operation of
reference types:
error: loop variable 'element' of type 'const std::1::basic_string<char>'
creates a copy from type 'const std::1::basic_string<char>'
[-Werror,-Wrange-loop-analysis]
for (const auto element : value):
use reference type 'const std::1::tuple<unsigned int, bool,
std::1::vector<unsigned char, std::__1::allocator<unsigned char> > > &' to
prevent copying
So there is no way to satisfy the warning other than disabling it.
Should the warning be improved for the template types?</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>