Internal compiler error

  • Thread starter Thread starter Benedikt Weber
  • Start date Start date
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;
}
 
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(); };
 
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>::operator`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
]
 
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>::operator T() const { return Parameter(); }

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

Benedikt
 
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
 
Thanks alot. I think it's important to give MS that feedback to improve
their product

Benedikt
 
Back
Top