Skip to content

Commit

Permalink
[clang-format] Fix a crash on C# goto case (#113056)
Browse files Browse the repository at this point in the history
Fixes #113011.
  • Loading branch information
owenca authored Oct 22, 2024
1 parent 2ce655c commit b5bcdb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,7 @@ bool UnwrappedLineParser::tryToParsePropertyAccessor() {
if (!Style.isCSharp())
return false;
// See if it's a property accessor.
if (FormatTok->Previous->isNot(tok::identifier))
if (!FormatTok->Previous || FormatTok->Previous->isNot(tok::identifier))
return false;

// See if we are inside a property accessor.
Expand Down
12 changes: 12 additions & 0 deletions clang/unittests/Format/FormatTestCSharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,18 @@ TEST_F(FormatTestCSharp, BrokenBrackets) {
EXPECT_NE("", format("int where b <")); // reduced from crasher
}

TEST_F(FormatTestCSharp, GotoCaseLabel) {
verifyNoCrash("switch (i) {\n"
"case 0:\n"
" goto case 1;\n"
"case 1:\n"
" j = 0;\n"
" {\n"
" break;\n"
" }\n"
"}");
}

} // namespace
} // namespace test
} // namespace format
Expand Down

0 comments on commit b5bcdb5

Please sign in to comment.