summaryrefslogtreecommitdiff
path: root/gc_cpp.cc
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2012-08-30 08:52:13 +0400
committerIvan Maidanski <ivmai@mail.ru>2012-08-30 18:01:57 +0400
commit0ac46cc66eb2367c321362f32f63aa95f01d97f5 (patch)
treef77cca5c3e4415bfb5d5e504d1a26346edf6d16d /gc_cpp.cc
parentbf9af533c3750d971240b03558a96fb798edf5bc (diff)
downloadbdwgc-0ac46cc66eb2367c321362f32f63aa95f01d97f5.tar.gz
Eliminate 'missing exception specification' warning in gc_cpp.cc (Clang)
* gc_cpp.cc (GC_NEW_DELETE_NEED_THROW): Define new macro (if not defined yet) for GCC v4.2+ (or clang). * gc_cpp.cc: Include new (for std::bad_alloc) if GC_NEW_DELETE_NEED_THROW. * gc_cpp.cc (GC_DECL_NEW_THROW, GC_DECL_DELETE_THROW): New macros (used to eliminate compiler "missing exception specification" warning for 'new' and 'delete' operators). * gc_cpp.cc (new, delete, new[], delete[]): Use GC_DECL_NEW/DELETE_THROW to define 'throw' clause properly.
Diffstat (limited to 'gc_cpp.cc')
-rw-r--r--gc_cpp.cc26
1 files changed, 20 insertions, 6 deletions
diff --git a/gc_cpp.cc b/gc_cpp.cc
index 86792b04..9f64b748 100644
--- a/gc_cpp.cc
+++ b/gc_cpp.cc
@@ -29,22 +29,36 @@ built-in "new" and "delete".
#include "gc_cpp.h"
-void* operator new( size_t size ) {
+#if !defined(GC_NEW_DELETE_NEED_THROW) && defined(__GNUC__) \
+ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
+# define GC_NEW_DELETE_NEED_THROW
+#endif
+
+#ifdef GC_NEW_DELETE_NEED_THROW
+# include <new> /* for std::bad_alloc */
+# define GC_DECL_NEW_THROW throw(std::bad_alloc)
+# define GC_DECL_DELETE_THROW throw()
+#else
+# define GC_DECL_NEW_THROW /* empty */
+# define GC_DECL_DELETE_THROW /* empty */
+#endif /* !GC_NEW_DELETE_NEED_THROW */
+
+void* operator new( size_t size ) GC_DECL_NEW_THROW {
return GC_MALLOC_UNCOLLECTABLE(size);
}
#if !defined(__CYGWIN__)
- void operator delete( void* obj ) {
+ void operator delete( void* obj ) GC_DECL_DELETE_THROW {
GC_FREE(obj);
}
#endif /* !__CYGWIN__ */
#ifdef GC_OPERATOR_NEW_ARRAY
- void* operator new[]( size_t size ) {
+ void* operator new[]( size_t size ) GC_DECL_NEW_THROW {
return GC_MALLOC_UNCOLLECTABLE(size);
}
- void operator delete[]( void* obj ) {
+ void operator delete[]( void* obj ) GC_DECL_DELETE_THROW {
GC_FREE(obj);
}
#endif /* GC_OPERATOR_NEW_ARRAY */
@@ -53,7 +67,7 @@ void* operator new( size_t size ) {
// This new operator is used by VC++ in case of Debug builds!
void* operator new( size_t size, int /* nBlockUse */,
- const char * szFileName, int nLine )
+ const char * szFileName, int nLine ) GC_DECL_NEW_THROW
{
# ifndef GC_DEBUG
return GC_malloc_uncollectable(size);
@@ -65,7 +79,7 @@ void* operator new( size_t size ) {
# if _MSC_VER > 1020
// This new operator is used by VC++ 7.0 and later in Debug builds.
void* operator new[]( size_t size, int nBlockUse,
- const char* szFileName, int nLine )
+ const char* szFileName, int nLine ) GC_DECL_NEW_THROW
{
return operator new(size, nBlockUse, szFileName, nLine);
}