From: Daniel Jasper Date: Fri, 5 Jul 2013 13:30:40 +0000 (+0000) Subject: Fix formatting for allocation of new pointer variables. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d6104f6c34639ebe66f83d955c5f32ea4a50c266;p=clang Fix formatting for allocation of new pointer variables. Before: T **t = new T * ; T **q = new T * (); After: T **t = new T *; T **q = new T *(); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185699 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index c2f89ec134..8db28635e8 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -591,7 +591,8 @@ private: NameFound = true; } else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) { Current.Type = - determineStarAmpUsage(Current, Contexts.back().IsExpression); + determineStarAmpUsage(Current, Contexts.back().CanBeExpression && + Contexts.back().IsExpression); } else if (Current.isOneOf(tok::minus, tok::plus, tok::caret)) { Current.Type = determinePlusMinusCaretUsage(Current); } else if (Current.isOneOf(tok::minusminus, tok::plusplus)) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9109781091..96ea9de9c6 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3378,8 +3378,12 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("A = new SomeType *[Length];"); 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("T** t = new T*;"); + verifyGoogleFormat("T** t = new T*();"); FormatStyle PointerLeft = getLLVMStyle(); PointerLeft.PointerBindsToType = true;