llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.6k stars 11.82k forks source link

Nested braced initializer lists not behaving as expected #63115

Open btowntkd opened 1 year ago

btowntkd commented 1 year ago

I am using Clang-Format and I have a particular block of code with nested braced initializers. I would like the code to look like this:

auto test = TheThing{ 
    Arg1{ blorp, bleep, bloop, blop, blip },
    Arg2{ blorp, bleep, bloop, blop, blop, blip } };

Note the desired behavior:

But Clang-Format keeps reformatting it thusly:

auto test = TheThing{ Arg1{ blorp, bleep, bloop, blop, blip },
                      Arg2{ blorp, bleep, bloop, blop, blop, blip } };

Note the undesired behavior:

This is the Clang-Format settings I currently use:

---
BasedOnStyle: Microsoft
AccessModifierOffset: -4
AlignArrayOfStructures: Left
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortLambdasOnASingleLine: Inline
AlignTrailingComments: true
BraceWrapping:
  AfterCaseLabel: true
  AfterClass: true
  AfterControlStatement: Always
  AfterEnum: true
  AfterFunction: true
  AfterNamespace: true
  AfterStruct: true
  AfterUnion: true
  AfterExternBlock: true
  BeforeCatch: true
  BeforeElse: true
  BeforeLambdaBody: true
  BeforeWhile: true
  IndentBraces: true
  SplitEmptyFunction: false
BreakBeforeBraces: Allman
BreakConstructorInitializers: AfterColon
ColumnLimit: 120
DerivePointerAlignment: false
FixNamespaceComments: false
IncludeBlocks: Regroup
IndentWidth: 4
NamespaceIndentation: All
PointerAlignment: Left
ReferenceAlignment: Left
SortIncludes: Never
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpaceAfterTemplateKeyword: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
TabWidth: 4
UseTab: Always

AlignAfterOpenBracket: AlwaysBreak
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
BinPackArguments: false
BinPackParameters: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Cpp11BracedListStyle: false
SpaceBeforeCpp11BracedList: false

I placed the settings that seem like they should be the most relevant in this case at the bottom.

Is there a setting I'm missing?

I am using the version of Clang-Format currently included with Visual Studio 2022 - version 13.0.1.

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-format

gedare commented 1 year ago

I get:

auto test = TheThing{
    Arg1{ blorp, bleep, bloop, blop, blip },
    Arg2{ blorp, bleep, bloop, blop, blop, blip }
};

with clang-format version 16.0.0 using your example code and format file.