[PATCH] D61222: [clang-format] Fix a bug in AlignConsecutiveDeclarations

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 1 11:20:02 PDT 2019


owenpan updated this revision to Diff 197566.
owenpan added a comment.

Removed a redundant test case.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61222

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


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10575,6 +10575,13 @@
                "  unsigned c;\n"
                "}",
                Alignment);
+
+  // See PR37175
+  FormatStyle Style = getMozillaStyle();
+  Style.AlignConsecutiveDeclarations = true;
+  EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n"
+            "foo(int a);",
+            format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ foo (int a);", Style));
 }
 
 TEST_F(FormatTest, LinuxBraceBreaking) {
Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -463,9 +463,21 @@
       [](Change const &C) {
         // tok::kw_operator is necessary for aligning operator overload
         // definitions.
-        return C.Tok->is(TT_StartOfName) ||
-               C.Tok->is(TT_FunctionDeclarationName) ||
-               C.Tok->is(tok::kw_operator);
+        if (C.Tok->isOneOf(TT_FunctionDeclarationName, tok::kw_operator))
+          return true;
+        if (C.Tok->isNot(TT_StartOfName))
+          return false;
+        // Check if there is a subsequent name that starts the same declaration.
+        for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) {
+          if (Next->is(tok::comment))
+            continue;
+          if (!Next->Tok.getIdentifierInfo())
+            break;
+          if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName,
+                            tok::kw_operator))
+            return false;
+        }
+        return true;
       },
       Changes, /*StartAt=*/0);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61222.197566.patch
Type: text/x-patch
Size: 1795 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190501/b3b64ec6/attachment.bin>


More information about the cfe-commits mailing list