Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -1290,7 +1290,9 @@ if (Style.AlwaysBreakAfterDefinitionReturnType && InFunctionDecl && Current->Type == TT_FunctionDeclarationName && - Line.Last->is(tok::l_brace)) // Only for definitions. + !Line.Last->isOneOf(tok::semi, tok::comment)) // Only for definitions. + // FIXME: Line.Last points to other characters than tok::semi + // and tok::lbrace. Current->MustBreakBefore = true; Current->CanBreakBefore = Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -4156,6 +4156,29 @@ "}\n" "const char *bar(void);\n", // No break here. AfterType); + verifyFormat("template \n" + "T *\n" + "f(T &c) {\n" // Break here. + " return NULL;\n" + "}\n" + "template T *f(T &c);\n", // No break here. + AfterType); + AfterType.BreakBeforeBraces = FormatStyle::BS_Stroustrup; + verifyFormat("const char *\n" + "f(void)\n" // Break here. + "{\n" + " return \"\";\n" + "}\n" + "const char *bar(void);\n", // No break here. + AfterType); + verifyFormat("template \n" + "T *\n" // Problem here: no line break + "f(T &c)\n" // Break here. + "{\n" + " return NULL;\n" + "}\n" + "template T *f(T &c);\n", // No break here. + AfterType); } TEST_F(FormatTest, AlwaysBreakBeforeMultilineStrings) {