Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,8 @@ void UnwrappedLineParser::parseStructuralElement(
case tok::kw_switch:
if (Style.Language == FormatStyle::LK_Java)
parseSwitch(/*IsExpr=*/true);
nextToken();
else
nextToken();
break;
case tok::kw_case:
// Proto: there are no switch/case statements.
Expand Down Expand Up @@ -2656,7 +2657,10 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
nextToken();
break;
case tok::kw_switch:
parseSwitch(/*IsExpr=*/true);
if (Style.Language == FormatStyle::LK_Java)
parseSwitch(/*IsExpr=*/true);
else
nextToken();
break;
case tok::kw_requires: {
auto RequiresToken = FormatTok;
Expand Down
7 changes: 7 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3571,6 +3571,13 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) {
EXPECT_TOKEN(Tokens[18], tok::greater, TT_TemplateCloser);
}

TEST_F(TokenAnnotatorTest, SwitchInMacroArgument) {
auto Tokens = annotate("FOOBAR(switch);\n"
"void f() {}");
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_FunctionLBrace);
}

} // namespace
} // namespace format
} // namespace clang
Loading