cplusplus / draft

C++ standards drafts
http://www.open-std.org/jtc1/sc22/wg21/
5.66k stars 748 forks source link

[dcl.fct.def.general] p2 "declarator;" is not described in [dcl.fct] #5539

Open xmh0511 opened 2 years ago

xmh0511 commented 2 years ago

[dcl.fct.def.general] p2 says

In a function-definition, either void declarator ; or declarator ; shall be a well-formed function declaration as described in [dcl.fct].

The latter form declarator ; presumably refers to the declaration of a constructor or destructor. However, it is not described in [dcl.fct]. In [dcl.fct], the declaration described in either [dcl.fct] p1 or p2 should have the form T D; where T should comprise a valid type since the function type "returning T", in either form. This option has confirmed in https://github.com/cplusplus/draft/pull/4737#discussion_r785042207

Constructors / destructors don't have a return type in the "function declaration" sense, and that absence makes "return something" syntactically ill-formed.

So, for the latter case, it should cross-reference [class.ctor] and [class.dtor] instead of [dcl.fct].

jensmaurer commented 2 years ago

Note that [class.ctor] and [class.dtor] directly refer to special cases of [dcl.fct]. The real issue is that [dcl.fct] does not, but should, describe the syntactic form of constructors and destructors.

xmh0511 commented 2 years ago

The real issue is that [dcl.fct] does not, but should, describe the syntactic form of constructors and destructors.

Yes, [dcl.fct] should cover the constructor and destructor cases. Moreover, [dcl.fct] should clarify what is "function declarator" and define that term; this is a Stackoverflow question: Is a pointer to function (sometimes/always?) a function declarator?