[clang] 82e1931 - [clang-format] Fix a bug in annotating lambda l_square (#95084)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 12 00:56:52 PDT 2024
Author: Owen Pan
Date: 2024-06-12T00:56:48-07:00
New Revision: 82e19318e660afc8277d9a2b1136d2d7836d67f8
URL: https://github.com/llvm/llvm-project/commit/82e19318e660afc8277d9a2b1136d2d7836d67f8
DIFF: https://github.com/llvm/llvm-project/commit/82e19318e660afc8277d9a2b1136d2d7836d67f8.diff
LOG: [clang-format] Fix a bug in annotating lambda l_square (#95084)
Fixes #95072.
Added:
Modified:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index eb96b54ec4c96..08387d2e08ee0 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 8cc5c239d30a1..3e9638d9f3c56 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);
More information about the cfe-commits
mailing list