]> granicus.if.org Git - clang/commitdiff
clang-format: Detect braced lists in subscript expressions.
authorDaniel Jasper <djasper@google.com>
Fri, 13 Sep 2013 10:55:31 +0000 (10:55 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 13 Sep 2013 10:55:31 +0000 (10:55 +0000)
Before (even with Style.Cpp11BracedListStyle):
  f(MyMap[{ composite, key }]);

After:
  f(MyMap[{composite, key}]);

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

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

index 3fb46f2f56fbcfac8797a01f41c1ffc85c844be0..605aebad02b9971b721623f45f81c6037b7a3f5d 100644 (file)
@@ -290,7 +290,7 @@ void UnwrappedLineParser::calculateBraceTypes() {
           //
           // We exclude + and - as they can be ObjC visibility modifiers.
           if (NextTok->isOneOf(tok::comma, tok::semi, tok::r_paren,
-                               tok::l_brace, tok::colon) ||
+                               tok::r_square, tok::l_brace, tok::colon) ||
               (NextTok->isBinaryOperator() &&
                !NextTok->isOneOf(tok::plus, tok::minus))) {
             Tok->BlockKind = BK_BracedInit;
index 5202073e16e42df7760cf94eea19d42429f586d7..6d504c0c786914e1f3cfe20ea14586436f837aed 100644 (file)
@@ -4271,6 +4271,7 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) {
     verifyFormat("return { arg1, arg2 };");
     verifyFormat("return { arg1, SomeType{ parameter } };");
     verifyFormat("new T{ arg1, arg2 };");
+    verifyFormat("f(MyMap[{ composite, key }]);");
     verifyFormat("class Class {\n"
                  "  T member = { arg1, arg2 };\n"
                  "};");
@@ -4305,6 +4306,7 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) {
     verifyFormat("return {arg1, arg2};", NoSpaces);
     verifyFormat("return {arg1, SomeType{parameter}};", NoSpaces);
     verifyFormat("new T{arg1, arg2};", NoSpaces);
+    verifyFormat("f(MyMap[{composite, key}]);", NoSpaces);
     verifyFormat("class Class {\n"
                  "  T member = {arg1, arg2};\n"
                  "};",