llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Björn Schäpers (HazardyKnusperkeks)
<details>
<summary>Changes</summary>
We did not consider dependent templates and thus ended the parsing after
template and forcing a line break there. The tests was formatted as:
template <typename T> struct S {
template <typename Foo>
requires T::template
Has<Foo> void func(Foo);
};
---
Full diff: https://github.com/llvm/llvm-project/pull/207542.diff
2 Files Affected:
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+1)
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+10)
``````````diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp
b/clang/lib/Format/UnwrappedLineParser.cpp
index 0a211f5325e6f..77244131e1305 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3860,6 +3860,7 @@ void UnwrappedLineParser::parseConstraintExpression() {
case tok::exclaim: // The same as above, but unary.
case tok::kw_requires: // Initial identifier of a requires clause.
case tok::equal: // Initial identifier of a concept declaration.
+ case tok::kw_template: // A dependent template.
break;
default:
return;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 8ef7e7387e269..06552bfee003e 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1711,6 +1711,16 @@ TEST_F(TokenAnnotatorTest,
UnderstandsRequiresExpressions) {
EXPECT_TOKEN(Tokens[3], tok::kw_requires, TT_RequiresExpression);
EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_RequiresExpressionLParen);
EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_RequiresExpressionLBrace);
+
+ Tokens = annotate("template <typename T>\n"
+ "struct S {\n"
+ " template <typename Foo>\n"
+ " requires T::template Has<Foo>\n"
+ " void func(Foo);\n"
+ "};");
+ ASSERT_EQ(Tokens.size(), 30u) << Tokens;
+ EXPECT_TOKEN(Tokens[20], tok::greater, TT_TemplateCloser);
+ EXPECT_TRUE(Tokens[20]->ClosesRequiresClause);
}
TEST_F(TokenAnnotatorTest, UnderstandsPragmaRegion) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/207542
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits