[clang-format] Honour "// clang-format off" when using QualifierOrder.

Fixes https://github.com/llvm/llvm-project/issues/53643.

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D119218
This commit is contained in:
Marek Kurdej 2022-02-09 21:58:22 +01:00
parent e6d9bab558
commit e329b5866f
2 changed files with 26 additions and 0 deletions

View File

@ -390,6 +390,10 @@ LeftRightQualifierAlignmentFixer::analyze(
for (AnnotatedLine *Line : AnnotatedLines) {
FormatToken *First = Line->First;
assert(First);
if (First->Finalized)
continue;
const auto *Last = Line->Last;
for (const auto *Tok = First; Tok && Tok != Last && Tok->Next;

View File

@ -858,5 +858,27 @@ TEST_F(QualifierFixerTest, QualifierTemplates) {
Style);
}
TEST_F(QualifierFixerTest, DisableRegions) {
FormatStyle Style = getLLVMStyle();
Style.QualifierAlignment = FormatStyle::QAS_Custom;
Style.QualifierOrder = {"inline", "static", "const", "type"};
ReplacementCount = 0;
verifyFormat("// clang-format off\n"
"int const inline static a = 0;\n"
"// clang-format on\n",
Style);
EXPECT_EQ(ReplacementCount, 0);
verifyFormat("// clang-format off\n"
"int const inline static a = 0;\n"
"// clang-format on\n"
"inline static const int a = 0;\n",
"// clang-format off\n"
"int const inline static a = 0;\n"
"// clang-format on\n"
"int const inline static a = 0;\n",
Style);
}
} // namespace format
} // namespace clang