[PATCH] D110359: [clang-format] [NFC] ensure clang-format command-line argument sets up the default left/right qualifier ordering

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 23 12:57:31 PDT 2021


MyDeveloperDay updated this revision to Diff 374652.
MyDeveloperDay added a comment.

Allow passing of desired qualifier order on the command line

  clang-format --qualifier-alignment="const static type volatile" test_file.cpp


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110359/new/

https://reviews.llvm.org/D110359

Files:
  clang/tools/clang-format/ClangFormat.cpp


Index: clang/tools/clang-format/ClangFormat.cpp
===================================================================
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -106,9 +106,9 @@
     cl::cat(ClangFormatCategory));
 
 static cl::opt<std::string> QualifierAlignment(
-    "qualifier-aligment",
+    "qualifier-alignment",
     cl::desc(
-        "If set, overrides the cvqualifier style behavior determined by the "
+        "If set, overrides the qualifier alignment style determined by the "
         "QualifierAlignment style flag"),
     cl::init(""), cl::cat(ClangFormatCategory));
 
@@ -418,6 +418,17 @@
           .Case("left", FormatStyle::QAS_Left)
           .Default(FormatStyle->QualifierAlignment);
 
+  if (FormatStyle->QualifierAlignment == FormatStyle::QAS_Left)
+    FormatStyle->QualifierOrder = {"const", "volatile", "type"};
+  else if (FormatStyle->QualifierAlignment == FormatStyle::QAS_Right)
+    FormatStyle->QualifierOrder = {"type", "const", "volatile"};
+  else if (ConstAlignment.contains("type")) {
+    FormatStyle->QualifierAlignment = FormatStyle::QAS_Custom;
+    SmallVector<StringRef> Qualifiers;
+    ConstAlignment.split(Qualifiers, " ", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
+    FormatStyle->QualifierOrder = {Qualifiers.begin(), Qualifiers.end()};
+  }
+
   if (SortIncludes.getNumOccurrences() != 0) {
     if (SortIncludes)
       FormatStyle->SortIncludes = FormatStyle::SI_CaseSensitive;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110359.374652.patch
Type: text/x-patch
Size: 1480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210923/f9ffbce8/attachment-0001.bin>


More information about the cfe-commits mailing list