Very interesting piece of code here. I have created it with the only purpose - to demonstrate the behaviour of the xlC compiler.
namespace ns {
template<typename T> inline T f() { return T(); }
template<> inline double f<double>() { return 0.001; } // test specialization
};
template<typename T >
class A1 {
public: A1( const T& arg = ns::f<T>() ) {};
};
template<typename T>
class D1 {
public: D1(T t = 0) : t_(t) {};
private: T t_;
};
class my {
A1< D1<int> > a;
public: my() ;
};
//namespace ns { template<> D1<int> f<D1<int> >() { return D1<int>(); } }
my::my() { };
void ff() {
my m;
A1<double> ad;
}
If you compile this code as it is, it's causing a compilation error:
!$ xlC -c b.cpp
"b.cpp", line 7.40: 1540-0253 (S) This use of undefined class "D1<int>" is not valid.
"b.cpp", line 22.10: 1540-1205 (I) The error occurred while converting to parameter 1 of "A1<D1<int> >::A1(const D1<int> &)".
!$ xlC -qversion
IBM XL C/C++ for AIX, V12.1 (5765-J02, 5725-C72)
!$ uname -a
AIX build25 1 6 00C8B3424C00 powerpc AIX
And now, if we uncomment the line started with the "//namespace" (which is nothing else but template specialization for the typename D1< int>, compiler error disappears.
Gnu compiler seems to have no problem with it. Does any of you have an idea?
PS. The problem was found of course in a real project and this is just a simplified example. In real project, there are hundreds of classes like D1< int>. They suppose to work out of the box. But for xlC I have to write the specialized functions for each particular case. That hurts a lot ...