Closed clnhlzmn closed 9 months ago
The static_assert
is a good idea.
I can also modify the code so that it uses alignas
for C++11 and above.
That would be awesome. I'm happy to help if I can. But I don't know the consequences of the change I suggested throughout the rest of etl.
I implemented a static_assert
to check that the requested alignment is achieved.
Also the code uses alignas
if C++11 or above, dropping back to the old method for C++03 and below.
I've run the CI locally and on Github with no issues.
If user code breaks then it will highlight an issue with their code.
Fixed 20.38.3
A coworker of mine is trying to use
etl::pool
to allocate objects (byte arrays) that must be aligned to 32 bytes. She has tried usingetl::generic_pool<..., 32, ...>
but it turns out that is failing to produce 32 byte aligned allocations becauseetl::type_with_alignment<32>::type
silently produceschar
astype
when the requested alignment doesn't match the alignment of one ofint_least8_t
,int_least16_t
,int32_t
,int64_t
,float
,double
, orvoid*
(https://github.com/ETLCPP/etl/blob/master/include/etl/alignment.h#L210).Example:
If I make this change to
type_with_alignment
:my example produces the correct alignment:
The
etl::pool
docs imply that the alignment will be correct forT
.It would be nice at least to get a static assert if the requested alignment cannot be achieved, but ideally the pool buffer should "just" meet the alignment requirements of the type being allocated.