Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-format] Change BracedInitializerIndentWidth to int #128988

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 6 additions & 5 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,9 @@ 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")));
ASSERT_TRUE(
FS.addFile("/e/withoutbase/sub/.clang-format", 0,
llvm::MemoryBuffer::getMemBuffer(
Expand All @@ -1452,15 +1453,15 @@ TEST(ConfigParseTest, GetStyleOfFile) {
ASSERT_TRUE(static_cast<bool>(Style9));
ASSERT_EQ(*Style9, [] {
auto Style = getLLVMStyle();
Style.ColumnLimit = 123;
Style.BracedInitializerIndentWidth = 2;
return Style;
}());

Style9 = getStyle("file", "/e/withoutbase/sub/code.cpp", "google", "", &FS);
ASSERT_TRUE(static_cast<bool>(Style9));
ASSERT_EQ(*Style9, [] {
auto Style = getLLVMStyle();
Style.ColumnLimit = 123;
Style.BracedInitializerIndentWidth = 2;
Style.IndentWidth = 7;
return Style;
}());
Expand Down