[PATCH] D95168: Add InsertBraces option
Tiago Macarios via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 22 09:56:43 PST 2021
tiagoma added inline comments.
================
Comment at: clang/docs/ClangFormatStyleOptions.rst:2254
+
+ * ``BIS_WrapLikely`` (in configuration: ``WrapLikely``)
+ Insert braces if wrapping is likely
----------------
curdeius wrote:
> Shouldn't it be consistent with clang-tidy? So instead of an enum, this option might take a number of lines that will trigger brace insertion? None may be sth like -1. "Likely" is very vague.
I am not sure this is possible. clang-tidy assumes the code is already formatted, we cannot assume that in clang-format. This pass runs before the formatter pass, so basing the behavior on line count would lead to different behavior across runs. For example:
Assuming we can set this option to 2 lines and we have the following code:
```
if (condition)
very_long_line_that_will_wrap(arg, arg, arg ,arg)
```
first run:
```
if (condition)
very_long_line_that_will_wrap(
arg, arg, arg ,arg)
```
second run:
```
if (condition) {
very_long_line_that_will_wrap(
arg, arg, arg ,arg)}
}
```
Likely is indeed vague by design. We "guess" that it will wrap in the formatter pass based on the current column value. See Format.cpp @ 1707. What might happen is that the line is incorrectly indentented and the wrapping never actually happens.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95168/new/
https://reviews.llvm.org/D95168
More information about the cfe-commits
mailing list