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,29 @@ " }\n" "g();"); + verifyFormat("if consteval {\n}"); + verifyFormat("if !consteval {\n}"); + verifyFormat("if not 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" @@ -1569,6 +1592,9 @@ verifyFormat("if (true) {}", AllowSimpleBracedStatements); verifyFormat("if constexpr (true) {}", AllowSimpleBracedStatements); verifyFormat("if CONSTEXPR (true) {}", AllowSimpleBracedStatements); + verifyFormat("if consteval {}", AllowSimpleBracedStatements); + verifyFormat("if !consteval {}", AllowSimpleBracedStatements); + verifyFormat("if CONSTEVAL {}", AllowSimpleBracedStatements); verifyFormat("MYIF (true) {}", AllowSimpleBracedStatements); verifyFormat("MYIF constexpr (true) {}", AllowSimpleBracedStatements); verifyFormat("MYIF CONSTEXPR (true) {}", AllowSimpleBracedStatements); @@ -1577,9 +1603,13 @@ verifyFormat("if (true) { f(); }", AllowSimpleBracedStatements); verifyFormat("if constexpr (true) { f(); }", AllowSimpleBracedStatements); verifyFormat("if CONSTEXPR (true) { f(); }", AllowSimpleBracedStatements); + verifyFormat("if consteval { f(); }", AllowSimpleBracedStatements); + verifyFormat("if CONSTEVAL { f(); }", AllowSimpleBracedStatements); verifyFormat("MYIF (true) { f(); }", AllowSimpleBracedStatements); verifyFormat("MYIF constexpr (true) { f(); }", AllowSimpleBracedStatements); verifyFormat("MYIF CONSTEXPR (true) { f(); }", AllowSimpleBracedStatements); + verifyFormat("MYIF consteval { f(); }", AllowSimpleBracedStatements); + verifyFormat("MYIF CONSTEVAL { f(); }", AllowSimpleBracedStatements); verifyFormat("while (true) { f(); }", AllowSimpleBracedStatements); verifyFormat("for (;;) { f(); }", AllowSimpleBracedStatements); verifyFormat("if (true) { fffffffffffffffffffffff(); }",