owenpan created this revision. owenpan added reviewers: curdeius, HazardyKnusperkeks, MyDeveloperDay. owenpan added a project: clang-format. Herald added a project: All. owenpan requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Fixes https://github.com/llvm/llvm-project/issues/55625. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D126132 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -21338,6 +21338,7 @@ 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& {};"); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1185,7 +1185,8 @@ } 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:
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -21338,6 +21338,7 @@ 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& {};"); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1185,7 +1185,8 @@ } 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:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits