This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


1055. Permissible uses of void

Section: 6.8.2  [basic.fundamental]     Status: C++11     Submitter: Nikolay Ivchenkov     Date: 2010-03-17

[Voted into the WP at the March, 2011 meeting as part of paper N3262.]

According to 6.8.2 [basic.fundamental] paragraph 9,

Any expression can be explicitly converted to type cv void (7.6.3 [expr.cast]). An expression of type void shall be used only as an expression statement (8.3 [stmt.expr]), as an operand of a comma expression (7.6.20 [expr.comma]), as a second or third operand of ?: (7.6.16 [expr.cond]), as the operand of typeid, or as the expression in a return statement (8.7.4 [stmt.return]) for a function with the return type void.

First, this is self-contradictory: if “any expression” can be converted to void, why is such a conversion not listed among the acceptable uses of an expression of type void?

Second, presumably an expression of type void can be used as an operand of decltype, but this use is not listed.

Finally, there are several places in the Standard that speak of expressions having a cv-qualified void type (7.6.16 [expr.cond] paragraph 2, 8.7.4 [stmt.return] paragraph 3) . However, an expression of type void is a non-class prvalue, and there are no cv-qualified non-class prvalues (7.2.1 [basic.lval] paragraph 4).

Proposed resolution (February, 2011) [SUPERSEDED]:

  1. Change 6.8.2 [basic.fundamental] paragraph 9 as follows:

  2. ...Any expression can be explicitly converted to type cv void (7.6.3 [expr.cast]). An expression of type void shall be used only as an expression statement (8.3 [stmt.expr]), as an operand of a comma expression (7.6.20 [expr.comma]), as a second or third operand of ?: (7.6.16 [expr.cond]), as the operand of typeid or decltype, or as the expression in a return statement (8.7.4 [stmt.return]) for a function with the return type void, or as the operand of an explicit conversion to type cv void.
  3. Change 7.6.16 [expr.cond] paragraph 2 as follows:

  4. If either the second or the third operand has type (possibly cv-qualified) void, then...
  5. Change 8.7.4 [stmt.return] paragraph 3 as follows:

  6. A return statement with an expression of type cv void can be used only in functions with a return type of cv void; the expression is evaluated just before the function returns to its caller.