Break after operator=( in clang-format - c++

I'm using clang-format from LLVM 7.0.0 with Windows 10 in C++.
I have following class
class FooooooooooooooooooC
{
public:
FooooooooooooooooooC() = default;
const FooooooooooooooooooC& operator=( const FooooooooooooooooooC& ) = delete;
};
and after running clang-format it should look like this
class FooooooooooooooooooC
{
public:
FooooooooooooooooooC() = default;
const FooooooooooooooooooC& operator=(
const FooooooooooooooooooC& ) = delete;
};
But actually it look like this after running clang-format
class FooooooooooooooooooC
{
public:
FooooooooooooooooooC() = default;
const FooooooooooooooooooC&
operator=( const FooooooooooooooooooC& ) = delete;
};
My clang-fromat settings in .clang-format are
---
AccessModifierOffset: -3
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAfterJavaFieldAnnotations: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
CommentPragmas: '^ IWYU pragma:'
ColumnLimit: 80
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 3
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 3
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 1000000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: true
SpacesInSquareBrackets: true
Standard: Cpp11
TabWidth: 3
UseTab: Never
...
Does somebody know how to configure clang-fromat to create a break after
operator=(
Thanks!

In summary, you can't quite do what you want.
Here is how to configure clang-format to not put a break after const FooooooooooooooooooC&.
When deciding how to break up the line, clang-format uses several weighting factors whose names all start with Penalty. In this case, you desire the return type to stay on the same line as the function name, so you want to adjust PenaltyReturnTypeOnItsOwnLine. The value in your .clang-format is 60. Instead, use:
PenaltyReturnTypeOnItsOwnLine: 200
Make it any value 110 or larger to prevent the line from get broken after the const FooooooooooooooooooC& return type. I suggest 200 to match the pre-defined clang-format styles for Chromium, Google, and Mozilla. (Also, I don't know why 110 is the threshold; the penalty values are fairly opaque and I only found that value by experimenting.)
However, what you then end up with is this:
const FooooooooooooooooooC& operator=( const FooooooooooooooooooC& ) =
delete;
I don't believe there is any way to force the break after operator=(. If your class name was 4 characters longer, then you would get what you're asking for, because the above split before the delete would exceed 80 characters.
The comments above mention ColumnLimit. Even if you were allowed to increase the column limit, it would only allow you to keep the operator= declaration on one line. It wouldn't allow you to force it to split the line after operator=(.
The comments above mention AllowAllParametersOfDeclarationOnNextLine: false. As you discovered, this doesn't solve the problem. When there is more than one parameter, this affects the decision of whether all parameters get put onto separate lines. But you have only one parameter. (See the documentation.)
Finally, a caveat, I am using clang-format 6.0.0, compared to your 7.0.0. But there do not appear to be any differences in clang-format which would make any difference here:
The ReleaseNotes.html doesn't mention anything that would matter
There are several new clang-format style options in 7.0.0 compared to 6.0.0 (which I notice because clang-format 6.0.0 complains about them in your .clang-format file), but none are related to this issue.

Related

clang-format and functions: always add new line after open parenthesis when closing parenthesis is in new line

I've managed to achieve following output after using clang-format:
void doSomethingBlaBlaBla(
very::looooooooooooong::Type veryLongParamNameThatExceedsColumnLimitIfPutAbove
) override;
Meaning that if such line:
void doSomethingBlaBlaBla(very::looooooooooooong::Type veryLongParamNameThatExceedsColumnLimitIfPutAbove) override;
exceeds ColumnLimit, it's being broken like you see above. But I can see that in corner cases clang would handle it differently - where corner case is that this exceeds ColumnLimit:
void doSomethingBlaBlaBla(very::looong::Type veryLongParamNameThatExceedsColumnLimitIfPutAbove) override;
but this alone (note lack of ) override;) doesn't:
void doSomethingBlaBlaBla(very::looong::Type veryLongParamNameThatExceedsColumnLimitIfPutAbove
In such case, clang formats it in a following manner:
void doSomethingBlaBlaBla(very::looong::Type veryLongParamNameThatExceedsColumnLimitIfPutAbove
) override;
It doesn't break line after opening parenthesis, but breaks it before closing one. Is there a config option that would break line after opening parenthesis in this situation?
This is my clang-format so far:
BasedOnStyle: Microsoft
AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent
AllowShortLambdasOnASingleLine: None
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterNamespace: false
AfterControlStatement: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: AfterColon
ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: true
DeriveLineEnding: false
DerivePointerAlignment: true
ExperimentalAutoDetectBinPacking: true
MaxEmptyLinesToKeep: 2
SortIncludes: false
SpaceAfterTemplateKeyword: false
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: false
SpaceBeforeRangeBasedForLoopColon: false
UseCRLF: true
ReflowComments: false
AlwaysBreakTemplateDeclarations: Yes
DeriveLineEnding: true
AllowAllArgumentsOnNextLine: false
...

Is there a way to split logical conditions on new lines?

for example I want to have my line length at 120 - so generally code is only wrapped after 120 chars. But more often then not we want to have our logcal conditions on new lines:
I have the follow expression:
if ((long_function_name_12345().get_some_status1() != status1) ||
(long_function_name_12345().get_some_status2() != status2) ||
force ||
some_other_logical_bool)
{
}
When I clang-format it I get:
if ((long_function_name_12345().get_some_status1() != status1) ||
(long_function_name_12345().get_some_status2() != status2) || force || some_other_logical_bool)
{
}
Which is not as nice. I want the behaviour to be, once we go over the column limit (120 in this case) then break on any logical block. I have found one way to force it:
if ((long_function_name_12345().get_some_status1() != status1) ||
(long_function_name_12345().get_some_status2() != status2) || // break
force || // break
some_other_logical_bool)
{
}
It's a bit crap but works but is (IMO) less ugly then wrapping it in // clang-format off/on tags...
clang-format version 10.0.0-4ubuntu1~18.04.2
.clang-format contents:
---
Language: Cpp
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
# Don't allow function on one line, e.g. 'int f() {return 1;}' - unless its inline
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: false
BinPackParameters: false
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
IndentBraces: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
# have line breaks after operators: 'if (a ||' instead of on the next line ' || b'
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
# effectively the line length limit before clang-format starts to use multiple lines
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
# format braces lists (uniform init) like a function param list
Cpp11BracedListStyle: true
DeriveLineEnding: 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
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
# 'int *p' instead of 'int* p;'
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
...
I could not find anything obvious for this - and maybe its a bit too specific.
This is the best I could find / come up with (as noted in my updated question):
if ((long_function_name_12345().get_some_status1() != status1) ||
(long_function_name_12345().get_some_status2() != status2) || // break
force || // break
some_other_logical_bool)
{
}
i.e. by adding some sort of comment it forces clangformat to not merge the lines

clang format line break in the wrong place

Given the following line of code:
get_abc_manager().get_platform_status(abc_platform_status, sw_update_status, fill_update_status, actions_allowed_status);
I want clang format to break the line on the parameters like - which is what it does in most places (for basic function calls)
get_abc_manager().get_platform_status(
abc_platform_status,
sw_update_status,
fill_update_status,
actions_allowed_status);
But, I think, because it's got the "." to access the returned abc_managers function get_platform_status() it seems to use that as a line to break on so I get:
get_abc_manager().
get_platform_status(abc_platform_status, sw_update_status, fill_update_status, actions_allowed_status);
Line length limit is 120 - so if the params got any longer then it probably would break over the params. In fact, I tried that:
get_abc_manager().get_platform_status(
abc_platform_status,
sw_update_stadddddddddddddddddddddddddtus,
fill_update_status,
actions_allowed_status);
So it's just this "middle" case I don't like where it shortens the line by breaking after the dot before breaking the param list.
Is there a way to prefer breaking the line on the parameters first?
update: clang-format version 10.0.0-4ubuntu1~18.04.2
---
Language: Cpp
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
# Don't allow function on one line, e.g. 'int f() {return 1;}' - unless its inline
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: false
BinPackParameters: false
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
IndentBraces: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
# have line breaks after operators: 'if (a ||' instead of on the next line ' || b'
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
# effectively the line length limit before clang-format starts to use multiple lines
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
# format braces lists (uniform init) like a function param list
Cpp11BracedListStyle: true
DeriveLineEnding: 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
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
# 'int *p' instead of 'int* p;'
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
...

Clang-Format does not properly allign function arguments

I'm trying to format my code this way :
int foo(int a,
int b,
int c)
{
}
However, all my attempts led to this results :
int foo(int a,
int b,
int c)
{
}
Here is my clang-format configuration, running on Manjaro :
# Under Visual studio, the plugin https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.ClangFormat makes the use of the clang formatter easier.
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align #AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: true
ColumnLimit: 120
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
FixNamespaceComments: true
IndentCaseLabels: false
IndentPPDirectives: BeforeHash
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
PointerAlignment: Middle
ReflowComments: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: false
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 4
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never
## Penalites: This decides what order things should be done if a line is too long.
## For instance, using the policies specified here: https://stackoverflow.com/questions/26635370/in-clang-format-what-do-the-penalties-do
PenaltyBreakAssignment: 5
PenaltyBreakBeforeFirstCallParameter: 5
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10
PenaltyBreakTemplateDeclaration : 30
PenaltyExcessCharacter: 30
PenaltyReturnTypeOnItsOwnLine: 30
Does anyone knows how to force this alignement ?
FYI, already tried : Clang-format: Align Function Parameter Names and clang-format: break function parameters
Thanks a lot
Cheers
As I said, I already tried these solutions without success... Setting AlignConsecutiveDeclarations to true generates
Scene(const std::filesystem::path scene_directory,
Object3D * parent,
Magnum::SceneGraph::DrawableGroup3D * group);
EDIT 1 : Found out the issue ! It was induced by my IDE for some unknown reasons. Copy pasting into a text editor shows the formatting is correct.. Thanks for the help !

Clang format not always respecting BinPackParameters: false

I'm trying to use a .clang-format file with Visual Studio 2017 but it doesn't always seem to respect the BinPackParameters argument which I set to false.
With the following parameters set:
AlignAfterOpenBracket: AlwaysBreak
AllowAllParametersOfDeclarationOnNextLine: false
BinPackArguments: false
BinPackParameters: false
ColumnLimit: 110
I would expect my method calls that were too long (i.e. greater than the ColumnWidth parameter) to always line break every parameter to a method so that they are each on different lines like so:
LongMethodNameCall(
someLongParameter1,
someLongParameter2,
someLongParameter3,
someLongParameter4 );
This is the case sometimes, but other times I get:
LongMethodNameCall(
someLongParameter1, someLongParameter2, someLongParameter3, someLongParameter4 );
To be clear I want it to always line-break after the opening bracket and put each parameter onto one line if the whole statement exceeds the ColumnWidth parameter.
Here is my .clang-format file:
Language: Cpp
#DisableFormat: true
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
BreakStringLiterals: true
ColumnLimit: 110
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
IncludeCategories:
- Regex: '\/stdafx.h'
Priority: -1
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakAssignment: 100
PenaltyBreakBeforeFirstCallParameter: 0
PenaltyBreakComment: 0
PenaltyBreakFirstLessLess: 100
PenaltyBreakString: 50
PenaltyExcessCharacter: 20
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesInAngles: true
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: true
SpacesInSquareBrackets: true
TabWidth: 4
UseTab: Never
The only time BinPackParameters: false is not respected is when AllowAllParametersOfDeclarationOnNextLine is set to true, which is not in your case.
I tried with the provided config and could not reproduce the issue.
The tool has probably been modified in the meanwhile.
To clarify, it is crucial to set PenaltyReturnTypeOnItsOwnLine: 1000, which you are already doing. It prevents having the return code on a single line if it enables fitting the rest on a single line:
std::vector<std::string>
test(std::string const & var1, std::string const & var2);
becomes
std::vector<std::string> test(std::string const & var1,
std::string const & var2);