[PATCH] D125593: [clang-format] Handle "if consteval { ... }" for RemoveBracesLLVM
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 13 16:39:20 PDT 2022
owenpan created this revision.
owenpan added reviewers: curdeius, HazardyKnusperkeks, MyDeveloperDay.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125593
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
@@ -25379,6 +25379,18 @@
"}",
Style);
+ verifyFormat("if consteval {\n"
+ " f();\n"
+ "} else {\n"
+ " g();\n"
+ "}",
+ Style);
+
+ verifyFormat("if !consteval {\n"
+ " g();\n"
+ "}",
+ Style);
+
Style.ColumnLimit = 65;
verifyFormat("if (condition) {\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2473,7 +2473,12 @@
nextToken();
if (FormatTok->is(tok::exclaim))
nextToken();
+
+ bool KeepIfBraces = false;
+ bool KeepElseBraces = false;
if (FormatTok->is(tok::kw_consteval)) {
+ KeepIfBraces = true;
+ KeepElseBraces = true;
nextToken();
} else {
if (FormatTok->isOneOf(tok::kw_constexpr, tok::identifier))
@@ -2501,7 +2506,6 @@
parseUnbracedBody();
}
- bool KeepIfBraces = false;
if (Style.RemoveBracesLLVM) {
assert(!NestedTooDeep.empty());
KeepIfBraces = (IfLeftBrace && !IfLeftBrace->MatchingParen) ||
@@ -2558,8 +2562,9 @@
return nullptr;
assert(!NestedTooDeep.empty());
- const bool KeepElseBraces =
- (ElseLeftBrace && !ElseLeftBrace->MatchingParen) || NestedTooDeep.back();
+ KeepElseBraces = KeepElseBraces ||
+ (ElseLeftBrace && !ElseLeftBrace->MatchingParen) ||
+ NestedTooDeep.back();
NestedTooDeep.pop_back();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125593.429387.patch
Type: text/x-patch
Size: 1765 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220513/d522e447/attachment.bin>
More information about the cfe-commits
mailing list