[clang] [Clang] enhance diagnostic by attaching source location to deduced type in trailing return without auto (PR #115786)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 12 05:50:18 PST 2024
================
@@ -4887,9 +4887,18 @@ 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();
+ SourceLocation Loc = D.getDeclSpec().getTypeSpecTypeLoc();
+ SourceRange SR = D.getDeclSpec().getSourceRange();
+ if (Loc.isInvalid()) {
+ TypeSourceInfo *TSI = nullptr;
+ S.GetTypeFromParser(FTI.getTrailingReturnType(), &TSI);
+ if (TSI) {
+ TypeLoc TSILoc = TSI->getTypeLoc();
+ Loc = TSILoc.getBeginLoc();
+ SR = TSILoc.getSourceRange();
+ }
+ }
+ S.Diag(Loc, diag::err_trailing_return_without_auto) << T << SR;
----------------
Sirraide wrote:
I guess another option would be to put the caret before the function name, but I don’t know how well that would work; i.e. something like this:
```
1 | foo() -> bar;
| ^
```
https://github.com/llvm/llvm-project/pull/115786
More information about the cfe-commits
mailing list