[LLVMbugs] [Bug 10278] New: Problem with Custom Allocator
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue Jul 5 02:38:05 PDT 2011
http://llvm.org/bugs/show_bug.cgi?id=10278
Summary: Problem with Custom Allocator
Product: libc++
Version: unspecified
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
AssignedTo: hhinnant at apple.com
ReportedBy: cullmann at absint.de
CC: llvmbugs at cs.uiuc.edu
Hi,
given the following allocator:
/**
* Generic Pool Allocator Template
*/
template <typename T> class PoolAllocator
{
public:
/**
* Size
*/
typedef size_t size_type;
/**
* Pointer difference
*/
typedef ptrdiff_t difference_type;
/**
* Pointer
*/
typedef T* pointer;
/**
* Const Pointer
*/
typedef const T* const_pointer;
/**
* Reference
*/
typedef T& reference;
/**
* Const Reference
*/
typedef const T& const_reference;
/**
* Value
*/
typedef T value_type;
/**
* Rebind
*/
template <class U> struct rebind {
/**
* Rebind implementation
*/
typedef PoolAllocator<U> other;
};
/**
* Constructor
*/
PoolAllocator()
{
}
/**
* Copy-Constructor
* @param other other allocator
*/
template <class U> PoolAllocator (const PoolAllocator<U> &other)
{
(void) other;
}
/**
* Give address
* @param x reference
* @return address for reference
*/
pointer address(reference x) const
{
return &x;
}
/**
* Give address (const)
* @param x reference
* @return address for reference
*/
const_pointer address(const_reference x) const
{
return &x;
}
/**
* Allocate memory for given count of elements
* @param size number of elements to allocate
* @param hint optimizer hint
* @return allocated memory or 0
*/
pointer allocate(size_type size, PoolAllocator<void>::const_pointer
hint = 0)
{
(void) hint;
return static_cast<pointer> (poolAllocate(size*sizeof(T)));
}
/**
* Deallocate given memory with given number of elements
* @param p pointer to deallocate
* @param size number of elements allocated there
*/
void deallocate(pointer p, size_type size)
{
poolDeallocate(p, size*sizeof(T));
}
/**
* Maximal amount allocatable
* @return maximal number of elements allocatable
*/
size_type max_size() const throw()
{
return size_t(-1) / sizeof(value_type);
}
/**
* Construct object
* @param p pointer where to construct
*/
void construct(pointer p)
{
new(p) T();
}
/**
* Construct object
* @param p pointer where to construct
* @param val value
*/
void construct(pointer p, const T& val)
{
new(p) T(val);
}
/**
* Deconstruct object
* @param p pointer where to deconstruct
*/
void destroy(pointer p)
{
p->~T();
}
};
I get this error message that no usable construct function is available:
/local/cullmann/build/llvm.default.release/usr/include/c++/v1/memory:1530:18:
error: no matching member function for call to 'construct'
{__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
~~~~^~~~~~~~~
/local/cullmann/build/llvm.default.release/usr/include/c++/v1/memory:1468:14:
note: in instantiation of function template specialization
'std::__1::allocator_traits<Ur::PoolAllocator<std::__1::__tree_node<std::__1::pair<const
char *, int>, void *> > >::__construct<int, >' requested here
{__construct(__has_construct<allocator_type, pointer, _Args...>(),
^
/local/cullmann/build/llvm.default.release/usr/include/c++/v1/map:1228:20:
note: in instantiation of function template specialization
'std::__1::allocator_traits<Ur::PoolAllocator<std::__1::__tree_node<std::__1::pair<const
char *, int>, void *> > >::construct<int, >' requested here
__node_traits::construct(__na, _VSTD::addressof(__h->__value_.second),
_VSTD::forward<_Args>(__args)...);
^
/local/cullmann/build/llvm.default.release/usr/include/c++/v1/map:1279:29:
note: in instantiation of function template specialization 'std::__1::map<const
char *, int, Ur::StrLess, Ur::PoolAllocator<std::__1::pair<const
char *, int> > >::__construct_node<const char *, , void>' requested here
__node_holder __h = __construct_node(_VSTD::move(__k));
^
/local/cullmann/build/llvm.default.release/libtf14net/src/to_string.cpp:730:17:
note: in instantiation of member function 'std::__1::map<const char *, int,
Ur::StrLess, Ur::PoolAllocator<std::__1::pair<const char *,
int> > >::operator[]' requested here
topo[type->cast_TypeNamed()->name()] = level;
^
/local/cullmann/build/llvm.default.release/usr/include/ur/poolallocator.h:231:14:
note: candidate function not viable: no known conversion from 'int *' to
'pointer' (aka
'std::__1::__tree_node<std::__1::pair<const char *, int>, void *> *') for
1st argument
void construct(pointer p)
^
/local/cullmann/build/llvm.default.release/usr/include/ur/poolallocator.h:241:14:
note: candidate function not viable: requires 2 arguments, but 1 was provided
void construct(pointer p, const T& val)
^
Only wait to get this compiling is introducing ambigious function
void construct(pointer p, const T& val = T ())
in addition to
void construct(pointer p)
The allocator works well with gcc stl and MSVC stl.
Is this a problem with libc++ or with clang not finding the correct overloaded
variant? Or dumb error on my side?
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list