https://github.com/HazardyKnusperkeks created
https://github.com/llvm/llvm-project/pull/207542
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);
};
From eef6272bcd2d9db51b334e4376317c21ae5fb5a5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= <[email protected]>
Date: Sat, 4 Jul 2026 22:59:48 +0200
Subject: [PATCH] [clang-format] Improve requires clause parsing
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);
};
---
clang/lib/Format/UnwrappedLineParser.cpp | 1 +
clang/unittests/Format/TokenAnnotatorTest.cpp | 10 ++++++++++
2 files changed, 11 insertions(+)
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) {
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits