mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-26 16:19:30 +03:00
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
This commit is contained in:
parent
f5ba405795
commit
57bf80682e
1 changed files with 11 additions and 13 deletions
|
|
@ -1,6 +1,8 @@
|
|||
#include "../../unittestpp.h"
|
||||
#include "RecordingReporter.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
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());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue