[llvm-bugs] [Bug 32823] New: Warn about accidental coping of data in range based for

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Apr 27 03:58:26 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=32823

            Bug ID: 32823
           Summary: Warn about accidental coping of data in range based
                    for
           Product: clang
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: antoshkka at gmail.com
                CC: llvm-bugs at lists.llvm.org

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170427/f55c1641/attachment-0001.html>


More information about the llvm-bugs mailing list