How do I create a noexcept function pointer?

620 Views Asked by At

I'd like to create a function pointer like this:

void(*function_pointer)()noexcept;

But, this doesn't work. It seems that an exception specifier in a function declaration is invalid. There must be a way to do this though. Right?

This was linked to a question that is not the same as this. Here I'm asking how to create a function pointer with a noexcept specifier. That was not asked or answered in the question "noexcept specifiers in function typedefs".

1

There are 1 best solutions below

0
On BEST ANSWER

[except.spec]/2:

An exception-specification shall appear only on a function declarator for a function type, pointer to function type, reference to function type, or pointer to member function type that is the top-level type of a declaration or definition, or on such a type appearing as a parameter or return type in a function declarator.

So your declaration is indeed well-formed, and Clang compiles it.

Presumably your compiler is not up to date.