[cfe-commits] r113861 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/SemaCXX/new-delete.cpp
John McCall
rjmccall at apple.com
Tue Sep 14 14:34:24 PDT 2010
Author: rjmccall
Date: Tue Sep 14 16:34:24 2010
New Revision: 113861
URL: http://llvm.org/viewvc/llvm-project?rev=113861&view=rev
Log:
The paired 'operator delete' for a placement 'operator new' is always a
placement 'operator delete', even if there are no placement args (i.e.
overload resolution selected an operator new with default arguments).
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/new-delete.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=113861&r1=113860&r2=113861&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Sep 14 16:34:24 2010
@@ -1046,7 +1046,14 @@
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
Modified: cfe/trunk/test/SemaCXX/new-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete.cpp?rev=113861&r1=113860&r2=113861&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/new-delete.cpp (original)
+++ cfe/trunk/test/SemaCXX/new-delete.cpp Tue Sep 14 16:34:24 2010
@@ -354,3 +354,21 @@
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>();
+ }
+}
More information about the cfe-commits
mailing list