[LifetimeSafety] Diagnose `std::optional<T&>` captures
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
https://godbolt.org/z/hzEK87abr
```cpp
#include
#include
int main() {
std::optional p;
{
auto x = 42;
p = x;
}
auto result = *p;
printf("%d", result);
}
```
`-std=c++26 -Wlifetime-safety-all -Xclang=-flifetime-safety-inference -fsanitize=address,undefined`
I think this is similar to `std::optional`, `std::unique_ptr` or any gsl::Owner that owns a pointer. And therefore clang::lifetimebound interactions with `std::optional&` can be rather complicated.
Contributor guide
Research direction
Start with the Godbolt reproducer and its C++26 lifetime-safety flags, then compare the behavior of std::optional with the optional pointer and lifetimebound cases mentioned in the issue. Done means establishing and implementing the expected diagnostic behavior for the dangling capture, including the interaction with lifetimebound.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100