This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 4/4] Fix undefined behaviour in libstdc++ testsuite


This fixes a couple of places where we replaced operator delete(void*)
but not the version that was needed by the tests (the first case used
to be correct, but was broken by the sized deallocation change in
C++14, so uses the feature-test macro to decide whether the extra
overload is needed).

   Define missing delete operators in libstdc++ testsuite
* testsuite/23_containers/vector/zero_sized_allocations.cc:
   	Define sized deallocation function.
   	* testsuite/util/testsuite_new_operators.h:
   	(operator delete(void*, const std::nothrow_t&)): Define nothrow
   	deallocation function.

Tested powerpc64-linux, committed to trunk.

commit 1e92e2338780cd47f624d13345f3575abd1bf369
Author: redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Jul 21 19:38:57 2016 +0000

    Define missing delete operators in libstdc++ testsuite
    
    	* testsuite/23_containers/vector/zero_sized_allocations.cc:
    	Define sized deallocation function.
    	* testsuite/util/testsuite_new_operators.h:
    	(operator delete(void*, const std::nothrow_t&)): Define nothrow
    	deallocation function.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@238610 138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/libstdc++-v3/testsuite/23_containers/vector/zero_sized_allocations.cc b/libstdc++-v3/testsuite/23_containers/vector/zero_sized_allocations.cc
index 236b82f..74fa95c 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/zero_sized_allocations.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/zero_sized_allocations.cc
@@ -22,7 +22,7 @@
 
 unsigned int zero_sized_news = 0;
 
-void *operator new(size_t size) throw (std::bad_alloc)
+void *operator new(std::size_t size) throw (std::bad_alloc)
 {
   /* malloc(0) is unpredictable; avoid it.  */
   if (size == 0)
@@ -45,6 +45,14 @@ void operator delete(void *ptr) throw()
     std::free(ptr);
 }
 
+#if __cpp_sized_deallocation
+void operator delete(void *ptr, std::size_t) throw()
+{
+  if (ptr != 0)
+    std::free(ptr);
+}
+#endif
+
 // http://gcc.gnu.org/ml/libstdc++/2007-09/msg00006.html
 void test01()
 {
@@ -57,7 +65,7 @@ void test01()
   VERIFY( zero_sized_news == 0 );
 
   v->resize(10);
-  delete(v);
+  delete v;
   VERIFY( zero_sized_news == 0 );
 }
 
diff --git a/libstdc++-v3/testsuite/util/testsuite_new_operators.h b/libstdc++-v3/testsuite/util/testsuite_new_operators.h
index 70603fa..6713fb8 100644
--- a/libstdc++-v3/testsuite/util/testsuite_new_operators.h
+++ b/libstdc++-v3/testsuite/util/testsuite_new_operators.h
@@ -64,6 +64,13 @@ void operator delete(void* p) throw()
     std::free(p);
 }
 
+void operator delete(void* p, const std::nothrow_t&) throw()
+{
+  if (p)
+    std::free(p);
+}
+
+
 #endif // _GLIBCXX_TESTSUITE_NEW_OPERATORS_H
 
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]