This revision was automatically updated to reflect the committed changes. Closed by commit rG13351fdf8cb4: [clang-format] Recognize "if consteval". (authored by curdeius).
Changed prior to commit: https://reviews.llvm.org/D120806?vs=412366&id=412444#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D120806/new/ https://reviews.llvm.org/D120806 Files: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ 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(); }", Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ 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;
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ 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(); }", Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits