public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Question on explicit template expansion
@ 2005-05-12 21:13 Garrett Kajmowicz
  2005-05-13 14:24 ` Nathan Sidwell
  0 siblings, 1 reply; 4+ messages in thread
From: Garrett Kajmowicz @ 2005-05-12 21:13 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question on explicit template expansion
  2005-05-12 21:13 Question on explicit template expansion Garrett Kajmowicz
@ 2005-05-13 14:24 ` Nathan Sidwell
  2005-05-13 16:43   ` Garrett Kajmowicz
  0 siblings, 1 reply; 4+ messages in thread
From: Nathan Sidwell @ 2005-05-13 14:24 UTC (permalink / raw)
  To: gkajmowi; +Cc: gcc-help

Garrett Kajmowicz wrote:
> 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

This doesn't compile. Do you have a test case that does compile?

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question on explicit template expansion
  2005-05-13 14:24 ` Nathan Sidwell
@ 2005-05-13 16:43   ` Garrett Kajmowicz
  2005-05-17 15:26     ` Nathan Sidwell
  0 siblings, 1 reply; 4+ messages in thread
From: Garrett Kajmowicz @ 2005-05-13 16:43 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 457 bytes --]

> This doesn't compile. Do you have a test case that does compile?

I do now.

The problem I've been encountering occurs on both GCC 3.3.5 and GCC 4.0.0.  
This test case was only tested on GCC 3.3.5.

The attached test case comes with a Makefile.  Type make and watch the warning 
message occur.  Note that the warning messages occur only for the constructor 
and destructor, and not for the other method.


Please let me know what's going on.


-	Garrett

[-- Attachment #2: inlined.tar.gz --]
[-- Type: application/x-tgz, Size: 871 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question on explicit template expansion
  2005-05-13 16:43   ` Garrett Kajmowicz
@ 2005-05-17 15:26     ` Nathan Sidwell
  0 siblings, 0 replies; 4+ messages in thread
From: Nathan Sidwell @ 2005-05-17 15:26 UTC (permalink / raw)
  To: gkajmowi; +Cc: gcc-help

Garrett Kajmowicz wrote:

> The attached test case comes with a Makefile.  Type make and watch the warning 
> message occur.  Note that the warning messages occur only for the constructor 
> and destructor, and not for the other method.

header.h contains
	#ifndef __EXPAND_LIBRARY_FOR_COMPILE__
	template <> myclass<char>::myclass();
	template <> myclass<char>::~myclass();
	template <> void myclass<char>::method();
	#endif
these *declare* specializations of the myclass ctor,dtor and method.  There's
no reason to make them NOT visible when compiling the library.

However, it does appear to be a g++ bug in that the inline attribute is
copied from the general template to the specialization.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-05-17 15:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-12 21:13 Question on explicit template expansion Garrett Kajmowicz
2005-05-13 14:24 ` Nathan Sidwell
2005-05-13 16:43   ` Garrett Kajmowicz
2005-05-17 15:26     ` Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).