Skip to content

Commit

Permalink
Move C++ GC_ATTR_EXPLICIT and GC_NOEXCEPT definition to gc_config_mac…
Browse files Browse the repository at this point in the history
…ros.h

(code refactoring)

* gc_badalc.cc: Do not include gc_cpp.h.
* gc_cpp.cc: Remove GC_NOEXCEPT in comment for an include.
* include/gc_allocator.h [!GC_ATTR_EXPLICIT] (GC_ATTR_EXPLICIT): Do
not define.
* include/gc_allocator.h [!GC_NOEXCEPT] (GC_NOEXCEPT): Likewise.
* include/gc_cpp.h [!GC_NOEXCEPT] (GC_NOEXCEPT): Likewise.
* tests/test_cpp.cc [!GC_ATTR_EXPLICIT] (GC_ATTR_EXPLICIT): Likewise.
* include/gc_config_macros.h [__cplusplus && !GC_ATTR_EXPLICIT]
(GC_ATTR_EXPLICIT): Define macro (moved from gc_allocator.h).
* include/gc_config_macros.h [__cplusplus && !GC_NOEXCEPT]
(GC_NOEXCEPT): Likewise.
  • Loading branch information
ivmai committed Apr 15, 2020
1 parent 7f2bdab commit b57ee7d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 53 deletions.
2 changes: 0 additions & 2 deletions gc_badalc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#include <new> // for bad_alloc, precedes include of gc_cpp.h

#include "gc_cpp.h" // for GC_NEW_ABORTS_ON_OOM

#if defined(GC_NEW_ABORTS_ON_OOM) || defined(_LIBCPP_NO_EXCEPTIONS)
# define GC_ALLOCATOR_THROW_OR_ABORT() GC_abort_on_oom()
#else
Expand Down
2 changes: 1 addition & 1 deletion gc_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ built-in "new" and "delete".

#include <new> // for bad_alloc, precedes include of gc_cpp.h

#include "gc_cpp.h" // for GC_OPERATOR_NEW_ARRAY, GC_NOEXCEPT
#include "gc_cpp.h" // for GC_OPERATOR_NEW_ARRAY

#if !(defined(_MSC_VER) || defined(__DMC__)) || defined(GC_NO_INLINE_STD_NEW)

Expand Down
25 changes: 0 additions & 25 deletions include/gc_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,11 @@
#include "gc.h"
#include <new> // for placement new and bad_alloc

#ifndef GC_ATTR_EXPLICIT
# if __cplusplus >= 201103L && !defined(__clang__) || _MSVC_LANG >= 201103L \
|| defined(CPPCHECK)
# define GC_ATTR_EXPLICIT explicit
# else
# define GC_ATTR_EXPLICIT /* empty */
# endif
#endif

#if !defined(GC_NO_MEMBER_TEMPLATES) && defined(_MSC_VER) && _MSC_VER <= 1200
// MSVC++ 6.0 do not support member templates.
# define GC_NO_MEMBER_TEMPLATES
#endif

#ifndef GC_NOEXCEPT
# if defined(__DMC__) || (defined(__BORLANDC__) \
&& (defined(_RWSTD_NO_EXCEPTIONS) || defined(_RWSTD_NO_EX_SPEC))) \
|| (defined(_MSC_VER) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS) \
|| (defined(__WATCOMC__) && !defined(_CPPUNWIND))
# define GC_NOEXCEPT /* empty */
# ifndef GC_NEW_ABORTS_ON_OOM
# define GC_NEW_ABORTS_ON_OOM
# endif
# elif __cplusplus >= 201103L || _MSVC_LANG >= 201103L
# define GC_NOEXCEPT noexcept
# else
# define GC_NOEXCEPT throw()
# endif
#endif // !GC_NOEXCEPT

#if defined(GC_NEW_ABORTS_ON_OOM) || defined(_LIBCPP_NO_EXCEPTIONS)
# define GC_ALLOCATOR_THROW_OR_ABORT() GC_abort_on_oom()
#else
Expand Down
29 changes: 29 additions & 0 deletions include/gc_config_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,33 @@

#endif /* GC_PTHREADS */

#ifdef __cplusplus

#ifndef GC_ATTR_EXPLICIT
# if __cplusplus >= 201103L && !defined(__clang__) || _MSVC_LANG >= 201103L \
|| defined(CPPCHECK)
# define GC_ATTR_EXPLICIT explicit
# else
# define GC_ATTR_EXPLICIT /* empty */
# endif
#endif

#ifndef GC_NOEXCEPT
# if defined(__DMC__) || (defined(__BORLANDC__) \
&& (defined(_RWSTD_NO_EXCEPTIONS) || defined(_RWSTD_NO_EX_SPEC))) \
|| (defined(_MSC_VER) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS) \
|| (defined(__WATCOMC__) && !defined(_CPPUNWIND))
# define GC_NOEXCEPT /* empty */
# ifndef GC_NEW_ABORTS_ON_OOM
# define GC_NEW_ABORTS_ON_OOM
# endif
# elif __cplusplus >= 201103L || _MSVC_LANG >= 201103L
# define GC_NOEXCEPT noexcept
# else
# define GC_NOEXCEPT throw()
# endif
#endif

#endif /* __cplusplus */

#endif
16 changes: 0 additions & 16 deletions include/gc_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,6 @@ by UseGC. GC is an alias for UseGC, unless GC_NAME_CONFLICT is defined.
# define GC_PLACEMENT_DELETE
#endif

#ifndef GC_NOEXCEPT
# if defined(__DMC__) || (defined(__BORLANDC__) \
&& (defined(_RWSTD_NO_EXCEPTIONS) || defined(_RWSTD_NO_EX_SPEC))) \
|| (defined(_MSC_VER) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS) \
|| (defined(__WATCOMC__) && !defined(_CPPUNWIND))
# define GC_NOEXCEPT /* empty */
# ifndef GC_NEW_ABORTS_ON_OOM
# define GC_NEW_ABORTS_ON_OOM
# endif
# elif __cplusplus >= 201103L || _MSVC_LANG >= 201103L
# define GC_NOEXCEPT noexcept
# else
# define GC_NOEXCEPT throw()
# endif
#endif // !GC_NOEXCEPT

#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)
Expand Down
9 changes: 0 additions & 9 deletions tests/test_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ extern "C" {
__LINE__ ); \
exit( 1 ); }

#ifndef GC_ATTR_EXPLICIT
# if __cplusplus >= 201103L && !defined(__clang__) || _MSVC_LANG >= 201103L \
|| defined(CPPCHECK)
# define GC_ATTR_EXPLICIT explicit
# else
# define GC_ATTR_EXPLICIT /* empty */
# endif
#endif

class A {public:
/* An uncollectible class. */

Expand Down

0 comments on commit b57ee7d

Please sign in to comment.