]> granicus.if.org Git - clang/commitdiff
clang-format: Fix bad space before braced initializer.
authorDaniel Jasper <djasper@google.com>
Wed, 7 May 2014 07:59:03 +0000 (07:59 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 7 May 2014 07:59:03 +0000 (07:59 +0000)
Before:
  new int {1};

After:
  new int{1};

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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 8becd00897a2f415eabd8216716dcd8437b5acda..a41992679ad6a6451d2eeb8db4f576bf2222c34e 100644 (file)
@@ -1483,7 +1483,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
   if (Right.Type == TT_UnaryOperator)
     return !Left.isOneOf(tok::l_paren, tok::l_square, tok::at) &&
            (Left.isNot(tok::colon) || Left.Type != TT_ObjCMethodExpr);
-  if (Left.isOneOf(tok::identifier, tok::greater, tok::r_square) &&
+  if ((Left.isOneOf(tok::identifier, tok::greater, tok::r_square) ||
+       Left.isSimpleTypeSpecifier()) &&
       Right.is(tok::l_brace) && Right.getNextNonComment() &&
       Right.BlockKind != BK_Block)
     return false;
index aad0cb19fb2ed05251cbc419ca628027cb31d845..bd7e23f60b86b899085aefefbe8960a34c2d7fa4 100644 (file)
@@ -5093,6 +5093,7 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
   verifyFormat("Class::Class : member{1, 2, 3} {}");
   verifyFormat("new vector<int>{1, 2, 3};");
   verifyFormat("new int[3]{1, 2, 3};");
+  verifyFormat("new int{1};");
   verifyFormat("return {arg1, arg2};");
   verifyFormat("return {arg1, SomeType{parameter}};");
   verifyFormat("int count = set<int>{f(), g(), h()}.size();");