Wygląda to ważny przez draft C++11 standard, jeśli spojrzymy na odcinku 5.2.3
Jawna konwersja typu (notacja funkcjonalna) ustęp mówi (podkr):
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.[...]
sformułowanie jest dość podobna pre C++11 również.
to w porządku w constexpr choć sekcja 7.1.5
ustęp 3
mówi:
The definition of a constexpr function shall satisfy the following constraints:
i obejmuje tę kulę:
its return type shall be a literal type;
i void nie jest dosłowne w C++ 11 zgodnie z sekcją 3.9
ustęp , ale gdybyśmy potem spojrzeć w pkt daje wyjątek, który pasuje do tej sprawy, to mówi:
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.
Jak Casey noted w C++14 draft standardvoid jest dosłowny, to sekcja 3.9
Rodzaje pkt mówi:
A type is a literal type if it is:
i obejmuje:
— void; or
Cóż, wiem, że może mieć, powiedzmy, 'void foo() {} void bar() {return foo();}'. Nie jestem pewien co do tego. – chris
O co konkretnie chodzi? O zwrocie 'void' (który, BTW, zawsze był legalny w C++)? Lub o kombinacji 'constexpr void'? – AnT
Może powinieneś wyjaśnić, co Twoim zdaniem powinien być błąd? –