cryptickey
cryptickey

Reputation: 308

clang-format reflowing comments incorrectly and is non repeatable

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
}

Upvotes: 4

Views: 1159

Answers (0)

Related Questions