diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2023-04-15 15:58:18 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2023-04-17 12:05:54 +0300 |
commit | 17364f0611fd147a5babc4258917b204ca88f586 (patch) | |
tree | 37b7137ecd6d7aa70e5d150c06e72f41eebd7eb2 /include | |
parent | 08eb0da6f5dbc9de1c0bf6e2ad7a7dedb24ac551 (diff) | |
download | bdwgc-17364f0611fd147a5babc4258917b204ca88f586.tar.gz |
Fix 'operator new is missing throw(bad_alloc)' clang warning in gc_cpp.h
The warning was reported on Window and only if __cplusplus < 201103L.
* gc_cpp.cc [GC_NEW_DELETE_THROW_NOT_NEEDED
&& !GC_NEW_DELETE_NEED_THROW && GC_GNUC_PREREQ(4,2)
&& (__cplusplus<201103L || __clang__)] (GC_NEW_DELETE_NEED_THROW):
Move definition to gc_cpp.h.
* include/gc/gc_cpp.h [!GC_NO_INLINE_STD_NEW && (_MSC_VER || __DMC__
|| (__BORLANDC__ || __CYGWIN__ || __CYGWIN32__ || __MINGW32__
|| __WATCOMC__) && !GC_BUILD && !GC_NOT_DLL)]
(GC_DECL_INLINE_NEW_THROW): New macro.
* include/gc/gc_cpp.h [!GC_NO_INLINE_STD_NEW && (_MSC_VER || __DMC__
|| (__BORLANDC__ || __CYGWIN__ || __CYGWIN32__ || __MINGW32__
|| __WATCOMC__) && !GC_BUILD && !GC_NOT_DLL)] (operator new): Add
GC_DECL_INLINE_NEW_THROW attribute.
Diffstat (limited to 'include')
-rw-r--r-- | include/gc/gc_cpp.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/include/gc/gc_cpp.h b/include/gc/gc_cpp.h index 0f9ed90d..c6c964ce 100644 --- a/include/gc/gc_cpp.h +++ b/include/gc/gc_cpp.h @@ -166,6 +166,12 @@ by UseGC. GC is an alias for UseGC, unless GC_NAME_CONFLICT is defined. # define GC_PLACEMENT_DELETE #endif +#if !defined(GC_NEW_DELETE_THROW_NOT_NEEDED) \ + && !defined(GC_NEW_DELETE_NEED_THROW) && GC_GNUC_PREREQ(4, 2) \ + && (__cplusplus < 201103L || defined(__clang__)) +# define GC_NEW_DELETE_NEED_THROW +#endif + #if defined(GC_NEW_ABORTS_ON_OOM) || defined(_LIBCPP_NO_EXCEPTIONS) # define GC_OP_NEW_OOM_CHECK(obj) \ do { if (!(obj)) GC_abort_on_oom(); } while (0) @@ -292,8 +298,14 @@ inline void* operator new(GC_SIZE_T, GC_NS_QUALIFY(GCPlacement), // Inlining done to avoid mix up of new and delete operators by VC++ 9 // (due to arbitrary ordering during linking). +# if defined(GC_NEW_DELETE_NEED_THROW) && defined(GC_INCLUDE_NEW) +# define GC_DECL_INLINE_NEW_THROW throw(std::bad_alloc) +# else +# define GC_DECL_INLINE_NEW_THROW /* empty */ +# endif + # ifdef GC_OPERATOR_NEW_ARRAY - inline void* operator new[](GC_SIZE_T size) + inline void* operator new[](GC_SIZE_T size) GC_DECL_INLINE_NEW_THROW { void* obj = GC_MALLOC_UNCOLLECTABLE(size); GC_OP_NEW_OOM_CHECK(obj); @@ -306,7 +318,7 @@ inline void* operator new(GC_SIZE_T, GC_NS_QUALIFY(GCPlacement), } # endif // GC_OPERATOR_NEW_ARRAY - inline void* operator new(GC_SIZE_T size) + inline void* operator new(GC_SIZE_T size) GC_DECL_INLINE_NEW_THROW { void* obj = GC_MALLOC_UNCOLLECTABLE(size); GC_OP_NEW_OOM_CHECK(obj); |