1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
2 | |
3 | // The hd function template is instantiated three times. |
4 | // |
5 | // Two of those instantiations call a device function, which is an error when |
6 | // compiling for host. Clang should report both errors. |
7 | |
8 | #include "Inputs/cuda.h" |
9 | |
10 | template <typename T> |
11 | struct Selector {}; |
12 | |
13 | template <> |
14 | struct Selector<int> { |
15 | __host__ void f() {} |
16 | }; |
17 | |
18 | template <> |
19 | struct Selector<float> { |
20 | __device__ void f() {} // expected-note {{declared here}} |
21 | }; |
22 | |
23 | template <> |
24 | struct Selector<double> { |
25 | __device__ void f() {} // expected-note {{declared here}} |
26 | }; |
27 | |
28 | template <typename T> |
29 | inline __host__ __device__ void hd() { |
30 | Selector<T>().f(); |
31 | // expected-error@-1 2 {{reference to __device__ function}} |
32 | } |
33 | |
34 | void host_fn() { |
35 | hd<int>(); |
36 | hd<double>(); // expected-note {{function template specialization 'hd<double>'}} |
37 | // expected-note@-1 {{called by 'host_fn'}} |
38 | hd<float>(); // expected-note {{function template specialization 'hd<float>'}} |
39 | // expected-note@-1 {{called by 'host_fn'}} |
40 | } |
41 | |