Skip to content

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

Closed

Description

@fbusato

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

Activity

  1. moved this from Todo to In Review in CCCLon Sep 17, 2024
  2. miscco commented on Sep 19, 2024

    @miscco
    Contributor
  3. fbusato commented on Sep 19, 2024

    @fbusato
    ContributorAuthor

    it can be only be reproduced with latest version of CCCL

  4. moved this from In Review to Done in CCCLon Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions