Missing requirement that class member types be complete
11.4 [class.mem]
Michiel Salters

Created on 2001-12-10.00:00:00 last changed 162 months ago


Date: 2004-03-15.00:00:00

[Voted into WP at March 2004 meeting.]

Date: 2002-04-15.00:00:00

Proposed Resolution (April 2002, revised April 2003):

Change the first bullet of the note in 6.3 [basic.def.odr] paragraph 4 and add two new bullets following it, as follows:

  • an object of type T is defined (6.2 [basic.def], [expr.new]), or
  • a non-static class data member of type T is declared (11.4 [class.mem]), or
  • T is used as the object type or array element type in a new-expression ( [expr.new]), or

Replace 11.4 [class.mem] paragraph 8 by:

Non-static (11.4.9 [class.static]) data members shall not have incomplete types. In particular, a class C shall not contain a non-static member of class C, but it can contain a pointer or reference to an object of class C.

See also 6.8 [basic.types] paragraph 6, which is relevant but not changed by the Proposed Resolution.

Date: 2001-12-10.00:00:00

Is it legal to use an incomplete type (6.8 [basic.types] paragraph 6) as a class member, if no object of such class is ever created ?

And as a class template member, even if the template is instantiated, but no object of the instantiated class is created?

The consensus seems to be NO, but no wording was found in the standard which explicitly disallows it.

The problem seems to be that most of the restrictions on incomplete types are on their use in objects, but class members are not objects.

A possible resolution, if this is considered a defect, is to add to 6.3 [basic.def.odr] paragraph 4, (situations when T must be complete), the use of T as a member of a class or instantiated class template.

The thread on comp.std.c++ which brought up the issue was "Compiler differences: which is correct?", started 2001 11 30. <3c07c8fb$0$8507$ed9e5944@reading.news.pipex.net>

Date User Action Args
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2004-04-09 00:00:00adminsetmessages: + msg1014
2004-04-09 00:00:00adminsetstatus: ready -> wp
2003-11-15 00:00:00adminsetstatus: review -> ready
2003-04-25 00:00:00adminsetstatus: ready -> review
2002-11-08 00:00:00adminsetstatus: review -> ready
2002-05-10 00:00:00adminsetmessages: + msg622
2002-05-10 00:00:00adminsetstatus: open -> review
2001-12-10 00:00:00admincreate