Title
Completeness of return and parameter types of member functions
Status
c++20
Section
11.4 [class.mem]
Submitter
Krystian Stasiowski

Created on 2019-08-23.00:00:00 last changed 40 months ago

Messages

Date: 2019-10-15.00:00:00

Proposed resolution (October, 2019):

Change 9.5.1 [dcl.fct.def.general] paragraph 2 as follows:

...The type of a parameter or the return type for a function definition shall not be an incomplete or abstract (possibly cv-qualified) class type in the context of the function definition a (possibly cv-qualified) class type that is incomplete or abstract within the function body unless the function is deleted (9.5.3 [dcl.fct.def.delete]).
Date: 2019-11-15.00:00:00

[Adopted as a DR at the November, 2019 meeting.]

According to 11.4 [class.mem] paragraph 7,

A class is considered a completely-defined object type (6.8 [basic.types]) (or complete type) at the closing } of the class-specifier. The class is regarded as complete within its complete-class contexts; otherwise it is regarded as incomplete within its own class member-specification.

The complete-class contexts (paragraph 6) include the body of a member function but not its return and parameter types. Thus it appears that an example like the following is ill-formed:

  struct S {
    S f(S s) { return s; }
  };

because of 9.5.1 [dcl.fct.def.general] paragraph 2

The type of a parameter or the return type for a function definition shall not be an incomplete or abstract (possibly cv-qualified) class type in the context of the function definition unless the function is deleted (9.5.3 [dcl.fct.def.delete]).

The words “in the context of the function definition” were added by the resolution of issue 1824 to address this problem, but “context” is most naturally read as referring to the lexical context where the definition appears rather than within its body.

History
Date User Action Args
2020-12-15 00:00:00adminsetmessages: + msg6464
2019-08-23 00:00:00admincreate