public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [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
@ 2011-03-01 13:07 skagget77 at gmail dot com
  2011-03-01 13:28 ` [Bug c++/47942] " skagget77 at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: skagget77 at gmail dot com @ 2011-03-01 13:07 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-06-05 15:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-01 13:07 [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 skagget77 at gmail dot com
2011-03-01 13:28 ` [Bug c++/47942] " skagget77 at gmail dot com
2011-03-01 13:37 ` redi at gcc dot gnu.org
2011-03-01 13:45 ` redi at gcc dot gnu.org
2011-03-01 13:58 ` skagget77 at gmail dot com
2011-06-05 15:25 ` pluto at agmk dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).