From 10fc9e06eb7693592d2152f1f7116d27d7f04bb7 Mon Sep 17 00:00:00 2001 From: Hugh Winkler Date: Mon, 1 Jun 2020 13:00:21 -0500 Subject: [PATCH] Add assignment operator to TestBar test util class. I added a an assignment operator to the class, and I added a field named `magic` that I set to certain value during construction. Only an object that has been constructed is likely to have that magic value properly set. An assignment precondition is that the left-hand side is valid. The assignment operators I added assert that the `magic` member of the lhs has the correct value. --- test/test_util.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/test_util.h b/test/test_util.h index d44b939ebd..9d7631f90b 100644 --- a/test/test_util.h +++ b/test/test_util.h @@ -1140,6 +1140,7 @@ struct NumericTraits // Complex data type TestBar (with optimizations for fence-free warp-synchrony) //--------------------------------------------------------------------- +#define MAGIC 895245 /** * TestBar complex data type */ @@ -1147,22 +1148,33 @@ struct TestBar { long long x; int y; + int magic; // Constructor - __host__ __device__ __forceinline__ TestBar() : x(0), y(0) + __host__ __device__ __forceinline__ TestBar() : x(0), y(0), magic(MAGIC) {} // Constructor - __host__ __device__ __forceinline__ TestBar(int b) : x(b), y(b) + __host__ __device__ __forceinline__ TestBar(int b) : x(b), y(b), magic(MAGIC) {} // Constructor - __host__ __device__ __forceinline__ TestBar(long long x, int y) : x(x), y(y) + __host__ __device__ __forceinline__ TestBar(long long x, int y) : x(x), y(y), magic(MAGIC) {} + // Assignment operator + __host__ __device__ __forceinline__ TestBar& operator =(const TestBar& that) + { + assert (magic == MAGIC); + x = that.x; + y = that.y; + return *this; + } + // Assignment from int operator __host__ __device__ __forceinline__ TestBar& operator =(int b) { + assert (magic == MAGIC); x = b; y = b; return *this;