diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index ab9c8c88597f..75b173ef4f46 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 715c55fd48bf..9e6a60961bce 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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) {