[clang] bd3dd10 - [clang-format] Concepts: allow identifiers after negation
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 5 03:36:12 PDT 2022
Author: Emilia Dreamer
Date: 2022-09-05T12:35:40+02:00
New Revision: bd3dd10a8b489ce50823b4cc0049f16610adeee2
URL: https://github.com/llvm/llvm-project/commit/bd3dd10a8b489ce50823b4cc0049f16610adeee2
DIFF: https://github.com/llvm/llvm-project/commit/bd3dd10a8b489ce50823b4cc0049f16610adeee2.diff
LOG: [clang-format] Concepts: allow identifiers after negation
Previously, the formatter would refuse to treat identifiers within a
compound concept definition as actually part of the definition, if
they were after the negation operator !. It is now made consistent
with the likes of && and ||.
Fixes https://github.com/llvm/llvm-project/issues/55898
Differential Revision: https://reviews.llvm.org/D131978
Added:
Modified:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 1e775f70a24a..02b13be0d92e 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3544,7 +3544,8 @@ void UnwrappedLineParser::parseConstraintExpression() {
switch (FormatTok->Previous->Tok.getKind()) {
case tok::coloncolon: // Nested identifier.
case tok::ampamp: // Start of a function or variable for the
- case tok::pipepipe: // constraint expression.
+ case tok::pipepipe: // constraint expression. (binary)
+ 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.
break;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 4383a903b2f6..88c16884d0d8 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24217,6 +24217,15 @@ TEST_F(FormatTest, Concepts) {
"concept DelayedCheck = false || requires(T t) { t.bar(); } && "
"sizeof(T) <= 8;");
+ verifyFormat("template <typename T>\n"
+ "concept DelayedCheck = Unit<T> && !DerivedUnit<T>;");
+
+ verifyFormat("template <typename T>\n"
+ "concept DelayedCheck = Unit<T> && !(DerivedUnit<T>);");
+
+ verifyFormat("template <typename T>\n"
+ "concept DelayedCheck = Unit<T> && !!DerivedUnit<T>;");
+
verifyFormat("template <typename T>\n"
"concept DelayedCheck = !!false || requires(T t) { t.bar(); } "
"&& sizeof(T) <= 8;");
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 60684d72605e..a839fb29115f 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -374,6 +374,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) {
EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator);
EXPECT_TOKEN(Tokens[16], tok::ampamp, TT_BinaryOperator);
+ Tokens = annotate("template <typename T>\n"
+ "concept C = Foo && !Bar;");
+
+ ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+ EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
+ EXPECT_TOKEN(Tokens[10], tok::exclaim, TT_UnaryOperator);
+
Tokens = annotate("template <typename T>\n"
"concept C = requires(T t) {\n"
" { t.foo() };\n"
More information about the cfe-commits
mailing list