================
@@ -396,6 +400,21 @@ class LifetimeSafetySemaHelperImpl : public
LifetimeSafetySemaHelper {
}
private:
+ static std::string getLifetimeDiagSubject(const internal::Loan *L) {
+ if (L->getAccessPath().getAsMaterializeTemporaryExpr())
+ return "local temporary";
+
+ const auto *DRE = dyn_cast<DeclRefExpr>(L->getIssuingExpr());
+ assert(DRE && "expected lifetime diagnostic loan issued by a DeclRefExpr");
+
+ const ValueDecl *VD = DRE->getDecl();
+ std::string Subject =
+ isa<ParmVarDecl>(VD) ? "parameter '" : "local variable '";
+ Subject += VD->getNameAsString();
+ Subject += "'";
+ return Subject;
----------------
usx95 wrote:
Consider using `stringstream` and `getNameForDiagnostic` for this.
```cpp
std::string Res;
llvm::raw_string_ostream OS(Res);
OS << isa<ParmVarDecl>(VD) ? "parameter" : "local variable";
OS << " '";
VD->getNameForDiagnostic(OS, S.getPrintingPolicy(), false);
OS << "'";
```
https://github.com/llvm/llvm-project/pull/199432
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits