diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2023-04-19 09:02:29 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2023-04-19 20:46:37 +0300 |
commit | aaa432bc82d224955ebcbfaa67373b1d869e725c (patch) | |
tree | b043c05851cfa51d7573c1fcdd4a168fc4bb6548 | |
parent | 8fe38c6fbd7725fa4c3d4e8132d440251e73e807 (diff) | |
download | bdwgc-aaa432bc82d224955ebcbfaa67373b1d869e725c.tar.gz |
Fix 'C++17 does not allow dynamic exc spec' warn if GC_NO_INLINE_STD_NEW
(fix of commit 17364f061)
* gc_cpp.cc: Do not include <new> directly.
* gc_cpp.cc [!GC_INCLUDE_NEW] (GC_INCLUDE_NEW): Define macro.
* gc_cpp.cc (GC_DECL_NEW_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): Do not define.
* include/gc/gc_cpp.h [GC_NEW_DELETE_NEED_THROW
&& !(__cplusplus>=201703L || _MSVC_LANG>=201703L) && !GC_INCLUDE_NEW]
(GC_DECL_NEW_THROW): Define to empty.
* 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,
operator new[]): Replace GC_DECL_INLINE_NEW_THROW attribute to
GC_DECL_NEW_THROW.
-rw-r--r-- | gc_cpp.cc | 15 | ||||
-rw-r--r-- | include/gc/gc_cpp.h | 22 |
2 files changed, 17 insertions, 20 deletions
@@ -33,8 +33,9 @@ built-in "new" and "delete". #define GC_DONT_INCL_WINDOWS_H #include "gc/gc.h" -#include <new> // for std, bad_alloc; precedes include of gc_cpp.h - +#ifndef GC_INCLUDE_NEW +# define GC_INCLUDE_NEW +#endif #include "gc/gc_cpp.h" #if !(defined(_MSC_VER) || defined(__DMC__)) || defined(GC_NO_INLINE_STD_NEW) @@ -46,16 +47,6 @@ built-in "new" and "delete". # define GC_ALLOCATOR_THROW_OR_ABORT() throw std::bad_alloc() # endif -# ifndef GC_NEW_DELETE_NEED_THROW -# define GC_DECL_NEW_THROW /* empty */ -# elif __cplusplus >= 201703L || _MSVC_LANG >= 201703L - // The "dynamic exception" syntax had been deprecated in C++11 - // and was removed in C++17. -# define GC_DECL_NEW_THROW noexcept(false) -# else -# define GC_DECL_NEW_THROW throw(std::bad_alloc) -# endif // GC_NEW_DELETE_NEED_THROW - void* operator new(GC_SIZE_T size) GC_DECL_NEW_THROW { void* obj = GC_MALLOC_UNCOLLECTABLE(size); if (0 == obj) diff --git a/include/gc/gc_cpp.h b/include/gc/gc_cpp.h index 99df1aa5..ea05989e 100644 --- a/include/gc/gc_cpp.h +++ b/include/gc/gc_cpp.h @@ -175,6 +175,18 @@ by UseGC. GC is an alias for UseGC, unless GC_NAME_CONFLICT is defined. # define GC_NEW_DELETE_NEED_THROW #endif +#ifndef GC_NEW_DELETE_NEED_THROW +# define GC_DECL_NEW_THROW /* empty */ +#elif __cplusplus >= 201703L || _MSVC_LANG >= 201703L + // The "dynamic exception" syntax had been deprecated in C++11 + // and was removed in C++17. +# define GC_DECL_NEW_THROW noexcept(false) +#elif defined(GC_INCLUDE_NEW) +# define GC_DECL_NEW_THROW throw(std::bad_alloc) +#else +# define GC_DECL_NEW_THROW /* empty (as bad_alloc might be undeclared) */ +#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) @@ -301,14 +313,8 @@ 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) GC_DECL_INLINE_NEW_THROW + inline void* operator new[](GC_SIZE_T size) GC_DECL_NEW_THROW { void* obj = GC_MALLOC_UNCOLLECTABLE(size); GC_OP_NEW_OOM_CHECK(obj); @@ -321,7 +327,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) GC_DECL_INLINE_NEW_THROW + inline void* operator new(GC_SIZE_T size) GC_DECL_NEW_THROW { void* obj = GC_MALLOC_UNCOLLECTABLE(size); GC_OP_NEW_OOM_CHECK(obj); |