[PATCH] D69179: [Format] Add format check for coroutine keywords with negative numbers
Jonathan Thomas via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 18 09:25:14 PDT 2019
jonathoma created this revision.
Herald added subscribers: cfe-commits, modocache.
Herald added a project: clang.
jonathoma retitled this revision from "[Format] Add format check for throwing negative numbers" to "[Format] Add format check for coroutine keywords with negative numbers".
jonathoma edited the summary of this revision.
jonathoma abandoned this revision.
As a followup to D69144 <https://reviews.llvm.org/D69144>, this diff fixes the coroutine keyword spacing
for `co_yield` / `co_return`ing negative numbers.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D69179
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6912,6 +6912,7 @@
verifyFormat("alignof(char);", getGoogleStyle());
verifyFormat("return -1;");
+ verifyFormat("throw -1;");
verifyFormat("switch (a) {\n"
"case -1:\n"
" break;\n"
@@ -6925,6 +6926,9 @@
verifyFormat("int a = /* confusing comment */ -1;");
// FIXME: The space after 'i' is wrong, but hopefully, this is a rare case.
verifyFormat("int a = i /* confusing comment */++;");
+
+ verifyFormat("co_yield -1;");
+ verifyFormat("co_return -1;");
}
TEST_F(FormatTest, DoesNotIndentRelativeToUnaryOperators) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1693,7 +1693,8 @@
if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
tok::comma, tok::semi, tok::kw_return, tok::colon,
tok::equal, tok::kw_delete, tok::kw_sizeof,
- tok::kw_throw) ||
+ tok::kw_throw, tok::kw_co_return,
+ tok::kw_co_yield) ||
PrevToken->isOneOf(TT_BinaryOperator, TT_ConditionalExpr,
TT_UnaryOperator, TT_CastRParen))
return TT_UnaryOperator;
@@ -1756,7 +1757,7 @@
// Use heuristics to recognize unary operators.
if (PrevToken->isOneOf(tok::equal, tok::l_paren, tok::comma, tok::l_square,
tok::question, tok::colon, tok::kw_return,
- tok::kw_case, tok::at, tok::l_brace))
+ tok::kw_case, tok::at, tok::l_brace, tok::kw_throw))
return TT_UnaryOperator;
// There can't be two consecutive binary operators.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69179.225649.patch
Type: text/x-patch
Size: 1993 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191018/98af1dd3/attachment.bin>
More information about the cfe-commits
mailing list