xref: /llvm-project/clang/test/SemaCUDA/trivial-ctor-dtor.cu (revision 2b76e20ea782790a78ec58d5f94ce88a173bab7f)
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;
AA9   A() {}
~AA10   ~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;
TATA19   TA() {}
~TATA20   ~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;
TBTB29   TB() { static int nontrivial_ctor = 1; }
~TBTB30   ~TB() {}
31 };
32 
33 template<typename T>
34 struct TC : TB<T> {
35   T x;
TCTC36   TC() {}
~TCTC37   ~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 {
CC47     explicit C() {};
48 };
49 
C()50 template <> C<int>::C() {};
51 __device__ C<int> ci_d;
52 C<int> ci_h;
53 
54 // Check non-trivial ctor specialization
C()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;
58