ANSI C++ interpretation: explicit template instantiations

Marc Espie Marc.Espie@liafa.jussieu.fr
Wed Jul 21 06:53:00 GMT 1999


Consider the following snippet:

#include <vector>
#include <cstdlib>

template vector<std::size_t>;
template vector<unsigned int>;

...
on many implementations, std::size_t just happens to be typedef'ed to
unsigned int, and this code does fail with:

a.C:5: duplicate explicit instantiation of `class vector<unsigned
int,allocator<unsigned int> >'


I believe this is a bug, namely, we're talking about a template explicit
instantiation, not a specialization.

Looking closely at the standard (template section), I've seen no 
indication whatsoever that template explicit instantiations  are 
anything but declarations, and so I don't see why they should 
obey the one-definition-rule.


Leaving standard legalese for an instant, the above example clearly shows
why the one-definition-rule isn't practical here: this would make it necessary
for the client of a library to know about insider details that they shouldn't
care about. Namely, we don't want to have to distinguish between cases where
size_t and unsigned int are equal/different types, from the client point of
view.  We only want to use logical distinct types vector<unsigned int>,
and vector<std::size_t>, and we shouldn't have to care about specific
implementation details...
-- 
	Marc Espie		
|anime, sf, juggling, unicycle, acrobatics, comics...
|AmigaOS, OpenBSD, C++, perl, Icon, PostScript...
| `real programmers don't die, they just get out of beta'


More information about the Gcc-bugs mailing list