[llvm] [ADT] Add `[[clang::lifetimebound]]` annotations to Twine.h (PR #210474)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 18 07:47:32 PDT 2026
================
@@ -458,7 +466,8 @@ class Twine {
/// This returns the twine as a single StringRef if it can be
/// represented as such. Otherwise the twine is written into the given
/// SmallVector and a StringRef to the SmallVector's data is returned.
- StringRef toStringRef(SmallVectorImpl<char> &Out) const {
+ StringRef toStringRef(SmallVectorImpl<char> &Out LLVM_LIFETIME_BOUND) const
----------------
isuckatcs wrote:
> I think "out" outlives the Twine - thus that annotation is wrong.
For this annotation, doesn't it have to outlive the returned `StringRef`?
```c++
StringRef toStringRef(SmallVectorImpl<char> &Out) const {
if (isSingleStringRef())
return getSingleStringRef();
toVector(Out);
return StringRef(Out.data(), Out.size());
}
```
The returned `StringRef` references the data of `Out`. I think both `Out` and `this` should be annotated.
https://github.com/llvm/llvm-project/pull/210474
More information about the llvm-commits
mailing list