NVIDIA / cccl

CUDA Core Compute Libraries
https://nvidia.github.io/cccl/
Other
1.16k stars 138 forks source link

[BUG]: `is_common_type` trait is broken when mixing rvalue references #2419

Open fbusato opened 1 week ago

fbusato commented 1 week ago

Is this a duplicate?

Type of Bug

Compile-time Error

Component

libcu++

Describe the bug

is_common_type does not work as expected when mixing rvalue references in C++11

How to Reproduce

C++11:

__half array_h[6];
auto value1 = cub::Min{}(array_h[0], array_h[1]);
auto value2 = cub::Min{}(cub::Min{}(array_h[0], array_h[1]), array_h[2]);
static_assert(cuda::std::is_same<decltype(value1), __half>::value, ""); // ok
static_assert(cuda::std::is_same<decltype(value2), float>::value, "");  // ok, ??? 
static_assert(cuda::std::is_same<decltype(value2), __half>::value, ""); // fail

for refernce, cub::Min is defined as

struct Min
{
  /// Boolean min operator, returns `(t < u) ? t : u`
  template <typename T, typename U>
  _CCCL_NODISCARD _CCCL_HOST_DEVICE _CCCL_FORCEINLINE _CCCL_CONSTEXPR_CXX14
  typename ::cuda::std::common_type<T, U>::type
  operator()(T&& t, U&& u) const
  {
    return CUB_MIN(t, u);
  }
};

#define CUB_MIN(a, b) (((b) < (a)) ? (b) : (a))

Expected behavior

static_assert(cuda::std::is_same<decltype(value2), __half>::value, ""); // ok

Reproduction link

No response

Operating System

No response

nvidia-smi output

No response

NVCC version

No response

miscco commented 1 week ago

I cannot reproduce the issue you are seeing: https://godbolt.org/z/6P9KKe896

fbusato commented 1 week ago

it can be only be reproduced with latest version of CCCL