This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Question on explicit template expansion
- From: Garrett Kajmowicz <gkajmowi at tbaytel dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 12 May 2005 17:14:29 -0400
- Subject: Question on explicit template expansion
- Reply-to: gkajmowi at tbaytel dot net
I'm working on the embedded C++ library at cxx.uclibc.org
As a part of my work, I've been pushing some of the common template expansions
out into the binary library to reduce overall expansion. This works well
*except* for constructors and destructors. I would like an explanation as to
why the following occurs and what I can go to deal with it.
Given (say) class string, I have:
//In the header file
template<class Ch, class Tr, class A> class basic_string {
public:
explicit basic_string(const A& al = A()) { return; }
~basic_string() { }
// <snip>
// <snip>
// <snip>
};
#ifndef __UCLIBCXX_COMPILE_STRING__
template <> string::basic_string(const allocator<char> &);
template <> string::~basic_string();
#endif
//End of header file
And then inside the source file for the library I have
//Source file
#define __UCLIBCXX_COMPILE_STRING__ 1
#include <string>
template string::basic_string(const allocator<char> &);
template string::~basic_string();
//End of source file
I do this for a large number of functions. This allows me to use only one
instance of the code (that I have to type out) while creating the required
instances.
This seems to work for most code. However, for constructors and destructors I
am left with the following error messages when I go to use the library:
../include/string:71: warning: inline function `std::basic_string<Ch, Tr,
A>::basic_string(const A&) [with Ch = char, Tr = std::char_traits<char>, A
=
std::allocator<char>]' used but never defined
../include/string:100: warning: inline function `std::basic_string<Ch, Tr,
A>::~basic_string() [with Ch = char, Tr = std::char_traits<char>, A =
std::allocator<char>]' used but never defined
Any thoughts as to why this happens, and why it only happens for constructors
and destructors.
Thanks.
- Garrett Kajmowicz