]> granicus.if.org Git - clang/commitdiff
Correct spacing around new and delete.
authorDaniel Jasper <djasper@google.com>
Fri, 11 Jan 2013 16:09:04 +0000 (16:09 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 11 Jan 2013 16:09:04 +0000 (16:09 +0000)
This fixes llvm.org/PR14913.

Before:  A *a = new(placement) A;
After:   A *a = new (placement) A;

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

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

index 56bb6ec426a215410666043d64d6ed6d412d1718..38d39bca635496b08c5b2b3b7b7b2dd7e80e04f9 100644 (file)
@@ -1063,7 +1063,8 @@ private:
       return CurrentLineType == LT_ObjCDecl || Left.is(tok::kw_if) ||
              Left.is(tok::kw_for) || Left.is(tok::kw_while) ||
              Left.is(tok::kw_switch) || Left.is(tok::kw_return) ||
-             Left.is(tok::kw_catch);
+             Left.is(tok::kw_catch) || Left.is(tok::kw_new) ||
+             Left.is(tok::kw_delete);
     }
     if (Left.is(tok::at) &&
         Right.FormatTok.Tok.getObjCKeywordID() != tok::objc_not_keyword)
index 47e6bdd114f4ff1848f93e7a0a5344a26128f90f..cb634fc7e18e4742772cfb1843ca3b9b377efb8b 100644 (file)
@@ -980,6 +980,13 @@ TEST_F(FormatTest, UndestandsOverloadedOperators) {
   verifyFormat("void operator delete[](void *ptr);");
 }
 
+TEST_F(FormatTest, UnderstandsNewAndDelete) {
+  verifyFormat("A *a = new A;");
+  verifyFormat("A *a = new (placement) A;");
+  verifyFormat("delete a;");
+  verifyFormat("delete (A *)a;");
+}
+
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("int *f(int *a) {}");
   verifyFormat("f(a, *a);");