[clang] Suggest lifetime annotations [Issue Id: 169375] (PR #169767)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 27 06:50:22 PST 2025


================
@@ -31,7 +31,7 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, LoanID ID) {
 struct AccessPath {
   const clang::ValueDecl *D;
 
-  AccessPath(const clang::ValueDecl *D) : D(D) {}
+  AccessPath(const clang::ValueDecl *D = nullptr) : D(D) {}
----------------
Xazax-hun wrote:

> This is different from borrowing the ParmVarDecl​ itself. 

Whoops, indeed! I wonder if it is better to have a flag in that case to distinguish between these two cases. It feels wrong to throw away this information. 

> Another thing is that these placeholder loans never expire

Could there still be cases where they are invalidated? E.g. in the earlier example (even if we do not detect this for now).

```
int* func(std::vector<int>& v [[clang::lifetimebound]]) {
  v.push_back(0);
  return v[0];
}
```

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


More information about the cfe-commits mailing list