<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 - Warn about accidental coping of data in range based for"
href="https://bugs.llvm.org/show_bug.cgi?id=32823">32823</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Warn about accidental coping of data in range based for
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>antoshkka@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Here's a small example with accidental copying that could be often seen in
code:
```
#include <map>
#include <string>
#include <iostream>
int main() {
std::map<std::string, std::string> m = {
{"This is ", "an exmple, "},
{"were user ", "accidently copies"},
};
for (const std::pair<std::string, std::string>& s : m) {
std::cout << s.first << s.second;
}
}
```
User provided `const std::pair<std::string, std::string>&` type instead of
`const std::pair<const std::string, std::string>&` so the std::pair is copied.
Please add a "Value will be copied because types differ" warning for range
based for loops and show it when:
user provides a const reference type in for-range-declaration and that type
when decayed differs from decayed iterator dereference type.</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>