Add details for -Wlifetime-safety-invalidation diags
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
https://godbolt.org/z/jTb1zEcfP
```cpp
#include
void f(std::vector a, std::vector b, bool flag) {
int* pa = &a[0];
int* pb = &b[0];
std::vector* pv = (flag ? &a : &b);
pv->push_back(42);
(void)pa;
(void)pb;
}
```
Current:
```cpp
:3:16: warning: object whose reference is captured is later invalidated [-Wlifetime-safety-invalidation]
3 | int* pa = &a[0];
| ^
:6:9: note: invalidated here
6 | pv->push_back(42);
| ~~~~^~~~~~~~~~~~~
:7:11: note: later used here
7 | (void)pa;
| ^~
:4:16: warning: object whose reference is captured is later invalidated [-Wlifetime-safety-invalidation]
4 | int* pb = &b[0];
| ^
:6:9: note: invalidated here
6 | pv->push_back(42);
| ~~~~^~~~~~~~~~~~~
:8:11: note: later used here
8 | (void)pb;
| ^~
```
Expected:
* local variable 'a' is later invalidated
* local variable 'b' is later invalidated
Contributor guide
Assessment
This issue has not been assessed yet.