Skip to content

Commit 67e0b64

Browse files
mkurdejtstellar
authored andcommitted
[clang-format] Honour "// clang-format off" when using QualifierOrder.
Fixes llvm#53643. Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D119218 (cherry picked from commit e329b58)
1 parent a42f1f8 commit 67e0b64

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

clang/lib/Format/QualifierAlignmentFixer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ LeftRightQualifierAlignmentFixer::analyze(
396396

397397
for (AnnotatedLine *Line : AnnotatedLines) {
398398
FormatToken *First = Line->First;
399+
assert(First);
400+
if (First->Finalized)
401+
continue;
402+
399403
const auto *Last = Line->Last;
400404

401405
for (const auto *Tok = First; Tok && Tok != Last && Tok->Next;

clang/unittests/Format/QualifierFixerTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,5 +858,27 @@ TEST_F(QualifierFixerTest, QualifierTemplates) {
858858
Style);
859859
}
860860

861+
TEST_F(QualifierFixerTest, DisableRegions) {
862+
FormatStyle Style = getLLVMStyle();
863+
Style.QualifierAlignment = FormatStyle::QAS_Custom;
864+
Style.QualifierOrder = {"inline", "static", "const", "type"};
865+
866+
ReplacementCount = 0;
867+
verifyFormat("// clang-format off\n"
868+
"int const inline static a = 0;\n"
869+
"// clang-format on\n",
870+
Style);
871+
EXPECT_EQ(ReplacementCount, 0);
872+
verifyFormat("// clang-format off\n"
873+
"int const inline static a = 0;\n"
874+
"// clang-format on\n"
875+
"inline static const int a = 0;\n",
876+
"// clang-format off\n"
877+
"int const inline static a = 0;\n"
878+
"// clang-format on\n"
879+
"int const inline static a = 0;\n",
880+
Style);
881+
}
882+
861883
} // namespace format
862884
} // namespace clang

0 commit comments

Comments
 (0)