Internal compiler error

B

Benedikt Weber

The following code gives an internal compiler error on VC++ .net 2003. It
compiles on Comeau online, so I guess its leagal code.

Can anybody confirm the error and report it to MS?

Benedikt


#include "stdafx.h"

class Parameter
{
public:
virtual operator int() const {throw "Error";}
virtual operator double() const {throw "Error";}
};

template<class T>
class Variable:
public Parameter
{
public:
virtual operator T() const;
};

int main()
{
Variable<double> v;
}
 
D

Daniel P.

It is a bug in the compiler because it does not return a meaningful error
message but your code also has an error.

virtual operator T() const;

does not have a body. Try:
virtual operator T() const { return T(); };
 
D

Daniel P.

Or maybe
virtual operator T() const { return Parameter(); };

S the following will compile fine:

Variable<double> v;
double a = v;
Variable<int> v2;
int b = v2;


while
Variable<CString> v3;
CString c = v3;

will fire a compiling error as expected:


d:\TEMP\ICE\ICE.cpp(25) : error C2664:
'ATL::CStringT<BaseType,StringTraits>::CStringT(const VARIANT &)' : cannot
convert parameter 1 from 'Parameter' to 'const VARIANT &'
with
[
BaseType=char,
StringTraits=StrTraitMFC_DLL<char>
]
Reason: cannot convert from 'Parameter' to 'const VARIANT'
No constructor could take the source type, or constructor overload
resolution was ambiguous
d:\TEMP\ICE\ICE.cpp(24) : while compiling class-template member
function 'Variable<T>::blush:perator`T'(void) const'
with
[
T=CString
]
d:\TEMP\ICE\ICE.cpp(35) : see reference to class template
instantiation 'Variable<T>' being compiled
with
[
T=CString
]
 
B

Benedikt Weber

Well, I reduced the example to the bare minimum. The function definition was
actually defined outside of the class. With this the internal compiler error
pops up again.

template<class T>
Variable<T>::blush:perator T() const { return Parameter(); }

I will use the inline to solve my problem. Thanks for the hint.

Benedikt
 
D

David Lowndes

The following code gives an internal compiler error on VC++ .net 2003. It
compiles on Comeau online, so I guess its leagal code.

Can anybody confirm the error and report it to MS?

Benedikt,

I've passed your code sample on to MS since it also gives the C1001
with the alpha release of the Whidbey compiler.

Dave
 
B

Benedikt Weber

Thanks alot. I think it's important to give MS that feedback to improve
their product

Benedikt
 

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