objects of incomplete type in a STL template instantiation [ strigi/src/streams/archivereader.cpp ]

Adriaan de Groot groot at kde.org
Thu Apr 24 08:37:50 BST 2008


On Thursday 24 April 2008 00:53:55 Stefan Teleman wrote:
> A class that has been declared but not defined, or an array of unknown
> size or of incomplete element type, is an incompletely-defined object
> type. [38]. Incompletely defined object type and the void type are
> incomplete type (3.9.1). Objects shall not be defined to have an
> incomplete type.
>
> In the example above, the type SubEntry is an incomplete type, because
> it has been declared, but it has not yet been defined.
> Compilation of this translation unit fails with Sun Studio 12, because
> the compiler would be required to allow instantiation of an incomplete
> type.

As a bit of clarification, it's possible to implement this part of the STL so 
that you can use incompletely defined types in container classes; gcc does 
this (by using a pointer to the object -- even for incompletely defined types 
A, the type A* is completely defined).

So this is one of those bits of code where the implementation used by gcc 
satisfies the standard but also allows non-standard behavior.

Stefan's proposed use of boost::shared_ptr is one way to go about it, but may 
introduce an unwanted dependency for Strigi. If Qt is an acceptable 
dependency (I don't think it is), QMap might be used. Finally, using A* in 
the map instead of A solves the problem as well, at the cost of introducing 
uglier code elsewhere as you need to work away the *.

A patch for the latter -- using std::map<std::string, SubEntryMap *> -- is 
also in Dude, http://svn2.cvsdude.com/kdesolaris/trunk/Build/Patches . The 
relevant file is kdesupport.diff (the other kdesupport-strigi one works 
around the existence of a system header event.h that was getting pulled in in 
the wrong places).


[ade]




More information about the kde-core-devel mailing list