Clang Project

clang_source_code/test/SemaCUDA/bad-calls-on-same-line.cu
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
10template <typename T>
11struct Selector {};
12
13template <>
14struct Selector<int> {
15  __host__ void f() {}
16};
17
18template <>
19struct Selector<float> {
20  __device__ void f() {} // expected-note {{declared here}}
21};
22
23template <>
24struct Selector<double> {
25  __device__ void f() {} // expected-note {{declared here}}
26};
27
28template <typename T>
29inline __host__ __device__ void hd() {
30  Selector<T>().f();
31  // expected-error@-1 2 {{reference to __device__ function}}
32}
33
34void 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