From 1ec31065e83f582a0890208f7fa82098324733ce Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 28 May 2013 18:50:02 +0000 Subject: [PATCH] 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 } }; llvm-svn: 182788 --- clang/lib/Format/UnwrappedLineParser.cpp | 5 ----- clang/unittests/Format/FormatTest.cpp | 19 ++++++------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index f74fbc10ec4d..f20e109ba702 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 96f0ed128b7f..44873f75df48 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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" "}"); }