Skip to content

Commit 243ba90

Browse files
owencagithub-actions[bot]
authored andcommitted
Automerge: [clang-format] Fix a crash on BAS_BlockIndent (#164047)
Fixes #163355
2 parents 0f65954 + 44a77f2 commit 243ba90

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
411411
}
412412
if (CurrentState.BreakBeforeClosingBrace &&
413413
(Current.closesBlockOrBlockTypeList(Style) ||
414-
(Current.is(tok::r_brace) &&
414+
(Current.is(tok::r_brace) && Current.MatchingParen &&
415415
Current.isBlockIndentedInitRBrace(Style)))) {
416416
return true;
417417
}

clang/lib/Format/FormatToken.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ bool FormatToken::isTypeOrIdentifier(const LangOptions &LangOpts) const {
6565

6666
bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const {
6767
assert(is(tok::r_brace));
68+
assert(MatchingParen);
69+
assert(MatchingParen->is(tok::l_brace));
6870
if (!Style.Cpp11BracedListStyle ||
6971
Style.AlignAfterOpenBracket != FormatStyle::BAS_BlockIndent) {
7072
return false;
7173
}
7274
const auto *LBrace = MatchingParen;
73-
assert(LBrace && LBrace->is(tok::l_brace));
7475
if (LBrace->is(BK_BracedInit))
7576
return true;
7677
if (LBrace->Previous && LBrace->Previous->is(tok::equal))

clang/unittests/Format/AlignBracketsTest.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,19 @@ TEST_F(AlignBracketsTest, ParenthesesAndOperandAlignment) {
778778
Style);
779779
}
780780

781+
TEST_F(AlignBracketsTest, BlockIndentAndNamespace) {
782+
auto Style = getLLVMStyleWithColumns(120);
783+
Style.AllowShortNamespacesOnASingleLine = true;
784+
Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
785+
786+
verifyNoCrash(
787+
"namespace {\n"
788+
"void xxxxxxxxxxxxxxxxxxxxx(nnnnn::TTTTTTTTTTTTT const *mmmm,\n"
789+
" YYYYYYYYYYYYYYYYY &yyyyyyyyyyyyyy);\n"
790+
"} //",
791+
Style);
792+
}
793+
781794
} // namespace
782795
} // namespace test
783796
} // namespace format

0 commit comments

Comments
 (0)