Skip to content

Commit b5bcdb5

Browse files
authored
[clang-format] Fix a crash on C# goto case (#113056)
Fixes #113011.
1 parent 2ce655c commit b5bcdb5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ bool UnwrappedLineParser::tryToParsePropertyAccessor() {
21482148
if (!Style.isCSharp())
21492149
return false;
21502150
// See if it's a property accessor.
2151-
if (FormatTok->Previous->isNot(tok::identifier))
2151+
if (!FormatTok->Previous || FormatTok->Previous->isNot(tok::identifier))
21522152
return false;
21532153

21542154
// See if we are inside a property accessor.

clang/unittests/Format/FormatTestCSharp.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,18 @@ TEST_F(FormatTestCSharp, BrokenBrackets) {
16881688
EXPECT_NE("", format("int where b <")); // reduced from crasher
16891689
}
16901690

1691+
TEST_F(FormatTestCSharp, GotoCaseLabel) {
1692+
verifyNoCrash("switch (i) {\n"
1693+
"case 0:\n"
1694+
" goto case 1;\n"
1695+
"case 1:\n"
1696+
" j = 0;\n"
1697+
" {\n"
1698+
" break;\n"
1699+
" }\n"
1700+
"}");
1701+
}
1702+
16911703
} // namespace
16921704
} // namespace test
16931705
} // namespace format

0 commit comments

Comments
 (0)