Community
Participate
Working Groups
Using CDT 8.0.0.201108031635 template <class T> class SmartPtr { public: template<typename OtherT> operator const SmartPtr<OtherT>&() const { return *this; } template<typename OtherT> operator SmartPtr<OtherT>() const { return *this; } }; class A { }; class B : public A { }; void func(SmartPtr<A>) { } int main() { SmartPtr<B> b; func(b); // func is ambiguous } This code compiles with MinGW GCC 4.4 but it doesn't with VC 9. I'm not sure who's right but gcc calls the operator that returns a value and that looks right to me.
I thing gcc is wrong, it fails to deduce the template argument for the first conversion operator. When I replace the templates with non-template conversions then gcc reports the ambiguity: class A {}; class B : public A {}; template <class T> class SmartPtr { public: operator const SmartPtr<A>&() const; operator SmartPtr<A>() const; }; void func(SmartPtr<A>) { } int main() { SmartPtr<B> b; func(b); // func is ambiguous }
Thanks! http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50306