[PATCH] D39587: [clang-format] Handle unary operator overload with arguments and specifiers

Igor Sugak via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 2 21:19:44 PDT 2017


sugak created this revision.

Before:

  int operator++(int)noexcept;

After:

  int operator++(int) noexcept;


https://reviews.llvm.org/D39587

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5591,6 +5591,7 @@
   verifyFormat("bool operator!=();");
   verifyFormat("int operator+();");
   verifyFormat("int operator++();");
+  verifyFormat("int operator++(int) volatile noexcept;");
   verifyFormat("bool operator,();");
   verifyFormat("bool operator();");
   verifyFormat("bool operator()();");
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -696,7 +696,8 @@
           CurrentToken->Type = TT_PointerOrReference;
         consumeToken();
         if (CurrentToken &&
-            CurrentToken->Previous->isOneOf(TT_BinaryOperator, tok::comma))
+            CurrentToken->Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator,
+                                            tok::comma))
           CurrentToken->Previous->Type = TT_OverloadedOperator;
       }
       if (CurrentToken) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39587.121432.patch
Type: text/x-patch
Size: 1108 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171103/b56ce0ef/attachment.bin>


More information about the cfe-commits mailing list