clang-format reflowing comments incorrectly and is non repeatable

807 Views Asked by At

The following code snippet in C++, when formatted using clang-format-8, gives incorrect result in the first run (disrespecting ColumnWidth=80) and correct result in the second and subsequent runs. Note: the code contains tab in the comments (something which was not indented using spaces, as they were mere comments). It seems ReflowComments is not working as intended. Why is it so and how to handle such cases, especially when we need to reflow long comments and merge changes across previously formatted code in different git branch.

clang-format-8 -style=Google -i src/test.cpp

void f() {
  // arg0,
  // arg1,                                              arg2,                                               arg3,                                               arg4,
  //                                                arg5,
  //                                                arg6,
  //                                                arg7,
  //                                                arg8,
  //                                                arg9,
  //                                                arg10
}

Formatted Version 1 (Incorrect)

void f() {
  // arg0,
  // arg1,                                              arg2,
  // arg3,
  // arg4,                                              arg5,                                               arg6,                                               arg7,                                               arg8,                                               arg9,                                               arg10
}

Formatted Version 2 (Not incorrect)

void f() {
  // arg0,
  // arg1,
  // arg2, arg3, arg4,
  // arg5,                                              arg6,
  // arg7,                                              arg8,
  // arg9,
  // arg10
}
0

There are 0 best solutions below