From 57bf80682e174479fd32e65f9ebd4c765a86a658 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:45:25 -0600 Subject: [PATCH] r28 | charles.nicholson | 2010-07-29 17:43:45 -0500 (Thu, 29 Jul 2010) | 1 line fix strict aliasing violation, was causing gcc failures. use std::memcpy instead of union-cast --- src/tests/TestChecks.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/tests/TestChecks.cpp b/src/tests/TestChecks.cpp index f32d2e7..10b3071 100644 --- a/src/tests/TestChecks.cpp +++ b/src/tests/TestChecks.cpp @@ -1,6 +1,8 @@ #include "../../unittestpp.h" #include "RecordingReporter.h" +#include + using namespace UnitTest; @@ -119,25 +121,21 @@ TEST(CheckCloseWithZeroEpsilonWorksForSameNumber) TEST(CheckCloseWithNaNFails) { - union - { - unsigned int bitpattern; - float nan; - }; - bitpattern = 0xFFFFFFFF; - TestResults results; + const unsigned int bitpattern = 0xFFFFFFFF; + float nan; + std::memcpy(&nan, &bitpattern, sizeof(bitpattern)); + + TestResults results; CheckClose(results, 3.0f, nan, 0.1f, TestDetails("", "", "", 0)); CHECK_EQUAL(1, results.GetFailureCount()); } TEST(CheckCloseWithNaNAgainstItselfFails) { - union - { - unsigned int bitpattern; - float nan; - }; - bitpattern = 0xFFFFFFFF; + const unsigned int bitpattern = 0xFFFFFFFF; + float nan; + std::memcpy(&nan, &bitpattern, sizeof(bitpattern)); + TestResults results; CheckClose(results, nan, nan, 0.1f, TestDetails("", "", "", 0)); CHECK_EQUAL(1, results.GetFailureCount());