Loading clang/lib/Format/TokenAnnotator.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -2476,6 +2476,14 @@ static bool isFunctionDeclarationName(const FormatToken &Current, if (Next->MatchingParen->Next && Next->MatchingParen->Next->is(TT_PointerOrReference)) return true; // Check for K&R C function definitions, e.g.: // int f(i) // { // return i + 1; // } if (Next->Next && Next->Next->is(tok::identifier) && !(Next->MatchingParen->Next && Next->MatchingParen->Next->is(tok::semi))) return true; for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen; Tok = Tok->Next) { if (Tok->is(TT_TypeDeclarationParen)) Loading clang/unittests/Format/FormatTest.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -8209,6 +8209,16 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { "}\n", Style); Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterFunction = true; verifyFormat("int f(i);\n" // No break here. "int\n" // Break here. "f(i)\n" "{\n" " return i + 1;\n" "}\n", Style); Style = getGNUStyle(); // Test for comments at the end of function declarations. Loading Loading
clang/lib/Format/TokenAnnotator.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -2476,6 +2476,14 @@ static bool isFunctionDeclarationName(const FormatToken &Current, if (Next->MatchingParen->Next && Next->MatchingParen->Next->is(TT_PointerOrReference)) return true; // Check for K&R C function definitions, e.g.: // int f(i) // { // return i + 1; // } if (Next->Next && Next->Next->is(tok::identifier) && !(Next->MatchingParen->Next && Next->MatchingParen->Next->is(tok::semi))) return true; for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen; Tok = Tok->Next) { if (Tok->is(TT_TypeDeclarationParen)) Loading
clang/unittests/Format/FormatTest.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -8209,6 +8209,16 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { "}\n", Style); Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterFunction = true; verifyFormat("int f(i);\n" // No break here. "int\n" // Break here. "f(i)\n" "{\n" " return i + 1;\n" "}\n", Style); Style = getGNUStyle(); // Test for comments at the end of function declarations. Loading