llvm / llvm-project

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

Changing results of the continuation indenter #58592

Open hel-ableton opened 2 years ago

hel-ableton commented 2 years ago

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: NonAssignment

And 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: https://github.com/llvm/llvm-project/commit/4636debc271f09f730697ab6873137a657c828f9

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-format

owenca commented 1 year ago

https://reviews.llvm.org/D136154