Questo sembra valida dal draft C++11 standard, se guardiamo alla sezione 5.2.3
conversione di tipo esplicita (notazione funzionale) paragrafo dice (sottolineatura mia):
The expression T(), where T is a simple-type-specifier or typename-specifier for a non-array complete object type or the (possibly cv-qualified) void type, creates a prvalue of the specified type, whose value is that produced by value-initializing (8.5) an object of type T; no initialization is done for the void() case.[...]
la formulazione è abbastanza simile pre C++11 pure.
Questo va bene in un constexpr anche se la sezione 7.1.5
comma 3
dice:
The definition of a constexpr function shall satisfy the following constraints:
e comprende questo proiettile:
its return type shall be a literal type;
e vuoto non è un letterale in C++ 11 come da sezione 3.9
comma , ma Se poi guardiamo al paragrafo dà un'eccezione che si inserisce questo caso, si dice:
If the instantiated template specialization of a constexpr function template or member function of a class template would fail to satisfy the requirements for a constexpr function or constexpr constructor, that specialization is not a constexpr function or constexpr constructor. [ Note: If the function is a member function it will still be const as described below. —end note ] If no specialization of the template would yield a constexpr function or constexpr constructor, the program is ill-formed; no diagnostic required.
Come Casey noted nel C++14 draft standardvuoto è un letterale, questa è la sezione 3.9
Tipi paragrafo dice:
A type is a literal type if it is:
e comprende:
— void; or
fonte
2013-12-09 19:15:53
Beh, so che stai permesso di avere, per esempio, 'foo void() {} bar void() {return foo();}'. Non sono sicuro di questo. – chris
Qual è la tua domanda su, in particolare? Informazioni sulla restituzione di 'void' (che, BTW, è sempre stato legale in C++)? O sulla combinazione 'constexpr void'? – AnT
Forse dovresti spiegare cosa pensi che dovrebbe essere l'errore? –