llvm / llvm/llvm-project

[LifetimeSafety] provide more details on lifetimebound violation

Open
#209,763 18 comments 0 reactions 0 assignees View on GitHub
clang:temporal-safety enhancement
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```cpp
#include

struct S
{
S(const std::vector& v); // missing annotation
};

S f2(const std::vector& v [[clang::lifetimebound]])
{
return {v}; // actual violation location
}

S f1(const std::vector& v [[clang::lifetimebound]])
{
return f2(v);
}
```

```
:8:34: warning: could not verify that the return value can be lifetime bound to 'v' [-Wlifetime-safety-lifetimebound-violation]
8 | S f2(const std::vector& v [[clang::lifetimebound]])
| ^~~~~~~~~~~~~~~~~~~~
```

https://godbolt.org/z/Wex6xaW1n

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the warning with the C++ example and compiler flag shown in the issue, using the linked Godbolt case as the reference. Trace the lifetimebound diagnostic from the reported location in f2; done means the warning provides more useful details about the missing annotation or actual violation while preserving the diagnostic's correctness.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.