diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 29eaaa8b58..0f91b11033 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -173,7 +173,9 @@ private: } if (CurrentToken->isOneOf(tok::r_square, tok::r_brace)) return false; - if (CurrentToken->Parent->Type == TT_PointerOrReference && + if (Left->Parent && + !Left->Parent->isOneOf(tok::kw_sizeof, tok::kw_alignof) && + CurrentToken->Parent->Type == TT_PointerOrReference && CurrentToken->Parent->Parent->isOneOf(tok::l_paren, tok::coloncolon)) Left->DefinesFunctionType = true; updateParameterCount(Left, CurrentToken); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b2ae3d2560..b2393f578b 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2790,6 +2790,10 @@ TEST_F(FormatTest, FormatsFunctionTypes) { verifyGoogleFormat("A;"); verifyGoogleFormat("void* (*a)(int);"); + + // Other constructs can look like function types: + verifyFormat("A a;"); + verifyFormat("A a;"); } TEST_F(FormatTest, BreaksLongDeclarations) {