From: Daniel Jasper Date: Thu, 23 May 2013 21:35:49 +0000 (+0000) Subject: More tests and a fix for braced init lists. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ce93356e2719d2992763ea747b65beada99f4c9b;p=clang More tests and a fix for braced init lists. Before: f(new vector { 1, 2, 3 }); After: f(new vector{ 1, 2, 3 }); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182614 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 4d346bd051..1fc9f9cbc1 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1095,8 +1095,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.is(tok::identifier) && Right.is(tok::l_brace) && - Right.getNextNoneComment()) + if (Left.isOneOf(tok::identifier, tok::greater, tok::r_square) && + Right.is(tok::l_brace) && Right.getNextNoneComment()) return false; if (Right.is(tok::ellipsis)) return false; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index ce551e9d1b..f72013a448 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3159,6 +3159,8 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) { verifyFormat("auto v = Foo{ 1 };"); verifyFormat("f({ 1, 2 }, { { 2, 3 }, { 4, 5 } }, c, { d });"); verifyFormat("Class::Class : member{ 1, 2, 3 } {}"); + verifyFormat("new vector{ 1, 2, 3 };"); + verifyFormat("new int[3]{ 1, 2, 3 };"); verifyFormat("return { arg1, arg2 };"); verifyFormat("new T{ arg1, arg2 };"); verifyFormat("class Class {\n" @@ -3173,6 +3175,8 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) { 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("new vector{1, 2, 3};", NoSpaces); + verifyFormat("new int[3]{1, 2, 3};", NoSpaces); verifyFormat("return {arg1, arg2};", NoSpaces); verifyFormat("new T{arg1, arg2};", NoSpaces); verifyFormat("class Class {\n"