I'm trying to compile the following code with clang++ -std=c++11 -c
and it fails:
void g() noexcept {}
template <typename Func>
void f(Func && func) noexcept(noexcept(func()))
{ static_assert(noexcept(func()), "func()"); } // No error!
void h() { f(&g); } // No error!
static_assert(noexcept(f(&g)), "Error!");
The error message Clang 3.4.2 gives me is:
test.h:9:1: error: static_assert failed "Error!"
static_assert(noexcept(f(&g)), "Error!");
^ ~~~~~~~~~~~~~~~
What am I missing here?
noexcept
is not a part of a function type.
Thus, &g
is just your run of the mill expression of type void(*)()
, with no special noexcept
powers. So is g
, as it decays to the function pointer. When such a function pointer is eventually called, it has no noexcept
specification, and thus the entire expression is not noexcept
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With