[Bug c++/34124] New: auto_ptr ambiguous conversion
Hi, Running the following code: #include using namespace std; class CBase {}; class CDerived : public CBase {}; void Set(auto_ptr base) { } int main(int argc, char *argv[]) { auto_ptr derived(new CDerived); Set(derived); // error: conversion from 'std::auto_ptr' to 'std::auto_ptr' is ambiguous auto_ptr base(derived); // but this is OK base = derived; // this is OK too } the Set(derived) gives the mentioned error in the comment. The next two lines compiles without error so both the copy constructor and the operator= of auto_ptr works fine. But for some reason the conversion is ambiguous if a function (in this case Set) is called. In the next two lines of the compiler output, there are two notes: /usr/include/c++/4.2.1/memory:368: note: candidates are: std::auto_ptr<_Tp>::operator std::auto_ptr<_Tp1>() [with _Tp1 = CBase, _Tp = CDerived] /usr/include/c++/4.2.1/memory:212: note: std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp1>&) [with _Tp1 = CDerived, _Tp = CBase] Please could you check if this is a bug or I made something wrong? Thanks, Csaba -- Summary: auto_ptr ambiguous conversion Product: gcc Version: 4.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: cfekete1 at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34124
[Bug c++/34125] New: auto_ptr ambiguous conversion
Hi, Running the following code: #include using namespace std; class CBase {}; class CDerived : public CBase {}; void Set(auto_ptr base) { } int main(int argc, char *argv[]) { auto_ptr derived(new CDerived); Set(derived); // error: conversion from 'std::auto_ptr' to 'std::auto_ptr' is ambiguous auto_ptr base(derived); // but this is OK base = derived; // this is OK too } the Set(derived) gives the mentioned error in the comment. The next two lines compiles without error so both the copy constructor and the operator= of auto_ptr works fine. But for some reason the conversion is ambiguous if a function (in this case Set) is called. In the next two lines of the compiler output, there are two notes: /usr/include/c++/4.2.1/memory:368: note: candidates are: std::auto_ptr<_Tp>::operator std::auto_ptr<_Tp1>() [with _Tp1 = CBase, _Tp = CDerived] /usr/include/c++/4.2.1/memory:212: note: std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp1>&) [with _Tp1 = CDerived, _Tp = CBase] Please could you check if this is a bug or I made something wrong? Thanks, Csaba -- Summary: auto_ptr ambiguous conversion Product: gcc Version: 4.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: cfekete1 at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34125