]> granicus.if.org Git - clang/commitdiff
[clang-format] broken after lambda with return type template with boolean literal
authorPaul Hoad <mydeveloperday@gmail.com>
Tue, 5 Mar 2019 22:20:25 +0000 (22:20 +0000)
committerPaul Hoad <mydeveloperday@gmail.com>
Tue, 5 Mar 2019 22:20:25 +0000 (22:20 +0000)
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

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 4bc624db7dd1249ef2ad40c0c3711685c70fef4e..de7e646b17cf9b8db98983cff0b86713010f99fd 100644 (file)
@@ -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:
index 094db349ae1e1cc62d5e64a23e6e42dd0ba27540..650636b763396e8cc5762f3d9ec4354084ac2ecc 100644 (file)
@@ -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<true> {};");
+  verifyFormat("[]() -> a<true> {};");
+  verifyFormat("[]() -> a<true> { ; };");
+  verifyFormat("[]() -> a<true> { ; }();");
+  verifyFormat("[a, a]() -> a<false> {};");
+  verifyFormat("[]() -> a<false> {};");
+  verifyFormat("[]() -> a<false> { ; };");
+  verifyFormat("[]() -> a<false> { ; }();");
+  verifyFormat("auto foo{[]() -> foo<false> { ; }};");
+  verifyFormat("namespace bar {\n"
+               "auto foo{[]() -> foo<false> { ; }};\n"
+               "} // namespace bar");
   verifyFormat("auto aaaaaaaa = [](int i, // break for some reason\n"
                "                   int j) -> int {\n"
                "  return ffffffffffffffffffffffffffffffffffffffffffff(i * j);\n"