[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
This commit is contained in:
Emilia Dreamer 2022-09-05 12:33:59 +02:00 committed by Björn Schäpers
parent c6e7752f8e
commit bd3dd10a8b
3 changed files with 18 additions and 1 deletions

View File

@ -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;

View File

@ -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;");

View File

@ -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"