[PATCH] D69144: [Format] Add format check for throwing negative numbers
Jonathan Thomas via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 17 14:46:44 PDT 2019
jonathoma created this revision.
jonathoma added a reviewer: modocache.
jonathoma added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
jonathoma edited the summary of this revision.
jonathoma added reviewers: sammccall, Quuxplusone.
The code `throw -1;` is currently formatted by clang-format as
`throw - 1;`. This diff adds a fix for this edge case and a test to check
for this in the future.
For context, I am looking into a related bug in the clang-formatting of
coroutine keywords: `co_yield -1;` is also reformatted in this manner
as `co_yield - 1;`. A later diff will add these changes and tests for the
`co_yield` and `co_return` keywords.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D69144
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"
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1756,7 +1756,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: D69144.225525.patch
Type: text/x-patch
Size: 1082 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191017/715f0a6a/attachment.bin>
More information about the cfe-commits
mailing list