Lo standard proibisce esplicitamente che una specifica di eccezione venga visualizzata in una typedef
o una dichiarazione di alias. Ma afferma anche che lo specificatore di eccezione può apparire in un tipo di puntatore a funzione.
§15.4/2[except.spec]
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. An exception-specification shall not appear in a typedef
declaration or alias-declaration.
E se un puntatore alla funzione non ha una specifica eccezione, poi quello puntatore funzione deve sempre essere assegnato un tipo di funzione che ha un specifica delle eccezioni compatibile.
§15.4/5
...
A similar restriction applies to assignment to and initialization of pointers to functions, pointers to member functions, and references to functions: the target entity shall allow at least the exceptions allowed by the source value in the assignment or initialization. ...
L'utilizzo di questi due, si può ottenere la specifica noexcept
nella funzione tipo di puntatore in un modo rotonda.
void (*foo_ptr)(void *) noexcept = nullptr;
using function_type = decltype(foo_ptr);
Ora, non è possibile assegnare una funzione senza una specifica noexcept(true)
ad un puntatore a funzione di tipo function_type
. clang will fail to compile il codice con l'errore
error: target exception specification is not superset of source
g ++ compila bene. Forse ignora semplicemente l'identificatore ... – DarioP
GCC non è conforme allo standard qui. Clang è corretto. – Columbo
Hm, è uno strano bug gcc. Ut non accetta un typedef ma accetta 'using'. –