Fix strict aliasing violation, make C4Real pass is_pod

alut-include-path
Julius Michaelis 2017-04-02 18:22:03 +02:00
parent f03a1d618d
commit 97bdddba24
2 changed files with 8 additions and 5 deletions

View File

@ -74,8 +74,8 @@ public:
public:
// constructors
inline C4Fixed () { }
inline C4Fixed (const C4Fixed &rCpy): val(rCpy.val) { }
inline C4Fixed () = default;
inline C4Fixed (const C4Fixed &) = default;
// Conversion must be done by the conversion routines itofix, fixtoi, ftofix and fixtof
// in order to be backward compatible, so everything is private.

View File

@ -240,10 +240,13 @@ struct StdCastAdapt
inline void CompileFunc(StdCompiler *pComp) const
{
// Cast
assert(sizeof(to_t) == sizeof(T));
to_t vVal = *reinterpret_cast<to_t *>(&rValue);
static_assert(sizeof(to_t) == sizeof(T), "CastAdapt sanity: sizes match");
static_assert(std::is_pod<to_t>::value, "CastAdapt sanity: to-type is POD");
static_assert(std::is_pod<T>::value, "CastAdapt sanity: from-type is POD");
to_t vVal;
std::memcpy(&vVal, &rValue, sizeof(to_t));
pComp->Value(vVal);
rValue = *reinterpret_cast<T *>(&vVal);
std::memcpy(&rValue, &vVal, sizeof(T));
}
// Operators for default checking/setting
template <class D> inline bool operator == (const D &nValue) const { return rValue == nValue; }