]> granicus.if.org Git - clang/commitdiff
clang-format: Make SpaceBeforeParens work with overloaded operators.
authorDaniel Jasper <djasper@google.com>
Tue, 11 Aug 2015 20:32:24 +0000 (20:32 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 11 Aug 2015 20:32:24 +0000 (20:32 +0000)
Patch by Jon Chesterfield, thank you!

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

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

index bd6fde0911397139c54e6dfbdbe6ac069935e445..25ec7e6023d4647ad4d51229f0880a44f2151ad0 100644 (file)
@@ -1997,7 +1997,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
   if (Right.isOneOf(TT_CtorInitializerColon, TT_ObjCBlockLParen))
     return true;
   if (Right.is(TT_OverloadedOperatorLParen))
-    return false;
+    return Style.SpaceBeforeParens == FormatStyle::SBPO_Always;
   if (Right.is(tok::colon)) {
     if (Line.First->isOneOf(tok::kw_case, tok::kw_default) ||
         !Right.getNextNonComment() || Right.getNextNonComment()->is(tok::semi))
index f71f63c7ddf778cf2af8e285ba2c2f1f6988b9d2..6eee541d0ba7e4c8c0466a31e268487a94fd7f07 100644 (file)
@@ -8279,6 +8279,8 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   verifyFormat("static_assert(sizeof(char) == 1, \"Impossible!\");", NoSpace);
   verifyFormat("int f() throw(Deprecated);", NoSpace);
   verifyFormat("typedef void (*cb)(int);", NoSpace);
+  verifyFormat("T A::operator()();", NoSpace);
+  verifyFormat("X A::operator++(T);", NoSpace);
 
   FormatStyle Space = getLLVMStyle();
   Space.SpaceBeforeParens = FormatStyle::SBPO_Always;
@@ -8324,6 +8326,8 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   verifyFormat("static_assert (sizeof (char) == 1, \"Impossible!\");", Space);
   verifyFormat("int f () throw (Deprecated);", Space);
   verifyFormat("typedef void (*cb) (int);", Space);
+  verifyFormat("T A::operator() ();", Space);
+  verifyFormat("X A::operator++ (T);", Space);
 }
 
 TEST_F(FormatTest, ConfigurableSpacesInParentheses) {