Skip to content

Commit

Permalink
inplace_function: Use a conditional macro to throw.
Browse files Browse the repository at this point in the history
You can now use "inplace_function.h" with -fno-exceptions.

The intended usage is

    #define SG14_INPLACE_FUNCTION_THROW(x) __builtin_unreachable()
    #include "inplace_function.h"

Thanks to @AndWass for the patch!

Fixes #152.
Fixes #153.
  • Loading branch information
Quuxplusone committed Mar 16, 2019
1 parent 76784f8 commit 3b81451
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion SG14/inplace_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#include <utility>
#include <functional>

#ifndef SG14_INPLACE_FUNCTION_THROW
#define SG14_INPLACE_FUNCTION_THROW(x) throw (x)
#endif

namespace stdext {

namespace inplace_function_detail {
Expand Down Expand Up @@ -92,7 +96,7 @@ template<typename R, typename... Args> struct vtable

explicit constexpr vtable() noexcept :
invoke_ptr{ [](storage_ptr_t, Args&&...) -> R
{ throw std::bad_function_call(); }
{ SG14_INPLACE_FUNCTION_THROW(std::bad_function_call()); }
},
copy_ptr{ [](storage_ptr_t, storage_ptr_t) -> void {} },
relocate_ptr{ [](storage_ptr_t, storage_ptr_t) -> void {} },
Expand Down

0 comments on commit 3b81451

Please sign in to comment.