This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
gcc 3.4, explicit template instantiations and STL
- From: Alain Roy <roy at cs dot wisc dot edu>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 16 Nov 2004 10:56:22 -0600
- Subject: gcc 3.4, explicit template instantiations and STL
I'm not sure what to do. Code that used to work in gcc has apparently been
outlawed by the C++ standard, and I don't know how to get my code to
compile with the gcc 3.4.
===== Setup =====
I'm writing a library that I would like to be able to compile with multiple
versions of gcc on multiple platforms. The library is used by a larger
project, and we need portability. Using the latest gcc is not always an
option, so we live with multiple versions. I can't change this.
My library contains STL.
To avoid code bloat, it uses explicit template instantiation.
===== The offending code =====
There is lots of offending code, but it is all similar. I have code that
looks like this:
template map<string, void*, CaseIgnLTStr>;
template map<string, void*, CaseIgnLTStr>::iterator;
This doesn't compile with gcc 3.4. Line #1 is no problem: I just have to
add "class", like so:
template class map<string, void*, CaseIgnLTStr>;
The second line--the one with the iterator--is the real problem. It is
needed or I get linking error. However, it is apparently no longer
acceptable code because iterator is a typdef. The gcc 3.4 release notes state:
# Using a name introduced by a typedef in a friend declaration or in an
explicit instantiation is now rejected, as specified by the ISO C++ standard.
(From http://gcc.gnu.org/gcc-3.4/changes.html#cplusplus )
====== The resolution? =====
I'm trying to figure out my options.
1) Give up and use implict template instantiation.
2) Unwind the typedefs and instantiate what I need. This is pain, it's
ugly, and it may not be portable across versions of the compiler.
3) Rewrite my code to not use STL.
4) Whine loudly and see if I can get someone to listen.
#3 is probably a bad idea and #4 doesn't seem likely to help. I'm not
terribly happy with #1 or #2, but I would listen to arguments for them. Is
there anything else I can do?
Thanks,
-alain