curdeius created this revision.
curdeius added reviewers: MyDeveloperDay, HazardyKnusperkeks, owenpan.
Herald added a project: All.
curdeius requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Fixes https://github.com/llvm/llvm-project/issues/54140.
Repository:
rG LLVM Github Monorepo
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,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"
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,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"
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
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits