r375258 - [Format] Add format check for throwing negative numbers
Brian Gesiak via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 18 09:59:03 PDT 2019
Author: modocache
Date: Fri Oct 18 09:59:02 2019
New Revision: 375258
URL: http://llvm.org/viewvc/llvm-project?rev=375258&view=rev
Log:
[Format] Add format check for throwing negative numbers
Summary:
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.
Patch by Jonathan Thomas (jonathoma)!
Reviewers: modocache, sammccall, Quuxplusone
Reviewed By: sammccall
Subscribers: cfe-commits
Tags: #clang-format, #clang
Differential Revision: https://reviews.llvm.org/D69144
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=375258&r1=375257&r2=375258&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Oct 18 09:59:02 2019
@@ -1757,7 +1757,7 @@ private:
// 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.
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=375258&r1=375257&r2=375258&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Oct 18 09:59:02 2019
@@ -6912,6 +6912,7 @@ TEST_F(FormatTest, UnderstandsUnaryOpera
verifyFormat("alignof(char);", getGoogleStyle());
verifyFormat("return -1;");
+ verifyFormat("throw -1;");
verifyFormat("switch (a) {\n"
"case -1:\n"
" break;\n"
More information about the cfe-commits
mailing list