Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing results of the continuation indenter #58592

Open
hel-ableton opened this issue Oct 25, 2022 · 2 comments
Open

Changing results of the continuation indenter #58592

hel-ableton opened this issue Oct 25, 2022 · 2 comments

Comments

@hel-ableton
Copy link

hel-ableton commented Oct 25, 2022

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:
4636deb

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 25, 2022

@llvm/issue-subscribers-clang-format

@owenca owenca added the awaiting-review Has pending Phabricator review label Oct 27, 2022
@owenca
Copy link
Contributor

owenca commented Oct 27, 2022

owenca added a commit to owenca/llvm-project that referenced this issue Sep 14, 2023
@owenca owenca removed the awaiting-review Has pending Phabricator review label Sep 15, 2023
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this issue Sep 19, 2023
zahiraam pushed a commit to tahonermann/llvm-project that referenced this issue Oct 24, 2023
zahiraam pushed a commit to tahonermann/llvm-project that referenced this issue Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants