[clang] [Clang] fix missing source location for ':' error in macro-expanded case statements (PR #143460)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 9 17:34:59 PDT 2025
================
@@ -833,9 +833,23 @@ StmtResult Parser::ParseCaseStatement(ParsedStmtContext StmtCtx,
<< FixItHint::CreateReplacement(ColonLoc, ":");
} else {
SourceLocation ExpectedLoc = PP.getLocForEndOfToken(PrevTokLocation);
+ SourceLocation ExprLoc =
+ LHS.get() ? LHS.get()->getExprLoc() : SourceLocation();
+
+ if (ExpectedLoc.isInvalid() && ExprLoc.isMacroID()) {
+ ExpectedLoc = PP.getSourceManager().getSpellingLoc(ExprLoc);
+ }
+
Diag(ExpectedLoc, diag::err_expected_after)
<< "'case'" << tok::colon
<< FixItHint::CreateInsertion(ExpectedLoc, ":");
+
+ if (ExprLoc.isMacroID()) {
+ Diag(ExprLoc, diag::note_macro_expansion)
----------------
efriedma-quic wrote:
We usually let the diagnostic infrastructure generate this sort of note; trying to write it out is likely to get it wrong.
https://github.com/llvm/llvm-project/pull/143460
More information about the cfe-commits
mailing list