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 @@ -2384,10 +2384,16 @@ assert(FormatTok->is(tok::kw_if) && "'if' expected"); nextToken(); - if (FormatTok->isOneOf(tok::kw_constexpr, tok::identifier)) + if (FormatTok->is(tok::exclaim)) nextToken(); - if (FormatTok->is(tok::l_paren)) - parseParens(); + if (FormatTok->is(tok::kw_consteval)) { + nextToken(); + } else { + if (FormatTok->isOneOf(tok::kw_constexpr, tok::identifier)) + nextToken(); + if (FormatTok->is(tok::l_paren)) + parseParens(); + } HandleAttributes(); bool NeedsUnwrappedLine = false; 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 @@ -583,6 +583,28 @@ " }\n" "g();"); + verifyFormat("if consteval {\n}"); + verifyFormat("if !consteval {\n}"); + verifyFormat("if consteval {\n} else {\n}"); + verifyFormat("if !consteval {\n} else {\n}"); + verifyFormat("if consteval {\n" + " f();\n" + "}"); + verifyFormat("if !consteval {\n" + " f();\n" + "}"); + verifyFormat("if consteval {\n" + " f();\n" + "} else {\n" + " g();\n" + "}"); + verifyFormat("if CONSTEVAL {\n" + " f();\n" + "}"); + verifyFormat("if !CONSTEVAL {\n" + " f();\n" + "}"); + verifyFormat("if (a)\n" " g();"); verifyFormat("if (a) {\n"