This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
ANSI C++ interpretation: explicit template instantiations
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: ANSI C++ interpretation: explicit template instantiations
- From: Marc Espie <Marc dot Espie at liafa dot jussieu dot fr>
- Date: Wed, 21 Jul 1999 15:53:13 +0200
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'