This patch makes -fsized-delete define a macro __GXX_DELETE_WITH_SIZE__. If
this macro is defined, the deallocate function in new_allocator.h invokes
the two parameter delete operator with the size of the object. Tested by
bootstrapping the compiler and ensuring no tests are broken. Also verified
that compiling a C++ program that uses std::vector with -fsized-delete invokes
the two parameter version of operator delete.

OK for google/main and google/4_6 branches?

2012-03-12   Easwaran Raman  <>

        * c-cppbuiltin.c (c_cpp_builtins): Define __GXX_DELETE_WITH_SIZE__ for
        C++ files compiled with -fsized-delete.

2012-03-12   Easwaran Raman  <>
        * include/ext/new_allocator.h (deallocate): Call delete with size if
        __GXX_DELETE_WITH_SIZE__ is defined.

diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index ccf57fd..3c9a96b 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -970,6 +970,8 @@ c_cpp_builtins (cpp_reader *pfile)
      format.  */
     cpp_define (pfile, "__DECIMAL_BID_FORMAT__");
+  if (c_dialect_cxx () && flag_sized_delete)
+    cpp_define (pfile, "__GXX_DELETE_WITH_SIZE__");
 /* Pass an object-like macro.  If it doesn't lie in the user's
diff --git a/libstdc++-v3/include/ext/new_allocator.h 
index 0c82bd0..c972c1e 100644
--- a/libstdc++-v3/include/ext/new_allocator.h
+++ b/libstdc++-v3/include/ext/new_allocator.h
        return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
+      // __p is not permitted to be a null pointer.
+      void
+      deallocate(pointer __p, size_type __t)
+      { ::operator delete(__p, __t * sizeof(_Tp)); }
       // __p is not permitted to be a null pointer.
       deallocate(pointer __p, size_type)
       { ::operator delete(__p); }
       max_size() const _GLIBCXX_USE_NOEXCEPT

This patch is available for review at

Reply via email to