From: Daniel Jasper Date: Wed, 8 May 2013 15:06:58 +0000 (+0000) Subject: Further fix to pointer to member formatting. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4b7b104c2c66550ecc4ebfe39225fe067858b9aa;p=clang Further fix to pointer to member formatting. With style where the *s go with the type: Before: typedef bool* (Class:: *Member)() const; After: typedef bool* (Class::*Member)() const; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181439 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index ab9c8c8859..75b173ef4f 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1035,7 +1035,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return Right.FormatTok.Tok.isLiteral() || ((Right.Type != TT_PointerOrReference) && Right.isNot(tok::l_paren) && Style.PointerBindsToType && - Left.Parent && Left.Parent->isNot(tok::l_paren)); + Left.Parent && + !Left.Parent->isOneOf(tok::l_paren, tok::coloncolon)); if (Right.is(tok::star) && Left.is(tok::l_paren)) return false; if (Left.is(tok::l_square)) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 715c55fd48..9e6a60961b 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2418,7 +2418,7 @@ TEST_F(FormatTest, UnderstandsBinaryOperators) { TEST_F(FormatTest, UnderstandsPointersToMembers) { verifyFormat("int A::*x;"); verifyFormat("int (S::*func)(void *);"); - verifyFormat("typedef bool (Class::*Member)() const;"); + verifyFormat("typedef bool *(Class::*Member)() const;"); verifyFormat("void f() {\n" " (a->*f)();\n" " a->*x;\n" @@ -2426,6 +2426,9 @@ TEST_F(FormatTest, UnderstandsPointersToMembers) { " ((*a).*f)();\n" " a.*x;\n" "}"); + FormatStyle Style = getLLVMStyle(); + Style.PointerBindsToType = true; + verifyFormat("typedef bool* (Class::*Member)() const;", Style); } TEST_F(FormatTest, UnderstandsUnaryOperators) {