| Issue |
53149
|
| Summary |
[clang-format] AllowShortIfStatementsOnASingleLine doesn't treat short braced-substatements as short
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
MarkRebane
|
```
> clang-format --version
clang-format version 13.0.1 (https://github.com/llvm/llvm-project.git 9dc7d6d5e3261f2cb1ae746ddaaf2f4d4f1f5350)
```
Consider:
```c++
if (true)
break;
if (true)
{
break;
}
```
Given the `.clang-format` configuration:
```
---
Language: Cpp
AllowShortIfStatementsOnASingleLine: WithoutElse
...
```
Actual:
```c++
if (true) break;
if (true) {
break;
}
```
Expected:
```c++
if (true) break;
if (true) { break; }
```
As such, when the substatement in a _selection-statement_ is a single statement, clang-format produces a different output than when the substatement is a _compound-statement_ that contains a single statement. Semantically, the first is as-if the second and so it's confusing to treat them differently without an explicit option.
Additionally, the current behaviour appears to be a regression since when `AllowShortIfStatementsOnASingleLine` was previously a boolean set to `true`, then the above example would produce the expected result.
Instead, I think `AllowShortIfStatementsOnASingleLine` ought to treat these two cases identically for both `if` and `else` forms of the `if` statement for all supported options. This change would improve the consistency with other `AllowShortXOnASingleLine` options and make these options universally useful for coding standards that require braces around all control statement substatements.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs