From b09075a24068694c8d982c6df97646c91d133876 Mon Sep 17 00:00:00 2001 From: Anders Waldenborg Date: Tue, 19 May 2015 16:54:26 +0000 Subject: [PATCH] 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 llvm-svn: 237704 --- clang/lib/Format/TokenAnnotator.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 7d38f8317e71..c2e29080dcfb 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index ead063fe41da..4684d1d746b5 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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) {