[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCUDA / implicit-member-target-inherited.cu
blob2178172ed01930deb5a0786bc7b403986e78959b
1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -Wno-defaulted-function-deleted
3 #include "Inputs/cuda.h"
5 //------------------------------------------------------------------------------
6 // Test 1: infer inherited default ctor to be host.
8 struct A1_with_host_ctor {
9   A1_with_host_ctor() {}
11 // expected-note@-3 {{candidate constructor (the implicit copy constructor) not viable}}
12 // expected-note@-4 {{candidate constructor (the implicit move constructor) not viable}}
14 // The inherited default constructor is inferred to be host, so we'll encounter
15 // an error when calling it from a __device__ function, but not from a __host__
16 // function.
17 struct B1_with_implicit_default_ctor : A1_with_host_ctor {
18   using A1_with_host_ctor::A1_with_host_ctor;
21 // expected-note@-4 {{call to __host__ function from __device__}}
22 // expected-note@-5 {{candidate constructor (the implicit copy constructor) not viable}}
23 // expected-note@-6 {{candidate constructor (the implicit move constructor) not viable}}
24 // expected-note@-6 2{{constructor from base class 'A1_with_host_ctor' inherited here}}
26 void hostfoo() {
27   B1_with_implicit_default_ctor b;
30 __device__ void devicefoo() {
31   B1_with_implicit_default_ctor b; // expected-error {{no matching constructor}}
34 //------------------------------------------------------------------------------
35 // Test 2: infer inherited default ctor to be device.
37 struct A2_with_device_ctor {
38   __device__ A2_with_device_ctor() {}
40 // expected-note@-3 {{candidate constructor (the implicit copy constructor) not viable}}
41 // expected-note@-4 {{candidate constructor (the implicit move constructor) not viable}}
43 struct B2_with_implicit_default_ctor : A2_with_device_ctor {
44   using A2_with_device_ctor::A2_with_device_ctor;
47 // expected-note@-4 {{call to __device__ function from __host__}}
48 // expected-note@-5 {{candidate constructor (the implicit copy constructor) not viable}}
49 // expected-note@-6 {{candidate constructor (the implicit move constructor) not viable}}
50 // expected-note@-6 2{{constructor from base class 'A2_with_device_ctor' inherited here}}
52 void hostfoo2() {
53   B2_with_implicit_default_ctor b;  // expected-error {{no matching constructor}}
56 __device__ void devicefoo2() {
57   B2_with_implicit_default_ctor b;
60 //------------------------------------------------------------------------------
61 // Test 3: infer inherited copy ctor
63 struct A3_with_device_ctors {
64   __host__ A3_with_device_ctors() {}
65   __device__ A3_with_device_ctors(const A3_with_device_ctors&) {}
68 struct B3_with_implicit_ctors : A3_with_device_ctors {
69   using A3_with_device_ctors::A3_with_device_ctors;
71 // expected-note@-3 2{{call to __device__ function from __host__ function}}
72 // expected-note@-4 {{default constructor}}
75 void hostfoo3() {
76   B3_with_implicit_ctors b;  // this is OK because the inferred inherited default ctor
77                              // here is __host__
78   B3_with_implicit_ctors b2 = b; // expected-error {{no matching constructor}}
82 //------------------------------------------------------------------------------
83 // Test 4: infer inherited default ctor from a field, not a base
85 struct A4_with_host_ctor {
86   A4_with_host_ctor() {}
89 struct B4_with_inherited_host_ctor : A4_with_host_ctor{
90   using A4_with_host_ctor::A4_with_host_ctor;
93 struct C4_with_implicit_default_ctor {
94   B4_with_inherited_host_ctor field;
97 // expected-note@-4 {{call to __host__ function from __device__}}
98 // expected-note@-5 {{candidate constructor (the implicit copy constructor) not viable}}
99 // expected-note@-6 {{candidate constructor (the implicit move constructor) not viable}}
101 void hostfoo4() {
102   C4_with_implicit_default_ctor b;
105 __device__ void devicefoo4() {
106   C4_with_implicit_default_ctor b; // expected-error {{no matching constructor}}
109 //------------------------------------------------------------------------------
110 // Test 5: inherited copy ctor with non-const param
112 struct A5_copy_ctor_constness {
113   __host__ A5_copy_ctor_constness() {}
114   __host__ A5_copy_ctor_constness(A5_copy_ctor_constness&) {}
117 struct B5_copy_ctor_constness : A5_copy_ctor_constness {
118   using A5_copy_ctor_constness::A5_copy_ctor_constness;
121 // expected-note@-4 {{candidate constructor (the implicit copy constructor) not viable: call to __host__ function from __device__ function}}
122 // expected-note@-5 {{candidate constructor (the implicit default constructor) not viable}}
124 void hostfoo5(B5_copy_ctor_constness& b_arg) {
125   B5_copy_ctor_constness b = b_arg;
128 __device__ void devicefoo5(B5_copy_ctor_constness& b_arg) {
129   B5_copy_ctor_constness b = b_arg; // expected-error {{no matching constructor}}
132 //------------------------------------------------------------------------------
133 // Test 6: explicitly defaulted ctor
135 struct A6_with_device_ctor {
136   __device__ A6_with_device_ctor() {}
139 struct B6_with_defaulted_ctor : A6_with_device_ctor {
140   using A6_with_device_ctor::A6_with_device_ctor;
141   __host__ B6_with_defaulted_ctor() = default;
144 // expected-note@-3 {{explicitly defaulted function was implicitly deleted here}}
145 // expected-note@-6 {{default constructor of 'B6_with_defaulted_ctor' is implicitly deleted because base class 'A6_with_device_ctor' has no default constructor}}
147 void hostfoo6() {
148   B6_with_defaulted_ctor b; // expected-error {{call to implicitly-deleted default constructor}}
151 __device__ void devicefoo6() {
152   B6_with_defaulted_ctor b;
155 //------------------------------------------------------------------------------
156 // Test 7: inherited copy assignment operator
158 struct A7_with_copy_assign {
159   A7_with_copy_assign() {}
160   __device__ A7_with_copy_assign& operator=(const A7_with_copy_assign&) {}
163 struct B7_with_copy_assign : A7_with_copy_assign {
164   using A7_with_copy_assign::A7_with_copy_assign;
167 // expected-note@-4 {{candidate function (the implicit copy assignment operator) not viable: call to __device__ function from __host__ function}}
168 // expected-note@-5 {{candidate function (the implicit move assignment operator) not viable: call to __device__ function from __host__ function}}
170 void hostfoo7() {
171   B7_with_copy_assign b1, b2;
172   b1 = b2; // expected-error {{no viable overloaded '='}}
175 //------------------------------------------------------------------------------
176 // Test 8: inherited move assignment operator
178 // definitions for std::move
179 namespace std {
180 inline namespace foo {
181 template <class T> struct remove_reference { typedef T type; };
182 template <class T> struct remove_reference<T&> { typedef T type; };
183 template <class T> struct remove_reference<T&&> { typedef T type; };
185 template <class T> typename remove_reference<T>::type&& move(T&& t);
189 struct A8_with_move_assign {
190   A8_with_move_assign() {}
191   __device__ A8_with_move_assign& operator=(A8_with_move_assign&&) {}
192   __device__ A8_with_move_assign& operator=(const A8_with_move_assign&) {}
195 struct B8_with_move_assign : A8_with_move_assign {
196   using A8_with_move_assign::A8_with_move_assign;
199 // expected-note@-4 {{candidate function (the implicit copy assignment operator) not viable: call to __device__ function from __host__ function}}
200 // expected-note@-5 {{candidate function (the implicit move assignment operator) not viable: call to __device__ function from __host__ function}}
202 void hostfoo8() {
203   B8_with_move_assign b1, b2;
204   b1 = std::move(b2); // expected-error {{no viable overloaded '='}}