<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/121294>121294</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] Check request: avoid dangerous ctad constructing container from iterators pair
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
denzor200
</td>
</tr>
</table>
<pre>
Assume we have a vector of 4 integers:
```
std::vector<int> v = {1,2,3,4};
```
And then imagine we need to make a copy of that vector:
```
auto v2 = std::vector{v.begin(), v.end()};
```
Are you expecting `v2` to be a vector of 4 integers? Surprise :) This is a `std::vector<std::vector<int>::iterator>` with 2 iterators.
The way to fix that copying:
```
auto v2 = std::vector(v.begin(), v.end());
```
Note that it's easy to reach that typo due to code styles which are forcing programmers to always use auto and always prefer braced initialization.
You may suggest to change copying to `auto v2 = v;`, that's correct but not always possible - imagine we are copying subarray.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUlEGPozgQhX-NuZQ6AkNIOHBIpyfHvexc9ljYFfAO2KxdJsP8-pVJstPq3V5pJCTEw6731ZNdGILpLVEr9q9i_5Zh5MH5VpP94bzM86xzem1FfjqFECeCG8GACwHCQoqdB3eFCoxl6skHUZ5EfhJ1_njyU2CdxPJ0Xy7Ks7Esyi-wgCjfQBxeCyHPUshzKeS5Eoc3Ub5-qJHcrQYeyIKZsDd247BEGtjBhN8Sj3Lzmmh4QIan20ccjOxgkZv3R7TD67LrqDdWyKOQjZBnWHZk9ePzMzJPsLoI9H0mxcb2IOp8kaLOE1v3eVIX-D362ZtAkDBkA18HE8AEwFTi38F9FuVdNEweN_lL8r4ZHkDCUw07kZ--DgQ3XBPX1Xy_B5VSM7b_taTk8X-Tks1_JvWbY7qbGhbyEIAwbDCeUA33P7zODnSkJCunCQKvIwW4DUYNgJ7g6rxKKc_e9R6niXxIi3G84RogBoKNHK1-arOnK3noPCrSYKxhg6P5gWycTbH84SJMuEKIfU-BN-sBbU_PcJIi6vx9IkvqsM5T54l7a0c570kxdJHBOv7H3oVgupHg5f3hTa08y4fYofe4JphMt6VuygYzaotDua-O8tgcsqHVSnWqK4ouJ7rqQ0lIzTW_qgplTc2xy0wrc1kVUjZFVVb7w67WjdwfVVXsu5p0WYsqpwnNuBvHZdo532cmhEhtIQvZVNmIHY1hmwNSqhFt_8JGr0LKNBd8m3a9dLEPospHEzj8rMOGx22CvNu2f4PzQOobePorUmBRngAXZzTolK13MYBi1KCcDezj_e4oZxmNJQ9X76afxxdmND6LfmwH5nmbM_Ii5KU3PMRup9wk5CXxPF4vs3d_kmIhL1uTQcjLo8-llX8HAAD__5XckTY">