]> granicus.if.org Git - clang/commitdiff
clang-format: Recognize braced lists with trailing function call.
authorDaniel Jasper <djasper@google.com>
Fri, 22 Nov 2013 07:26:53 +0000 (07:26 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 22 Nov 2013 07:26:53 +0000 (07:26 +0000)
Before:
  int count = set<int> { f(), g(), h() }
      .size();

After:
  int count = set<int>{f(), g(), h()}.size();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195417 91177308-0d34-0410-b5e6-96231b3b80d8

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

index d0743081018217da0c417b3d4f06516b3d279010..016c4db07bf41fd45d6beb20365d58187eae9e18 100644 (file)
@@ -322,7 +322,7 @@ void UnwrappedLineParser::calculateBraceTypes() {
           // (for example while parsing lambdas).
           //
           // We exclude + and - as they can be ObjC visibility modifiers.
-          if (NextTok->isOneOf(tok::comma, tok::semi, tok::r_paren,
+          if (NextTok->isOneOf(tok::comma, tok::semi, tok::r_paren, tok::period,
                                tok::r_square, tok::l_brace, tok::colon) ||
               (NextTok->isBinaryOperator() &&
                !NextTok->isOneOf(tok::plus, tok::minus))) {
index ab3303ea928b6db3d843552dd2c0adeec799107a..b0b1c0f5615fb59335269a0c30496b7d952f130d 100644 (file)
@@ -4671,6 +4671,7 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) {
     verifyFormat("new int[3]{ 1, 2, 3 };");
     verifyFormat("return { arg1, arg2 };");
     verifyFormat("return { arg1, SomeType{ parameter } };");
+    verifyFormat("int count = set<int>{ f(), g(), h() }.size();");
     verifyFormat("new T{ arg1, arg2 };");
     verifyFormat("f(MyMap[{ composite, key }]);");
     verifyFormat("class Class {\n"
@@ -4706,6 +4707,7 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) {
     verifyFormat("new int[3]{1, 2, 3};", NoSpaces);
     verifyFormat("return {arg1, arg2};", NoSpaces);
     verifyFormat("return {arg1, SomeType{parameter}};", NoSpaces);
+    verifyFormat("int count = set<int>{f(), g(), h()}.size();", NoSpaces);
     verifyFormat("new T{arg1, arg2};", NoSpaces);
     verifyFormat("f(MyMap[{composite, key}]);", NoSpaces);
     verifyFormat("class Class {\n"