Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66227 - in sandbox/function/boost/function: . detail
From: dsaritz_at_[hidden]
Date: 2010-10-28 09:07:28


Author: psiha
Date: 2010-10-28 09:07:24 EDT (Thu, 28 Oct 2010)
New Revision: 66227
URL: http://svn.boost.org/trac/boost/changeset/66227

Log:
Added the BF_NORETURN and BF_HAS_NORETURN compiler specific macros and used them for the new get_default_value<>() helper function.
Text files modified:
   sandbox/function/boost/function/detail/platform_specifics.hpp | 6 ++++++
   sandbox/function/boost/function/function_base.hpp | 32 ++++++++++++++++++++------------
   2 files changed, 26 insertions(+), 12 deletions(-)

Modified: sandbox/function/boost/function/detail/platform_specifics.hpp
==============================================================================
--- sandbox/function/boost/function/detail/platform_specifics.hpp (original)
+++ sandbox/function/boost/function/detail/platform_specifics.hpp 2010-10-28 09:07:24 EDT (Thu, 28 Oct 2010)
@@ -46,6 +46,9 @@
 
     #define BF_FORCEINLINE __forceinline
     #define BF_NOINLINE __declspec( noinline )
+ #define BF_NORETURN __declspec( noreturn )
+
+ #define BF_HAS_NORETURN
 
     #define BF_OVERRIDE override
     #define BF_SEALED sealed
@@ -81,6 +84,9 @@
         #define BF_FORCEINLINE __attribute__(( always_inline ))
     #endif
     #define BF_NOINLINE __attribute__(( noinline ))
+ #define BF_NORETURN __attribute__(( noreturn ))
+
+ #define BF_HAS_NORETURN
 
     #define BF_OVERRIDE
     #define BF_SEALED

Modified: sandbox/function/boost/function/function_base.hpp
==============================================================================
--- sandbox/function/boost/function/function_base.hpp (original)
+++ sandbox/function/boost/function/function_base.hpp 2010-10-28 09:07:24 EDT (Thu, 28 Oct 2010)
@@ -1029,6 +1029,22 @@
           ,BF_VT_DEREF &Manager::get_typed_functor
         #endif // BOOST_FUNCTION_NO_RTTI
       };
+
+
+ template <typename T>
+ T get_default_value( mpl::false_ /*not a reference type*/ ) { return T(); }
+
+ template <>
+ inline void get_default_value<void>( mpl::false_ /*not a reference type*/ ) {}
+
+ template <typename T>
+ T get_default_value( mpl::true_ /*a reference type*/ )
+ {
+ BF_UNREACHABLE_CODE
+ typedef typename remove_reference<T>::type actual_type_t;
+ static T invalid_reference( *static_cast<actual_type_t *>( 0 ) );
+ return invalid_reference;
+ }
     } // end namespace function
   } // end namespace detail
 
@@ -1062,7 +1078,7 @@
 
       ~cleaner() { conditional_clear( pFunction_ != 0 ); }
 
- void cancel() { assert( pFunction_ ); pFunction_ = 0; }
+ void cancel() { BOOST_ASSERT( pFunction_ ); pFunction_ = 0; }
 
   private:
       void conditional_clear( bool const clear )
@@ -1375,26 +1391,18 @@
 class throw_on_empty
 {
 private:
- #ifdef BOOST_MSVC
- __declspec( noinline noreturn )
- #else
- BF_NOINLINE
- #endif // BOOST_MSVC
- static void throw_bad_call()
+ static void BF_NORETURN throw_bad_call()
     {
         boost::throw_exception( bad_function_call() );
     }
 
 public:
     template <class result_type>
- #ifdef BOOST_MSVC
- __declspec( noreturn )
- #endif // BOOST_MSVC
     static result_type handle_empty_invoke()
     {
         throw_bad_call();
- #ifndef BOOST_MSVC
- return result_type();
+ #ifndef BF_HAS_NORETURN
+ return get_default_value<result_type>( is_reference<result_type>() );
         #endif // BOOST_MSVC
     }
 };


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk