Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Add assignment operator to the TestBar test util class. #185

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions test/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -1140,29 +1140,41 @@ struct NumericTraits<TestFoo>
// Complex data type TestBar (with optimizations for fence-free warp-synchrony)
//---------------------------------------------------------------------

#define MAGIC 895245
/**
* TestBar complex data type
*/
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be something other than assert - in a release build, asserts may be turned off, and we want to catch cases where miscompiles in -O3 lead to missed assignments as well. Perhaps it should use the CUB error reporting machinery.

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;
Expand Down