Issue |
153591
|
Summary |
clangd-tidy: bugprone-branch-clone: ignore switch cases which contain only "break" keyword
|
Labels |
new issue
|
Assignees |
|
Reporter |
nvartolomei
|
I want to propose to change the behavior of the https://clang.llvm.org/extra/clang-tidy/checks/bugprone/branch-clone.html check such that it also ignores cases where the branch contains only the `break` keyword similar to how it ignores `[[fallthrough]]`.
The way to silence the warning is to either silence it explicitly or convert the code to use `[[fallthrough]]` and I find them both being worse than keeping the `break` keyword. Ideally it would be done only before pre-processing rather than post to make sure that indeed there is only `break` statement there (impossible?).
I have code like this
```cpp
switch (/* ... */) {
// ...
case config::datalake_catalog_auth_mode::aws_sigv4: {
// AWS SigV4 signing will be handled after build() is called
break;
}
case config::datalake_catalog_auth_mode::gcp: {
// GCP credentials are handled by the credential manager and will be
// applied after build() is called
break;
}
}
```
This now is readable and has nice comments saying why the break statement is there. The comment and implementation are local too. Comment says there is nothing to be done and `break` keyword "implements" that.
If we were to refactor it with `[[fallthrough]]` now the action is not as close. I have to keep reading to see the actual behavior. Sometimes for many branches.
Not only that, if someone comes in the future and changes slightly the behavior of `gcp` case in this example then by accident the behavior of `aws_sigv4` also changes. I'd say that `[[fallthrough]]` here is actually more bugprone.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs