Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2480,6 +2480,10 @@ return false; if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square)) return false; + if (Right.is(tok::r_brace) && Right.MatchingParen && + Right.MatchingParen->endsSequence(TT_DictLiteral, tok::at)) + // Objective-C dictionary literal -> no space before closing brace. + return false; return true; } Index: unittests/Format/FormatTestObjC.cpp =================================================================== --- unittests/Format/FormatTestObjC.cpp +++ unittests/Format/FormatTestObjC.cpp @@ -1000,6 +1000,21 @@ " (aaaaaaaa id)aaaaaaaaa : (aaaaaaaa id)aaaaaaaaaaaaaaaaaaaaaaaa,\n" " (aaaaaaaa id)aaaaaaaaaaaaaa : (aaaaaaaa id)aaaaaaaaaaaaaa,\n" "};"); + Style.ColumnLimit = 40; + verifyFormat("int Foo() {\n" + " a12345 = @{a12345 : a12345};\n" + "}"); + verifyFormat("int Foo() {\n" + " a12345 = @{(Foo *)a12345 : @(a12345)};\n" + "}"); + Style.SpacesInContainerLiterals = false; + verifyFormat("int Foo() {\n" + " b12345 = @{b12345: b12345};\n" + "}"); + verifyFormat("int Foo() {\n" + " b12345 = @{(Foo *)b12345: @(b12345)};\n" + "}"); + Style.SpacesInContainerLiterals = true; Style = getGoogleStyle(FormatStyle::LK_ObjC); verifyFormat( @@ -1055,6 +1070,21 @@ verifyFormat("[someFunction someLooooooooooooongParameter:@[\n" " NSBundle.mainBundle.infoDictionary[@\"a\"]\n" "]];"); + Style.ColumnLimit = 40; + verifyFormat("int Foo() {\n" + " a12345 = @[ a12345, a12345 ];\n" + "}"); + verifyFormat("int Foo() {\n" + " a123 = @[ (Foo *)a12345, @(a12345) ];\n" + "}"); + Style.SpacesInContainerLiterals = false; + verifyFormat("int Foo() {\n" + " b12345 = @[b12345, b12345];\n" + "}"); + verifyFormat("int Foo() {\n" + " b12345 = @[(Foo *)b12345, @(b12345)];\n" + "}"); + Style.SpacesInContainerLiterals = true; Style.ColumnLimit = 20; // We can't break string literals inside NSArray literals // (that raises -Wobjc-string-concatenation).