Title
Completeness of return type vs point of instantiation
Status
cd4
Section
9.3.4.6 [dcl.fct]
Submitter
Steve Clamage

Created on 2013-12-19.00:00:00 last changed 95 months ago

Messages

Date: 2014-11-15.00:00:00

[Moved to DR at the November, 2014 meeting.]

Date: 2014-02-15.00:00:00

Proposed resolution (February, 2014):

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

Types shall not be defined in return or parameter types. The type of a parameter or the return type for a function definition shall not be an incomplete class type (possibly cv-qualified) in the context of the function definition unless the function is deleted (9.5.3 [dcl.fct.def.delete]) or the definition is nested within the member-specification for that class (including definitions in nested classes defined within the class).
Date: 2013-12-19.00:00:00

Consider the following example:

  template<typename T> struct A {
    T t;
  };
  struct S {
    A<S> f() { return A<S>(); }
  };

According to 9.3.4.6 [dcl.fct] paragraph 9,

The type of a parameter or the return type for a function definition shall not be an incomplete class type (possibly cv-qualified) unless the function is deleted (9.5.3 [dcl.fct.def.delete]) or the definition is nested within the member-specification for that class (including definitions in nested classes defined within the class).

Thus type A<S> must be a complete type. The requirement for a complete type triggers the instantiation of the template, which requires that its template argument be complete in order to use it as the type of a non-static data member.

According to 13.8.4.1 [temp.point] paragraph 4, the point of instantiation of A<S> is “immediately preced[ing] the namespace scope declaration or definition that refers to the specialization.” Thus the point of instantiation precedes the definition of S, making this example ill-formed. Most or all current implementations accept the example, however.

Perhaps the specification in 9.3.4.6 [dcl.fct] ought to say that the completeness of the type is checked from the context of the function body (at which S is a complete type)?

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: drwp -> cd4
2015-05-25 00:00:00adminsetstatus: dr -> drwp
2015-04-13 00:00:00adminsetmessages: + msg5375
2014-11-24 00:00:00adminsetstatus: ready -> dr
2014-03-03 00:00:00adminsetmessages: + msg4829
2014-03-03 00:00:00adminsetstatus: open -> ready
2013-12-19 00:00:00admincreate