clang-format: incorrect indentation after #elif
| Bugzilla Link | 48664 |
| Version | unspecified |
| OS | Linux |
Extended Description
The code is:
void loop()
{
int iter = 0;
#if FOO
for (; iter < 10; iter++) {
#else
for (;; iter++) {
#endif
for (;;) {
#if BAR && BAZ
if (foo1())
continue;
#elif BAR
if (foo2())
continue;
#else
if (foo3())
continue;
#endif
break;
}
}
}
The bug is foo3 mis-indentation.
This breaks builds because clang later errors on the code produced by clang-format:
This may have something to do with #elif, because this works:
void loop()
{
int iter = 0;
#if FOO
for (; iter < 10; iter++) {
#else
for (;; iter++) {
#endif
for (;;) {
#if BAR
#if BAZ
if (foo1())
continue;
#else
if (foo2())
continue;
#endif
#else
if (foo3())
continue;
#endif
break;
}
}
}
The style is:
BasedOnStyle: LLVM IndentWidth: 8 UseTab: Always BreakBeforeBraces: Linux IndentCaseLabels: false DerivePointerAlignment: false PointerAlignment: Left AlignTrailingComments: true AllowShortBlocksOnASingleLine: false AllowShortFunctionsOnASingleLine: false AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false ColumnLimit: 0 AlignTrailingComments: false
Factored out of: llvm/llvm-project#44188 #c4
For context see: https://github.com/google/syzkaller/pull/2364
Tested with 11.0.0 ca2dcbd030eadbf0aa9b660efe864ff08af6e18b and 38d32e4fd70cc2b1f6ec10b578a56e631e8ed658.
Edited top post to preserve meaningful whitespace.