Using incomplete types to instantiate STL-Templates?

Christian Ehrhardt ehrhardt@mathematik.uni-ulm.de
Wed Apr 30 16:49:00 GMT 2003


Hi,

the following piece of code fails with --enable-concept-checks
(this is PR 10505):

------- cut ----------
#include <list>
class   Foo
{
public:
	int x;
	std::list<Foo>  children;
};
------- cut ----------

This happens because instantiation of std::list<Foo> will try to
declare a variable of type Foo. This fails because Foo is incomplete
at the point of instantiation. Basically the question is:
Is this construct legal?

I could only find two things that might be relevant to this in the
standard:
* Generally it is allowed to instatiate a template with an incomplete type.
  However, the program may be ill-formed depending on what the template does
  with this incomplete type (I can dig up the section numbers if this is
  necessary).
* For the standard library there is this restriction in 17.3.4.6[2]:

	In particular, the effects are undefined in the following cases:
	[ ... ]
	-- if an incomplete type (3.9) is used as a template argument
	   when instantiating a template component.

I'm not sure if the second point is really relevant. Mostly because
I'm not entirely sure what a template component is supposed to be.

   regards    Christian

--
THAT'S ALL FOLKS!



More information about the Gcc mailing list