This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/47942] New: Not possible to initialize a shared_ptr with a class defined in function scope, inheriting from a global scope base class


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: unassigned@gcc.gnu.org
        ReportedBy: skagget77@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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]