aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2024-06-12 00:56:48 -0700
committerGitHub <noreply@github.com>2024-06-12 00:56:48 -0700
commit82e19318e660afc8277d9a2b1136d2d7836d67f8 (patch)
treea2ad12353fc7d2ca93cccfad1bd30b5d74426fbc /clang
parent8ad82b419b88102746735505effe5bc09f26ae54 (diff)
downloadllvm-82e19318e660afc8277d9a2b1136d2d7836d67f8.zip
llvm-82e19318e660afc8277d9a2b1136d2d7836d67f8.tar.gz
llvm-82e19318e660afc8277d9a2b1136d2d7836d67f8.tar.bz2
[clang-format] Fix a bug in annotating lambda l_square (#95084)
Fixes #95072.
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp2
-rw-r--r--clang/unittests/Format/TokenAnnotatorTest.cpp6
2 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index eb96b54..08387d2 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2257,6 +2257,8 @@ bool UnwrappedLineParser::tryToParseLambda() {
break;
case tok::kw_auto:
case tok::kw_class:
+ case tok::kw_struct:
+ case tok::kw_union:
case tok::kw_template:
case tok::kw_typename:
case tok::amp:
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 8cc5c23..3e9638d 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1655,6 +1655,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
EXPECT_TOKEN(Tokens[2], tok::arrow, TT_TrailingReturnArrow);
EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_LambdaLBrace);
+ Tokens = annotate("[] -> struct S { return {}; }");
+ ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+ EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+ EXPECT_TOKEN(Tokens[2], tok::arrow, TT_TrailingReturnArrow);
+ EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
+
Tokens = annotate("foo([&](u32 bar) __attribute__((attr)) -> void {});");
ASSERT_EQ(Tokens.size(), 22u) << Tokens;
EXPECT_TOKEN(Tokens[2], tok::l_square, TT_LambdaLSquare);