-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clang-format-18 ColumnLimit: 0
breaks formatting when encountering empty #if 0 ... #endif
section
#68404
Labels
Comments
Bisected to e9ed1aa. |
rymiel
added a commit
to rymiel/llvm-project
that referenced
this issue
Oct 18, 2023
Pull request llvm#65409 changed the brace kind heuristic to not treat a preprocessor if directive as a in statement, however, this caused some regressions. If the contents of a brace don't immediately determine the brace kind, the heuristic will look at the characters immediately before and after the closing brace to determine the brace type. Unfortunately, if the closing brace was preceded by a preprocessor directive, for example `#endif`, the preceding token was `endif`, seen as just an identifier, so the braces were understood as a braced list. This patch fixes this behaviour by skipping all preprocessor directives when calculating brace types. Comments were already being skipped, so now preprocessor lines are skipped alongside comments. Fixes llvm#68404
rymiel
added a commit
that referenced
this issue
Nov 3, 2023
Pull request #65409 changed the brace kind heuristic to not treat a preprocessor if directive as a in statement, however, this caused some regressions. If the contents of a brace don't immediately determine the brace kind, the heuristic will look at the characters immediately before and after the closing brace to determine the brace type. Unfortunately, if the closing brace was preceded by a preprocessor directive, for example `#endif`, the preceding token was `endif`, seen as just an identifier, so the braces were understood as a braced list. This patch fixes this behaviour by skipping all preprocessor directives when calculating brace types. Comments were already being skipped, so now preprocessor lines are skipped alongside comments. Fixes #68404
qihangkong
pushed a commit
to rvgpu/llvm
that referenced
this issue
Apr 18, 2024
Pull request #65409 changed the brace kind heuristic to not treat a preprocessor if directive as a in statement, however, this caused some regressions. If the contents of a brace don't immediately determine the brace kind, the heuristic will look at the characters immediately before and after the closing brace to determine the brace type. Unfortunately, if the closing brace was preceded by a preprocessor directive, for example `#endif`, the preceding token was `endif`, seen as just an identifier, so the braces were understood as a braced list. This patch fixes this behaviour by skipping all preprocessor directives when calculating brace types. Comments were already being skipped, so now preprocessor lines are skipped alongside comments. Fixes llvm/llvm-project#68404
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Given following
.clang-format
file:And following
foo.cpp
source file:I expect that
clang-format-18 foo.cpp
will not perform formatting (or at least not in a broken way), however, it does:After changing the value of
ColumnLimit: 0
to something like 80, the issue is no more. We can also add some code into the#if 0
part, andclang-format
will not perform formatting in broken way anymore withColumnLimit: 0
.clang-format-18
version:The text was updated successfully, but these errors were encountered: