aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/QualifierAlignmentFixer.cpp
diff options
context:
space:
mode:
authorRuoyu Zhong <zhongruoyu@outlook.com>2025-09-28 11:12:36 +0800
committerGitHub <noreply@github.com>2025-09-27 20:12:36 -0700
commit9a01561760a2785fbf6d66f86ba2361d36a648f7 (patch)
tree642b89a0b70dfda74dec4123167c784832f971ac /clang/lib/Format/QualifierAlignmentFixer.cpp
parent9630b321a50a3712ca092a53a4a4c7bea94b3af2 (diff)
downloadllvm-9a01561760a2785fbf6d66f86ba2361d36a648f7.zip
llvm-9a01561760a2785fbf6d66f86ba2361d36a648f7.tar.gz
llvm-9a01561760a2785fbf6d66f86ba2361d36a648f7.tar.bz2
[clang-format] Fix qualifier ordering for lines after PP directives (#160731)
Lines appearing after preprocessor conditional blocks (like `#endif`) were not having their qualifiers reordered by `QualifierOrder`, while lines inside the conditional blocks were processed correctly. The issue was that tokens on lines following preprocessor directives have `MustBreakBefore` = `true`. The qualifier alignment logic was breaking immediately upon encountering any token with `MustBreakBefore` = `true`, preventing analysis of the entire line. The fix allows processing to continue when `MustBreakBefore` = `true` on the first token of a line, since this is expected behavior (the token legitimately starts a new line). Only tokens with `MustBreakBefore` = `true` that appear mid-line will cause the analysis loop to break. Fixes https://github.com/llvm/llvm-project/issues/160487.
Diffstat (limited to 'clang/lib/Format/QualifierAlignmentFixer.cpp')
-rw-r--r--clang/lib/Format/QualifierAlignmentFixer.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 441a37a..043d957 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -571,7 +571,7 @@ void LeftRightQualifierAlignmentFixer::fixQualifierAlignment(
for (const auto *Tok = First; Tok && Tok != Last && Tok->Next;
Tok = Tok->Next) {
- if (Tok->MustBreakBefore)
+ if (Tok->MustBreakBefore && Tok != First)
break;
if (Tok->is(tok::comment))
continue;