| Summary: | Ambiguous function call with parameter using conversion operator | ||
|---|---|---|---|
| Product: | [Tools] CDT | Reporter: | Marc-André Laperle <malaperle> |
| Component: | cdt-parser | Assignee: | Project Inbox <cdt-parser-inbox> |
| Status: | RESOLVED WONTFIX | QA Contact: | Markus Schorn <mschorn.eclipse> |
| Severity: | normal | ||
| Priority: | P3 | CC: | cdtdoug |
| Version: | 8.0 | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
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
}
|
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.