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
* [Bug c++/47942] 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 [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 ` skagget77 at gmail dot com
2011-03-01 13:37 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: skagget77 at gmail dot com @ 2011-03-01 13:28 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47942
--- Comment #1 from Johan Andersson <skagget77 at gmail dot com> 2011-03-01 13:28:26 UTC ---
I might add that this bug is also present in gcc (Debian 4.4.5-11) 4.4.5.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/47942] 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 [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
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2011-03-01 13:37 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47942
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-03-01 13:37:25 UTC ---
1) GCC 4.1.2 is ancient and unmaintained
2) your example code doesn't compile (should #include <tr1/memory>)
3) in C++03 you cannot use a type without linkage as a template argument
4) You should not use reinterpret_cast, static_cast is correct
Your options are either to use C++0x mode (classes without linkage can be used
as template arguments in C++0x) or to upcast the pointer
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/47942] 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 [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
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2011-03-01 13:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47942
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-03-01 13:45:26 UTC ---
(In reply to comment #2)
> Your options are either to use C++0x mode (classes without linkage can be used
> as template arguments in C++0x) or to upcast the pointer
It seems that the change to allow local types as template args (see
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm for the
proposal) was implemented in GCC 4.5, so you can't rely on that in 4.4
So the best option is:
return BasePtr(static_cast<Base*>(new InlineImpl));
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/47942] 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 [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
` (2 preceding siblings ...)
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
4 siblings, 0 replies; 6+ messages in thread
From: skagget77 at gmail dot com @ 2011-03-01 13:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47942
--- Comment #4 from Johan Andersson <skagget77 at gmail dot com> 2011-03-01 13:58:00 UTC ---
Thanks for the quick reply and advice to use static_cast, the reinterpret_cast
was a temporary memory lapse!
The old GCC version was because I used a web-interface to verify the problem.
I'm normally on Windows and Visual C++.
(In reply to comment #3)
> (In reply to comment #2)
> > Your options are either to use C++0x mode (classes without linkage can be used
> > as template arguments in C++0x) or to upcast the pointer
>
> It seems that the change to allow local types as template args (see
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm for the
> proposal) was implemented in GCC 4.5, so you can't rely on that in 4.4
>
> So the best option is:
>
> return BasePtr(static_cast<Base*>(new InlineImpl));
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/47942] 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 [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
` (3 preceding siblings ...)
2011-03-01 13:58 ` skagget77 at gmail dot com
@ 2011-06-05 15:25 ` pluto at agmk dot net
4 siblings, 0 replies; 6+ messages in thread
From: pluto at agmk dot net @ 2011-06-05 15:25 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47942
Pawel Sikora <pluto at agmk dot net> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pluto at agmk dot net
--- Comment #5 from Pawel Sikora <pluto at agmk dot net> 2011-06-05 15:25:07 UTC ---
*** Bug 49291 has been marked as a duplicate of this bug. ***
^ 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).