[clang] [Clang] fix missing source location for errors in macro-expanded (PR #143460)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 11 11:46:50 PDT 2025
================
@@ -1873,6 +1873,17 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC,
return AnnotatedNameKind::Unresolved;
}
+SourceLocation Parser::getEndOfPreviousToken() const {
+ SourceLocation TokenEndLoc = PP.getLocForEndOfToken(PrevTokLocation);
+ if (TokenEndLoc.isValid())
+ return TokenEndLoc;
+
+ if (Tok.getLocation().isMacroID())
+ return PP.getSourceManager().getSpellingLoc(Tok.getLocation());
----------------
efriedma-quic wrote:
In cases where the we don't try to compute the end of a token, the diagnostic usually looks something like this:
```
#define D if x==3) {}
void f(int x) { D }
<stdin>:2:17: error: expected '(' after 'if'
2 | void f(int x) { D }
| ^
<stdin>:1:14: note: expanded from macro 'D'
1 | #define D if x==3) {}
| ^
1 error generated.
```
Which... maybe you could argue there's room for improvement, but we should behave consistently across diagnostics.
https://github.com/llvm/llvm-project/pull/143460
More information about the cfe-commits
mailing list