Open gmarull opened 2 years ago
@llvm/issue-subscribers-clang-format
Just FYI: With clang-format 14.0.6 and a little "bisecting" the content of .clang-format, I came to the interesting conclusion that just setting "Cpp11BracedListStyle: true" magically fixes the misaligned line continuation backslashes I saw in long macro calls.
I've added Cpp11BracedListStyle: true
to our latest .clang-format, but it doesn't resolve the problem described here.
What a pity. Then it only helps with your .clang-format on v3.1-branch.
Just tried with v3.1, not solving the problem either.
Please note that I commented in this LLVM issue to bring to the attention of the clang-format maintainers that Cpp11BracedListStyle
has a seemingly totally unrelated effect on trailing backslash alignment. Not sure if I highjacked the issue somehow.
Regarding Zephyr's .clang-format, here's my example, formatted with .clang-format on v3.1-branch. It can be repaired both by using .clang-format from main (dddb5dd) or just setting Cpp11BracedListStyle: true.
#define GPIO_FOO_INIT(n) \
static const struct foo_gpio_config foo_gpio_config_##n = { \
.common = \
{ \
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n), \
}, \
.base = DT_INST_REG_ADDR(n), \
.config_func = port_##n##_foo_config_func, \
}; \
\
static struct foo_gpio_runtime foo_gpio_runtime_##n;
In Zephyr RTOS we have added a .clang-format that matches our style guide (similar to the Linux Kernel one). We use tabs for indentation, and spaces to align when needed.
We have found that in multiline macros (something we use extensively), empty lines start with leading spaces. We would expect to have a tab first instead, as other macro lines do.
It turns out to be a problem on our side since we also run
checkpatch.pl
(from Linux) on our patches: it complains about bad indentation/leading spaces. The best solution I have come out is by patching checkpatch so that it ignores such edge case: https://github.com/zephyrproject-rtos/zephyr/pull/46611, however, I wonder if this is an issueclang-format
could address, or, if there's an option I have missed.