]> granicus.if.org Git - clang/commitdiff
Fixes issues around pulling in the next line in simple if statements.
authorManuel Klimek <klimek@google.com>
Fri, 18 Jan 2013 14:46:43 +0000 (14:46 +0000)
committerManuel Klimek <klimek@google.com>
Fri, 18 Jan 2013 14:46:43 +0000 (14:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172822 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index 1821937ec3e91ff9d4b24d61404c92b8687fae62..d234006a25a5e861fd9e161991a94da5112a37c9 100644 (file)
@@ -1749,6 +1749,10 @@ private:
                         unsigned Limit) {
     if (!Style.AllowShortIfStatementsOnASingleLine)
       return;
+    if ((I + 1)->InPPDirective != I->InPPDirective ||
+        ((I + 1)->InPPDirective &&
+         (I + 1)->First.FormatTok.HasUnescapedNewline))
+      return;
     AnnotatedLine &Line = *I;
     if (Line.Last->isNot(tok::r_paren))
       return;
index 6b77868776a73d092f7c04c3ae7d753b4d3815e6..1434f32e2f395e3e906d6192672e802506ed3d13 100644 (file)
@@ -1542,20 +1542,23 @@ TEST_F(FormatTest, MergeHandlingInTheFaceOfPreprocessorDirectives) {
   AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true;
   verifyFormat("void f() { f(); }\n#error E", AllowsMergedIf);
   verifyFormat("if (true) return 42;\n#error E", AllowsMergedIf);
-
-  // FIXME:
-  // verifyFormat("if (true)\n#error E\n  return 42;", AllowsMergedIf);
+  verifyFormat("if (true)\n#error E\n  return 42;", AllowsMergedIf);
+  EXPECT_EQ("if (true) return 42;",
+            format("if (true)\nreturn 42;", AllowsMergedIf));
+  FormatStyle ShortMergedIf = AllowsMergedIf;
+  ShortMergedIf.ColumnLimit = 25;
+  verifyFormat("#define A               \\\n"
+               "  if (true) return 42;", ShortMergedIf);
+  verifyFormat("#define A               \\\n"
+               "  f();                  \\\n"
+               "  if (true)\n"
+               "#define B", ShortMergedIf);
+  verifyFormat("#define A               \\\n"
+               "  f();                  \\\n"
+               "  if (true)\n"
+               "g();", ShortMergedIf);
 }
 
-// FIXME: This breaks the order of the unwrapped lines:
-// TEST_F(FormatTest, OrderUnwrappedLines) {
-//   verifyFormat("{\n"
-//                "  bool a; //\n"
-//                "#error {\n"
-//                "  int a;\n"
-//                "}");
-// }
-
 //===----------------------------------------------------------------------===//
 // Objective-C tests.
 //===----------------------------------------------------------------------===//