]> granicus.if.org Git - clang/commitdiff
Disable inlining of short ifs in Google style.
authorDaniel Jasper <djasper@google.com>
Wed, 16 Jan 2013 15:44:34 +0000 (15:44 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 16 Jan 2013 15:44:34 +0000 (15:44 +0000)
Various reasons seem to speak against it, so I am disabling this for
now.

Changed tests to still test this option.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172618 91177308-0d34-0410-b5e6-96231b3b80d8

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

index f4fa6fc35f0fd613c24a727d2eb0ae9904c6d4e0..4be41daf005e315c0bd471a8a291b56999badbe9 100644 (file)
@@ -167,7 +167,7 @@ FormatStyle getGoogleStyle() {
   GoogleStyle.SpacesBeforeTrailingComments = 2;
   GoogleStyle.BinPackParameters = false;
   GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
-  GoogleStyle.AllowShortIfStatementsOnASingleLine = true;
+  GoogleStyle.AllowShortIfStatementsOnASingleLine = false;
   GoogleStyle.ObjCSpaceBeforeProtocolList = false;
   GoogleStyle.ObjCSpaceBeforeReturnType = false;
   return GoogleStyle;
index 066e8881eb2d38016906001377f9f753ba18a753..7d8ed14191f1802b5f64a016117f97451d7283b7 100644 (file)
@@ -151,23 +151,31 @@ TEST_F(FormatTest, FormatIfWithoutCompountStatement) {
   verifyFormat("if (true)\n  f();\ng();");
   verifyFormat("if (a)\n  if (b)\n    if (c)\n      g();\nh();");
   verifyFormat("if (a)\n  if (b) {\n    f();\n  }\ng();");
-  verifyGoogleFormat("if (a)\n"
-                     "  // comment\n"
-                     "  f();");
-  verifyFormat("if (a) return;", getGoogleStyleWithColumns(14));
-  verifyFormat("if (a)\n  return;", getGoogleStyleWithColumns(13));
+
+  FormatStyle AllowsMergedIf = getGoogleStyle();
+  AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true;
+  verifyFormat("if (a)\n"
+               "  // comment\n"
+               "  f();", AllowsMergedIf);
+
+  verifyFormat("if (a)  // Can't merge this\n"
+               "  f();\n", AllowsMergedIf);
+  verifyFormat("if (a) /* still don't merge */\n"
+               "  f();", AllowsMergedIf);
+  verifyFormat("if (a) {  // Never merge this\n"
+               "  f();\n"
+               "}", AllowsMergedIf);
+  verifyFormat("if (a) { /* Never merge this */\n"
+               "  f();\n"
+               "}", AllowsMergedIf);
+
+  AllowsMergedIf.ColumnLimit = 14;
+  verifyFormat("if (a) return;", AllowsMergedIf);
   verifyFormat("if (aaaaaaaaa)\n"
-               "  return;", getGoogleStyleWithColumns(14));
-  verifyGoogleFormat("if (a)  // Can't merge this\n"
-                     "  f();\n");
-  verifyGoogleFormat("if (a) /* still don't merge */\n"
-                     "  f();");
-  verifyGoogleFormat("if (a) {  // Never merge this\n"
-                     "  f();\n"
-                     "}");
-  verifyGoogleFormat("if (a) { /* Never merge this */\n"
-                     "  f();\n"
-                     "}");
+               "  return;", AllowsMergedIf);
+
+  AllowsMergedIf.ColumnLimit = 13;
+  verifyFormat("if (a)\n  return;", AllowsMergedIf);
 }
 
 TEST_F(FormatTest, ParseIfElse) {