-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Open
Labels
Description
Our codebase is currently formatted using clang-format 6.0.0, so we urgently need to upgrade. Of course we would like to keep the diff as small as possible. Let's assume a minimum .clang-format file:
AlignAfterOpenBracket: AlwaysBreak
BinPackParameters: false
BinPackArguments: false
ContinuationIndentWidth: 2
BreakBeforeBinaryOperators: NonAssignmentAnd here are three examples of what our code would currently look like:
struct Derived {
Derived(
int firstArgWithLongName,
int secondArgWithLongName,
int thirdArgWithLongName,
int fourthArgWithLongName)
: Base(
firstArgWithLongName,
secondArgWithLongName,
thirdArgWithLongName,
fourthArgWithLongName) {}
};
{
return LongFunctionName(Arg1, ArgWithLongName2)
? SomeVeryLongFunctionCall(
Arg1,
Arg2,
NestedFunctionCallWithAveryLongName(
ArgToTheNestedFunctionCallWhichAlsoHasLongName))
: SomeOtherFunctionCall(Arg);
}
{
return VeryLongFunctionNameWithAVeryLongName(Arg1, Arg2)
|| FunctionName(
Arg1, Arg2, ArgWithLongName, ArgWithEvenLongerVeryLongName);
}Using clang-format 16.0.0, the formatting would change to this:
struct Derived {
Derived(
int firstArgWithLongName,
int secondArgWithLongName,
int thirdArgWithLongName,
int fourthArgWithLongName)
: Base(
firstArgWithLongName, // <- changed indentation
secondArgWithLongName,
thirdArgWithLongName,
fourthArgWithLongName) {}
};
{
return LongFunctionName(Arg1, ArgWithLongName2) ? SomeVeryLongFunctionCall(
Arg1, // <- changed linebreaks...
Arg2,
NestedFunctionCallWithAveryLongName(
ArgToTheNestedFunctionCallWhichAlsoHasLongName))
: SomeOtherFunctionCall(Arg);
}
{
return VeryLongFunctionNameWithAVeryLongName(Arg1, Arg2)
|| FunctionName(
Arg1, Arg2, ArgWithLongName, ArgWithEvenLongerVeryLongName); // <- changed indentation
}Here's a patch that would keep all three examples formatted as they are:
0001-Fix-Continuation-Indenter-1.patch.txt
And here's a patch that would fix only the first example:
0001-Fix-Continuation-Indenter-2.patch.txt
The issue was most probably a by-product of this bugfix:
4636deb