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

           Summary: Not possible to initialize a shared_ptr with a class
                    defined in function scope, inheriting from a global
                    scope base class
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: skagge...@gmail.com


Here's some code reproducing the problem:

#include <memory>

struct Base {
    virtual ~Base() {}
};

typedef std::tr1::shared_ptr<Base> BasePtr;

BasePtr GetImpl() {
    struct InlineImpl : Base{
    };

    return BasePtr(new InlineImpl);
}

int main() {
   BasePtr ptr = GetImpl();
}

The result is:

In function 'BasePtr GetImpl()':
Line 13: error: no matching function for call to
'std::tr1::shared_ptr<Base>::shared_ptr(GetImpl()::InlineImpl*)'

If I change from shared_ptr<Base> to Base* it works as expected. It also works
as expected if I do return Base(reinterpret_cast<Base*>(new InlineImpl)).

Best regards,

Johan Andersson

Reply via email to