From 97bdddba24de5e128e1f10c308f7247ef4b9ad59 Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Sun, 2 Apr 2017 18:22:03 +0200 Subject: [PATCH] Fix strict aliasing violation, make C4Real pass is_pod --- src/lib/C4Real.h | 4 ++-- src/lib/StdAdaptors.h | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib/C4Real.h b/src/lib/C4Real.h index 116dc5fb9..720e599e7 100644 --- a/src/lib/C4Real.h +++ b/src/lib/C4Real.h @@ -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. diff --git a/src/lib/StdAdaptors.h b/src/lib/StdAdaptors.h index e3753c7fa..2d3e6adee 100644 --- a/src/lib/StdAdaptors.h +++ b/src/lib/StdAdaptors.h @@ -240,10 +240,13 @@ struct StdCastAdapt inline void CompileFunc(StdCompiler *pComp) const { // Cast - assert(sizeof(to_t) == sizeof(T)); - to_t vVal = *reinterpret_cast(&rValue); + static_assert(sizeof(to_t) == sizeof(T), "CastAdapt sanity: sizes match"); + static_assert(std::is_pod::value, "CastAdapt sanity: to-type is POD"); + static_assert(std::is_pod::value, "CastAdapt sanity: from-type is POD"); + to_t vVal; + std::memcpy(&vVal, &rValue, sizeof(to_t)); pComp->Value(vVal); - rValue = *reinterpret_cast(&vVal); + std::memcpy(&rValue, &vVal, sizeof(T)); } // Operators for default checking/setting template inline bool operator == (const D &nValue) const { return rValue == nValue; }