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
2 changes: 1 addition & 1 deletion clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
}
if (CurrentState.BreakBeforeClosingBrace &&
(Current.closesBlockOrBlockTypeList(Style) ||
(Current.is(tok::r_brace) &&
(Current.is(tok::r_brace) && Current.MatchingParen &&
Current.isBlockIndentedInitRBrace(Style)))) {
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Format/FormatToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ bool FormatToken::isTypeOrIdentifier(const LangOptions &LangOpts) const {

bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const {
assert(is(tok::r_brace));
assert(MatchingParen);
assert(MatchingParen->is(tok::l_brace));
if (!Style.Cpp11BracedListStyle ||
Style.AlignAfterOpenBracket != FormatStyle::BAS_BlockIndent) {
return false;
}
const auto *LBrace = MatchingParen;
assert(LBrace && LBrace->is(tok::l_brace));
if (LBrace->is(BK_BracedInit))
return true;
if (LBrace->Previous && LBrace->Previous->is(tok::equal))
Expand Down
13 changes: 13 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9727,6 +9727,19 @@ TEST_F(FormatTest, ParenthesesAndOperandAlignment) {
Style);
}

TEST_F(FormatTest, BlockIndentAndNamespace) {
auto Style = getLLVMStyleWithColumns(120);
Style.AllowShortNamespacesOnASingleLine = true;
Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;

verifyNoCrash(
"namespace {\n"
"void xxxxxxxxxxxxxxxxxxxxx(nnnnn::TTTTTTTTTTTTT const *mmmm,\n"
" YYYYYYYYYYYYYYYYY &yyyyyyyyyyyyyy);\n"
"} //",
Style);
}

TEST_F(FormatTest, BreaksConditionalExpressions) {
verifyFormat(
"aaaa(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa\n"
Expand Down
Loading