[llvm-branch-commits] [clang] 67e0b64 - [clang-format] Honour "// clang-format off" when using QualifierOrder.

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Feb 14 14:15:38 PST 2022


Author: Marek Kurdej
Date: 2022-02-14T14:12:07-08:00
New Revision: 67e0b64c0e6c769126b354b39bc5fa3f5d9d73d1

URL: https://github.com/llvm/llvm-project/commit/67e0b64c0e6c769126b354b39bc5fa3f5d9d73d1
DIFF: https://github.com/llvm/llvm-project/commit/67e0b64c0e6c769126b354b39bc5fa3f5d9d73d1.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

(cherry picked from commit e329b5866f1732f5c24cf2ae96479971f7101914)

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 b3a4684bead1a..0142a6c08ed30 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -396,6 +396,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 llvm-branch-commits mailing list