Skip to content

Commit ef2548f

Browse files
committed
[clang-format] Change BracedInitializerIndentWidth to int
Fixes #108526
1 parent d29a1be commit ef2548f

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,9 +2582,9 @@ the configuration (without a prefix: ``Auto``).
25822582

25832583
.. _BracedInitializerIndentWidth:
25842584

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

25892589
.. code-block:: c++
25902590

clang/include/clang/Format/Format.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ struct FormatStyle {
12891289
BitFieldColonSpacingStyle BitFieldColonSpacing;
12901290

12911291
/// The number of columns to use to indent the contents of braced init lists.
1292-
/// If unset, ``ContinuationIndentWidth`` is used.
1292+
/// If unset or negative, ``ContinuationIndentWidth`` is used.
12931293
/// \code
12941294
/// AlignAfterOpenBracket: AlwaysBreak
12951295
/// BracedInitializerIndentWidth: 2
@@ -1319,7 +1319,7 @@ struct FormatStyle {
13191319
/// }
13201320
/// \endcode
13211321
/// \version 17
1322-
std::optional<unsigned> BracedInitializerIndentWidth;
1322+
int BracedInitializerIndentWidth;
13231323

13241324
/// Different ways to wrap braces after control statements.
13251325
enum BraceWrappingAfterControlStatementStyle : int8_t {

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,9 +1921,9 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
19211921
NewIndent = Style.IndentWidth +
19221922
std::min(State.Column, CurrentState.NestedBlockIndent);
19231923
} else if (Current.is(tok::l_brace)) {
1924-
NewIndent =
1925-
CurrentState.LastSpace + Style.BracedInitializerIndentWidth.value_or(
1926-
Style.ContinuationIndentWidth);
1924+
const auto Width = Style.BracedInitializerIndentWidth;
1925+
NewIndent = CurrentState.LastSpace +
1926+
(Width < 0 ? Style.ContinuationIndentWidth : Width);
19271927
} else {
19281928
NewIndent = CurrentState.LastSpace + Style.ContinuationIndentWidth;
19291929
}

clang/lib/Format/Format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
15121512
LLVMStyle.BinPackLongBracedList = true;
15131513
LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
15141514
LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
1515-
LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
1515+
LLVMStyle.BracedInitializerIndentWidth = -1;
15161516
LLVMStyle.BraceWrapping = {/*AfterCaseLabel=*/false,
15171517
/*AfterClass=*/false,
15181518
/*AfterControlStatement=*/FormatStyle::BWACS_Never,

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ TEST(ConfigParseTest, ParsesConfigurationIntegers) {
265265
Style.Language = FormatStyle::LK_Cpp;
266266

267267
CHECK_PARSE_INT(AccessModifierOffset);
268+
CHECK_PARSE_INT(BracedInitializerIndentWidth);
268269
CHECK_PARSE_INT(PPIndentWidth);
269270

270-
CHECK_PARSE_UNSIGNED(BracedInitializerIndentWidth);
271271
CHECK_PARSE_UNSIGNED(ColumnLimit);
272272
CHECK_PARSE_UNSIGNED(ConstructorInitializerIndentWidth);
273273
CHECK_PARSE_UNSIGNED(ContinuationIndentWidth);
@@ -1441,8 +1441,9 @@ TEST(ConfigParseTest, GetStyleOfFile) {
14411441
ASSERT_EQ(*Style9, SubSubStyle);
14421442

14431443
// Test 9.8: use inheritance from a file without BasedOnStyle
1444-
ASSERT_TRUE(FS.addFile("/e/withoutbase/.clang-format", 0,
1445-
llvm::MemoryBuffer::getMemBuffer("ColumnLimit: 123")));
1444+
ASSERT_TRUE(FS.addFile(
1445+
"/e/withoutbase/.clang-format", 0,
1446+
llvm::MemoryBuffer::getMemBuffer("BracedInitializerIndentWidth: 2")));
14461447
ASSERT_TRUE(
14471448
FS.addFile("/e/withoutbase/sub/.clang-format", 0,
14481449
llvm::MemoryBuffer::getMemBuffer(
@@ -1452,15 +1453,15 @@ TEST(ConfigParseTest, GetStyleOfFile) {
14521453
ASSERT_TRUE(static_cast<bool>(Style9));
14531454
ASSERT_EQ(*Style9, [] {
14541455
auto Style = getLLVMStyle();
1455-
Style.ColumnLimit = 123;
1456+
Style.BracedInitializerIndentWidth = 2;
14561457
return Style;
14571458
}());
14581459

14591460
Style9 = getStyle("file", "/e/withoutbase/sub/code.cpp", "google", "", &FS);
14601461
ASSERT_TRUE(static_cast<bool>(Style9));
14611462
ASSERT_EQ(*Style9, [] {
14621463
auto Style = getLLVMStyle();
1463-
Style.ColumnLimit = 123;
1464+
Style.BracedInitializerIndentWidth = 2;
14641465
Style.IndentWidth = 7;
14651466
return Style;
14661467
}());

0 commit comments

Comments
 (0)