Option: Use __builtin_launder to ensure that the compiler doesn't label this as UB
This commit is contained in:
parent
79078ff21e
commit
6eff41e7af
@ -138,26 +138,16 @@ template <typename T> class Option
|
||||
private:
|
||||
struct Storage
|
||||
{
|
||||
u8 buffer[sizeof(T)];
|
||||
|
||||
T* fetch_ptr()
|
||||
{
|
||||
return (T*)buffer;
|
||||
}
|
||||
alignas(T) u8 buffer[sizeof(T)];
|
||||
|
||||
T& fetch_reference()
|
||||
{
|
||||
return *fetch_ptr();
|
||||
}
|
||||
|
||||
const T* fetch_ptr() const
|
||||
{
|
||||
return (const T*)buffer;
|
||||
return *__builtin_launder(reinterpret_cast<T*>(&buffer));
|
||||
}
|
||||
|
||||
const T& fetch_reference() const
|
||||
{
|
||||
return *fetch_ptr();
|
||||
return *__builtin_launder(reinterpret_cast<const T*>(&buffer));
|
||||
}
|
||||
|
||||
void store_reference(const T& ref)
|
||||
|
Loading…
Reference in New Issue
Block a user