Issue 148662
Summary readability-else-after-return breaks comments (needs newline)
Labels new issue
Assignees
Reporter higher-performance
    This check turns code such as
```
void f(int a) {
  if (a > 0) {
    return;
  } else {
    // comment-1
 return;
  }
}
```
into
```
void f(int a) {
  if (a > 0) {
 return;
  }     // comment-1
    // another line
 return;

}
```
which is problematic because `comment-1` is associated with the subsequent line, not with the preceding closing brace. This trips up clang-format as well.

A better fix would have been
```
void f(int a) {
 if (a > 0) {
    return;
  }
    // comment-1
    // another line
 return;

}
```
which can then get formatted correctly by clang-format.

I'm not sure how to produce the correct fix here without breaking other cases, though.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to