]> granicus.if.org Git - clang/commitdiff
Support uniform inits in braced lists.
authorDaniel Jasper <djasper@google.com>
Tue, 28 May 2013 18:50:02 +0000 (18:50 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 28 May 2013 18:50:02 +0000 (18:50 +0000)
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

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index f74fbc10ec4d65802e33172047996089bd1370da..f20e109ba702769aa6651e3633da74b307510062 100644 (file)
@@ -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;
index 96f0ed128b7f47bad64dc1b96035d4c0bb013ae9..44873f75df4884ae05a7a34f9e896334f334e9d8 100644 (file)
@@ -3386,6 +3386,7 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) {
     verifyFormat("new vector<int>{ 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<int>{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"
                "}");
 }