[clang-format] Fix a crash on lambda trailing return type

Fixes #55625.
This commit is contained in:
owenca 2022-05-21 15:50:50 -07:00
parent f4d52cad67
commit 130a9cc0a5
2 changed files with 3 additions and 1 deletions

View File

@ -1185,7 +1185,8 @@ private:
}
break;
case tok::arrow:
if (Tok->Previous && Tok->Previous->is(tok::kw_noexcept))
if (Tok->isNot(TT_LambdaArrow) && Tok->Previous &&
Tok->Previous->is(tok::kw_noexcept))
Tok->setType(TT_TrailingReturnArrow);
break;
default:

View File

@ -21338,6 +21338,7 @@ TEST_F(FormatTest, FormatsLambdas) {
verifyFormat("int c = []() -> int * { return 2; }();\n");
verifyFormat("int c = []() -> vector<int> { return {2}; }();\n");
verifyFormat("Foo([]() -> std::vector<int> { return {2}; }());");
verifyFormat("foo([]() noexcept -> int {});");
verifyGoogleFormat("auto a = [&b, c](D* d) -> D* {};");
verifyGoogleFormat("auto a = [&b, c](D* d) -> pair<D*, D*> {};");
verifyGoogleFormat("auto a = [&b, c](D* d) -> D& {};");