objects of incomplete type in a STL template instantiation [ strigi/src/streams/archivereader.cpp ]
Stefan Teleman
stefan.teleman at gmail.com
Wed Apr 23 23:53:55 BST 2008
Hi.
In file strigi/src/streams/archivereader.cpp [ comments omitted for brevity ]:
class ArchiveEntryCache {
public:
class SubEntry {
public:
EntryInfo entry;
std::map<std::string, SubEntry> entries;
// snip
};
class RootSubEntry : public SubEntry {
public:
RootSubEntry() :SubEntry() {}
bool indexed;
};
std::map<std::string, RootSubEntry> cache;
vector<EntryInfo> entries(const std::string& url);
// snip
};
The declarations
std::map<std::string, SubEntry> entries;
and
std::map<std::string, RootSubEntry> cache;
are illegal in Standard C++:
ISO/IEC:14882:2003.3.9.6:
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.
References:
http://groups.google.ca/group/comp.lang.c++.moderated/browse_thread/thread/bcb2dff332585510/4f078bb02e01018b
http://www.ddj.com/database/184403814
Proposed workaround:
class ArchiveEntryCache {
public:
class SubEntry;
typedef boost::shared_ptr<ArchiveEntryCache::SubEntry> SubEntryPtr;
class RootSubEntry;
typedef boost::shared_ptr<ArchiveEntryCache::RootSubEntry> RootSubEntryPtr;
class SubEntry {
public:
EntryInfo entry;
std::map<std::string, ArchiveEntryCache::SubEntryPtr> entries;
// snip
class RootSubEntry : public SubEntry {
public:
RootSubEntry() : SubEntry(), indexed(false) { }
bool indexed;
};
std::map<std::string, ArchiveEntryCache::RootSubEntryPtr> cache;
std::vector<EntryInfo> entries(const std::string& url);
const ArchiveEntryCache::SubEntryPtr findEntry(const std::string&
url) const;
std::map<std::string, RootSubEntryPtr>::const_iterator
findRootEntry(const string& url)
const;
void print() const;
// snip
};
With full patch set, this code compiles.
Full patch set (for a slightly older version of strigi) available at:
http://svn2.cvsdude.com/kdesolaris/trunk/STRIGI/0.5.7/Solaris/diffs/
--Stefan
--
Stefan Teleman
KDE e.V.
stefan.teleman at gmail.com
More information about the kde-core-devel
mailing list