[clang] [LifetimeSafety] Warn on incorrectly placed `[[clang::lifetimebound]]` attributes (PR #196144)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Fri May 8 07:12:34 PDT 2026
================
@@ -624,12 +624,19 @@ Warning to detect invalidation of references.
}];
}
+def LifetimeSafetyLifetimeboundViolation : DiagGroup<"lifetime-safety-lifetimebound-violation"> {
+ code Documentation = [{
+Warning to detect lifetimebound violations introduced by marking parameter as lifetimebound but not returning it in any way.
----------------
Xazax-hun wrote:
Technically, it is not necessarily the parameter that needs to escape.
Consider:
```
int * f(const std::vector<int>& v [[clang::lifetimebound]]) {
return v.data();
}
```
Here, we do not escape the address of vector itself, but we return a pointer to an inner buffer. So technically, we did not escape the lifetimebound marked value, but this code is still fine!
https://github.com/llvm/llvm-project/pull/196144
More information about the cfe-commits
mailing list