`optional` storage may be misaligned
TartanLlama opened this issue · 5 comments
TartanLlama commented
The implementation of optional
in helpers
stores objects in a character buffer, but the buffer may not meet the alignment requirements for types stored in it.
TartanLlama commented
I'd get rid of the [1], but otherwise yeah!
joboccara commented
Ok thanks. For the record, I can't seem to get rid of it and still specify I'd like one T in my buffer: the code doesn't compile if I just remove [1]. Maybe it's because I'm not familiar with aligned_storage, but it's no big issue anyway.
TartanLlama commented
If you remove the [1]
you'd also need to explicitly take the address of m_object
when you reinterpret_cast
or placement new
into it.