Skip to content

Commit e9f5343

Browse files
committed
Also test the copy and move constructors
1 parent 92b5836 commit e9f5343

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

External/CUDA/array.cu

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,33 @@
1414
#include <assert.h>
1515

1616
#if __cplusplus >= 201402L && STDLIB_VERSION >= 2014
17-
constexpr
17+
// call the function in a constexpr and a non-constexpr context
18+
#define TEST(expr) \
19+
do { \
20+
size_t M = expr; \
21+
(void)(M); \
22+
constexpr size_t N = expr; \
23+
(void)(N); \
24+
} while (0)
25+
#define MAYBE_CONSTEXPR constexpr
26+
#else
27+
#define TEST(expr) \
28+
do { \
29+
size_t M = expr; \
30+
(void)(M); \
31+
} while (0)
32+
#define MAYBE_CONSTEXPR
1833
#endif
19-
__host__ __device__ size_t
20-
test_array() {
34+
35+
MAYBE_CONSTEXPR __host__ __device__ size_t test_array() {
2136
std::array<int, 4> A = {0, 1, 2, 3};
37+
std::array<int, 4> CtorCopy(A);
38+
std::array<int, 4> CtorMove(std::move(CtorCopy));
39+
std::array<int, 4> CopyCopy = A;
40+
std::array<int, 4> CopyMove = std::move(CopyCopy);
41+
(void)CtorMove;
42+
(void)CopyMove;
43+
2244
size_t N = A.size();
2345
assert(N == 4);
2446

@@ -35,17 +57,9 @@ constexpr
3557
return N;
3658
}
3759

38-
__host__ __device__ void do_test() {
39-
// call the function in a constexpr and a non-constexpr context
40-
size_t M = test_array();
41-
(void)(M);
42-
#if __cplusplus >= 201402L && STDLIB_VERSION >= 2014
43-
constexpr size_t N = test_array();
44-
(void)(N);
45-
#endif
46-
}
60+
__host__ __device__ void do_all_tests() { TEST(test_array()); }
4761

48-
__global__ void kernel() { do_test(); }
62+
__global__ void kernel() { do_all_tests(); }
4963

5064
int main() {
5165
kernel<<<32, 32>>>();
@@ -55,7 +69,7 @@ int main() {
5569
return 1;
5670
}
5771

58-
do_test();
72+
do_all_tests();
5973

6074
printf("Success!\n");
6175
return 0;

0 commit comments

Comments
 (0)