[PATCH] Revert "[clang-format] Fix AlignConsecutive on PP blocks"
authorSylvestre Ledru <sylvestre@debian.org>
Mon, 12 Oct 2020 16:47:30 +0000 (18:47 +0200)
committerSylvestre Ledru <sylvestre@debian.org>
Sat, 7 Nov 2020 14:53:51 +0000 (14:53 +0000)
This reverts commit b2eb439317576ce718193763c12bff9fccdfc166.

Gbp-Pq: Name fix-clang-format-bug-47589.patch

clang/lib/Format/FormatToken.h
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/FormatTestComments.cpp

index d4287f53fde3738f8889862be0d5df07501a5bd2..b132a3e84da55c6ea66a4308193b3a7df5861018 100644 (file)
@@ -183,12 +183,6 @@ struct FormatToken {
   /// before the token.
   bool MustBreakBefore = false;
 
-  /// Whether to not align across this token
-  ///
-  /// This happens for example when a preprocessor directive ended directly
-  /// before the token, but very rarely otherwise.
-  bool MustBreakAlignBefore = false;
-
   /// The raw text of the token.
   ///
   /// Contains the raw token text without leading whitespace and without leading
index a37386425aaed1bbfb757364389562a8eb0cd24f..ea8a41cfba82aeac8a69ce8ffe0fb126ef765cb5 100644 (file)
@@ -3037,7 +3037,6 @@ void UnwrappedLineParser::readToken(int LevelDifference) {
       }
       FormatTok = Tokens->getNextToken();
       FormatTok->MustBreakBefore = true;
-      FormatTok->MustBreakAlignBefore = true;
     }
 
     if (!PPStack.empty() && (PPStack.back().Kind == PP_Unreachable) &&
@@ -3062,7 +3061,6 @@ void UnwrappedLineParser::pushToken(FormatToken *Tok) {
   Line->Tokens.push_back(UnwrappedLineNode(Tok));
   if (MustBreakBeforeNextToken) {
     Line->Tokens.back().Tok->MustBreakBefore = true;
-    Line->Tokens.back().Tok->MustBreakAlignBefore = true;
     MustBreakBeforeNextToken = false;
   }
 }
index 32e0b685ea0f430288975fe4725f5826c903d94d..3a265bd09168111a2567245e94ed463d0c491d39 100644 (file)
@@ -411,11 +411,9 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
     if (Changes[i].NewlinesBefore != 0) {
       CommasBeforeMatch = 0;
       EndOfSequence = i;
-      // If there is a blank line, there is a forced-align-break (eg,
-      // preprocessor), or if the last line didn't contain any matching token,
-      // the sequence ends here.
-      if (Changes[i].NewlinesBefore > 1 ||
-          Changes[i].Tok->MustBreakAlignBefore || !FoundMatchOnLine)
+      // If there is a blank line, or if the last line didn't contain any
+      // matching token, the sequence ends here.
+      if (Changes[i].NewlinesBefore > 1 || !FoundMatchOnLine)
         AlignCurrentSequence();
 
       FoundMatchOnLine = false;
@@ -726,8 +724,6 @@ void WhitespaceManager::alignTrailingComments() {
     if (Changes[i].StartOfBlockComment)
       continue;
     Newlines += Changes[i].NewlinesBefore;
-    if (Changes[i].Tok->MustBreakAlignBefore)
-      BreakBeforeNext = true;
     if (!Changes[i].IsTrailingComment)
       continue;
 
index 17d302f0b659dce20ed87e5fe2056101b7e6fff0..7e4d1fca5096800ea024b3ac4d6b445d4c0d3be2 100644 (file)
@@ -11968,29 +11968,6 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
   verifyFormat("int oneTwoThree = 123; // comment\n"
                "int oneTwo      = 12;  // comment",
                Alignment);
-
-  // Bug 25167
-  verifyFormat("#if A\n"
-               "#else\n"
-               "int aaaaaaaa = 12;\n"
-               "#endif\n"
-               "#if B\n"
-               "#else\n"
-               "int a = 12;\n"
-               "#endif\n",
-               Alignment);
-  verifyFormat("enum foo {\n"
-               "#if A\n"
-               "#else\n"
-               "  aaaaaaaa = 12;\n"
-               "#endif\n"
-               "#if B\n"
-               "#else\n"
-               "  a = 12;\n"
-               "#endif\n"
-               "};\n",
-               Alignment);
-
   EXPECT_EQ("int a = 5;\n"
             "\n"
             "int oneTwoThree = 123;",
index 47509f29744cb9a29407e6a81196ceb58a823894..d5b9f8e0885ac502d1e72d727523f4baf5384216 100644 (file)
@@ -2780,27 +2780,6 @@ TEST_F(FormatTestComments, AlignTrailingComments) {
                    "       // line 2 about b\n"
                    "       long b;",
                    getLLVMStyleWithColumns(80)));
-
-  // Checks an edge case in preprocessor handling.
-  // These comments should *not* be aligned
-  EXPECT_EQ(
-      "#if FOO\n"
-      "#else\n"
-      "long a; // Line about a\n"
-      "#endif\n"
-      "#if BAR\n"
-      "#else\n"
-      "long b_long_name; // Line about b\n"
-      "#endif\n",
-      format("#if FOO\n"
-             "#else\n"
-             "long a;           // Line about a\n" // Previous (bad) behavior
-             "#endif\n"
-             "#if BAR\n"
-             "#else\n"
-             "long b_long_name; // Line about b\n"
-             "#endif\n",
-             getLLVMStyleWithColumns(80)));
 }
 
 TEST_F(FormatTestComments, AlignsBlockCommentDecorations) {