================
@@ -180,11 +180,25 @@ class LifetimeSafetySemaHelperImpl : public 
LifetimeSafetySemaHelper {
 
   void reportLifetimeboundViolation(
       const ParmVarDecl *ParmWithLifetimebound) override {
+    const auto *Attr = ParmWithLifetimebound->getAttr<LifetimeBoundAttr>();
     StringRef ParamName = ParmWithLifetimebound->getName();
     bool HasName = ParamName.size() > 0;
-    S.Diag(ParmWithLifetimebound->getLocation(),
-           diag::warn_lifetime_safety_param_lifetimebound_violation)
-        << HasName << ParamName << ParmWithLifetimebound->getSourceRange();
+    S.Diag(Attr->getLocation(),
+           diag::warn_lifetime_safety_lifetimebound_violation)
+        << HasName << ParamName << Attr->getRange();
+  }
+
+  void reportLifetimeboundViolation(
+      const CXXMethodDecl *MDWithLifetimebound) override {
+    const Stmt *Body = MDWithLifetimebound->getBody();
+    assert(Body && "Expected a body");
+    // FIXME: When #196549 lands, we can extract the attribute location and 
warn
+    // on it, for now warn on everything before the body.
+    S.Diag(MDWithLifetimebound->getLocation(),
+           diag::warn_lifetime_safety_lifetimebound_violation)
+        << 2 << "this"
+        << CharSourceRange::getCharRange(MDWithLifetimebound->getBeginLoc(),
+                                         Body->getBeginLoc());
----------------
NeKon69 wrote:

I think I can write some really bad code to find out where the attribute is 
placed, but I think it would be better to wait for that PR to be merged, as it 
might simplify the process.

https://github.com/llvm/llvm-project/pull/196824
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to