remove _BOX_CPP directive support as it causes undefined behaviour on stack popping

lib
Avril 4 years ago
parent 2bab6235db
commit 7e9f2083be
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -31,7 +31,8 @@
#ifdef __cplusplus
#ifdef _BOX_CPP
#warning "Using BOX with non-POD types is discouraged"
#include <utility>
#error "Using BOX with non-POD types causes memory leaks"
#endif
#include <cstdlib>
@ -52,11 +53,23 @@ inline T* box()
return (T*)ptr;
}
#ifdef _BOX_CPP
template<typename T>
inline T* box(T&& val)
{
return new T(std::move(val));
}
#endif
template<typename T>
inline T* box(T val)
{
#ifdef _BOX_CPP
T* ptr = new T(std::move(val));
#else
T* ptr = box<T>();
*ptr = val;
#endif
return ptr;
}

Loading…
Cancel
Save