From 44fde85b2496750b78939247d1d19a67c5b3dc71 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 14 Nov 2016 15:24:14 +0200 Subject: C++11-compatibility fixes and improvements --- cutl/shared-ptr/base.cxx | 9 ++++++--- cutl/shared-ptr/base.hxx | 21 ++++++++++++++++----- cutl/shared-ptr/base.ixx | 9 ++++++--- 3 files changed, 28 insertions(+), 11 deletions(-) (limited to 'cutl/shared-ptr') diff --git a/cutl/shared-ptr/base.cxx b/cutl/shared-ptr/base.cxx index 1ff8469..4541e39 100644 --- a/cutl/shared-ptr/base.cxx +++ b/cutl/shared-ptr/base.cxx @@ -16,7 +16,7 @@ cutl::share exclusive = cutl::share (2); namespace cutl { char const* not_shared:: - what () const throw () + what () const LIBCUTL_NOTHROW_NOEXCEPT { return "object is not shared"; } @@ -25,7 +25,10 @@ namespace cutl // // void* -operator new (size_t n, cutl::share s) throw (std::bad_alloc) +operator new (size_t n, cutl::share s) +#ifndef LIBCUTL_CXX11 + throw (std::bad_alloc) +#endif { if (s == shared) { @@ -45,7 +48,7 @@ operator new (size_t n, cutl::share s) throw (std::bad_alloc) } void -operator delete (void* p, cutl::share s) throw () +operator delete (void* p, cutl::share s) LIBCUTL_NOTHROW_NOEXCEPT { // This version of operator delete is only called when the c-tor // fails. In this case there is no object and we can just free the diff --git a/cutl/shared-ptr/base.hxx b/cutl/shared-ptr/base.hxx index f2bfecc..5eb1032 100644 --- a/cutl/shared-ptr/base.hxx +++ b/cutl/shared-ptr/base.hxx @@ -10,11 +10,12 @@ #include +#include #include namespace cutl { - struct LIBCUTL_EXPORT share + struct share { explicit share (char id); @@ -30,18 +31,23 @@ namespace cutl extern LIBCUTL_EXPORT cutl::share shared; extern LIBCUTL_EXPORT cutl::share exclusive; +#ifdef LIBCUTL_CXX11 +LIBCUTL_EXPORT void* +operator new (std::size_t, cutl::share); +#else LIBCUTL_EXPORT void* operator new (std::size_t, cutl::share) throw (std::bad_alloc); +#endif LIBCUTL_EXPORT void -operator delete (void*, cutl::share) throw (); +operator delete (void*, cutl::share) LIBCUTL_NOTHROW_NOEXCEPT; namespace cutl { struct LIBCUTL_EXPORT not_shared: exception { virtual char const* - what () const throw (); + what () const LIBCUTL_NOTHROW_NOEXCEPT; }; struct LIBCUTL_EXPORT shared_base @@ -60,14 +66,19 @@ namespace cutl std::size_t _ref_count () const; +#ifdef LIBCUTL_CXX11 + void* + operator new (std::size_t, share); +#else void* operator new (std::size_t, share) throw (std::bad_alloc); +#endif void - operator delete (void*, share) throw (); + operator delete (void*, share) LIBCUTL_NOTHROW_NOEXCEPT; void - operator delete (void*) throw (); + operator delete (void*) LIBCUTL_NOTHROW_NOEXCEPT; protected: std::size_t counter_; diff --git a/cutl/shared-ptr/base.ixx b/cutl/shared-ptr/base.ixx index 14dd0ac..3dd982b 100644 --- a/cutl/shared-ptr/base.ixx +++ b/cutl/shared-ptr/base.ixx @@ -59,19 +59,22 @@ namespace cutl } inline void* shared_base:: - operator new (std::size_t n, share) throw (std::bad_alloc) + operator new (std::size_t n, share) +#ifndef LIBCUTL_CXX11 + throw (std::bad_alloc) +#endif { return ::operator new (n); } inline void shared_base:: - operator delete (void* p, share) throw () + operator delete (void* p, share) LIBCUTL_NOTHROW_NOEXCEPT { ::operator delete (p); } inline void shared_base:: - operator delete (void* p) throw () + operator delete (void* p) LIBCUTL_NOTHROW_NOEXCEPT { ::operator delete (p); } -- cgit v1.1