This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53654] New: move constructor incorrectly delete copy constructor defined by template
- From: "kirbyzhou at sogou-inc dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 13 Jun 2012 08:03:56 +0000
- Subject: [Bug c++/53654] New: move constructor incorrectly delete copy constructor defined by template
- Auto-submitted: auto-generated
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.