template function compiler bug? 
Author Message
 template function compiler bug?

Hi,

I'm facing a problem and I would like to know if this is a compiler bug,
since I think I'm not doing anything too complicated. See the following
code, some of you might have faced the same problem...

<header>

    template<class T> class A {};

    class B : public A<some type> {};

    class C : public B {};

    class D : public B {};

</header>

<cpp>

    template<class T> void function()
    {
        do something based on T;
    }

    void main()
    {
        function<C>();
        function<D>();
    }

<cpp>

Well, in main() the template funciton would get called two times with
different template parameter, the code compiles smoothly in MSVC++ 6 SP5,
but at run time it appears that only the LAST REFERENCED template
parameter's instance of the function gets called BOTH TIMES (here
function<D>() is getting the two calls)... if the function is called only
once the correct type gets instanciated. So there is something I don't
understand...
BTW I'm mentionning the full derivation tree in case it could help finding
out, even if I belive it should not interfere with the function type
determination..

The question would be : what are the exact trigger conditions if this is a
known bug and, Is there some known workaround ?

Thanks for any comment.

Lo.



Sat, 26 Mar 2005 22:12:31 GMT  
 template function compiler bug?

Quote:

>     template<class T> void function()
>     {
>         do something based on T;
>     }

FYI - void main is illegal and requires a diagnostic, VC incorrectly
accepts it.

Quote:
>     void main()
>     {
>         function<C>();
>         function<D>();
>     }

> Well, in main() the template funciton would get called two times with
> different template parameter, the code compiles smoothly in MSVC++ 6 SP5,
> but at run time it appears that only the LAST REFERENCED template
> parameter's instance of the function gets called BOTH TIMES (here
> function<D>() is getting the two calls)... if the function is called only
> once the correct type gets instanciated. So there is something I don't
> understand...

> The question would be : what are the exact trigger conditions if this is a
> known bug and, Is there some known workaround ?

Known problem, related, I think, to not having the template arguments in
the mangled name of the function.  The workaround is to provide a
defaulted argument that uses the template argument so that the template
argument will participate in the manged name.

e.g.

template <typename T> void function(T* = NULL)
{
// etc.

Quote:
}

int main(void) {
    function<C>();
    function<D>();

Quote:
}

The trigger condition is two instantiations of a template function that
differ in signature only by the template arguments, not by function
arguments.


Sat, 26 Mar 2005 22:36:25 GMT  
 template function compiler bug?

Quote:
> FYI - void main is illegal and requires a diagnostic, VC incorrectly
> accepts it.

... okok.. this only was for focussing on the data..

Quote:
> Known problem, related, I think, to not having the template arguments in
> the mangled name of the function. The workaround is to provide a
> defaulted argument that uses the template argument so that the template
> argument will participate in the manged name.

Yep, indeed it worked ok.. thats fine now.

Thanks a lot!

Lo.



Mon, 28 Mar 2005 02:16:56 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. C++ compiler bug: template and non template function overload resolution

2. C2660 with template member function: Compiler bug?

3. BUG: Template Friend Function Causes Compiler Error C2248 still NOT CORRECTED in VC++6.0

4. BUG: Template Friend Function Causes Compiler Error C2248

5. Compiler bug: Overloaded function template pattern matching

6. template function inside template class bug

7. MS compiler seems to mal function/setting const value to template function

8. Values as template parameters (compiler bug?)

9. Compiler Bug with template constructors?

10. almost another compiler bug (templates)

11. Is this a compiler bug? (templates)

12. No code for template - compiler bug?

 

 
Powered by phpBB® Forum Software