| Issue |
183091
|
| Summary |
[clang-format] Trailing comma breaks formatting in nested braced initializer
|
| Labels |
clang-format
|
| Assignees |
|
| Reporter |
Merloran
|
clang-format version: 21.1.5
OS: Windows 11
.clang-format:
```yaml
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignConsecutiveAssignments:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignConsecutiveBitFields:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AlignEscapedNewlines: Left
InsertBraces: true
BreakAfterReturnType: None
AllowAllParametersOfDeclarationOnNextLine: false
AllowAllArgumentsOnNextLine: false
AlignAfterOpenBracket: Align
PenaltyReturnTypeOnItsOwnLine: 1000
PenaltyBreakAssignment: 500
BreakBeforeBinaryOperators: NonAssignment
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBraces: Custom
BreakConstructorInitializers: BeforeComma
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ContinuationIndentWidth: 8
Cpp11BracedListStyle: false
IncludeCategories:
- Regex: '^".*'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 4
UseTab: Never
InsertNewlineAtEOF: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
TabWidth: 4
ReflowComments: true
SortUsingDeclarations: true
Standard: c++20
...
```
When formatting code containing a nested braced initializer, adding a trailing comma inside the inner initializer causes clang-format to stop reformatting that section(only indent of first line works).
Example:
```cpp
mTextureCopies . push_back({ .dstTexture = &dst, .srcOffset = static_cast<vk::DeviceSize>(mCurrentOffset),
.extent = { .width = dst.get_size().x, .height = dst.get_size().y, .depth = 1, },.generateMips = generateMips,
});
```
After removing the trailing comma inside the nested initializer:
```cpp
mTextureCopies.push_back({
.dstTexture = &dst,
.srcOffset = static_cast<vk::DeviceSize>(mCurrentOffset),
.extent = { .width = dst.get_size().x, .height = dst.get_size().y, .depth = 1 },
.generateMips = generateMips,
});
```
The only difference is the trailing comma after `.depth = 1`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs