Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -41,7 +41,28 @@ // Returns \c true if \c Tok is the "." or "->" of a call and starts the next // segment of a builder type call. static bool startsSegmentOfBuilderTypeCall(const FormatToken &Tok) { - return Tok.isMemberAccess() && Tok.Previous && Tok.Previous->closesScope(); + if (Tok.isMemberAccess() && Tok.Previous && Tok.Previous->closesScope()) { + // Ensure that closing scope was function or method call, instantiation + // or indexed access, not eg. a type cast or Objective-C call. + const FormatToken *LeftParen = Tok.Previous->MatchingParen; + if (!LeftParen) + return false; + // We expect previous token is an identifier ... + const FormatToken *ExpectedIdentifier = LeftParen->getPreviousNonComment(); + if (!ExpectedIdentifier) + return false; + // or template closing ... + if (ExpectedIdentifier->is(TT_TemplateCloser)) { + const FormatToken *TemplateOpener = ExpectedIdentifier->MatchingParen; + if (!TemplateOpener) + return false; + const FormatToken *ExpectedIdentifier = TemplateOpener->getPreviousNonComment(); + // ... of template preceeded by identifier. + return ExpectedIdentifier && ExpectedIdentifier->is(tok::identifier); + } + return ExpectedIdentifier->is(tok::identifier); + } + return false; } // Returns \c true if \c Current starts a new parameter. Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -4167,6 +4167,21 @@ verifyFormat("aaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaa()\n" " ->aaaaaaaaaaaaaae(0)\n" " ->aaaaaaaaaaaaaaa();"); + verifyFormat("(aaaa).aaaaaaaaaaaaaaa()\n" + " .aaaaaaaaaaaaaaa()\n" + " .aaaaaaaaaaaaaaa()\n" + " .aaaaaaaaaaaaaaa()\n" + " .aaaaaaaaaaaaaaa();"); + verifyFormat("aaaa()\n" + " .aaaaaaaaaaaaaaa()\n" + " .aaaaaaaaaaaaaaa()\n" + " .aaaaaaaaaaaaaaa()\n" + " .aaaaaaaaaaaaaaa()\n" + " .aaaaaaaaaaaaaaa();"); + verifyFormat("[aaaaa aaaaaaaaaaaaaaa].aaaaaaaaaaaaaaa()\n" + " .aaaaaaaaaaaaaaa()\n" + " .aaaaaaaaaaaaaaa()\n" + " .aaaaaaaaaaaaaaa();"); // Don't linewrap after very short segments. verifyFormat("a().aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()\n"