Compiler Bug in VS 2003?

M

Martin Zenkel

The follwing code compiles and works well under VS 2002
with or without the line "template A<int>". Using VS 2003
the code throws an exception if the line "template
A<int>" is removed.

From my point of view explicit instantiation of templates
should not be necessary and usually produces more code
than needed.

Is this a known bug of the c++ compiler?

#include <iostream>
#using <mscorlib.dll>

template <class C>
class A
{
public:
C c;
int i;

A(): i(0), c(C())
{
}

A(const A& a): i(a.i), c(a.c)
{
}

~A()
{

}

const A& operator=(const A& a)
{
if (this != &a)
{
c = a.c;
i = a.i;
}

return a;
}
};

//template A<int>;


public __gc class M
{
public:
M()
{
}

void compute(A<int> a)
{
std::cout << "M::compute(...): a.i: " <<
a.i;
}

void test()
{
A<int> a;

compute(a);
}

};

using namespace std;


int main()
{
cout << "Program active" << endl << endl;

M* m = new M();

m->test();

cout << endl << "Program terminated." << endl;

int c;

cin >> c;

return 0;
}
 
C

Carl Daniel [VC++ MVP]

Martin said:
The follwing code compiles and works well under VS 2002
with or without the line "template A<int>". Using VS 2003
the code throws an exception if the line "template
A<int>" is removed.

From my point of view explicit instantiation of templates
should not be necessary and usually produces more code
than needed.

Is this a known bug of the c++ compiler?

Apparently so - this code runs as expected with or without the explicit
instantiation when compiled with the current Whidbey alpha versionn of the
compiler. I was able to reproduce the problem you describe compiling with
VC7.1.

-cd
 
G

Gary Chang

Hi Martin,

Thanks for you posting in the group!

It is a confirmed bug of the VC7.1, and has already been fixed in the
latest Whidbey version.

Thanks again for your reporting of this bug as well as your interest of
VC7.1.


Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top