Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-format RemoveBracesLLVM should handle else block containing an if block #55663

Closed
owenca opened this issue May 23, 2022 · 2 comments
Closed
Assignees
Labels
clang-format enhancement Improving things as opposed to bug fixing, e.g. new or missing feature

Comments

@owenca
Copy link
Contributor

owenca commented May 23, 2022

The RemoveBracesLLVM option doesn't remove the braces of an else block that contains a single if statement when the body of the if statement is a block:

$ cat test.cpp
void f() {
  if (a1)
    f1();
  else {
    if (a2)
      f2();
  }

  if (a3)
    f3();
  else {
    if (b) {
      g();
      h();
    }
  }
}
$ clang-format -version
clang-format version 15.0.0 (https://github.com/llvm/llvm-project 09865ae95dbf0322bbf3e7b3847b2b11373a0297)
$ clang-format -style="{InsertBraces: true, RemoveBracesLLVM: true}" test.cpp
void f() {
  if (a1)
    f1();
  else if (a2)
    f2();

  if (a3) {
    f3();
  } else {
    if (b) {
      g();
      h();
    }
  }
}

Expected output:

...
  if (a3) {
    f3();
  } else if (b) {
    g();
    h();
  }
...
@owenca owenca added enhancement Improving things as opposed to bug fixing, e.g. new or missing feature clang-format labels May 23, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented May 23, 2022

@llvm/issue-subscribers-clang-format

owenca added a commit that referenced this issue Jun 7, 2022
Change the signatures of parseBlock(), parseLevel(), and
parseStructuralElement() to support combining else and if when
removing braces. See #55663.

Differential Revision: https://reviews.llvm.org/D127005
@owenca owenca self-assigned this Jun 7, 2022
@owenca
Copy link
Contributor Author

owenca commented Jun 7, 2022

@owenca owenca added the awaiting-review Has pending Phabricator review label Jun 7, 2022
@owenca owenca closed this as completed in 5ead1f1 Jun 8, 2022
@github-actions github-actions bot removed the awaiting-review Has pending Phabricator review label Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format enhancement Improving things as opposed to bug fixing, e.g. new or missing feature
Projects
None yet
Development

No branches or pull requests

2 participants