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

             Bug #: 50306
           Summary: g++ accepts code with ambiguous, templated conversion
                    operators
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: malape...@omnialabs.net


This code does not generate an error or warning:

class A{};
class B : public A {};

template <class T> class SmartPtr{
public:
    template<typename OtherT> operator const SmartPtr<OtherT>&() const;

    template<typename OtherT> operator SmartPtr<OtherT>() const;
};

void func(SmartPtr<A>) {
}

int main() {
    SmartPtr<B> b;
    func(b); // this should be ambiguous?
}

But it is an error with MSVC 10 and Clang 2.8.

If the templates on the operators are removed, it also becomes ambiguous with
gcc:

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
}

Reply via email to