]> granicus.if.org Git - clang/commitdiff
The paired 'operator delete' for a placement 'operator new' is always a
authorJohn McCall <rjmccall@apple.com>
Tue, 14 Sep 2010 21:34:24 +0000 (21:34 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 14 Sep 2010 21:34:24 +0000 (21:34 +0000)
placement 'operator delete', even if there are no placement args (i.e.
overload resolution selected an operator new with default arguments).

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

lib/Sema/SemaExprCXX.cpp
test/SemaCXX/new-delete.cpp

index e03c5721c6c5b8d45e8830a31b438d0d190f7b8f..6d8c9146541db61f21cde99bdcc2a9d78ad4d1b8 100644 (file)
@@ -1046,7 +1046,14 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
 
   llvm::SmallVector<std::pair<DeclAccessPair,FunctionDecl*>, 2> Matches;
 
-  if (NumPlaceArgs > 0) {
+  // Whether we're looking for a placement operator delete is dictated
+  // by whether we selected a placement operator new, not by whether
+  // we had explicit placement arguments.  This matters for things like
+  //   struct A { void *operator new(size_t, int = 0); ... };
+  //   A *a = new A()
+  bool isPlacementNew = (NumPlaceArgs > 0 || OperatorNew->param_size() != 1);
+
+  if (isPlacementNew) {
     // C++ [expr.new]p20:
     //   A declaration of a placement deallocation function matches the
     //   declaration of a placement allocation function if it has the
index ef20aee009c4841246b2e986b3e22e97263a18aa..f6129d19841b46baa62191221c32e7b9702a939a 100644 (file)
@@ -354,3 +354,21 @@ namespace DeleteParam {
     void operator delete(void* const);
   };
 }
+
+// <rdar://problem/8427878>
+// Test that the correct 'operator delete' is selected to pair with
+// the unexpected placement 'operator new'.
+namespace PairedDelete {
+  template <class T> struct A {
+    A();
+    void *operator new(size_t s, double d = 0);
+    void operator delete(void *p, double d);
+    void operator delete(void *p) {
+      T::dealloc(p);
+    }
+  };
+
+  A<int> *test() {
+    return new A<int>();
+  }
+}