mardi 29 janvier 2019

Exception specification in ˋtypedefˋ completely forbidden or only at toplevel?

In C++14 Sec 15.4;2 it is stated, that ... An exception-specification shall not appear in a typedef declaration or alias-declaration.

That mean following is forbidden:

typedef void (*fn)(int) noexcept;

But does the the wording shall not appear mean the token ˋnoexceptˋ cannot appear anywhere in a typedef declaration?

For instance are these both are forbidden as well?

typedef void (*fn1)(void (*)(int) noexcept);
typedef decltype(std::declval<void (*)(int)noexcept>()) fn2;

These both try to define a type ˋfn1ˋ and ˋfn2ˋ being able to point to a function that takes a pointer to a function taking an ˋintˋ and returning nothing while promising to never throw an exception.

So in my examples the exception-specification is not applied to the toplevel type ˋfn1ˋ resp. ˋfn2ˋ that are introduced by ˋtypedefˋ but to the parameters these function may receive.

So should I take 15.4;2 verbatim and therefore my both examples are invalid? Or is only application to a type-definition forbidden and my examples are correct?

Aucun commentaire:

Enregistrer un commentaire