[PATCH] D140330: [clang-format] Set requires expression params as not an expression
Emilia Dreamer via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 19 12:41:54 PST 2022
rymiel updated this revision to Diff 484040.
rymiel added a comment.
Small spacing typo
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140330/new/
https://reviews.llvm.org/D140330
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -711,19 +711,50 @@
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
EXPECT_TOKEN(Tokens[2], tok::kw_requires, TT_RequiresExpression);
EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_RequiresExpressionLParen);
+ EXPECT_TOKEN(Tokens[6], tok::star, TT_PointerOrReference);
EXPECT_TOKEN(Tokens[10], tok::l_brace, TT_RequiresExpressionLBrace);
Tokens = annotate("foo(requires(T const* volatile t) {});");
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
EXPECT_TOKEN(Tokens[2], tok::kw_requires, TT_RequiresExpression);
EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_RequiresExpressionLParen);
+ EXPECT_TOKEN(Tokens[6], tok::star, TT_PointerOrReference);
EXPECT_TOKEN(Tokens[10], tok::l_brace, TT_RequiresExpressionLBrace);
+ Tokens = annotate("foo(requires(T& t) {});");
+ ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+ EXPECT_TOKEN(Tokens[2], tok::kw_requires, TT_RequiresExpression);
+ EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_RequiresExpressionLParen);
+ EXPECT_TOKEN(Tokens[5], tok::amp, TT_PointerOrReference);
+ EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_RequiresExpressionLBrace);
+
+ Tokens = annotate("foo(requires(T&& t) {});");
+ ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+ EXPECT_TOKEN(Tokens[2], tok::kw_requires, TT_RequiresExpression);
+ EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_RequiresExpressionLParen);
+ EXPECT_TOKEN(Tokens[5], tok::ampamp, TT_PointerOrReference);
+ EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_RequiresExpressionLBrace);
+
+ Tokens = annotate("bool foo = requires(T& t) {};");
+ ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+ EXPECT_TOKEN(Tokens[3], tok::kw_requires, TT_RequiresExpression);
+ EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_RequiresExpressionLParen);
+ EXPECT_TOKEN(Tokens[6], tok::amp, TT_PointerOrReference);
+ EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_RequiresExpressionLBrace);
+
+ Tokens = annotate("bool foo = requires(T&& t) {};");
+ ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+ EXPECT_TOKEN(Tokens[3], tok::kw_requires, TT_RequiresExpression);
+ EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_RequiresExpressionLParen);
+ EXPECT_TOKEN(Tokens[6], tok::ampamp, TT_PointerOrReference);
+ EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_RequiresExpressionLBrace);
+
Tokens =
annotate("foo(requires(const typename Outer<T>::Inner * const t) {});");
ASSERT_EQ(Tokens.size(), 21u) << Tokens;
EXPECT_TOKEN(Tokens[2], tok::kw_requires, TT_RequiresExpression);
EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_RequiresExpressionLParen);
+ EXPECT_TOKEN(Tokens[12], tok::star, TT_PointerOrReference);
EXPECT_TOKEN(Tokens[16], tok::l_brace, TT_RequiresExpressionLBrace);
Tokens = annotate("template <typename T>\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -321,6 +321,8 @@
} else if (isLambdaParameterList(&OpeningParen)) {
// This is a parameter list of a lambda expression.
Contexts.back().IsExpression = false;
+ } else if (OpeningParen.is(TT_RequiresExpressionLParen)) {
+ Contexts.back().IsExpression = false;
} else if (Line.InPPDirective &&
(!OpeningParen.Previous ||
!OpeningParen.Previous->is(tok::identifier))) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140330.484040.patch
Type: text/x-patch
Size: 3521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221219/f6623073/attachment-0001.bin>
More information about the cfe-commits
mailing list