]> granicus.if.org Git - clang/commitdiff
Don't recognize unnamed pointer parameters as casts.
authorDaniel Jasper <djasper@google.com>
Sat, 23 Feb 2013 08:07:18 +0000 (08:07 +0000)
committerDaniel Jasper <djasper@google.com>
Sat, 23 Feb 2013 08:07:18 +0000 (08:07 +0000)
This fixes llvm.org/PR15061.

Before: virtual void f(int *)const;
After:  virtual void f(int *) const;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175960 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 359923f02f856c1c226ebbe6addbd46ead798340..80780185c0ee60b721a46a9688d8d7fc6e570beb 100644 (file)
@@ -602,7 +602,8 @@ private:
             !Current.Children.empty() && (Current.Children[0].is(tok::equal) ||
                                           Current.Children[0].is(tok::semi) ||
                                           Current.Children[0].is(tok::l_brace));
-        if (ParensNotExpr && !ParensCouldEndDecl)
+        if (ParensNotExpr && !ParensCouldEndDecl &&
+            Contexts.back().IsExpression)
           // FIXME: We need to get smarter and understand more cases of casts.
           Current.Type = TT_CastRParen;
       } else if (Current.is(tok::at) && Current.Children.size()) {
index 3cf151e43f882ade8e64a6a16d7cdcff4179cf74..daaeca3fa03d2094cb25fb4e1dd59bb47ad3714f 100644 (file)
@@ -1728,10 +1728,12 @@ TEST_F(FormatTest, UndestandsOverloadedOperators) {
 }
 
 TEST_F(FormatTest, UnderstandsNewAndDelete) {
-  verifyFormat("A *a = new A;");
-  verifyFormat("A *a = new (placement) A;");
-  verifyFormat("delete a;");
-  verifyFormat("delete (A *)a;");
+  verifyFormat("void f() {\n"
+               "  A *a = new A;\n"
+               "  A *a = new (placement) A;\n"
+               "  delete a;\n"
+               "  delete (A *)a;\n"
+               "}");
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
@@ -1895,6 +1897,11 @@ TEST_F(FormatTest, FormatsCasts) {
   verifyFormat("void f(int i = (kA * kB) & kMask) {}");
   verifyFormat("int a = sizeof(int) * b;");
   verifyFormat("int a = alignof(int) * b;");
+  
+  // These are not casts, but at some point were confused with casts.
+  verifyFormat("virtual void foo(int *) override;");
+  verifyFormat("virtual void foo(char &) const;");
+  verifyFormat("virtual void foo(int *a, char *) const;");
 }
 
 TEST_F(FormatTest, FormatsFunctionTypes) {