[PATCH] D126132: [clang-format] Fix a crash on lambda trailing return type
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat May 21 15:57:13 PDT 2022
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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126132.431183.patch
Type: text/x-patch
Size: 1161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220521/5401e2df/attachment.bin>
More information about the cfe-commits
mailing list