From: Daniel Jasper Date: Mon, 19 Aug 2013 10:16:18 +0000 (+0000) Subject: clang-format: Fix return type line break decision. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92495a8032d8624495a0ce769d5a6cdeba2dc8d8;p=clang clang-format: Fix return type line break decision. This accidentally introduced by r186077, as function names were not correctly recognized in templated declarations. Before: template SomeReturnType SomeFunction(TemplateIt begin, TemplateIt end, TemplateIt* stop) {} After: template SomeReturnType SomeFunction(TemplateIt begin, TemplateIt end, TemplateIt* stop) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188665 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 94acbd3e4e..ad6f41005c 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -717,9 +717,13 @@ private: PreviousNotConst->Previous && PreviousNotConst->Previous->is(tok::hash); + if (PreviousNotConst->Type == TT_TemplateCloser) + return PreviousNotConst && PreviousNotConst->MatchingParen && + PreviousNotConst->MatchingParen->Previous && + PreviousNotConst->MatchingParen->Previous->isNot(tok::kw_template); + return (!IsPPKeyword && PreviousNotConst->is(tok::identifier)) || PreviousNotConst->Type == TT_PointerOrReference || - PreviousNotConst->Type == TT_TemplateCloser || isSimpleTypeSpecifier(*PreviousNotConst); } @@ -1041,11 +1045,10 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, return 3; if (Left.Type == TT_StartOfName) return 20; - else if (Line.MightBeFunctionDecl && Right.BindingStrength == 1) + if (Line.MightBeFunctionDecl && Right.BindingStrength == 1) // FIXME: Clean up hack of using BindingStrength to find top-level names. return Style.PenaltyReturnTypeOnItsOwnLine; - else - return 200; + return 200; } if (Left.is(tok::equal) && Right.is(tok::l_brace)) return 150; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 27800cdcdd..e9384c4644 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2523,6 +2523,10 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) { // 1) break amongst arguments. verifyFormat("Aaaaaaaaaaaaaa bbbbbbbbbbbbbb(Cccccccccccccc cccccccccccccc,\n" " Cccccccccccccc cccccccccccccc);"); + verifyFormat( + "template \n" + "SomeReturnType SomeFunction(TemplateIt begin, TemplateIt end,\n" + " TemplateIt *stop) {}"); // 2) break after return type. verifyFormat( @@ -3859,11 +3863,10 @@ TEST_F(FormatTest, BreaksLongDeclarations) { "SomeLoooooooooooooooooooooongType<\n" " typename some_namespace::SomeOtherType::Type>\n" "Function() {}"); - verifyFormat( - "aaaaaaaaaaaaaaaa::aaaaaaaaaaaaaaaa\n" - " aaaaaaaaaaaaaaaaaaaaaaa;", - getGoogleStyle()); + verifyGoogleFormat( + "aaaaaaaaaaaaaaaa::aaaaaaaaaaaaaaaa\n" + " aaaaaaaaaaaaaaaaaaaaaaa;"); verifyGoogleFormat( "TypeSpecDecl* TypeSpecDecl::Create(ASTContext& C, DeclContext* DC,\n" " SourceLocation L) {}");