1 // RUN: %clang_cc1 -fcuda-is-device -fsyntax-only -verify=dev,com %s \
2 // RUN: -std=c++11 -fgpu-defer-diag
3 // RUN: %clang_cc1 -fsyntax-only -verify=host,com %s \
4 // RUN: -std=c++11 -fgpu-defer-diag
5 // RUN: %clang_cc1 -fopenmp -fsyntax-only -verify=host,com %s \
6 // RUN: -std=c++11 -fgpu-defer-diag
8 // With -fgpu-defer-diag, clang defers overloading resolution induced
9 // diagnostics when the full candidates set include host device
10 // functions or wrong-sided candidates. This roughly matches nvcc's
13 #include "Inputs/cuda.h"
15 // When callee is called by a host function with integer arguments, there is an error for ambiguity.
16 // It should be deferred since it involves wrong-sided candidates.
17 __device__ void callee(int);
18 __host__ void callee(float); // host-note {{candidate function}}
19 __host__ void callee(double); // host-note {{candidate function}}
21 // When callee2 is called by a device function without arguments, there is an error for 'no matching function'.
22 // It should be deferred since it involves wrong-sided candidates.
23 __host__ void callee2(); // dev-note{{candidate function not viable: call to __host__ function from __device__ function}}
25 // When callee3 is called by a device function without arguments, there is an error for 'no matching function'.
26 // It should be deferred since it involves wrong-sided candidates.
27 __host__ void callee3(); // dev-note{{candidate function not viable: call to __host__ function from __device__ function}}
28 __device__ void callee3(int); // dev-note{{candidate function not viable: requires 1 argument, but 0 were provided}}
30 // When callee4 is called by a host or device function without arguments, there is an error for 'no matching function'.
31 // It should be immediate since it involves no wrong-sided candidates (it is not a viable candiate due to signature).
32 __host__ void callee4(int); // com-note 2{{candidate function not viable: requires 1 argument, but 0 were provided}}
34 // When callee5 is called by a host function with integer arguments, there is an error for ambiguity.
35 // It should be immediate since it involves no wrong-sided candidates.
36 __host__ void callee5(float); // com-note {{candidate function}}
37 __host__ void callee5(double); // com-note {{candidate function}}
39 // When '<<` operator is called by a device function, there is error for 'invalid operands'.
40 // It should be deferred since it involves wrong-sided candidates.
42 __host__ S &operator <<(int i); // dev-note {{candidate function not viable}}
46 callee(1); // host-error {{call to 'callee' is ambiguous}}
49 callee4(); // com-error {{no matching function for call to 'callee4'}}
50 callee5(1); // com-error {{call to 'callee5' is ambiguous}}
53 undeclared_func(); // com-error {{use of undeclared identifier 'undeclared_func'}}
56 __device__ void df() {
58 callee2(); // dev-error {{no matching function for call to 'callee2'}}
59 callee3(); // dev-error {{no matching function for call to 'callee3'}}
60 callee4(); // com-error {{no matching function for call to 'callee4'}}
62 s << 1; // dev-error {{invalid operands to binary expression}}
65 struct A { int x; typedef int isA; };
68 // This function is invalid for A and B by SFINAE.
69 // This fails to substitue for A but no diagnostic
71 template<typename T, typename T::foo* = nullptr>
72 __host__ __device__ void sfinae(T t) { // host-note {{candidate template ignored: substitution failure [with T = B]}}
76 // This function is defined for A only by SFINAE.
77 // Calling it with A should succeed, with B should fail.
78 // The error should not be deferred since it happens in
81 template<typename T, typename T::isA* = nullptr>
82 __host__ __device__ void sfinae(T t) { // host-note {{candidate template ignored: substitution failure [with T = B]}}
88 sfinae(B()); // host-error{{no matching function for call to 'sfinae'}}
91 // Make sure throw is diagnosed in OpenMP parallel region in host function.
93 #pragma omp parallel for
94 for (int i = 0; i < 10; i++) {
99 // If a syntax error causes a function not declared, it cannot
102 inline __host__ __device__ void bad_func() { // com-note {{to match this '{'}}
103 // com-error {{expected '}'}}