From: Daniel Jasper Date: Wed, 7 May 2014 07:59:03 +0000 (+0000) Subject: clang-format: Fix bad space before braced initializer. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65f588f5a910767f487adeedc8e124bcb74d23ba;p=clang clang-format: Fix bad space before braced initializer. 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 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 8becd00897..a41992679a 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index aad0cb19fb..bd7e23f60b 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5093,6 +5093,7 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) { verifyFormat("Class::Class : member{1, 2, 3} {}"); verifyFormat("new vector{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{f(), g(), h()}.size();");