[clang-format] Correctly format loops and `if` statements even if preceded with comments.
Fixes https://github.com/llvm/llvm-project/issues/53758. Braces in loops and in `if` statements with leading (block) comments were formatted according to `BraceWrapping.AfterFunction` and not `AllowShortBlocksOnASingleLine`/`AllowShortLoopsOnASingleLine`/`AllowShortIfStatementsOnASingleLine`. Previously, the code: ``` while (true) { f(); } /*comment*/ while (true) { f(); } ``` was incorrectly formatted to: ``` while (true) { f(); } /*comment*/ while (true) { f(); } ``` when using config: ``` BasedOnStyle: LLVM BreakBeforeBraces: Custom BraceWrapping: AfterFunction: false AllowShortBlocksOnASingleLine: false AllowShortLoopsOnASingleLine: false ``` and it was (correctly but by chance) formatted to: ``` while (true) { f(); } /*comment*/ while (true) { f(); } ``` when using enabling brace wrapping after functions: ``` BasedOnStyle: LLVM BreakBeforeBraces: Custom BraceWrapping: AfterFunction: true AllowShortBlocksOnASingleLine: false AllowShortLoopsOnASingleLine: false ``` Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D119649
parent
986afe84
Please register or sign in to comment