Using the C ++ grammar hyperlink , parsing decltype(void()) :
decltype( expression ) decltype( assignment-expression ) decltype( conditional-expression )
... there are many steps related to the order of operations ...
decltype( postfix-expression ) decltype( simple-type-specifier ( expression-listopt ) ) decltype( void() )
So void() is a kind of expression , in particular postfix-expression .
In particular, citing section 5.2.3 [expr.type.conf] paragraph 2 of the 2011 ISO C ++ standard:
The expression T() , where T is a simple type specifier or typename-specifier for an object type without an array or a type (possibly cv-qualit) void , creates a character value of the given type, which is initialized with a value (8.5; no initialization is done for the case of void() ).
So void() is an expression of type void , just as int() is an expression of type int (with a value of 0 ). Obviously, the void expression does not matter, but here it is the decltype operand, so it is not evaluated. decltype refers only to the type of operand, and not to its value.
decltype(void()) is just a detailed way to access the void type.
Yakk Sep 01 '16 at 19:52 2016-09-01 19:52
source share