[PATCH] D128496: [clang-format] Further improve requires clause detection
Björn Schäpers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 24 19:43:55 PDT 2022
This revision was automatically updated to reflect the committed changes.
HazardyKnusperkeks marked an inline comment as done.
Closed by commit rGb3aeca3962bb: [clang-format] Further improve requires clause detection (authored by HazardyKnusperkeks).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128496/new/
https://reviews.llvm.org/D128496
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -402,6 +402,33 @@
EXPECT_TOKEN(Tokens[25], tok::less, TT_TemplateOpener);
EXPECT_TOKEN(Tokens[27], tok::greater, TT_TemplateCloser);
EXPECT_TOKEN(Tokens[28], tok::greater, TT_TemplateCloser);
+
+ Tokens = annotate("auto bar() -> int requires(is_integral_v<T>) {}");
+ ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+ EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+ Tokens = annotate("auto bar() -> void requires(is_integral_v<T>) {}");
+ ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+ EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+ Tokens = annotate("auto bar() -> MyType requires(is_integral_v<T>) {}");
+ ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+ EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+ Tokens =
+ annotate("auto bar() -> SOME_MACRO_TYPE requires(is_integral_v<T>) {}");
+ ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+ EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+ Tokens =
+ annotate("auto bar() -> qualified::type requires(is_integral_v<T>) {}");
+ ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+ EXPECT_TOKEN(Tokens[8], tok::kw_requires, TT_RequiresClause);
+
+ Tokens =
+ annotate("auto bar() -> Template<type> requires(is_integral_v<T>) {}");
+ ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+ EXPECT_TOKEN(Tokens[9], tok::kw_requires, TT_RequiresClause);
}
TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3168,6 +3168,11 @@
break;
}
default:
+ if (PreviousNonComment->isTypeOrIdentifier()) {
+ // This is a requires clause.
+ parseRequiresClause(RequiresToken);
+ return true;
+ }
// It's an expression.
parseRequiresExpression(RequiresToken);
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128496.439944.patch
Type: text/x-patch
Size: 2166 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220625/e06deca5/attachment.bin>
More information about the cfe-commits
mailing list