[clang-format] Fix lambda with ellipsis in return type
authormydeveloperday <mydeveloperday@gmail.com>
Thu, 30 Apr 2020 10:02:42 +0000 (11:02 +0100)
committermydeveloperday <mydeveloperday@gmail.com>
Thu, 30 Apr 2020 10:02:42 +0000 (11:02 +0100)
Summary:
BTW my actual code that hit this issue is like

```
[a, b = std::move(b)](auto &&... c) mutable -> std::invoke_result_t<decltype(b), decltype(c)...> { /* omitted */ }
```

where this explicit return type is required for SFINAE.

Reviewed By: krasimir, MyDeveloperDay

Patch By: johnchen902

Subscribers: krasimir, dexonsmith, cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D78694

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

index 4734ff1..658773c 100644 (file)
@@ -1646,6 +1646,7 @@ bool UnwrappedLineParser::tryToParseLambda() {
     case tok::lessequal:
     case tok::question:
     case tok::colon:
+    case tok::ellipsis:
     case tok::kw_true:
     case tok::kw_false:
       if (SeenArrow) {
index 1cd1247..ace4113 100644 (file)
@@ -14125,6 +14125,8 @@ TEST_F(FormatTest, FormatsLambdas) {
                "    -> int {\n"
                "  return 1; //\n"
                "};");
+  verifyFormat("[]() -> Void<T...> {};");
+  verifyFormat("[a, b]() -> Tuple<T...> { return {}; };");
 
   // Lambdas with explicit template argument lists.
   verifyFormat(