[llvm] [ADT] Add `[[clang::lifetimebound]]` annotations to Twine.h (PR #210474)

via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 18 07:39:02 PDT 2026


================
@@ -254,7 +256,7 @@ class Twine {
   /// We take care here to optimize "" into the empty twine -- this will be
   /// optimized out for string constants. This allows Twine arguments have
   /// default "" values, without introducing unnecessary string constants.
-  /*implicit*/ Twine(const char *Str) {
+  /*implicit*/ Twine(const char *Str LLVM_LIFETIME_BOUND) {
----------------
isuckatcs wrote:

Hmm, this is another tricky case. If the string is empty, it is not lifetime bound, right?

```c++
llvm::Twine(std::string("").c_str());
```

I'm not sure how much this pattern is abused, but it can also result in false positives.

https://github.com/llvm/llvm-project/pull/210474


More information about the llvm-commits mailing list