C++ 11静态断言失败noExcept检查与Clang ++?

jot*_*tik 5 clang static-assert noexcept c++11

我正在尝试编译以下代码,clang++ -std=c++11 -c它失败了:

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!");
Run Code Online (Sandbox Code Playgroud)

Clang 3.4.2给出的错误信息是:

test.h:9:1: error: static_assert failed "Error!"
static_assert(noexcept(f(&g)), "Error!");
^             ~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?

n. *_* m. 2

noexcept不是函数类型的一部分。

因此,&g这只是类型的普通表达式void(*)(),没有特殊的noexcept能力。也是如此g,因为它衰减为函数指针。当最终调用这样的函数指针时,它没有noexcept规范,因此整个表达式不是noexcept