Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Template functi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 9576 of 9591
Post > Topic >>

Template function problem language or compiler bug?

by "Chris Morley" <chris.morley@[EMAIL PROTECTED] > May 7, 2008 at 11:43 AM

Hi,

I found a bit of a weirdo using Intel 4.5 compiler & I've seen similar bad
stuff in VC6. I don't know if it is a language 'feature' or a bug in the
compiler's template handling - the compilers are old.

Basically I have a template function (as a member in a class) with void
return & argument. To use the function you have to explicitly tell the
compiler what type - or the compiler errors (reasonable as it can't
determine the type!). The linked program then uses the first type
encountered for all links to that function (i.e. _same_ address)
regardless
of they type provided! To fix it, if I declare a return type of the
template
type instead of void, it links the explicitly defined function correctly!
Is
this a bug with "template<class T> void fn(void) hadnling by this compiler
or a language feature in all C++ compilers? (feels like a name
mangling/linker bug to me)

Chris

e.g.

HEADER

class foo
{
public:
     void SomeFN();
     template<class T> void Broken();
     template<class T> T Works();

};

template<class T> void Broken()
{
     assert(sizeof(double) == sizeof(T)); // some code which uses T
}

template<class T> T Works()
{
     assert(sizeof(double) == sizeof(T)); // some code which uses T
     return 1;
}

C++

void foo:SomeFN()
{
     Broken<float>(); // ok, type is float in expanded fn
     Broken<double>();  // broken, type is also float!
     Works<float>(); // ok, type is float
     Works<double>(); // ok, type is double
}



-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]




 4 Posts in Topic:
Template function problem language or compiler bug?
"Chris Morley"   2008-05-07 11:43:27 
Re: Template function problem language or compiler bug?
=?ISO-8859-1?Q?Daniel_Kr=  2008-05-07 18:32:18 
Re: Template function problem language or compiler bug?
"Chris Morley"   2008-05-08 09:13:28 
Re: Template function problem language or compiler bug?
=?ISO-8859-1?Q?Daniel_Kr=  2008-05-08 21:29:57 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon May 12 7:04:35 CDT 2008.