1 // RUN: %clang_cc1 -std=c++11 -fcuda-is-device -verify=dev,expected -fsyntax-only \
2 // RUN: -verify-ignore-unexpected=warning -verify-ignore-unexpected=note %s
3 // RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only \
4 // RUN: -verify-ignore-unexpected=warning -verify-ignore-unexpected=note %s
6 #include "Inputs/cuda.h"
8 __device__ void device_fn() {
10 f1(); // implicitly __device__
12 auto f2 = [&] __device__ {};
15 auto f3 = [&] __host__ {};
16 f3(); // expected-error {{no matching function}}
18 auto f4 = [&] __host__ __device__ {};
21 // Now do it all again with '()'s in the lambda declarations: This is a
22 // different parse path.
24 g1(); // implicitly __device__
26 auto g2 = [&]() __device__ {};
29 auto g3 = [&]() __host__ {};
30 g3(); // expected-error {{no matching function}}
32 auto g4 = [&]() __host__ __device__ {};
35 // Once more, with the '()'s in a different place.
37 h1(); // implicitly __device__
39 auto h2 = [&] __device__ () {};
42 auto h3 = [&] __host__ () {};
43 h3(); // expected-error {{no matching function}}
45 auto h4 = [&] __host__ __device__ () {};
49 // Behaves identically to device_fn.
50 __global__ void kernel_fn() {
52 f1(); // implicitly __device__
54 auto f2 = [&] __device__ {};
57 auto f3 = [&] __host__ {};
58 f3(); // expected-error {{no matching function}}
60 auto f4 = [&] __host__ __device__ {};
63 // No need to re-test all the parser contortions we test in the device
67 __host__ void host_fn() {
69 f1(); // implicitly __host__ (i.e., no magic)
71 auto f2 = [&] __device__ {};
72 f2(); // expected-error {{no matching function}}
74 auto f3 = [&] __host__ {};
77 auto f4 = [&] __host__ __device__ {};
81 __host__ __device__ void hd_fn() {
83 f1(); // implicitly __host__ __device__
85 auto f2 = [&] __device__ {};
88 // expected-error@-2 {{reference to __device__ function}}
91 auto f3 = [&] __host__ {};
94 // expected-error@-2 {{reference to __host__ function}}
97 auto f4 = [&] __host__ __device__ {};
101 // The special treatment above only applies to lambdas.
102 __device__ void foo() {
107 x.foo(); // dev-error {{reference to __host__ function 'foo' in __device__ function}}