================
@@ -2952,10 +2958,24 @@ class LifetimeSafetySemaHelperImpl : public 
LifetimeSafetySemaHelper {
     unsigned DiagID = (Scope == SuggestionScope::CrossTU)
                           ? diag::warn_lifetime_safety_cross_tu_this_suggestion
                           : 
diag::warn_lifetime_safety_intra_tu_this_suggestion;
-    SourceLocation InsertionPoint;
-    InsertionPoint = Lexer::getLocForEndOfToken(
-        MD->getTypeSourceInfo()->getTypeLoc().getEndLoc(), 0,
-        S.getSourceManager(), S.getLangOpts());
+    const auto MDL = MD->getTypeSourceInfo()->getTypeLoc();
+    SourceLocation InsertionPoint = Lexer::getLocForEndOfToken(
+        MDL.getEndLoc(), 0, S.getSourceManager(), S.getLangOpts());
+    if (const auto *FPT = MD->getType()->getAs<FunctionProtoType>();
+        FPT && FPT->hasTrailingReturn()) {
+      // For trailing return types, 'getEndLoc()' includes the return type
+      // after '->', placing the attribute in an invalid position.
+      // Instead use 'getLocalRangeEnd()' which gives the '->' location
+      // for trailing returns, so find the last token before it.
+      const auto FTL = MDL.getAs<FunctionTypeLoc>();
+      assert(FTL);
+      InsertionPoint = Lexer::getLocForEndOfToken(
----------------
Xazax-hun wrote:

While this looks good to me, I wonder if we should collect tricks like this in 
the `clangRewrite` library so we have a list of utility function to insert 
tokens at the right place. 

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

Reply via email to