3

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
}
cryptickey
  • 169
  • 8
  • 2
    Re-flowing comments is extremely difficult, and clang-format already has inherent trouble wrangling some features because of its unopinionated nature. This is likely a bug, or some 'correctly' functioning formatting. Either way, you can open a bug-report with clang-format, but I doubt you'll get any merge in the next 1-2 years lol. – Hunter Kohler Nov 28 '21 at 20:12

0 Answers0