r182601 - Increase test coverage for braced init lists.

Daniel Jasper djasper at google.com
Thu May 23 11:29:16 PDT 2013


Author: djasper
Date: Thu May 23 13:29:16 2013
New Revision: 182601

URL: http://llvm.org/viewvc/llvm-project?rev=182601&view=rev
Log:
Increase test coverage for braced init lists.

Also fix a minor bug for constructor initializers with braced init lists.

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=182601&r1=182600&r2=182601&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Thu May 23 13:29:16 2013
@@ -257,7 +257,7 @@ void UnwrappedLineParser::calculateBrace
           // brace blocks inside it braced init list. That works good enough
           // for now, but we will need to fix it to correctly handle lambdas.
           if (NextTok.Tok.is(tok::comma) || NextTok.Tok.is(tok::semi) ||
-              NextTok.Tok.is(tok::r_paren))
+              NextTok.Tok.is(tok::r_paren) || NextTok.Tok.is(tok::l_brace))
             LBraces[LBraceStack.back()] = BS_BracedInit;
           else
             LBraces[LBraceStack.back()] = BS_Block;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=182601&r1=182600&r2=182601&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu May 23 13:29:16 2013
@@ -3131,6 +3131,12 @@ TEST_F(FormatTest, LayoutCxx11Constructo
     verifyFormat("f({ 1, 2 });");
     verifyFormat("auto v = Foo{ 1 };");
     verifyFormat("f({ 1, 2 }, { { 2, 3 }, { 4, 5 } }, c, { d });");
+    verifyFormat("Class::Class : member{ 1, 2, 3 } {}");
+    verifyFormat("return { arg1, arg2 };");
+    verifyFormat("new T{ arg1, arg2 };");
+    verifyFormat("class Class {\n"
+                 "  T member = { arg1, arg2 };\n"
+                 "};");
 
     FormatStyle NoSpaces = getLLVMStyle();
     NoSpaces.SpacesInBracedLists = false;
@@ -3139,6 +3145,13 @@ TEST_F(FormatTest, LayoutCxx11Constructo
     verifyFormat("f({1, 2});", NoSpaces);
     verifyFormat("auto v = Foo{-1};", NoSpaces);
     verifyFormat("f({1, 2}, {{2, 3}, {4, 5}}, c, {d});", NoSpaces);
+    verifyFormat("Class::Class : member{1, 2, 3} {}", NoSpaces);
+    verifyFormat("return {arg1, arg2};", NoSpaces);
+    verifyFormat("new T{arg1, arg2};", NoSpaces);
+    verifyFormat("class Class {\n"
+                 "  T member = {arg1, arg2};\n"
+                 "};",
+                 NoSpaces);
 }
 
 TEST_F(FormatTest, LayoutTokensFollowingBlockInParentheses) {





More information about the cfe-commits mailing list