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
4 changes: 2 additions & 2 deletions clang/docs/ClangFormatStyleOptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2582,9 +2582,9 @@ the configuration (without a prefix: ``Auto``).

.. _BracedInitializerIndentWidth:

**BracedInitializerIndentWidth** (``Unsigned``) :versionbadge:`clang-format 17` :ref:`¶ <BracedInitializerIndentWidth>`
**BracedInitializerIndentWidth** (``Integer``) :versionbadge:`clang-format 17` :ref:`¶ <BracedInitializerIndentWidth>`
The number of columns to use to indent the contents of braced init lists.
If unset, ``ContinuationIndentWidth`` is used.
If unset or negative, ``ContinuationIndentWidth`` is used.

.. code-block:: c++

Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/Format/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ struct FormatStyle {
BitFieldColonSpacingStyle BitFieldColonSpacing;

/// The number of columns to use to indent the contents of braced init lists.
/// If unset, ``ContinuationIndentWidth`` is used.
/// If unset or negative, ``ContinuationIndentWidth`` is used.
/// \code
/// AlignAfterOpenBracket: AlwaysBreak
/// BracedInitializerIndentWidth: 2
Expand Down Expand Up @@ -1319,7 +1319,7 @@ struct FormatStyle {
/// }
/// \endcode
/// \version 17
std::optional<unsigned> BracedInitializerIndentWidth;
int BracedInitializerIndentWidth;

/// Different ways to wrap braces after control statements.
enum BraceWrappingAfterControlStatementStyle : int8_t {
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1921,9 +1921,9 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
NewIndent = Style.IndentWidth +
std::min(State.Column, CurrentState.NestedBlockIndent);
} else if (Current.is(tok::l_brace)) {
NewIndent =
CurrentState.LastSpace + Style.BracedInitializerIndentWidth.value_or(
Style.ContinuationIndentWidth);
const auto Width = Style.BracedInitializerIndentWidth;
NewIndent = CurrentState.LastSpace +
(Width < 0 ? Style.ContinuationIndentWidth : Width);
} else {
NewIndent = CurrentState.LastSpace + Style.ContinuationIndentWidth;
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.BinPackLongBracedList = true;
LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
LLVMStyle.BracedInitializerIndentWidth = -1;
LLVMStyle.BraceWrapping = {/*AfterCaseLabel=*/false,
/*AfterClass=*/false,
/*AfterControlStatement=*/FormatStyle::BWACS_Never,
Expand Down
10 changes: 7 additions & 3 deletions clang/unittests/Format/ConfigParseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ TEST(ConfigParseTest, ParsesConfigurationIntegers) {
Style.Language = FormatStyle::LK_Cpp;

CHECK_PARSE_INT(AccessModifierOffset);
CHECK_PARSE_INT(BracedInitializerIndentWidth);
CHECK_PARSE_INT(PPIndentWidth);

CHECK_PARSE_UNSIGNED(BracedInitializerIndentWidth);
CHECK_PARSE_UNSIGNED(ColumnLimit);
CHECK_PARSE_UNSIGNED(ConstructorInitializerIndentWidth);
CHECK_PARSE_UNSIGNED(ContinuationIndentWidth);
Expand Down Expand Up @@ -1441,8 +1441,10 @@ TEST(ConfigParseTest, GetStyleOfFile) {
ASSERT_EQ(*Style9, SubSubStyle);

// Test 9.8: use inheritance from a file without BasedOnStyle
ASSERT_TRUE(FS.addFile("/e/withoutbase/.clang-format", 0,
llvm::MemoryBuffer::getMemBuffer("ColumnLimit: 123")));
ASSERT_TRUE(FS.addFile(
"/e/withoutbase/.clang-format", 0,
llvm::MemoryBuffer::getMemBuffer("BracedInitializerIndentWidth: 2\n"
"ColumnLimit: 123")));
ASSERT_TRUE(
FS.addFile("/e/withoutbase/sub/.clang-format", 0,
llvm::MemoryBuffer::getMemBuffer(
Expand All @@ -1452,6 +1454,7 @@ TEST(ConfigParseTest, GetStyleOfFile) {
ASSERT_TRUE(static_cast<bool>(Style9));
ASSERT_EQ(*Style9, [] {
auto Style = getLLVMStyle();
Style.BracedInitializerIndentWidth = 2;
Style.ColumnLimit = 123;
return Style;
}());
Expand All @@ -1460,6 +1463,7 @@ TEST(ConfigParseTest, GetStyleOfFile) {
ASSERT_TRUE(static_cast<bool>(Style9));
ASSERT_EQ(*Style9, [] {
auto Style = getLLVMStyle();
Style.BracedInitializerIndentWidth = 2;
Style.ColumnLimit = 123;
Style.IndentWidth = 7;
return Style;
Expand Down