1
votes

I am facing some troubles with the clang-format outcome. I am using v3.8.0.246435 by the way.

Consider following code example:

if(foo)
{
   bar();
   foobar(
      arg1,
      arg2,
      arg3,
      arg4,
      arg5,
      arg6);
}

In the above code everything is indented with 3 spaces. Now if I run clang-format on this code (see bottom of my post for my clang-format config), I get the following output:

if(foo)
{
/*V 3 spaces here */
   bar();
   foobar(
       arg1,
       arg2,
       arg3,
       arg4,
       arg5,
       arg6);
   /*^ 4 spaces here */
}

I find this a very weird behaviour. I want the same indentation levels throughout the code. It seems clang-format always indents the function arguments/parameters with 4 spaces, no matter what value IndentWidth has. Is there a way to override this behaviour? Or is this a bug?

My clang-format cfg:

Language: Cpp
SpaceBeforeParens: Never
SpacesInParentheses: false
SpaceAfterCStyleCast: true
SpacesInSquareBrackets: false
AllowShortIfStatementsOnASingleLine: false
PointerAlignment: Right
AlignOperands: true
AlignConsecutiveAssignments: true
AlignAfterOpenBracket: false
UseTab: Never
IndentWidth: 3
TabWidth: 3
ColumnLimit: 100
MaxEmptyLinesToKeep: 4
KeepEmptyLinesAtTheStartOfBlocks: false
BreakBeforeBraces: Stroustrup
BinPackArguments: false
BinPackParameters: false
AllowShortFunctionsOnASingleLine: None
AlignEscapedNewlinesLeft: true
1

1 Answers

1
votes

Actually, I found out which command is missing. You have to add

ContinuationIndentWidth: 3

or whatever number you want, in order for it to indent continued lines the way you want. Default is 4.