Skip to content

Commit

Permalink
inplace_function: Remove noexcept-specifications from lambdas where i…
Browse files Browse the repository at this point in the history
…t doesn't matter.

These lambdas are immediately stored into function pointers which are *not*
declared `noexcept`, so the fact that the lambda itself is `noexcept` is not
going to help anyone. (Except compilers sufficiently smart to "devirtualize"
the call through the pointer and realize that the pointer always points to the
lambda. But in that hypothetical case, such a compiler is probably smart enough
to see that the lambda's body is noexcept, without needing "help" from us.)

This is a followup to my previous commit, which fixed a bug in one noexcept
specification. Even better than fixing buggy code is *removing* buggy code!
  • Loading branch information
Quuxplusone committed Mar 16, 2019
1 parent cb66020 commit 76784f8
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions SG14/inplace_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,31 +94,27 @@ template<typename R, typename... Args> struct vtable
invoke_ptr{ [](storage_ptr_t, Args&&...) -> R
{ throw std::bad_function_call(); }
},
copy_ptr{ [](storage_ptr_t, storage_ptr_t) noexcept -> void {} },
relocate_ptr{ [](storage_ptr_t, storage_ptr_t) noexcept -> void {} },
destructor_ptr{ [](storage_ptr_t) noexcept -> void {} }
copy_ptr{ [](storage_ptr_t, storage_ptr_t) -> void {} },
relocate_ptr{ [](storage_ptr_t, storage_ptr_t) -> void {} },
destructor_ptr{ [](storage_ptr_t) -> void {} }
{}

template<typename C> explicit constexpr vtable(wrapper<C>) noexcept :
invoke_ptr{ [](storage_ptr_t storage_ptr, Args&&... args)
noexcept(noexcept(std::declval<C>()(static_cast<Args&&>(args)...))) -> R
invoke_ptr{ [](storage_ptr_t storage_ptr, Args&&... args) -> R
{ return (*static_cast<C*>(storage_ptr))(
static_cast<Args&&>(args)...
); }
},
copy_ptr{ [](storage_ptr_t dst_ptr, storage_ptr_t src_ptr)
noexcept(std::is_nothrow_copy_constructible<C>::value) -> void
copy_ptr{ [](storage_ptr_t dst_ptr, storage_ptr_t src_ptr) -> void
{ ::new (dst_ptr) C{ (*static_cast<C*>(src_ptr)) }; }
},
relocate_ptr{ [](storage_ptr_t dst_ptr, storage_ptr_t src_ptr)
noexcept -> void
relocate_ptr{ [](storage_ptr_t dst_ptr, storage_ptr_t src_ptr) -> void
{
::new (dst_ptr) C{ std::move(*static_cast<C*>(src_ptr)) };
static_cast<C*>(src_ptr)->~C();
}
},
destructor_ptr{ [](storage_ptr_t src_ptr)
noexcept -> void
destructor_ptr{ [](storage_ptr_t src_ptr) -> void
{ static_cast<C*>(src_ptr)->~C(); }
}
{}
Expand Down

0 comments on commit 76784f8

Please sign in to comment.