1 // RUN: %clang_cc1 -std=c++11 -fcuda-is-device -verify -fsyntax-only -verify-ignore-unexpected=warning -verify-ignore-unexpected=note %s
2 // RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only -verify-ignore-unexpected=warning -verify-ignore-unexpected=note %s
4 #include "Inputs/cuda.h"
6 __device__ void device_fn() {
8 f1(); // implicitly __device__
10 auto f2 = [&] __device__ {};
13 auto f3 = [&] __host__ {};
14 f3(); // expected-error {{no matching function}}
16 auto f4 = [&] __host__ __device__ {};
19 // Now do it all again with '()'s in the lambda declarations: This is a
20 // different parse path.
22 g1(); // implicitly __device__
24 auto g2 = [&]() __device__ {};
27 auto g3 = [&]() __host__ {};
28 g3(); // expected-error {{no matching function}}
30 auto g4 = [&]() __host__ __device__ {};
33 // Once more, with the '()'s in a different place.
35 h1(); // implicitly __device__
37 auto h2 = [&] __device__ () {};
40 auto h3 = [&] __host__ () {};
41 h3(); // expected-error {{no matching function}}
43 auto h4 = [&] __host__ __device__ () {};
47 // Behaves identically to device_fn.
48 __global__ void kernel_fn() {
50 f1(); // implicitly __device__
52 auto f2 = [&] __device__ {};
55 auto f3 = [&] __host__ {};
56 f3(); // expected-error {{no matching function}}
58 auto f4 = [&] __host__ __device__ {};
61 // No need to re-test all the parser contortions we test in the device
65 __host__ void host_fn() {
67 f1(); // implicitly __host__ (i.e., no magic)
69 auto f2 = [&] __device__ {};
70 f2(); // expected-error {{no matching function}}
72 auto f3 = [&] __host__ {};
75 auto f4 = [&] __host__ __device__ {};
79 __host__ __device__ void hd_fn() {
81 f1(); // implicitly __host__ __device__
83 auto f2 = [&] __device__ {};
86 // expected-error@-2 {{reference to __device__ function}}
89 auto f3 = [&] __host__ {};
92 // expected-error@-2 {{reference to __host__ function}}
95 auto f4 = [&] __host__ __device__ {};
99 // The special treatment above only applies to lambdas.
100 __device__ void foo() {
105 x.foo(); // expected-error {{reference to __host__ function 'foo' in __device__ function}}