[cfe-dev] [llvm-dev] clang-format behaviour for braced lists indent

Owen Pan via cfe-dev cfe-dev at lists.llvm.org
Mon Mar 2 01:39:20 PST 2020


Hi Martin,

It seems to work well using the clang-format file you gave me before:

*bin*$ clang-format -version

clang-format version 10.0.0 (https://github.com/llvm/llvm-project.git
90c78073f73eac58f4f8b4772a896dc8aac023bc)

*bin*$ clang-format

// shows behaviour of clang-format for line-breaks with initializers

static t_component_list _component_list_variable[]

    = {E_COMPONENT_LIST_VALUE_0,

       E_COMPONENT_LIST_VALUE_1,

       E_COMPONENT_LIST_VALUE_0,

       E_COMPONENT_LIST_VALUE_1,

       E_COMPONENT_LIST_VALUE_0,

       E_COMPONENT_LIST_OTHER_VALUE};

// shows behaviour of clang-format for line-breaks with initializers

static t_component_list _component_list_variable[] = {

    E_COMPONENT_LIST_VALUE_0,

    E_COMPONENT_LIST_VALUE_1,

    E_COMPONENT_LIST_VALUE_0,

    E_COMPONENT_LIST_VALUE_1,

    E_COMPONENT_LIST_VALUE_0,

    E_COMPONENT_LIST_OTHER_VALUE};

*bin*$ cat .clang-format

---

Language: Cpp

BasedOnStyle: LLVM

# https://clang.llvm.org/docs/ClangFormatStyleOptions.html

# compare against `clang-format --style=webkit -dump-config > .clang-format`

AccessModifierOffset: -4

AlignAfterOpenBracket: AlwaysBreak

AlignConsecutiveAssignments: true

# aligns struct members but then also declarations, function prototypes

AlignConsecutiveDeclarations: false

# NYI in clang-format-8

# AlignConsecutiveMacros: true

AlignEscapedNewlines: Left

AlignOperands:   false

AlignTrailingComments: true

# AllowAllArgumentsOnNextLine: true

AllowAllParametersOfDeclarationOnNextLine: false

AllowShortBlocksOnASingleLine: false

AllowShortCaseLabelsOnASingleLine: false

AllowShortFunctionsOnASingleLine: None

AllowShortIfStatementsOnASingleLine: false

AllowShortLoopsOnASingleLine: false

AlwaysBreakBeforeMultilineStrings : true

AlwaysBreakAfterDefinitionReturnType: None

AlwaysBreakAfterReturnType: None

AlwaysBreakBeforeMultilineStrings: false

AlwaysBreakTemplateDeclarations: MultiLine

BinPackArguments: false

BinPackParameters: false

BraceWrapping:

#  AfterCaseLabel:  true

  AfterClass:      true

  AfterControlStatement: true

  AfterEnum:       true

  AfterFunction:   true

  AfterNamespace:  false

  AfterObjCDeclaration: false

  AfterStruct:     true

  AfterUnion:      true

  AfterExternBlock: true

  BeforeCatch:     true

  BeforeElse:      true

  IndentBraces:    false

  SplitEmptyFunction: true

  SplitEmptyRecord: true

  SplitEmptyNamespace: true

BreakBeforeBinaryOperators: None

BreakBeforeBraces: Custom

BreakBeforeInheritanceComma: false

BreakInheritanceList: BeforeComma

BreakBeforeTernaryOperators: true

BreakConstructorInitializersBeforeComma: true

BreakConstructorInitializers: BeforeComma

BreakAfterJavaFieldAnnotations: false

BreakStringLiterals: true

ColumnLimit:     120

CommentPragmas:  '^ IWYU pragma:'

CompactNamespaces: false

ConstructorInitializerAllOnOneLineOrOnePerLine: true

ConstructorInitializerIndentWidth: 4

ContinuationIndentWidth: 4

Cpp11BracedListStyle: true

DerivePointerAlignment: false

DisableFormat:   false

ExperimentalAutoDetectBinPacking: false

FixNamespaceComments: false

ForEachMacros:

  - foreach

  - Q_FOREACH

  - BOOST_FOREACH

IncludeBlocks:   Preserve

IncludeCategories:

  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'

    Priority:        2

  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'

    Priority:        3

  - Regex:           '.*'

    Priority:        1

IncludeIsMainRegex: '(Test)?$'

IndentCaseLabels: true

# doesn't seemt to work

# IndentPPDirectives: BeforeHash

IndentWidth:     4

IndentWrappedFunctionNames: false

JavaScriptQuotes: Leave

JavaScriptWrapImports: true

KeepEmptyLinesAtTheStartOfBlocks: false

MacroBlockBegin: ''

MacroBlockEnd:   ''

MaxEmptyLinesToKeep: 1

NamespaceIndentation: All

ObjCBinPackProtocolList: Auto

ObjCBlockIndentWidth: 2

ObjCSpaceAfterProperty: false

ObjCSpaceBeforeProtocolList: true

PenaltyBreakAssignment: 2

PenaltyBreakBeforeFirstCallParameter: 19

PenaltyBreakComment: 300

PenaltyBreakFirstLessLess: 120

PenaltyBreakString: 1000

PenaltyBreakTemplateDeclaration: 10

PenaltyExcessCharacter: 1000000

PenaltyReturnTypeOnItsOwnLine: 2000000

PointerAlignment: Right

ReflowComments:  true

SortIncludes:    true

SortUsingDeclarations: true

SpaceAfterCStyleCast: true

SpaceAfterTemplateKeyword: true

SpaceBeforeAssignmentOperators: true

SpaceBeforeCpp11BracedList: true

SpaceBeforeCtorInitializerColon: true

SpaceBeforeInheritanceColon: true

SpaceBeforeParens: ControlStatements

SpaceBeforeRangeBasedForLoopColon: true

SpaceInEmptyParentheses: false

SpacesBeforeTrailingComments: 1

SpacesInAngles:  false

SpacesInContainerLiterals: false

SpacesInCStyleCastParentheses: false

SpacesInParentheses: false

SpacesInSquareBrackets: false

Standard:        Cpp11

StatementMacros:

  - Q_UNUSED

  - QT_REQUIRE_VERSION

# using a big tab-width so abuse is shown immediately

TabWidth:        8

UseTab:          Never

...

*bin*$

On Fri, Feb 28, 2020 at 10:28 PM martin lampacher <lmapii at googlemail.com>
wrote:

> hi owen,
>
> i've been using my pre-built clang-format from SVN now for a while and
> tried to switch to clang-format-10, where i'm running into a similar issue.
> was this fix never merged or maybe it got lost during the transition to git?
>
> i'm seeing the following output now for such a formatted list:
>
> // shows behaviour of clang-format for line-breaks with initializers
> static t_component_list _component_list_variable[]
> = {E_COMPONENT_LIST_VALUE_0,
> E_COMPONENT_LIST_VALUE_1,
> E_COMPONENT_LIST_VALUE_0,
> E_COMPONENT_LIST_VALUE_1,
> E_COMPONENT_LIST_VALUE_0,
> E_COMPONENT_LIST_OTHER_VALUE};
>
> where i'd expect
>
> // shows behaviour of clang-format for line-breaks with initializers
> static t_component_list _component_list_variable[] = {
> E_COMPONENT_LIST_VALUE_0,
> E_COMPONENT_LIST_VALUE_1,
> E_COMPONENT_LIST_VALUE_0,
> E_COMPONENT_LIST_VALUE_1,
> E_COMPONENT_LIST_VALUE_0,
> E_COMPONENT_LIST_OTHER_VALUE};
>
> cheers.m
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200302/6683120d/attachment-0001.html>


More information about the cfe-dev mailing list