Template specialization, default args, typedef and an internal compiler
error
Hello,
I have a piece of code who don't compile in Visual C++ 2005 and I
suspect a bug of the compiler since it seems to be valid code (and is
compiled without complain by at least two other compilers):
class A {};
class B {};
// template function
template<class T>
T foo(B const &b, A const &a = A())
{
return T();
}
// specialization of the function
template<>
B foo<B>(B const &b, A const &a)
{
return B();
}
int main()
{
B b;
foo<B>(b); // << no problem
typedef B aliasB;
foo<aliasB>(b); // << don't compile
}
The error reads:
--------------
error C2440: 'default argument' : cannot convert from 'const A *__w64 '
to 'const A &'
Reason: cannot convert from 'const A *__w64 ' to 'const A'
No constructor could take the source type, or constructor
overload resolution was ambiguous
--------------
More over, if I remove "const &" for the parameter "a" of both function
foo, I obtain an internal compiler error at the same line:
--------------
fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'f:\RTM\VCTOOLS\Compiler\CxxFE\sl\P1\C\toil.c', line 7366)
--------------
This occurs in "debug" as well as in "release" mode.
Is this a known bug and what are the possible workarounds?
Thanks.
--
Cyrille