[PATCH] D108882: Add backward compatibility tests for PackConstructorInitializers

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 29 13:51:48 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG4b1fde8a2b68: [clang-format] Add PackConstructorInitializers backward compat test (authored by owenpan).

Changed prior to commit:
  https://reviews.llvm.org/D108882?vs=369308&id=369339#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108882

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18467,6 +18467,22 @@
               PackConstructorInitializers, FormatStyle::PCIS_CurrentLine);
   CHECK_PARSE("PackConstructorInitializers: NextLine",
               PackConstructorInitializers, FormatStyle::PCIS_NextLine);
+  // For backward compatibility:
+  CHECK_PARSE("BasedOnStyle: Google\n"
+              "ConstructorInitializerAllOnOneLineOrOnePerLine: true\n"
+              "AllowAllConstructorInitializersOnNextLine: false",
+              PackConstructorInitializers, FormatStyle::PCIS_CurrentLine);
+  Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
+  CHECK_PARSE("BasedOnStyle: Google\n"
+              "ConstructorInitializerAllOnOneLineOrOnePerLine: false",
+              PackConstructorInitializers, FormatStyle::PCIS_BinPack);
+  CHECK_PARSE("ConstructorInitializerAllOnOneLineOrOnePerLine: true\n"
+              "AllowAllConstructorInitializersOnNextLine: true",
+              PackConstructorInitializers, FormatStyle::PCIS_NextLine);
+  Style.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
+  CHECK_PARSE("ConstructorInitializerAllOnOneLineOrOnePerLine: true\n"
+              "AllowAllConstructorInitializersOnNextLine: false",
+              PackConstructorInitializers, FormatStyle::PCIS_CurrentLine);
 
   Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock;
   CHECK_PARSE("EmptyLineBeforeAccessModifier: Never",
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -658,7 +658,14 @@
 
     IO.mapOptional("PackConstructorInitializers",
                    Style.PackConstructorInitializers);
-    // For backward compatibility.
+    // For backward compatibility:
+    // The default value of ConstructorInitializerAllOnOneLineOrOnePerLine was
+    // false unless BasedOnStyle was Google or Chromium whereas that of
+    // AllowAllConstructorInitializersOnNextLine was always true, so the
+    // equivalent default value of PackConstructorInitializers is PCIS_NextLine
+    // for Google/Chromium or PCIS_BinPack otherwise. If the deprecated options
+    // had a non-default value while PackConstructorInitializers has a default
+    // value, set the latter to an equivalent non-default value if needed.
     StringRef BasedOn;
     IO.mapOptional("BasedOnStyle", BasedOn);
     const bool IsGoogleOrChromium = BasedOn.equals_insensitive("google") ||
@@ -668,17 +675,19 @@
     IO.mapOptional("ConstructorInitializerAllOnOneLineOrOnePerLine",
                    OnCurrentLine);
     IO.mapOptional("AllowAllConstructorInitializersOnNextLine", OnNextLine);
-    if (IsGoogleOrChromium &&
-        Style.PackConstructorInitializers == FormatStyle::PCIS_NextLine) {
+    if (!IsGoogleOrChromium) {
+      if (Style.PackConstructorInitializers == FormatStyle::PCIS_BinPack &&
+          OnCurrentLine) {
+        Style.PackConstructorInitializers = OnNextLine
+                                                ? FormatStyle::PCIS_NextLine
+                                                : FormatStyle::PCIS_CurrentLine;
+      }
+    } else if (Style.PackConstructorInitializers ==
+               FormatStyle::PCIS_NextLine) {
       if (!OnCurrentLine)
         Style.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
       else if (!OnNextLine)
         Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
-    } else if (Style.PackConstructorInitializers == FormatStyle::PCIS_BinPack &&
-               OnCurrentLine) {
-      Style.PackConstructorInitializers = OnNextLine
-                                              ? FormatStyle::PCIS_NextLine
-                                              : FormatStyle::PCIS_CurrentLine;
     }
 
     IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108882.369339.patch
Type: text/x-patch
Size: 4037 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210829/bab87bdb/attachment-0001.bin>


More information about the cfe-commits mailing list