Debian Codegraph @

clang/test/SemaSYCL/sycl-kernel-entry-point-attr-sfinae.cpp

raw
1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++17 -fsyntax-only -fsycl-is-device -verify %s
2 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++20 -fsyntax-only -fsycl-is-device -verify %s
3
4 // These tests are intended to validate that a sycl_kernel_entry_point attribute
5 // appearing in the declaration of a function template does not affect overload
6 // resolution or cause spurious errors during overload resolution due to either
7 // a substitution failure in the attribute argument or a semantic check of the
8 // attribute during instantiation of a specialization unless that specialization
9 // is selected by overload resolution.
10
11 // FIXME: C++23 [temp.expl.spec]p12 states:
12 // FIXME: ... Similarly, attributes appearing in the declaration of a template
13 // FIXME: have no effect on an explicit specialization of that template.
14 // FIXME: Clang currently instantiates and propagates attributes from a function
15 // FIXME: template to its explicit specializations resulting in the following
16 // FIXME: spurious error.
17 struct S1; // #S1-decl
18 // expected-error@+4 {{incomplete type 'S1' named in nested name specifier}}
19 // expected-note@+5 {{in instantiation of function template specialization 'ok1<S1>' requested here}}
20 // expected-note@#S1-decl {{forward declaration of 'S1'}}
21 template<typename T>
22 [[clang::sycl_kernel_entry_point(typename T::invalid)]] void ok1() {}
23 template<>
24 void ok1<S1>() {}
25 void test_ok1() {
26 // ok1<S1>() is not a call to a SYCL kernel entry point function.
27 ok1<S1>();
28 }
29
30 // FIXME: The sycl_kernel_entry_point attribute should not be instantiated
31 // FIXME: until after overload resolution has completed.
32 struct S2; // #S2-decl
33 // expected-error@+6 {{incomplete type 'S2' named in nested name specifier}}
34 // expected-note@+10 {{in instantiation of function template specialization 'ok2<S2>' requested here}}
35 // expected-note@#S2-decl {{forward declaration of 'S2'}}
36 template<typename T>
37 [[clang::sycl_kernel_entry_point(T)]] void ok2(int) {}
38 template<typename T>
39 [[clang::sycl_kernel_entry_point(typename T::invalid)]] void ok2(long) {}
40 void test_ok2() {
41 // ok2(int) is a better match and is therefore selected by overload
42 // resolution; the attempted instantiation of ok2(long) should not produce
43 // an error for the substitution failure into the attribute argument.
44 ok2<S2>(2);
45 }
46
47 // FIXME: The sycl_kernel_entry_point attribute should not be instantiated
48 // FIXME: until after overload resolution has completed.
49 struct S3;
50 struct Select3 {
51 using bad_type = int;
52 using good_type = S3;
53 };
54 // expected-error@+5 {{'typename Select3::bad_type' (aka 'int') is not a valid SYCL kernel name type; a non-union class type is required}}
55 // expected-note@+9 {{in instantiation of function template specialization 'ok3<Select3>' requested here}}
56 template<typename T>
57 [[clang::sycl_kernel_entry_point(typename T::good_type)]] void ok3(int) {}
58 template<typename T>
59 [[clang::sycl_kernel_entry_point(typename T::bad_type)]] void ok3(long) {}
60 void test_ok3() {
61 // ok3(int) is a better match and is therefore selected by overload
62 // resolution; the attempted instantiation of ok3(long) should not produce
63 // an error for the invalid kernel name provided as the attribute argument.
64 ok3<Select3>(2);
65 }