blob: 67923323a94fa5fd8af93c8ed322fdb3b509b07a [file] [log] [blame]
Justin Lebar9730ae92016-10-19 21:03:38 +00001// 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();
Justin Lebar4d38a5c2016-10-21 20:50:47 +000031 // expected-error@-1 2 {{reference to __device__ function}}
Justin Lebar9730ae92016-10-19 21:03:38 +000032}
33
34void host_fn() {
35 hd<int>();
36 hd<double>(); // expected-note {{function template specialization 'hd<double>'}}
Justin Lebar6c86e912016-10-19 21:15:01 +000037 // expected-note@-1 {{called by 'host_fn'}}
Justin Lebar9730ae92016-10-19 21:03:38 +000038 hd<float>(); // expected-note {{function template specialization 'hd<float>'}}
Justin Lebar6c86e912016-10-19 21:15:01 +000039 // expected-note@-1 {{called by 'host_fn'}}
Justin Lebar9730ae92016-10-19 21:03:38 +000040}