From: Anders Waldenborg Date: Tue, 19 May 2015 16:54:26 +0000 (+0000) Subject: clang-format: Add space in function pointers with SpaceBeforeParens=Always X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a78300001a53c722a7a1d7d3ed2756c6c00240e0;p=clang clang-format: Add space in function pointers with SpaceBeforeParens=Always "void (*my_function)(void)" should become "void (*my_function) (void)" when SpaceBeforeParens is set to 'Always' Differential Revision: http://reviews.llvm.org/D9835 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237704 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 7d38f8317e..c2e29080dc 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1827,7 +1827,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, tok::kw_new, tok::kw_delete) && (!Left.Previous || Left.Previous->isNot(tok::period))))) || (Style.SpaceBeforeParens == FormatStyle::SBPO_Always && - (Left.is(tok::identifier) || Left.isFunctionLikeKeyword()) && + (Left.is(tok::identifier) || Left.isFunctionLikeKeyword() || Left.is(tok::r_paren)) && Line.Type != LT_PreprocessorDirective); } if (Left.is(tok::at) && Right.Tok.getObjCKeywordID() != tok::objc_not_keyword) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index ead063fe41..4684d1d746 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -8454,6 +8454,7 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) { verifyFormat("size_t x = alignof(MyType);", NoSpace); verifyFormat("static_assert(sizeof(char) == 1, \"Impossible!\");", NoSpace); verifyFormat("int f() throw(Deprecated);", NoSpace); + verifyFormat("typedef void (*cb)(int);", NoSpace); FormatStyle Space = getLLVMStyle(); Space.SpaceBeforeParens = FormatStyle::SBPO_Always; @@ -8498,6 +8499,7 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) { verifyFormat("size_t x = alignof (MyType);", Space); verifyFormat("static_assert (sizeof (char) == 1, \"Impossible!\");", Space); verifyFormat("int f () throw (Deprecated);", Space); + verifyFormat("typedef void (*cb) (int);", Space); } TEST_F(FormatTest, ConfigurableSpacesInParentheses) {