Template member-function instantiation

5000ba958b9778b429999d687d507086
0
m1cky 101 Feb 11, 2005 at 12:36

Hello,
we have a template problem while upgrading from VC6 to VC7.

Normally only used member functions of a template are instantiated (compiled).
For example if there is a template class which has 3 methods, but only 2 of them are used in my code the third function is not evaluated/compiled.
This seems to work with VC7 as well as with VC6.

Well, if i compile our software i get an error cause the compiler instantiates one method of std::list which it should not compile !
This can have 2 reasons:

  • That uncomileable method is used somewhere in the code. I would not expect that since the code is still compileable with VC6

  • Under some circumstances the compiler is forced to compile all (even unused) template methods

I need an answer to the second point, had someone same problems or have an solution for this ?

Thx

3 Replies

Please log in or register to post a reply.

22b3033832c5c699c856814b0cf80cb1
0
bladder 101 Feb 11, 2005 at 13:10

The only times I’ve heard of code that could compile with vc6 and not vc7 was code that was non standard compliant. What piece of code is refusing to compile in vc7, there has to be some way to re-write it so that it would compile.

Also, just to check. Full optimization is done in release builds. Try compiling in that and see if it works out. You may also want to try fiddeling with the optimization options in teh project settings.

E6054bb6187225c187281ca54c21dbe6
0
AM_ 101 Feb 11, 2005 at 13:55

@m1cky

  • That uncomileable method is used somewhere in the code. I would not expect that since the code is still compileable with VC6

  • Under some circumstances the compiler is forced to compile all (even unused) template methods

I need an answer to the second point, had someone same problems or have an solution for this ?

Thx

[snapback]15988[/snapback]

Yes the compiler checks all code … also if it’s unused.

Are you using your own stl version (stlport) ?

5000ba958b9778b429999d687d507086
0
m1cky 101 Feb 11, 2005 at 19:04

@AM_

@m1cky

  • That uncomileable method is used somewhere in the code. I would not expect that since the code is still compileable with VC6

  • Under some circumstances the compiler is forced to compile all (even unused) template methods

I need an answer to the second point, had someone same problems or have an solution for this ?

Thx

[snapback]15988[/snapback]

Yes the compiler checks all code … also if it’s unused.

Are you using your own stl version (stlport) ?

[snapback]15991[/snapback]

no the compiler dont check all code.
Try this:

class A
{
public:
A(int) {}
};

template <typename T> class B
{
public:
B() {}

void instantiateA() {
T t;
}
};

int main()
{
B<A> b;
}

if you dont call instantiateA in the main u dont get an error message that A provides no default constructor.