In addition to what others have said, the caller also needs a return type to find out which destructor he should call on the result (the return value may be temporary).
Unfortunately, this is not as easy as
auto (*bar)() = foo;
Although GCC and Clang accept this. I need to double-check the specification to make sure that it is really correct.
Update: Specification Specified
An automatic type specifier means that the type of the declared variable must be inferred from its initializer or that the function declarator must include the return type of the return type.
This may be confusing for fast reading, but it is implemented by GCC and clang to apply only to the toplevel declarator. In our case, this is a pointer-pointer. A declaration nested within it is a function declaration. So just replace auto with void , and then the compiler will infer the type for you.
By the way, you can always do this work manually, but it requires several deceivers to work.
template<typename FunctionType> struct Params; template<typename ...Params> struct Params<void(Params...)> { template<typename T> using Identity = T; template<typename R> static Identity<R(Params...)> *get(R f(Params...)) { return f; } };
source share