public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53654] New: move constructor incorrectly delete copy constructor defined by template
@ 2012-06-13  8:04 kirbyzhou@sogou-inc.com
  2012-06-13  8:49 ` [Bug c++/53654] " redi at gcc dot gnu.org
  2012-07-25  9:43 ` paolo.carlini at oracle dot com
  0 siblings, 2 replies; 3+ messages in thread
From: kirbyzhou@sogou-inc.com @ 2012-06-13  8:04 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53654

             Bug #: 53654
           Summary: move constructor incorrectly delete copy constructor
                    defined by template
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: kirbyzhou@sogou-inc.com


shared_ptr<T> declares its copy constructor and assign operator by template (if
Y == T). But the nontrivial copy constructor is been deleted by the move
constructor declaration.

////////////////////////////////////////////////////////
template<class T>
struct shared_ptr
{
    template<class Y>
    shared_ptr( shared_ptr<Y> const & r );
    template<class Y>
    shared_ptr& operator=( shared_ptr<Y> && r );

    shared_ptr( shared_ptr<T> && r );
    shared_ptr& operator=( shared_ptr<T> && r );
};

struct TTransport {
};

struct TProtocol {
    shared_ptr<TTransport> func()
    {
        return p_;
    }
    shared_ptr<TTransport> p_;
};
////////////////////////////////////////////////////////

]# g++47 -std=gnu++0x -c tshareptr.cpp 
tshareptr.cpp: In member function 'shared_ptr<TTransport> TProtocol::func()':
tshareptr.cpp:20:10: error: use of deleted function 'constexpr
shared_ptr<TTransport>::shared_ptr(const shared_ptr<TTransport>&)'
tshareptr.cpp:3:8: note: 'constexpr shared_ptr<TTransport>::shared_ptr(const
shared_ptr<TTransport>&)' is implicitly declared as deleted because
'shared_ptr<TTransport>' declares a move constructor or move assignment
operator


Workaround:
declare a separate copy constructor individually.


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

* [Bug c++/53654] move constructor incorrectly delete copy constructor defined by template
  2012-06-13  8:04 [Bug c++/53654] New: move constructor incorrectly delete copy constructor defined by template kirbyzhou@sogou-inc.com
@ 2012-06-13  8:49 ` redi at gcc dot gnu.org
  2012-07-25  9:43 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2012-06-13  8:49 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53654

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-06-13 08:48:44 UTC ---
This behaviour is correct and required by the standard.

The template constructor is not a copy constructor, so a copy constructor is
still implicitly-declared and defined as deleted. The standard says
[class.copy]/2 "A non-template constructor for class X is a copy constructor if
its first parameter is of type X&, const X&, volatile X& or const volatile X&,
and either there are no other parameters or else all other parameters have
default values."

Your workaround is necessary (and exactly that change has been made to GCC's
own shared_ptr)

      shared_ptr(const shared_ptr&) noexcept = default;


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

* [Bug c++/53654] move constructor incorrectly delete copy constructor defined by template
  2012-06-13  8:04 [Bug c++/53654] New: move constructor incorrectly delete copy constructor defined by template kirbyzhou@sogou-inc.com
  2012-06-13  8:49 ` [Bug c++/53654] " redi at gcc dot gnu.org
@ 2012-07-25  9:43 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-07-25  9:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53654

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-07-25 09:42:49 UTC ---
Let's close this, then.


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

end of thread, other threads:[~2012-07-25  9:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-13  8:04 [Bug c++/53654] New: move constructor incorrectly delete copy constructor defined by template kirbyzhou@sogou-inc.com
2012-06-13  8:49 ` [Bug c++/53654] " redi at gcc dot gnu.org
2012-07-25  9:43 ` paolo.carlini at oracle dot com

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).