diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 909883016115505ebc4efdcadbd45b846b884d80..133c53521b23d43cd45e5cdde03d72e939574a1b 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -639,9 +639,9 @@ private: void next() { if (CurrentToken) { - determineTokenType(*CurrentToken); - CurrentToken->BindingStrength = Contexts.back().BindingStrength; CurrentToken->NestingLevel = Contexts.size() - 1; + CurrentToken->BindingStrength = Contexts.back().BindingStrength; + determineTokenType(*CurrentToken); CurrentToken = CurrentToken->Next; } @@ -745,7 +745,8 @@ private: // Line.MightBeFunctionDecl can only be true after the parentheses of a // function declaration have been found. In this case, 'Current' is a // trailing token of this declaration and thus cannot be a name. - if (isStartOfName(Current) && !Line.MightBeFunctionDecl) { + if (isStartOfName(Current) && + (!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) { Contexts.back().FirstStartOfName = &Current; Current.Type = TT_StartOfName; } else if (Current.is(tok::kw_auto)) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 15688cdb1bde031a64c30a801d91a33538a529a4..a10b4d7fb62e4518d938fc200c8c16dcffa7639b 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5180,6 +5180,10 @@ TEST_F(FormatTest, BreaksLongDeclarations) { "aaaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaa() {}"); verifyGoogleFormat("A<A<A>> aaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" " int aaaaaaaaaaaaaaaaaaaaaaa);"); + + verifyFormat("typedef size_t (*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(\n" + " const aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);"); } TEST_F(FormatTest, FormatsArrays) {