Debian Codegraph @

clang/test/SemaCUDA/trivial-ctor-dtor.cu

raw
1 // RUN: %clang_cc1 -isystem %S/Inputs -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -isystem %S/Inputs -fcuda-is-device -fsyntax-only -verify %s
3
4 #include <cuda.h>
5
6 // Check trivial ctor/dtor
7 struct A {
8 int x;
9 A() {}
10 ~A() {}
11 };
12
13 __device__ A a;
14
15 // Check trivial ctor/dtor of template class
16 template<typename T>
17 struct TA {
18 T x;
19 TA() {}
20 ~TA() {}
21 };
22
23 __device__ TA<int> ta;
24
25 // Check non-trivial ctor/dtor in parent template class
26 template<typename T>
27 struct TB {
28 T x;
29 TB() { static int nontrivial_ctor = 1; }
30 ~TB() {}
31 };
32
33 template<typename T>
34 struct TC : TB<T> {
35 T x;
36 TC() {}
37 ~TC() {}
38 };
39
40 template class TC<int>;
41
42 __device__ TC<int> tc; //expected-error {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
43
44 // Check trivial ctor specialization
45 template <typename T>
46 struct C {
47 explicit C() {};
48 };
49
50 template <> C<int>::C() {};
51 __device__ C<int> ci_d;
52 C<int> ci_h;
53
54 // Check non-trivial ctor specialization
55 template <> C<float>::C() { static int nontrivial_ctor = 1; }
56 __device__ C<float> cf_d; //expected-error {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
57 C<float> cf_h;