Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -559,7 +559,7 @@ Limit -= 2; unsigned MergedLines = 0; - if (MergeShortFunctions) { + if (MergeShortFunctions && TheLine->MustBeDeclaration) { MergedLines = tryMergeSimpleBlock(I + 1, E, Limit); // If we managed to merge the block, count the function header, which is // on a separate line. Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -7336,6 +7336,26 @@ "}\n" "}", BreakBeforeBrace); + + verifyFormat("#ifdef _DEBUG\n" + "int foo(int i = 0)\n" + "#else\n" + "int foo(int i = 5)\n" + "#endif\n" + "{\n" + " return i;\n" + "}\n" + "void foo1()\n" + "#ifdef _DEBUG\n" + "{\n" + " return 0;\n" + "}\n" + "#else\n" + "{\n" + " return 5;\n" + "}\n" + "#endif", + BreakBeforeBrace); } TEST_F(FormatTest, AllmanBraceBreaking) { @@ -7418,6 +7438,26 @@ "}\n", BreakBeforeBrace); + verifyFormat("#ifdef _DEBUG\n" + "int foo(int i = 0)\n" + "#else\n" + "int foo(int i = 5)\n" + "#endif\n" + "{\n" + " return i;\n" + "}\n" + "void foo1()\n" + "#ifdef _DEBUG\n" + "{\n" + " return 0;\n" + "}\n" + "#else\n" + "{\n" + " return 5;\n" + "}\n" + "#endif", + BreakBeforeBrace); + BreakBeforeBrace.ColumnLimit = 19; verifyFormat("void f() { int i; }", BreakBeforeBrace); BreakBeforeBrace.ColumnLimit = 18; @@ -7538,6 +7578,26 @@ " Y = 0,\n" "}\n", GNUBraceStyle); + + verifyFormat("#ifdef _DEBUG\n" + "int foo(int i = 0)\n" + "#else\n" + "int foo(int i = 5)\n" + "#endif\n" + "{\n" + " return i;\n" + "}\n" + "void foo1()\n" + "#ifdef _DEBUG\n" + "{\n" + " return 0;\n" + "}\n" + "#else\n" + "{\n" + " return 5;\n" + "}\n" + "#endif", + GNUBraceStyle); } TEST_F(FormatTest, CatchExceptionReferenceBinding) { verifyFormat("void f() {\n"