Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 355967 - Ambiguous function call with parameter using conversion operator
Summary: Ambiguous function call with parameter using conversion operator
Status: RESOLVED WONTFIX
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-26 13:35 EDT by Marc-André Laperle CLA
Modified: 2011-09-06 13:21 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc-André Laperle CLA 2011-08-26 13:35:22 EDT
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.
Comment 1 Markus Schorn CLA 2011-09-06 10:36:44 EDT
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
}
Comment 2 Marc-André Laperle CLA 2011-09-06 13:21:15 EDT
Thanks!

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50306