gedare updated this revision to Diff 541813.
gedare marked an inline comment as done.
gedare added a comment.

Revert deleted line in test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154755

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


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25494,12 +25494,56 @@
                "}",
                Style);
 
+  // Treating if clauses as block indents causes a known bug (#54808, #63383)
+  // breaking the following test. It gets formatted instead as:
+  // "if (quitelongarg != (alsolongarg - 1)\n"
+  // ") { // ABC is a very longgggggggggggg comment"
+  // "return;"
+  // "}"
+
+#if 0
   verifyFormat("if (quitelongarg !=\n"
                "    (alsolongarg - 1)) { // ABC is a very longgggggggggggg "
                "comment\n"
                "  return;\n"
                "}",
                Style);
+#endif
+
+  verifyFormat("void foo() {\n"
+               "  if (quitelongname < alsolongname ||\n"
+               "      anotherevenlongername <=\n"
+               "          thisreallyreallyreallyreallyreallyreallylongername 
||"
+               "\n"
+               "      othername < thislastname) {\n"
+               "    return;\n"
+               "  } else if (\n"
+               "      quitelongname < alsolongname ||\n"
+               "      anotherevenlongername <=\n"
+               "          thisreallyreallyreallyreallyreallyreallylongername 
||"
+               "\n"
+               "      othername < thislastname\n"
+               "  ) {\n"
+               "    return;\n"
+               "  }\n"
+               "}",
+               Style);
+
+  Style.ContinuationIndentWidth = 2;
+  verifyFormat("void foo() {\n"
+               "  if (\n"
+               "    ThisIsRatherALongIfClause && thatIExpectToBeBroken ||\n"
+               "    ontoMultipleLines && whenFormattedCorrectly\n"
+               "  ) {\n"
+               "    if (false) {\n"
+               "    } else if (\n"
+               "      thisIsRatherALongIfClause && thatIExpectToBeBroken ||\n"
+               "      ontoMultipleLines && whenFormattedCorrectly\n"
+               "    ) {\n"
+               "    }\n"
+               "  }\n"
+               "}",
+               Style);
 }
 
 TEST_F(FormatTest, AlignAfterOpenBracketBlockIndentForStatement) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -5499,7 +5499,7 @@
     if (Next && Next->is(tok::l_paren))
       return false;
     const FormatToken *Previous = Right.MatchingParen->Previous;
-    return !(Previous && (Previous->is(tok::kw_for) || Previous->isIf()));
+    return !(Previous && Previous->is(tok::kw_for));
   }
 
   // Allow breaking after a trailing annotation, e.g. after a method


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25494,12 +25494,56 @@
                "}",
                Style);
 
+  // Treating if clauses as block indents causes a known bug (#54808, #63383)
+  // breaking the following test. It gets formatted instead as:
+  // "if (quitelongarg != (alsolongarg - 1)\n"
+  // ") { // ABC is a very longgggggggggggg comment"
+  // "return;"
+  // "}"
+
+#if 0
   verifyFormat("if (quitelongarg !=\n"
                "    (alsolongarg - 1)) { // ABC is a very longgggggggggggg "
                "comment\n"
                "  return;\n"
                "}",
                Style);
+#endif
+
+  verifyFormat("void foo() {\n"
+               "  if (quitelongname < alsolongname ||\n"
+               "      anotherevenlongername <=\n"
+               "          thisreallyreallyreallyreallyreallyreallylongername ||"
+               "\n"
+               "      othername < thislastname) {\n"
+               "    return;\n"
+               "  } else if (\n"
+               "      quitelongname < alsolongname ||\n"
+               "      anotherevenlongername <=\n"
+               "          thisreallyreallyreallyreallyreallyreallylongername ||"
+               "\n"
+               "      othername < thislastname\n"
+               "  ) {\n"
+               "    return;\n"
+               "  }\n"
+               "}",
+               Style);
+
+  Style.ContinuationIndentWidth = 2;
+  verifyFormat("void foo() {\n"
+               "  if (\n"
+               "    ThisIsRatherALongIfClause && thatIExpectToBeBroken ||\n"
+               "    ontoMultipleLines && whenFormattedCorrectly\n"
+               "  ) {\n"
+               "    if (false) {\n"
+               "    } else if (\n"
+               "      thisIsRatherALongIfClause && thatIExpectToBeBroken ||\n"
+               "      ontoMultipleLines && whenFormattedCorrectly\n"
+               "    ) {\n"
+               "    }\n"
+               "  }\n"
+               "}",
+               Style);
 }
 
 TEST_F(FormatTest, AlignAfterOpenBracketBlockIndentForStatement) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -5499,7 +5499,7 @@
     if (Next && Next->is(tok::l_paren))
       return false;
     const FormatToken *Previous = Right.MatchingParen->Previous;
-    return !(Previous && (Previous->is(tok::kw_for) || Previous->isIf()));
+    return !(Previous && Previous->is(tok::kw_for));
   }
 
   // Allow breaking after a trailing annotation, e.g. after a method
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to