Skip to content

Commit 6ca816f

Browse files
authored
[clang-format] Fix a regression in parsing switch in macro call (llvm#114506)
Fixes llvm#114408.
1 parent a6fc677 commit 6ca816f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,8 @@ void UnwrappedLineParser::parseStructuralElement(
20912091
case tok::kw_switch:
20922092
if (Style.Language == FormatStyle::LK_Java)
20932093
parseSwitch(/*IsExpr=*/true);
2094-
nextToken();
2094+
else
2095+
nextToken();
20952096
break;
20962097
case tok::kw_case:
20972098
// Proto: there are no switch/case statements.
@@ -2656,7 +2657,10 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
26562657
nextToken();
26572658
break;
26582659
case tok::kw_switch:
2659-
parseSwitch(/*IsExpr=*/true);
2660+
if (Style.Language == FormatStyle::LK_Java)
2661+
parseSwitch(/*IsExpr=*/true);
2662+
else
2663+
nextToken();
26602664
break;
26612665
case tok::kw_requires: {
26622666
auto RequiresToken = FormatTok;

clang/unittests/Format/TokenAnnotatorTest.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -3571,6 +3571,13 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) {
35713571
EXPECT_TOKEN(Tokens[18], tok::greater, TT_TemplateCloser);
35723572
}
35733573

3574+
TEST_F(TokenAnnotatorTest, SwitchInMacroArgument) {
3575+
auto Tokens = annotate("FOOBAR(switch);\n"
3576+
"void f() {}");
3577+
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
3578+
EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_FunctionLBrace);
3579+
}
3580+
35743581
} // namespace
35753582
} // namespace format
35763583
} // namespace clang

0 commit comments

Comments
 (0)