1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
2 | |
3 | #include "Inputs/cuda.h" |
4 | |
5 | //------------------------------------------------------------------------------ |
6 | // Test 1: host method called from device function |
7 | |
8 | struct S1 { |
9 | void method() {} // expected-note {{'method' declared here}} |
10 | }; |
11 | |
12 | __device__ void foo1(S1& s) { |
13 | s.method(); // expected-error {{reference to __host__ function 'method' in __device__ function}} |
14 | } |
15 | |
16 | //------------------------------------------------------------------------------ |
17 | // Test 2: host method called from device function, for overloaded method |
18 | |
19 | struct S2 { |
20 | void method(int) {} // expected-note {{candidate function not viable: call to __host__ function from __device__ function}} |
21 | void method(float) {} // expected-note {{candidate function not viable: call to __host__ function from __device__ function}} |
22 | }; |
23 | |
24 | __device__ void foo2(S2& s, int i, float f) { |
25 | s.method(f); // expected-error {{no matching member function}} |
26 | } |
27 | |
28 | //------------------------------------------------------------------------------ |
29 | // Test 3: device method called from host function |
30 | |
31 | struct S3 { |
32 | __device__ void method() {} // expected-note {{'method' declared here}} |
33 | }; |
34 | |
35 | void foo3(S3& s) { |
36 | s.method(); // expected-error {{reference to __device__ function 'method' in __host__ function}} |
37 | } |
38 | |
39 | //------------------------------------------------------------------------------ |
40 | // Test 4: device method called from host&device function |
41 | |
42 | struct S4 { |
43 | __device__ void method() {} // expected-note {{'method' declared here}} |
44 | }; |
45 | |
46 | __host__ __device__ void foo4(S4& s) { |
47 | s.method(); // expected-error {{reference to __device__ function 'method' in __host__ __device__ function}} |
48 | } |
49 | |
50 | //------------------------------------------------------------------------------ |
51 | // Test 5: overloaded operators |
52 | |
53 | struct S5 { |
54 | S5() {} |
55 | S5& operator=(const S5&) {return *this;} // expected-note {{candidate function not viable}} |
56 | }; |
57 | |
58 | __device__ void foo5(S5& s, S5& t) { |
59 | s = t; // expected-error {{no viable overloaded '='}} |
60 | } |
61 | |
62 | //------------------------------------------------------------------------------ |
63 | // Test 6: call method through pointer |
64 | |
65 | struct S6 { |
66 | void method() {} // expected-note {{'method' declared here}}; |
67 | }; |
68 | |
69 | __device__ void foo6(S6* s) { |
70 | s->method(); // expected-error {{reference to __host__ function 'method' in __device__ function}} |
71 | } |
72 | |