From: Daniel Jasper Date: Sat, 26 Oct 2013 17:00:22 +0000 (+0000) Subject: clang-format: Fix ObjC method exprs with variadic parameters. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f54d881723ca7058807eee871913c812618bfda;p=clang clang-format: Fix ObjC method exprs with variadic parameters. Before: _versionLabel.text = [ NSString stringWithFormat:NSLocalizedString(@"version: %@", @"Label"), [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"] ]; After: _versionLabel.text = [NSString stringWithFormat:NSLocalizedString(@"version: %@", @"Label"), [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"]]; This fixed llvm.org/PR17695. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193475 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 9240c63481..621581c521 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -197,6 +197,7 @@ private: getBinOpPrecedence(Parent->Tok.getKind(), true, true) > prec::Unknown); ScopedContextCreator ContextCreator(*this, tok::l_square, 10); Contexts.back().IsExpression = true; + bool ColonFound = false; if (StartsObjCMethodExpr) { Contexts.back().ColonIsObjCMethodExpr = true; @@ -234,9 +235,11 @@ private: } if (CurrentToken->isOneOf(tok::r_paren, tok::r_brace)) return false; + if (CurrentToken->is(tok::colon)) + ColonFound = true; if (CurrentToken->is(tok::comma) && (Left->Type == TT_ArraySubscriptLSquare || - Left->Type == TT_ObjCMethodExpr)) + (Left->Type == TT_ObjCMethodExpr && !ColonFound))) Left->Type = TT_ArrayInitializerLSquare; updateParameterCount(Left, CurrentToken); if (!consumeToken()) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index ac95f27b2f..cbac133c4d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5304,6 +5304,10 @@ TEST_F(FormatTest, FormatObjCMethodExpr) { " aaaaaaaaaa:bbbbbbbbbbbbbbbbb\n" " aaaaa:bbbbbbbbbbb + bbbbbbbbbbbb\n" " aaaa:bbb];"); + + // Variadic parameters. + verifyFormat( + "NSArray *myStrings = [NSArray stringarray:@\"a\", @\"b\", nil];"); } TEST_F(FormatTest, ObjCAt) {