uncrustify
uncrustify copied to clipboard
Weird indentation inside parentheses in preprocessor directives
Uncrustify seems to sometimes indent preprocessor directives incorrectly when they contain a multiline parenthesized expression.
Configuration file:
indent_columns = 4
Sample input (only the first half with preprocessor directives matters, the second half is for illustration purposes):
#if (macro(foo) && \
bar)
#endif
#if (defined(foo) && \
bar)
#endif
#if ((foo1 || foo2) && \
bar)
#endif
{
if (macro(foo) &&
bar) {
}
if (defined(foo) &&
bar) {
}
if ((foo1 || foo2) &&
bar) {
}
}
Expected output: same as input
Actual output when continuing after defined(foo) &&
or (foo1 || foo2)
, the continuation line bar)
is intended to the indent_columns
setting, rather than to the same level as the first expression inside the parentheses:
#if (macro(foo) && \
bar)
#endif
#if (defined(foo) && \
bar)
#endif
#if ((foo1 || foo2) && \
bar)
#endif
{
if (macro(foo) &&
bar) {
}
if (defined(foo) &&
bar) {
}
if ((foo1 || foo2) &&
bar) {
}
}
Justification for expected output: I expect multiline expressions to be intended to the column after the opening parenthesis. This happens as expected in normal code, and it happens as expected in preprocessor directives sometimes, but not when the first line contains certain expressions such as defined(foo)
or an expression which is itself in parentheses.
I couldn't find a relevant configuration option that would give me the result I want, but it's of course possible that I missed something, and the default behavior doesn't make sense to me anyway (why would macro(foo)
vs defined(foo)
matter for the indentation of what's next?).
Real-world case: https://github.com/Mbed-TLS/mbedtls/pull/7808#discussion_r1237025799
The results are identical with uncrustify 0.75.1, 0.76.0 and 970fef45708d78535f89ccf8ba9ed4b0b38bf7a2.
Input, configuration, output and debug file: debug.zip
Merci pour le message! I can reproduce.