From: Daniel Jasper Date: Tue, 28 May 2013 18:50:02 +0000 (+0000) Subject: Support uniform inits in braced lists. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88959b764ede8aac9118434f6c21c15463dff595;p=clang Support uniform inits in braced lists. This made it necessary to remove an error detection which would let us bail out of braced lists in certain situations of missing "}". However, as we always entirely escape from the braced list on finding ";", this should not be a big problem. With this, we can no format braced lists with uniformat inits: return { arg1, SomeType { parameter } }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182788 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index f74fbc10ec..f20e109ba7 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -634,11 +634,6 @@ void UnwrappedLineParser::parseBracedList() { // might be to just implement a more or less complete expression parser. switch (FormatTok->Tok.getKind()) { case tok::l_brace: - if (!StartOfExpression) { - // Probably a missing closing brace. Bail out. - addUnwrappedLine(); - return; - } parseBracedList(); StartOfExpression = false; break; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 96f0ed128b..44873f75df 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3386,6 +3386,7 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) { verifyFormat("new vector{ 1, 2, 3 };"); verifyFormat("new int[3]{ 1, 2, 3 };"); verifyFormat("return { arg1, arg2 };"); + verifyFormat("return { arg1, SomeType{ parameter } };"); verifyFormat("new T{ arg1, arg2 };"); verifyFormat("class Class {\n" " T member = { arg1, arg2 };\n" @@ -3402,6 +3403,7 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) { verifyFormat("new vector{1, 2, 3};", NoSpaces); verifyFormat("new int[3]{1, 2, 3};", NoSpaces); verifyFormat("return {arg1, arg2};", NoSpaces); + verifyFormat("return {arg1, SomeType{parameter}};", NoSpaces); verifyFormat("new T{arg1, arg2};", NoSpaces); verifyFormat("class Class {\n" " T member = {arg1, arg2};\n" @@ -4161,15 +4163,8 @@ TEST_F(FormatTest, ObjCLiterals) { verifyFormat("return @{ @\"one\" : @1 };"); verifyFormat("@{ @\"one\" : @1, }"); - // FIXME: Breaking in cases where we think there's a structural error - // showed that we're incorrectly parsing this code. We need to fix the - // parsing here. - verifyFormat("@{ @\"one\" : @\n" - "{ @2 : @1 }\n" - "}"); - verifyFormat("@{ @\"one\" : @\n" - "{ @2 : @1 },\n" - "}"); + verifyFormat("@{ @\"one\" : @{ @2 : @1 } }"); + verifyFormat("@{ @\"one\" : @{ @2 : @1 }, }"); verifyFormat("@{ 1 > 2 ? @\"one\" : @\"two\" : 1 > 2 ? @1 : @2 }"); verifyFormat("[self setDict:@{}"); @@ -4458,10 +4453,8 @@ TEST_F(FormatTest, DoNotCreateUnreasonableUnwrappedLines) { verifyFormat("if (foo)\n" " return { forgot_closing_brace();\n" "test();"); - verifyFormat("int a[] = { void forgot_closing_brace()\n" - "{\n" - " f();\n" - " g();\n" + verifyFormat("int a[] = { void forgot_closing_brace() { f();\n" + "g();\n" "}"); }