[clang] [clang-format] fix incorrectly indents lambda trailing return (PR #94560)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 9 16:59:48 PDT 2024


================
@@ -22858,6 +22858,36 @@ TEST_F(FormatTest, FormatsLambdas) {
       "      //\n"
       "    });");
 
+  FormatStyle LLVMStyle = getLLVMStyleWithColumns(60);
+
+  verifyFormat("int main() {\n"
+               "  very_long_function_name_yes_it_is_really_long(\n"
+               "      [](auto n)\n"
+               "          -> std::unordered_map<very_long_type_name_A,\n"
+               "                                very_long_type_name_B> {\n"
+               "        really_do_something();\n"
+               "      });\n"
+               "}",
+               LLVMStyle);
+  verifyFormat("int main() {\n"
+               "  very_long_function_name_yes_it_is_really_long(\n"
+               "      [](auto n) noexcept\n"
+               "          -> std::unordered_map<very_long_type_name_A,\n"
+               "                                very_long_type_name_B> {\n"
+               "        really_do_something();\n"
+               "      });\n"
+               "}",
+               LLVMStyle);
----------------
owenca wrote:

```suggestion
  verifyFormat("very_long_function_name_yes_it_is_really_long(\n"
               "    [](auto n) noexcept [[back_attr]]\n"
               "        -> std::unordered_map<very_long_type_name_A,\n"
               "                              very_long_type_name_B> {\n"
               "      really_do_something();\n"
               "    });",
               Style);
```
Removes `main()` and adds `[[back_attr]]`.

https://github.com/llvm/llvm-project/pull/94560


More information about the cfe-commits mailing list