diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -3544,7 +3544,8 @@ 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 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -24217,6 +24217,15 @@ "concept DelayedCheck = false || requires(T t) { t.bar(); } && " "sizeof(T) <= 8;"); + verifyFormat("template \n" + "concept DelayedCheck = Unit && !DerivedUnit;"); + + verifyFormat("template \n" + "concept DelayedCheck = Unit && !(DerivedUnit);"); + + verifyFormat("template \n" + "concept DelayedCheck = Unit && !!DerivedUnit;"); + verifyFormat("template \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 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -374,6 +374,13 @@ EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator); EXPECT_TOKEN(Tokens[16], tok::ampamp, TT_BinaryOperator); + Tokens = annotate("template \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 \n" "concept C = requires(T t) {\n" " { t.foo() };\n"