Title
Permissible uses of void
Status
c++11
Section
6.8.2 [basic.fundamental]
Submitter
Nikolay Ivchenkov

Created on 2010-03-17.00:00:00 last changed 96 months ago

Messages

Date: 2011-03-15.00:00:00

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

Date: 2011-02-15.00:00:00

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.
Date: 2010-03-17.00:00:00

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).

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetmessages: + msg3304
2011-04-10 00:00:00adminsetstatus: review -> fdis
2011-02-28 00:00:00adminsetmessages: + msg3239
2011-02-28 00:00:00adminsetstatus: drafting -> review
2010-08-23 00:00:00adminsetstatus: open -> drafting
2010-03-17 00:00:00admincreate