From: Daniel Jasper Date: Tue, 11 Aug 2015 20:32:24 +0000 (+0000) Subject: clang-format: Make SpaceBeforeParens work with overloaded operators. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ef23307ace0b1dcdf21f7916d8ec77864d89fd07;p=clang clang-format: Make SpaceBeforeParens work with overloaded operators. Patch by Jon Chesterfield, thank you! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244660 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index bd6fde0911..25ec7e6023 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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)) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index f71f63c7dd..6eee541d0b 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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) {