| Issue |
181912
|
| Summary |
[clang][LifetimeSafety] False-positive warning after inserting into a std::set
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
theuni
|
After #179093, I'm seeing a false-positive when accessing an iterator after inserting into a `std::set` with `-Wlifetime-safety`. Here's a minimal reproducer:
```c++
#include <set>
#include <cassert>
void func()
{
std::set<int> foo;
foo.insert(0);
auto first = foo.begin();
foo.insert(2);
assert(*first == 0);
}
```
Results in:
```bash
testset.cpp:8:18: warning: object whose reference is captured is later invalidated [-Wlifetime-safety-invalidation]
8 | auto first = foo.begin();
| ^~~
testset.cpp:9:9: note: invalidated here
9 | foo.insert(2);
| ~~~~^~~~~~~~~
testset.cpp:10:13: note: later used here
10 | assert(*first == 0);
```
Inserting into a `std::set` should not invalidate any iterators or references, so I believe this warning is incorrect.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs