I'd like to do this:
using function_type = void (*)(void*)noexcept;
But I get an error "exception specifications are not allowed in type aliases." (clang in version 6.1 of Xcode)
Is there a workaround to create an alias with a noexcept specifier?
I'm looking for something that works as defined by the language (not an extension) for cross-platform capabilities.
The standard explicitly forbids an exception specification from appearing in a
typedef
or an alias declaration. But it also states that the exception specifier may appear in a function pointer type.§15.4/2 [except.spec]
And if a pointer to function does have an exception specification, then that function pointer must always be assigned a function type that has a compatible exception specification.
§15.4/5
Using these two, you can get the
noexcept
specification into the function pointer type in a roundabout fashion.Now, you cannot assign a function without a
noexcept(true)
specification to a function pointer of typefunction_type
. clang will fail to compile the code with the error