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

2024-04-18


577. void in an empty parameter list

Section: 9.3.4.6  [dcl.fct]     Status: CD3     Submitter: Ben Hutchings     Date: 22 April 2006

[Voted into the WP at the February, 2012 meeting; moved to DR at the October, 2012 meeting.]

9.3.4.6 [dcl.fct] paragraph 2 says,

The parameter list (void) is equivalent to the empty parameter list.

This special case is intended for C compatibility, but C99 describes it differently (6.7.5.3 paragraph 10):

The special case of an unnamed parameter of type void as the only item in the list specifies that the function has no parameters.

The C99 formulation allows typedefs for void, while C++ (and C90) accept only the keyword itself in this role. Should the C99 approach be adopted?

Notes from the October, 2006 meeting:

The CWG did not take a formal position on this issue; however, there was some concern expressed over the treatment of function templates and member functions of class templates if the C++ rule were changed: for a template parameter T, would a function taking a single parameter of type T become a no-parameter function if it were instantiated with T = void?

Proposed resolution (August, 2011):

Change 9.3.4.6 [dcl.fct] paragraph 4 as follows:

...If the parameter-declaration-clause is empty, the function takes no arguments. The parameter list (void) A parameter list consisting of a single unnamed parameter of non-dependent type void is equivalent to the an empty parameter list. Except for this special case, a parameter shall not have type cv void shall not be a parameter type (though types derived from void, such as void*, can). If the parameter-declaration-clause terminates...

This resolution also resolves issue 332.