Skip to content

Commit

Permalink
Try and fix MSVC issues
Browse files Browse the repository at this point in the history
  • Loading branch information
miscco committed Jul 5, 2024
1 parent 2bba82c commit 9a9f089
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
12 changes: 6 additions & 6 deletions libcudacxx/include/cuda/std/inplace_vector
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ struct __inplace_vector_base : __inplace_vector_destruct_base<_Tp, _Capacity, _S
// [containers.sequences.inplace.vector.members] size/capacity
_LIBCUDACXX_INLINE_VISIBILITY constexpr void __change_size(const ptrdiff_t __count) noexcept
{
this->__size_ += __count;
this->__size_ += static_cast<__size_type>(__count);
}

_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY constexpr size_type size() const noexcept
Expand Down Expand Up @@ -497,7 +497,7 @@ struct __inplace_vector_base<_Tp, _Capacity, __inplace_vector_specialization::__
// [containers.sequences.inplace.vector.members] size/capacity
_LIBCUDACXX_INLINE_VISIBILITY constexpr void __change_size(const ptrdiff_t __count) noexcept
{
__size_ += __count;
__size_ += static_cast<__size_type>(__count);
}

_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY constexpr size_type size() const noexcept
Expand Down Expand Up @@ -1771,8 +1771,8 @@ public:

// [containers.sequences.inplace.vector.erasure]
template <class _Up>
_LIBCUDACXX_INLINE_VISIBILITY friend constexpr size_type
erase(inplace_vector& __cont, const _Up& __value) noexcept(_CCCL_TRAIT(is_nothrow_move_assignable, _Tp))
_LIBCUDACXX_INLINE_VISIBILITY friend constexpr size_type erase(inplace_vector& __cont, const _Up& __value) noexcept(
_CCCL_TRAIT(is_nothrow_move_assignable, typename inplace_vector::value_type)) // MSVC2017 cannot handle _Tp here
{
_CCCL_IF_CONSTEXPR (_Capacity == 0)
{
Expand All @@ -1785,8 +1785,8 @@ public:
}

template <class _Pred>
_LIBCUDACXX_INLINE_VISIBILITY friend constexpr size_type
erase_if(inplace_vector& __cont, _Pred __pred) noexcept(_CCCL_TRAIT(is_nothrow_move_assignable, _Tp))
_LIBCUDACXX_INLINE_VISIBILITY friend constexpr size_type erase_if(inplace_vector& __cont, _Pred __pred) noexcept(
_CCCL_TRAIT(is_nothrow_move_assignable, typename inplace_vector::value_type)) // MSVC2017 cannot handle _Tp here
{
_CCCL_IF_CONSTEXPR (_Capacity == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,28 @@ __host__ __device__ constexpr void test_size()
{ // inplace_vector<T, 0> can be constructed from a size
cuda::std::inplace_vector<T, 0> vec(0);
assert(vec.empty());
#if !defined(TEST_COMPILER_GCC) || __GNUC__ >= 10
#if (!defined(TEST_COMPILER_GCC) || __GNUC__ >= 10) && !defined(TEST_COMPILER_MSVC_2017)
static_assert(!noexcept(cuda::std::inplace_vector<T, 0>(0)), "");
#endif // !TEST_COMPILER_GCC < 10
#endif // !TEST_COMPILER_GCC < 10 && !TEST_COMPILER_MSVC_2017
}

using inplace_vector = cuda::std::inplace_vector<T, 42>;
{ // inplace_vector<T, N> can be constructed from a size, is empty if zero
inplace_vector vec(0);
assert(vec.empty());
#if !defined(TEST_COMPILER_GCC) || __GNUC__ >= 10
#if (!defined(TEST_COMPILER_GCC) || __GNUC__ >= 10) && !defined(TEST_COMPILER_MSVC_2017)
static_assert(!noexcept(inplace_vector(0)), "");
#endif // !TEST_COMPILER_GCC < 10
#endif // !TEST_COMPILER_GCC < 10 && !TEST_COMPILER_MSVC_2017
}

{ // inplace_vector<T, N> can be constructed from a size, elements are value initialized
constexpr size_t size{3};
inplace_vector vec(size);
assert(!vec.empty());
assert(equal_range(vec, cuda::std::array<T, size>{T(0), T(0), T(0)}));
#if !defined(TEST_COMPILER_GCC) || __GNUC__ >= 10
#if (!defined(TEST_COMPILER_GCC) || __GNUC__ >= 10) && !defined(TEST_COMPILER_MSVC_2017)
static_assert(!noexcept(inplace_vector(3)), "");
#endif // !TEST_COMPILER_GCC < 10
#endif // !TEST_COMPILER_GCC < 10 && !TEST_COMPILER_MSVC_2017
}
}

Expand All @@ -137,28 +137,28 @@ __host__ __device__ constexpr void test_size_value()
{ // inplace_vector<T, 0> can be constructed from a size and a const T&
cuda::std::inplace_vector<T, 0> vec(0, T(42));
assert(vec.empty());
#if !defined(TEST_COMPILER_GCC) || __GNUC__ >= 10
#if (!defined(TEST_COMPILER_GCC) || __GNUC__ >= 10) && !defined(TEST_COMPILER_MSVC_2017)
static_assert(!noexcept(cuda::std::inplace_vector<T, 0>(0, T(42))), "");
#endif // !TEST_COMPILER_GCC < 10
#endif // !TEST_COMPILER_GCC < 10 && !TEST_COMPILER_MSVC_2017
}

using inplace_vector = cuda::std::inplace_vector<T, 42>;
{ // inplace_vector<T, N> can be constructed from a size and a const T&, is empty if zero
inplace_vector vec(0, T(42));
assert(vec.empty());
#if !defined(TEST_COMPILER_GCC) || __GNUC__ >= 10
#if (!defined(TEST_COMPILER_GCC) || __GNUC__ >= 10) && !defined(TEST_COMPILER_MSVC_2017)
static_assert(!noexcept(inplace_vector(0, T(42))), "");
#endif // !TEST_COMPILER_GCC < 10
#endif // !TEST_COMPILER_GCC < 10 && !TEST_COMPILER_MSVC_2017
}

{ // inplace_vector<T, N> can be constructed from a size and a const T&, elements are copied
constexpr size_t size{3};
inplace_vector vec(size, T(42));
assert(!vec.empty());
assert(equal_range(vec, cuda::std::array<T, size>{T(42), T(42), T(42)}));
#if !defined(TEST_COMPILER_GCC) || __GNUC__ >= 10
#if (!defined(TEST_COMPILER_GCC) || __GNUC__ >= 10) && !defined(TEST_COMPILER_MSVC_2017)
static_assert(!noexcept(inplace_vector(3, T(42))), "");
#endif // !TEST_COMPILER_GCC < 10
#endif // !TEST_COMPILER_GCC < 10 && !TEST_COMPILER_MSVC_2017
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ __host__ __device__ void test()
== cuda::std::numeric_limits<cuda::std::uint16_t>::max() + 1 + sizeof(cuda::std::uint32_t),
"");

#if !defined(TEST_COMPILER_MSVC) // too large array
// There is an overflow issue when using cuda::std::numeric_limits<cuda::std::uint32_t>::max() directly
constexpr size_t uint32_t_max = cuda::std::numeric_limits<cuda::std::uint32_t>::max();
static_assert(sizeof(cuda::std::inplace_vector<char, uint32_t_max>) == uint32_t_max + 1 + sizeof(cuda::std::uint32_t),
"");
static_assert(
sizeof(cuda::std::inplace_vector<char, uint32_t_max + 1>) == uint32_t_max + 1 + sizeof(cuda::std::uint64_t), "");
#endif // !TEST_COMPILER_MSVC

// Check the type aliases
using inplace_vector = cuda::std::inplace_vector<int, 42>;
Expand Down

0 comments on commit 9a9f089

Please sign in to comment.