This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/29266] New: Rule that binding rvalue to a refernce need a copy ctor don't work
- From: "yuanfei8077 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 28 Sep 2006 09:47:06 -0000
- Subject: [Bug c++/29266] New: Rule that binding rvalue to a refernce need a copy ctor don't work
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Hi,
I used to open a issue at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29261 and
it's closed as no a bug. Also it says that to bind an rvalue to a reference,
we need to let copy ctor of the class be accessible. However, I found that
this is not the case when the invokcation is happen in intialization list.
See below reproduction code and error message.
Env:
=====
G++ 4.1
No compile option is used
Source code:
==============
using std::cout;
using std::endl;
class MemPool {
public:
MemPool(){};
protected:
MemPool(const MemPool& mempool);
};
template <class Type> class MemAllocator{
public:
MemAllocator(MemPool& pool):m_pool(pool){}
MemPool& get_pool() const {
return m_pool;
}
template<class OtherType>
MemAllocator<Type>& operator=(const MemAllocator<OtherType>& rhs){
m_pool = rhs.get_pool();
return *this;
}
MemAllocator& operator=(const MemAllocator& rhs){
m_pool = rhs.get_pool();
return *this;
}
MemAllocator(const MemAllocator& other)
: m_pool(other.m_pool) {}
template<class OtherType>
MemAllocator(const MemAllocator<OtherType>& other)
: m_pool(other.get_pool()) {}
private:
MemAllocator();
// MemAllocator(const MemAllocator&);
MemPool &m_pool;
};
template <class _AllocType> class tdat_hash_map {
public:
typedef _AllocType _Alloc;
static void func(const _Alloc&) {};
_Alloc malloc;
private:
tdat_hash_map();
};
class CacheManager {
public:
typedef tdat_hash_map<MemAllocator<int> > Map;
Map caches;
MemPool pool;
CacheManager():caches(MemAllocator<int>(pool)){};
};
Error message:
==============
main.cpp: In constructor CacheManager::CacheManager()
main.cpp:56: error: no matching function for call to
tdat_hash_map<MemAllocator<int>
>::tdat_hash_map(MemAllocator<int>)main.cpp:49: note: candidates are:
tdat_hash_map<_AllocType>::tdat_hash_map() [with _AllocType =
MemAllocator<int>]
main.cpp:42: note: tdat_hash_map<MemAllocator<int>
>::tdat_hash_map(const tdat_hash_map<MemAllocator<int> >&)
--
Summary: Rule that binding rvalue to a refernce need a copy ctor
don't work
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: yuanfei8077 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29266