]> granicus.if.org Git - clang/commitdiff
Fix formatting for allocation of new pointer variables.
authorDaniel Jasper <djasper@google.com>
Fri, 5 Jul 2013 13:30:40 +0000 (13:30 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 5 Jul 2013 13:30:40 +0000 (13:30 +0000)
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

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

index c2f89ec134c741b29225fe13c62b820ee07d6484..8db28635e88a1d683be104591a75126f1a58fc76 100644 (file)
@@ -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)) {
index 9109781091ed0f165209e83ccb5db3188cf57706..96ea9de9c6733cbc4ec51821e88494d104ef7bb5 100644 (file)
@@ -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;