Avoid bin packing conditions inside if statement

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Avoid bin packing conditions inside if statement

Sumner, Brian via cfe-dev
Hi All,

I'm curious if anybody tried to implement an option for clang-format to prevent bin packing conditions inside if statements (or maybe it already exists and I missed it).

Here is an example,

% cat test.cpp
void func(int a,
          double b,
          bool c);
int main() {
  func(123456,
       1.23456,
       false);
  if(false ||
     true ||
     false) {
     // stuff
  }
  return 0;
}

Formatting with default settings (except a column limit) produces the following:

% ./clang-format -style="{BasedOnStyle: LLVM, ColumnLimit: 27}" test.cpp
void func(int a, double b,
          bool c);
int main() {
  func(123456, 1.23456,
       false);
  if (false || true ||
      false) {
    // stuff
  }
  return 0;
}

It's possible to prevent bin packing of function parameters and arguments:

% ./clang-format -style="{BasedOnStyle: LLVM, ColumnLimit: 27, BinPackParameters: false, BinPackArguments: false}" test.cpp
void func(int a,
          double b,
          bool c);
int main() {
  func(123456,
       1.23456,
       false);
  if (false || true ||
      false) {
    // stuff
  }
  return 0;
}

But nothing I can do about conditions inside the if statement. And I believe such an option would be quite useful as it provides the same readability benefits as BinPackParameters and BinPackArguments.

Thanks,
Mikhail


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...