NVIDIA / NVIDIA/cccl

[BUG]: `thrust::device_reference` doesn't support types with `operator==` defined as a member function.

Open
#1,453 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.5k
Forks
486
Avg merge
2d 6h
Merged PRs (30d)
295

Description

### Is this a duplicate?

- [X] I confirmed there appear to be no [duplicate issues](https://github.com/NVIDIA/cccl/issues) for this bug and that I agree to the [Code of Conduct](CODE_OF_CONDUCT.md)

### Type of Bug

Compile-time Error

### Component

Thrust

### Describe the bug

`thrust::device_reference` does not compile when used with a type that defines `operator==` as a member function:

```
thrust/detail/internal_functional.h(136): error: no operator "==" matches these operands
operand types are: const thrust::device_reference == const foo
return lhs == rhs;
```

A quick WAR is to change the member function into a friend function, as shown in the example.

### How to Reproduce

```
#include
#include

// Define to apply work-around
//#define USE_WAR

struct foo
{
#ifndef USE_WAR

// Doesn't compile:
__host__ __device__
bool operator==(const foo&) const
{
return true;
}

#else

// Compiles:
__host__ __device__
friend bool operator==(const foo&, const foo&)
{
return true;
}

#endif
};

int main()
{
thrust::device_vector vec;
thrust::count(vec.cbegin(), vec.cend(), foo{});
}
```

### Expected behavior

The example should compile when `USE_WAR` is undefined.

### Reproduction link

https://godbolt.org/z/1aYxbGc13

### Operating System

_No response_

### nvidia-smi output

_No response_

### NVCC version

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.