C ++ 11 static statement doesn't allow validation with Clang ++?

I am 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 Clang 3.4.2 error message gives me the following:

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

What am I missing here?

+5
source share
1 answer

noexcept not part of the function type.

So &g is just your launch of a mill expression like void(*)() without any special noexcept authority. So g , since it splits into a function pointer. When such a function pointer is ultimately called, it does not have a noexcept specification, and therefore the whole expression is not a noexcept .

+2
source

Source: https://habr.com/ru/post/1200649/


All Articles