Skip to content

Formatting issue with braced initialization list indentation #134539

Open
@19217041025

Description

@19217041025

Dear Clang-format team,

I've encountered an indentation issue when formatting braced initialization lists that I believe could be improved. Here are the details:

​​Expected formatting​​:

Image

Actual formatting​​ (with current clang-format):

clang+llvm-20.1.0-x86_64-pc-windows-msvc

Image

or

Image

​Problem​​:

The opening brace gets an extra level of indentation
The closing brace moves to a new line (when I prefer it on the same line as the last element for simple lists)
I've tried various combinations of BreakBeforeBraces, BraceWrapping, and IndentWidth options but couldn't achieve the desired formatting.

Would it be possible to:

Add an option to keep the opening brace at the same indentation level as the variable declaration?
Add more control over closing brace placement for initialization lists?
Thank you for your consideration. Let me know if you need any additional information.

.clang-format


AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignArrayOfStructures: Right
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Left
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AllowShortBlocksOnASingleLine: Empty
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: Inline
BasedOnStyle: LLVM
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
BeforeWhile: true
IndentBraces: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ColumnLimit: 0
Cpp11BracedListStyle: true
EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseBlocks: false
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
Language: Cpp
NamespaceIndentation: None
PackConstructorInitializers: CurrentLine
PointerAlignment: Left
SortIncludes: true
SpaceBeforeCaseColon: false
Standard: Cpp11
StatementMacros: ['UPROPERTY', 'UFUNCTION', 'UCLASS', 'USTRUCT', 'UENUM', 'UINTERFACE', 'GENERATED_BODY', 'v']
TabWidth: 4
UseTab: ForContinuationAndIndentation
QualifierAlignment: Left

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions