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

Marek Kurdej via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 9 13:15:26 PST 2022


Author: Marek Kurdej
Date: 2022-02-09T22:15:20+01:00
New Revision: e329b5866f1732f5c24cf2ae96479971f7101914

URL: https://github.com/llvm/llvm-project/commit/e329b5866f1732f5c24cf2ae96479971f7101914
DIFF: https://github.com/llvm/llvm-project/commit/e329b5866f1732f5c24cf2ae96479971f7101914.diff

LOG: [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

Added: 
    

Modified: 
    clang/lib/Format/QualifierAlignmentFixer.cpp
    clang/unittests/Format/QualifierFixerTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 13af32a9f4f47..233b081a95f6d 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -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;

diff  --git a/clang/unittests/Format/QualifierFixerTest.cpp b/clang/unittests/Format/QualifierFixerTest.cpp
index 0517de2820d9d..14f09d875e6be 100755
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -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


        


More information about the cfe-commits mailing list