[clang] 8682d29 - [Format] Add format check for coroutine keywords with negative numbers

Brian Gesiak via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 30 12:48:22 PST 2019


Author: Brian Gesiak
Date: 2019-11-30T15:47:58-05:00
New Revision: 8682d29a28772bab0283a141b8701bfaea8881a6

URL: https://github.com/llvm/llvm-project/commit/8682d29a28772bab0283a141b8701bfaea8881a6
DIFF: https://github.com/llvm/llvm-project/commit/8682d29a28772bab0283a141b8701bfaea8881a6.diff

LOG: [Format] Add format check for coroutine keywords with negative numbers

Summary:
As a followup to D69144, this diff fixes the coroutine keyword spacing
for co_yield / co_returning negative numbers.

Reviewers: modocache, sammccall, Quuxplusone

Reviewed By: modocache

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69180

Patch by Jonathan Thomas (jonathoma)!

Added: 
    

Modified: 
    clang/lib/Format/TokenAnnotator.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 9fe7fdc9ce93..74ff5b531496 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1829,7 +1829,8 @@ class AnnotatingParser {
     // 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_throw))
+                           tok::kw_case, tok::at, tok::l_brace, tok::kw_throw,
+                           tok::kw_co_return, tok::kw_co_yield))
       return TT_UnaryOperator;
 
     // There can't be two consecutive binary operators.

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index d89ad44e4577..e6fa829e7ff9 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6990,6 +6990,9 @@ TEST_F(FormatTest, UnderstandsUnaryOperators) {
   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) {


        


More information about the cfe-commits mailing list