[PATCH] D127260: [clang-format] Remove braces of else blocks that embody an if block

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 8 15:02:54 PDT 2022


owenpan added a comment.

In D127260#3567476 <https://reviews.llvm.org/D127260#3567476>, @curdeius wrote:

> Still looks good. Was there a particular case where the previous version didn't work?

The assertion I added on line 2626, which would ensure that the `RemoveBraces` lambda on line 898 didn't miss any potentially removable braces, would fail because `parseLevel()` was indiscriminately passing the `l_brace` of the last `if` in the level to its caller. This new version is also a tiny bit more efficient because `IfLBrace` on line 2624 will be null if the `else` block that encloses the `if` block is not a simple block.

Because neither version would remove non-optional braces, I decided not to add a test case just for the assertion, e.g.,

  if (a)
    b;
  else {
    c;
    if (d) {
      e;
      f;
    }
  }


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127260/new/

https://reviews.llvm.org/D127260



More information about the cfe-commits mailing list