diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -238,10 +238,11 @@ argument1, argument2 ) - \note + + .. note:: + This currently only applies to braced initializer lists (when ``Cpp11BracedListStyle`` is ``true``) and parentheses. - \endnote diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -363,7 +363,8 @@ } if (CurrentState.BreakBeforeClosingBrace && (Current.closesBlockOrBlockTypeList(Style) || - Current.isBlockIndentedInitRBrace(Style))) { + (Current.is(tok::r_brace) && + Current.isBlockIndentedInitRBrace(Style)))) { return true; } if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren)) diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -76,14 +76,13 @@ } bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const { - if (isNot(tok::r_brace)) - return false; - if (Style.Cpp11BracedListStyle != true || + assert(is(tok::r_brace)); + if (!Style.Cpp11BracedListStyle || Style.AlignAfterOpenBracket != FormatStyle::BAS_BlockIndent) { return false; } - auto LBrace = MatchingParen; - assert(LBrace); + 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)) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -25535,26 +25535,26 @@ " .foo = \"xxxxxxxxxxxxx\",\n" " .bar = \"yyyyyyyyyyyyy\",\n" " .baz = \"zzzzzzzzzzzzz\"\n" - "};\n", + "};", Style); // List initialization. verifyFormat("SomeStruct s{\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); verifyFormat("SomeStruct{\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); verifyFormat("new SomeStruct{\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); // Member initializer. verifyFormat("class SomeClass {\n" @@ -25563,62 +25563,62 @@ " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" " };\n" - "};\n", + "};", Style); // Constructor member initializer. verifyFormat("SomeClass::SomeClass : strct{\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - " } {}\n", + " } {}", Style); // Copy initialization. verifyFormat("SomeStruct s = SomeStruct{\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); // Copy list initialization. verifyFormat("SomeStruct s = {\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); // Assignment operand initialization. verifyFormat("s = {\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); // Returned object initialization. verifyFormat("return {\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); // Initializer list. verifyFormat("auto initializerList = {\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); // Function parameter initialization. verifyFormat("func({\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "});\n", + "});", Style); // Nested init lists. verifyFormat("SomeStruct s = {\n" " {{init1, init2, init3, init4, init5},\n" " {init1, init2, init3, init4, init5}}\n" - "};\n", + "};", Style); verifyFormat("SomeStruct s = {\n" " {{\n" @@ -25629,7 +25629,7 @@ " .init5 = 5,\n" " },\n" " {init1, init2, init3, init4, init5}}\n" - "};\n", + "};", Style); verifyFormat("SomeArrayT a[3] = {\n" " {\n" @@ -25641,7 +25641,7 @@ " bar,\n" " },\n" " SomeArrayT{},\n" - "};\n", + "};", Style); verifyFormat("SomeArrayT a[3] = {\n" " {foo},\n" @@ -25658,7 +25658,7 @@ " },\n" " },\n" " {baz},\n" - "};\n", + "};", Style); }