Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ Bug Fixes in This Version
- Fixed type mismatch error when 'builtin-elementwise-math' arguments have different qualifiers, this should be well-formed. (#GH141397)
- Constant evaluation now correctly runs the destructor of a variable declared in
the second clause of a C-style ``for`` loop. (#GH139818)
- Fixed incorrect diagnostic location for missing ``:`` in case statements expanded from macros. (#GH143216)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/DiagnosticCommonKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ let CategoryName = "Parse Issue" in {
def err_expected : Error<"expected %0">;
def err_expected_either : Error<"expected %0 or %1">;
def err_expected_after : Error<"expected %1 after %0">;
def note_macro_expansion : Note<"expanded from macro '%0'">;

def err_param_redefinition : Error<"redefinition of parameter %0">;
def warn_method_param_redefinition : Warning<"redefinition of method parameter %0">;
Expand Down
14 changes: 14 additions & 0 deletions clang/lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<< Lexer::getImmediateMacroNameForDiagnostics(
ExprLoc, PP.getSourceManager(), getLangOpts());
}

ColonLoc = ExpectedLoc;
}

Expand Down
13 changes: 13 additions & 0 deletions clang/test/Parser/switch-recovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,16 @@ void fn1() {
}
} // expected-error{{expected statement}}
}

namespace GH143216 {
#define FOO 1 case 3: // expected-error {{expected ':' after 'case'}}

int f(int x) {
switch (x) {
case FOO // expected-note {{expanded from macro 'FOO'}}
return 0;
default:
return 1;
}
}
}
Loading