cplusplus / nbballot

Handling of NB comments in response to ballots
14 stars 4 forks source link

GB-051 9.3.4.6 [dcl.fct], 9.3.4.7 [dcl.fct.default] Can an explicit object parameter have a default argument? #451

Closed wg21bot closed 1 year ago

wg21bot commented 1 year ago

The syntax and semantics appear to allow:

struct S { void f(S* this = nullptr); };

This is probably no more than an oddity, but perhaps it should be prevented.

Strike this[opt] at the 2nd and 4th occurrence in the grammar of parameter-declaration. Add a Note: an explicit-object-parameter-declaration cannot have an initializer-clause.

BengtGustafsson commented 1 year ago

Maybe interesting as a clarification but as you can't avoid providing an implicit object parameter before the dot there is no way that the default argument would ever be used. I noted that at least in the MSVC implementation the pointer type is a function pointer (not a member function pointer), but this does not mean that a default expression would be usable.

erichkeane commented 1 year ago
Accept the proposed resolution to GB-051, and forward this to CWG. SF F N A SA
7 8 5 0 0

Result: Consensus

erichkeane commented 1 year ago

Note the example is incorrect, however the 'default'-ness issue was understood in the room.

struct S { void f(this const S &= S{}); };
jensmaurer commented 1 year ago

CWG2653

jensmaurer commented 1 year ago

CWG 2022-11-08: Accepted with Modifications. See CWG2653 for details.