我正在尝试使用编译以下代码,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!");
Clang 3.4.2给我的错误消息是:
test.h:9:1: error: static_assert failed "Error!"
static_assert(noexcept(f(&g)), "Error!");
^ ~~~~~~~~~~~~~~~
我在这里想念什么?
noexcept
不是函数类型的一部分。
因此,&g
这只是type的mill表达式的运行void(*)()
,没有特殊的noexcept
功能。所以,是g
的,因为它衰变到函数指针。当最终调用这样的函数指针时,它没有noexcept
规范,因此整个表达式都不是noexcept
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句