forked from OSchip/llvm-project
[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:
parent
c6e7752f8e
commit
bd3dd10a8b
|
@ -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;
|
||||
|
|
|
@ -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;");
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue