jotik
jotik

Reputation: 17920

C++11 static assertion fails noexcept check with Clang++?

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?

Upvotes: 5

Views: 870

Answers (1)

n. m. could be an AI
n. m. could be an AI

Reputation: 120031

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.

Upvotes: 2

Related Questions