This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[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
- From: "skagget77 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 1 Mar 2011 13:07:52 +0000
- Subject: [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
- Auto-submitted: auto-generated
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