================
@@ -4887,9 +4887,20 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
                       cast<AutoType>(T)->getKeyword() !=
                           AutoTypeKeyword::Auto ||
                       cast<AutoType>(T)->isConstrained())) {
-            S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(),
-                   diag::err_trailing_return_without_auto)
-                << T << D.getDeclSpec().getSourceRange();
+            // Attach a valid source location for diagnostics on functions with
+            // trailing return types missing 'auto'. Attempt to get the 
location
+            // from the declared type; if invalid, fall back to the trailing
+            // return type's location.
+            SourceLocation Loc = D.getDeclSpec().getTypeSpecTypeLoc();
+            SourceRange SR = D.getDeclSpec().getSourceRange();
+            if (Loc.isInvalid()) {
+              TypeSourceInfo *TSI = nullptr;
+              S.GetTypeFromParser(FTI.getTrailingReturnType(), &TSI);
+              TypeLoc TSILoc = TSI->getTypeLoc();
+              Loc = TSILoc.getBeginLoc();
----------------
Fznamznon wrote:

I wonder if that suffice?
```suggestion
              Loc = FTI.getTrailingReturnTypeLoc()
```

https://github.com/llvm/llvm-project/pull/115786
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to