简体   繁体   中英

How do I create a noexcept function pointer?

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".

[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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM