]> granicus.if.org Git - clang/commitdiff
[clang-format] Handle unary operator overload with arguments and specifiers
authorDaniel Jasper <djasper@google.com>
Mon, 6 Nov 2017 12:11:51 +0000 (12:11 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 6 Nov 2017 12:11:51 +0000 (12:11 +0000)
Before:
  int operator++(int)noexcept;

After:
  int operator++(int) noexcept;

Patch by Igor Sugak. Thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317473 91177308-0d34-0410-b5e6-96231b3b80d8

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

index bc8fef8bda92e6ae25a1150b3632328ae7fdfeb0..aa5990e8c01f61863e2e05606ecd23ec286cf520 100644 (file)
@@ -696,7 +696,8 @@ private:
           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) {
index 82530c0376a1022cf1f93238df81cd0d5393eee7..c61a56921afbebe1c24c9634ea367227989d4151 100644 (file)
@@ -5591,6 +5591,7 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) {
   verifyFormat("bool operator!=();");
   verifyFormat("int operator+();");
   verifyFormat("int operator++();");
+  verifyFormat("int operator++(int) volatile noexcept;");
   verifyFormat("bool operator,();");
   verifyFormat("bool operator();");
   verifyFormat("bool operator()();");