[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 13 07:53:18 PST 2024


================
@@ -249,9 +254,10 @@ static void visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path,
                                                   LocalVisitor Visit);
 
 template <typename T> static bool isRecordWithAttr(QualType Type) {
-  if (auto *RD = Type->getAsCXXRecordDecl())
-    return RD->hasAttr<T>();
-  return false;
+  CXXRecordDecl *RD = Type.getNonReferenceType()->getAsCXXRecordDecl();
----------------
usx95 wrote:

I do not think there is a difference in the annotations in that respect.
For example, consider:
```cpp
std::string_view foo(std::string_view&& t [[clang::lifetimebound]]);

void use() {
    std::string_view x = foo(std::string_view()); // Clangs warns here.
}
```
I think this is, in principle, a false positive. Pointer-like types when appearing as a reference type should be considered values.
https://github.com/llvm/llvm-project/issues/116066

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


More information about the cfe-commits mailing list