Author: djasper Date: Tue Feb 7 15:38:16 2017 New Revision: 294358 URL: http://llvm.org/viewvc/llvm-project?rev=294358&view=rev Log: clang-format: Fix bad variable declaration detection.
Before: LooooooooooooooooongType variable(nullptr, [](A *a) {}); After: LooooooooooooooooongType variable(nullptr, [](A *a) {}); Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=294358&r1=294357&r2=294358&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Feb 7 15:38:16 2017 @@ -1707,7 +1707,7 @@ static bool isFunctionDeclarationName(co } } - // Check whether parameter list can be long to a function declaration. + // Check whether parameter list can belong to a function declaration. if (!Next || !Next->is(tok::l_paren) || !Next->MatchingParen) return false; // If the lines ends with "{", this is likely an function definition. @@ -1721,6 +1721,10 @@ static bool isFunctionDeclarationName(co return true; for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen; Tok = Tok->Next) { + if (Tok->is(tok::l_paren) && Tok->MatchingParen) { + Tok = Tok->MatchingParen; + continue; + } if (Tok->is(tok::kw_const) || Tok->isSimpleTypeSpecifier() || Tok->isOneOf(TT_PointerOrReference, TT_StartOfName, tok::ellipsis)) return true; Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=294358&r1=294357&r2=294358&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Feb 7 15:38:16 2017 @@ -6934,6 +6934,11 @@ TEST_F(FormatTest, BreaksLongVariableDec " LoooooooooooooooooooooooooooooooooooooooongVariable({});"); verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType\n" " LoooooooooooooooooooooooooooooooooooooongVariable([A a]);"); + + // Lambdas should not confuse the variable declaration heuristic. + verifyFormat("LooooooooooooooooongType\n" + " variable(nullptr, [](A *a) {});", + getLLVMStyleWithColumns(40)); } TEST_F(FormatTest, BreaksLongDeclarations) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits