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

Commit

Permalink
More test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
miscco committed Jan 23, 2023
1 parent 2e4fbe7 commit 5d38c3f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: nvrtc

// <functional>
//
// reference_wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: nvrtc

// <functional>

// reference_wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11
// UNSUPPORTED: nvrtc

// template <class T> constexpr add_const<T>& as_const(T& t) noexcept; // C++17
// template <class T> add_const<T>& as_const(const T&&) = delete; // C++17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class A

int main(int, char**)
{
static_assert((std::is_same<decltype(std::declval<A>()), A&&>::value), "");
static_assert((cuda::std::is_same<decltype(cuda::std::declval<A>()), A&&>::value), "");

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

#include "test_macros.h"

template <typename T>
__host__ __device__
constexpr bool unused(T &&) {return true;}

#if TEST_STD_VER > 11
__host__ __device__ TEST_CONSTEXPR_CXX14 bool test_constexpr() {
int v = 12;
Expand Down Expand Up @@ -57,17 +61,20 @@ __host__ __device__ TEST_CONSTEXPR_CXX14 bool test_noexcept() {
assert(x == 42);
}
{
TestNoexcept<true, true> x;
TestNoexcept<true, true> x{};
ASSERT_NOEXCEPT(cuda::std::exchange(x, cuda::std::move(x)));
ASSERT_NOT_NOEXCEPT(cuda::std::exchange(x, x)); // copy-assignment is not noexcept
unused(x);
}
{
TestNoexcept<true, false> x;
TestNoexcept<true, false> x{};
ASSERT_NOT_NOEXCEPT(cuda::std::exchange(x, cuda::std::move(x)));
unused(x);
}
{
TestNoexcept<false, true> x;
TestNoexcept<false, true> x{};
ASSERT_NOT_NOEXCEPT(cuda::std::exchange(x, cuda::std::move(x)));
unused(x);
}

return true;
Expand Down
48 changes: 6 additions & 42 deletions .upstream-tests/test/std/utilities/utility/forward/move.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,14 @@ __device__ const int& cx = x;
template <class QualInt>
__host__ __device__ QualInt get() TEST_NOEXCEPT { return static_cast<QualInt>(x); }

int copy_ctor = 0;
int move_ctor = 0;
_LIBCUDACXX_CPO_ACCESSIBILITY int copy_ctor = 0;
_LIBCUDACXX_CPO_ACCESSIBILITY int move_ctor = 0;

struct A {
A() {}
A(const A&) {++copy_ctor;}
A(A&&) {++move_ctor;}
A& operator=(const A&) = delete;
};

__device__ int device_copy_ctor = 0;
__device__ int device_move_ctor = 0;

struct D {
__device__ D() {}
__device__ D(const D&) {++device_copy_ctor;}
__device__ D(D&&) {++device_move_ctor;}
__device__ D& operator=(const D&) = delete;
__host__ __device__ A() {}
__host__ __device__ A(const A&) {++copy_ctor;}
__host__ __device__ A(A&&) {++move_ctor;}
__host__ __device__ A& operator=(const A&) = delete;
};

#if TEST_STD_VER > 11
Expand All @@ -79,7 +69,6 @@ int main(int, char**)
static_assert(cuda::std::is_same<decltype(cuda::std::move(get<const int&&>())), const int&&>::value, "");
ASSERT_NOEXCEPT(cuda::std::move(get<int const&&>()));
}
#ifndef __CUDA_ARCH__
{ // test copy and move semantics
A a;
const A ca = A();
Expand All @@ -103,31 +92,6 @@ int main(int, char**)
assert(copy_ctor == 3);
assert(move_ctor == 1);
}
#else
{ // test copy and move semantics
D d;
const D cd = D();

assert(device_copy_ctor == 0);
assert(device_move_ctor == 0);

D d2 = d; (void)d2;
assert(device_copy_ctor == 1);
assert(device_move_ctor == 0);

D d3 = cuda::std::move(d); (void)d3;
assert(device_copy_ctor == 1);
assert(device_move_ctor == 1);

D d4 = cd; (void)d4;
assert(device_copy_ctor == 2);
assert(device_move_ctor == 1);

D d5 = cuda::std::move(cd); (void)d5;
assert(device_copy_ctor == 3);
assert(device_move_ctor == 1);
}
#endif
{ // test on a move only type
move_only mo;
test(cuda::std::move(mo));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

#include "test_macros.h"

template <typename T>
__host__ __device__
constexpr bool unused(T &&) {return true;}

class A
{
__host__ __device__ A(const A&);
Expand All @@ -44,10 +48,15 @@ int main(int, char**)
{
int i = 0;
const int ci = 0;
unused(i);
unused(ci);

legacy l;
A a;
const A ca;
unused(l);
unused(a);
unused(ca);

static_assert((cuda::std::is_same<decltype(cuda::std::move_if_noexcept(i)), int&&>::value), "");
static_assert((cuda::std::is_same<decltype(cuda::std::move_if_noexcept(ci)), const int&&>::value), "");
Expand All @@ -61,7 +70,5 @@ int main(int, char**)
static_assert(i2 == 23, "" );
#endif

++i;

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class _LIBCUDACXX_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp
_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17
typename __invoke_of<type&, _ArgTypes...>::type
operator() (_ArgTypes&&... __args) const {
return std::__invoke(get(), std::forward<_ArgTypes>(__args)...);
return _CUDA_VSTD::__invoke(get(), _CUDA_VSTD::forward<_ArgTypes>(__args)...);
}
};

Expand Down

0 comments on commit 5d38c3f

Please sign in to comment.