From: Paul Hoad Date: Tue, 5 Mar 2019 22:20:25 +0000 (+0000) Subject: [clang-format] broken after lambda with return type template with boolean literal X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fea404bfc1a56d48b7534dc0802eb0e5215620e8;p=clang [clang-format] broken after lambda with return type template with boolean literal Summary: A Lamdba with a return type template with a boolean literal (true,false) behaves differently to an integer literal https://bugs.llvm.org/show_bug.cgi?id=40910 Reviewers: klimek, djasper, JonasToth, alexfh, krasimir, jkorous Reviewed By: jkorous Subscribers: jkorous, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D58922 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355450 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 4bc624db7d..de7e646b17 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1442,6 +1442,8 @@ bool UnwrappedLineParser::tryToParseLambda() { case tok::lessequal: case tok::question: case tok::colon: + case tok::kw_true: + case tok::kw_false: nextToken(); break; case tok::arrow: diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 094db349ae..650636b763 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -11936,6 +11936,21 @@ TEST_F(FormatTest, FormatsLambdas) { "// broken:\n" "auto foo{[]() -> foo<2 ? 1 : 0> { return {}; }};\n" "} // namespace bar"); + verifyFormat("[]() -> a<1> {};"); + verifyFormat("[]() -> a<1> { ; };"); + verifyFormat("[]() -> a<1> { ; }();"); + verifyFormat("[a, a]() -> a {};"); + verifyFormat("[]() -> a {};"); + verifyFormat("[]() -> a { ; };"); + verifyFormat("[]() -> a { ; }();"); + verifyFormat("[a, a]() -> a {};"); + verifyFormat("[]() -> a {};"); + verifyFormat("[]() -> a { ; };"); + verifyFormat("[]() -> a { ; }();"); + verifyFormat("auto foo{[]() -> foo { ; }};"); + verifyFormat("namespace bar {\n" + "auto foo{[]() -> foo { ; }};\n" + "} // namespace bar"); verifyFormat("auto aaaaaaaa = [](int i, // break for some reason\n" " int j) -> int {\n" " return ffffffffffffffffffffffffffffffffffffffffffff(i * j);\n"