[clang] 130a9cc - [clang-format] Fix a crash on lambda trailing return type
via cfe-commits
cfe-commits at lists.llvm.org
Sat May 21 16:18:29 PDT 2022
Author: owenca
Date: 2022-05-21T15:50:50-07:00
New Revision: 130a9cc0a5e25e3be8ff3738518e86ae3ae0b5ba
URL: https://github.com/llvm/llvm-project/commit/130a9cc0a5e25e3be8ff3738518e86ae3ae0b5ba
DIFF: https://github.com/llvm/llvm-project/commit/130a9cc0a5e25e3be8ff3738518e86ae3ae0b5ba.diff
LOG: [clang-format] Fix a crash on lambda trailing return type
Fixes #55625.
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 9afe4f8fb086..7f1c4b8e61b6 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1185,7 +1185,8 @@ class AnnotatingParser {
}
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:
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index aebb44ee9acd..83b8dbed75e3 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -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& {};");
More information about the cfe-commits
mailing list