[clang] [clang-format] Fix a bug in annotating lambda l_square (PR #95084)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 11 01:37:36 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->95072.
---
Full diff: https://github.com/llvm/llvm-project/pull/95084.diff
2 Files Affected:
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+2)
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+6)
``````````diff
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 3d609a1f041bc..0a1fb8c657ceb 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1591,6 +1591,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
EXPECT_TOKEN(Tokens[15], tok::arrow, TT_TrailingReturnArrow);
EXPECT_TOKEN(Tokens[17], tok::l_brace, TT_LambdaLBrace);
+ Tokens = annotate("auto l = [] -> struct S { return {}; };");
+ ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+ EXPECT_TOKEN(Tokens[3], tok::l_square, TT_LambdaLSquare);
+ EXPECT_TOKEN(Tokens[5], tok::arrow, TT_TrailingReturnArrow);
+ EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_LambdaLBrace);
+
Tokens = annotate("[] <typename T> () {}");
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
``````````
</details>
https://github.com/llvm/llvm-project/pull/95084
More information about the cfe-commits
mailing list