noexcept specifiers in function typedefs

1.6k Views Asked by At

Are noexcept specifiers accepted in function typedefs?

as in:

 typedef void (*fptr)()  noexcept;

Intuitively, noexcept specifiers seem to make sense since they would allow some optimisations at the caller's side.

I got a mixed answer from gcc 4.6.1.

 typedef void (*fptr)()  noexcept;

results in: error: ‘fptr’ declared with an exception specification

but:

template<void (*FPtr)()  noexcept>
struct A{};

compiles without warning.

1

There are 1 best solutions below

7
On BEST ANSWER

clang gives:

test.cpp:1:25: error: exception specifications are not allowed in typedefs
typedef void (*fptr)()  noexcept;
                        ^
1 error generated.

This is backed up in the C++11 standard in 15.4 [except.spec]/p2:

... An exception-specification shall not appear in a typedef declaration or alias-declaration.