llvm / llvm/llvm-project

Add details for -Wlifetime-safety-invalidation diags

Open
#200,243 4 comments 0 reactions 0 assignees View on GitHub
clang:temporal-safety
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.