14
14
#include < assert.h>
15
15
16
16
#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
18
33
#endif
19
- __host__ __device__ size_t
20
- test_array () {
34
+
35
+ MAYBE_CONSTEXPR __host__ __device__ size_t test_array () {
21
36
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
+
22
44
size_t N = A.size ();
23
45
assert (N == 4 );
24
46
@@ -35,17 +57,9 @@ constexpr
35
57
return N;
36
58
}
37
59
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 ()); }
47
61
48
- __global__ void kernel () { do_test (); }
62
+ __global__ void kernel () { do_all_tests (); }
49
63
50
64
int main () {
51
65
kernel<<<32 , 32 >>> ();
@@ -55,7 +69,7 @@ int main() {
55
69
return 1 ;
56
70
}
57
71
58
- do_test ();
72
+ do_all_tests ();
59
73
60
74
printf (" Success!\n " );
61
75
return 0 ;
0 commit comments