]> granicus.if.org Git - gc/commitdiff
Fix global operator delete definition for C++14 in gc_cpp
authorIvan Maidanski <ivmai@mail.ru>
Mon, 15 Jan 2018 05:20:02 +0000 (08:20 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 18 Jul 2018 05:27:44 +0000 (08:27 +0300)
(a cherry-pick of commit ede8f8c8 from 'release-7_6')

Issue #195 (bdwgc).

Sized variants of global operator delete should be defined along with
the non-sized ones.  Otherwise compiler might invoke the one from the
standard library (as observed in e.g. Cygwin) leading to a crash.

* gc_cpp.cc [!_MSC_VER && __cplusplus>201103L] (operator delete):
Define sized variant (the size argument is ignored for now).
* gc_cpp.cc [!_MSC_VER && __cplusplus>201103L && GC_OPERATOR_NEW_ARRAY
&& !CPPCHECK] (operator delete[]): Likewise.

gc_cpp.cc

index bf880c082ab96d5a1bb9bc6b40041d6eaf678d33..2b32e7aea76a7e8a26a188eb785434e5f886e6b3 100644 (file)
--- a/gc_cpp.cc
+++ b/gc_cpp.cc
@@ -83,4 +83,20 @@ void* operator new( size_t size ) GC_DECL_NEW_THROW {
     }
 # endif
 
-#endif /* _MSC_VER */
+#else
+
+# if __cplusplus > 201103L // C++14
+    void operator delete(void* obj, size_t size) GC_DECL_DELETE_THROW {
+      (void)size; // size is ignored
+      GC_FREE(obj);
+    }
+
+#   if defined(GC_OPERATOR_NEW_ARRAY) && !defined(CPPCHECK)
+      void operator delete[](void* obj, size_t size) GC_DECL_DELETE_THROW {
+        (void)size;
+        GC_FREE(obj);
+      }
+#   endif
+# endif // C++14
+
+#endif // !_MSC_VER