https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86483

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to gnzlbg from comment #0)
> I have to set the alloc_size attribute for smallocx_return_t.ptr

s/have to/want to/ surely? And if you did that, you'd be giving the compiler
bad information. The point of the new API is that smallocx_return_t::ptr points
to storage of size smallocx_return_t::usize bytes, **not** the size given by
the 'size' parameter. If you tell the compiler the storage is smaller than
'usize' you're asking it to treat accesses past 'size' bytes as undefined
behaviour (even though actually accesses up to usize are valid).


A related problem is that you can't say a function parameter specifies the
allocated size in some units other than bytes.
std::allocator<T>::allocate(size_t n) returns a pointer with space for n *
sizeof(T) but you can't use alloc_size to tell the compiler that.

Reply via email to