public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/61655] New: Copy constructor not called on CRTP schema @ 2014-06-30 7:38 fabien.picarougne@univ-nantes.fr 2014-06-30 7:46 ` [Bug c++/61655] " glisse at gcc dot gnu.org ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: fabien.picarougne@univ-nantes.fr @ 2014-06-30 7:38 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61655 Bug ID: 61655 Summary: Copy constructor not called on CRTP schema Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: critical Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: fabien.picarougne@univ-nantes.fr Created attachment 33033 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33033&action=edit Illustration of the problem When using a CRTP pattern on a class and returning an object of this class in a function, the copy constructor is not called. See test attached file that illustrate the problem. Output on gcc 4.9.0 is CBase::CBase() CDerived::CDerived() CBase::CBase() CDerived::CDerived() before test: operator* CBase::CBase() CDerived::CDerived() end operator* CBase::Display() after test: CDerived::~CDerived() CBase::~CBase() CDerived::~CDerived() CBase::~CBase() CDerived::~CDerived() CBase::~CBase() but the expected outpup is CBase::CBase() CDerived::CDerived() CBase::CBase() CDerived::CDerived() before test: operator* CBase::CBase() CDerived::CDerived() end operator* CBase::CBase(const CBase &obj) CDerived::CDerived(const CDerived &obj) CDerived::~CDerived() CBase::~CBase() CBase::Display() after test: CDerived::~CDerived() CBase::~CBase() CDerived::~CDerived() CBase::~CBase() CDerived::~CDerived() CBase::~CBase() This code works fine on MSVC2013 C++ compiler ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/61655] Copy constructor not called on CRTP schema 2014-06-30 7:38 [Bug c++/61655] New: Copy constructor not called on CRTP schema fabien.picarougne@univ-nantes.fr @ 2014-06-30 7:46 ` glisse at gcc dot gnu.org 2014-06-30 7:49 ` pinskia at gcc dot gnu.org ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: glisse at gcc dot gnu.org @ 2014-06-30 7:46 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61655 --- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> --- Try -fno-elide-constructors. Why would you want a copy? Is it because of the parentheses in the return statement that you expect elision not to be performed? ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/61655] Copy constructor not called on CRTP schema 2014-06-30 7:38 [Bug c++/61655] New: Copy constructor not called on CRTP schema fabien.picarougne@univ-nantes.fr 2014-06-30 7:46 ` [Bug c++/61655] " glisse at gcc dot gnu.org @ 2014-06-30 7:49 ` pinskia at gcc dot gnu.org 2014-06-30 8:17 ` fabien.picarougne@univ-nantes.fr 2014-06-30 8:29 ` glisse at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2014-06-30 7:49 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61655 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- The copy constructor does not need to be called if there is no copying going on. There is two optimizations going on here. The first is the named return value optimization. The second is related to that in the intilization of the new variable is handled inside the function itself. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/61655] Copy constructor not called on CRTP schema 2014-06-30 7:38 [Bug c++/61655] New: Copy constructor not called on CRTP schema fabien.picarougne@univ-nantes.fr 2014-06-30 7:46 ` [Bug c++/61655] " glisse at gcc dot gnu.org 2014-06-30 7:49 ` pinskia at gcc dot gnu.org @ 2014-06-30 8:17 ` fabien.picarougne@univ-nantes.fr 2014-06-30 8:29 ` glisse at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: fabien.picarougne@univ-nantes.fr @ 2014-06-30 8:17 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61655 --- Comment #3 from Fabien Picarougne <fabien.picarougne@univ-nantes.fr> --- This code is minimal and is just here to illustrate the problem, I use a more complex one to handle generic matrix. But The copy constructor here is not neutral, there is an output on stdout. So I think, the optimization should not take place here, isn't it? ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/61655] Copy constructor not called on CRTP schema 2014-06-30 7:38 [Bug c++/61655] New: Copy constructor not called on CRTP schema fabien.picarougne@univ-nantes.fr ` (2 preceding siblings ...) 2014-06-30 8:17 ` fabien.picarougne@univ-nantes.fr @ 2014-06-30 8:29 ` glisse at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: glisse at gcc dot gnu.org @ 2014-06-30 8:29 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61655 --- Comment #4 from Marc Glisse <glisse at gcc dot gnu.org> --- Look up "copy elision" (the wikipedia article will do). ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-06-30 8:29 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-06-30 7:38 [Bug c++/61655] New: Copy constructor not called on CRTP schema fabien.picarougne@univ-nantes.fr 2014-06-30 7:46 ` [Bug c++/61655] " glisse at gcc dot gnu.org 2014-06-30 7:49 ` pinskia at gcc dot gnu.org 2014-06-30 8:17 ` fabien.picarougne@univ-nantes.fr 2014-06-30 8:29 ` glisse at gcc dot gnu.org
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).