From: Daniel Jasper Date: Thu, 23 Apr 2015 10:23:53 +0000 (+0000) Subject: clang-format: Don't add unwanted space when creating new arrays. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=532a031422a341ede79c91441417f7bb860e9209;p=platform%2Fupstream%2Fllvm.git clang-format: Don't add unwanted space when creating new arrays. Before: char** newargv = new char* [argc]; After: char** newargv = new char*[argc]; llvm-svn: 235583 --- diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 3275ac1..6034402 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1710,7 +1710,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return true; if (Left.is(TT_PointerOrReference)) return Right.Tok.isLiteral() || Right.is(TT_BlockComment) || - (!Right.isOneOf(TT_PointerOrReference, tok::l_paren) && + (!Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare, + tok::l_paren) && (Style.PointerAlignment != FormatStyle::PAS_Right && !Line.IsMultiVariableDeclStmt) && Left.Previous && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 197357c..de46bba 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -5422,8 +5422,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("A = new SomeType *[Length]();"); verifyIndependentOfContext("T **t = new T *;"); verifyIndependentOfContext("T **t = new T *();"); - verifyGoogleFormat("A = new SomeType* [Length]();"); - verifyGoogleFormat("A = new SomeType* [Length];"); + verifyGoogleFormat("A = new SomeType*[Length]();"); + verifyGoogleFormat("A = new SomeType*[Length];"); verifyGoogleFormat("T** t = new T*;"); verifyGoogleFormat("T** t = new T*();"); @@ -5491,8 +5491,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyFormat("A a;", PointerMiddle); verifyFormat("A a;", PointerMiddle); verifyFormat("A a;", PointerMiddle); - verifyFormat("A = new SomeType * [Length]();", PointerMiddle); - verifyFormat("A = new SomeType * [Length];", PointerMiddle); + verifyFormat("A = new SomeType *[Length]();", PointerMiddle); + verifyFormat("A = new SomeType *[Length];", PointerMiddle); verifyFormat("T ** t = new T *;", PointerMiddle); }