xref: /llvm-project/clang/test/SemaSYCL/special-class-attribute.cpp (revision e692654a4dc017b0bddc4366b328dd6d68d2740a)
1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
2 
3 // No diagnostics
4 class [[clang::sycl_special_class]] class1 {
__init()5   void __init(){}
6 };
7 class __attribute__((sycl_special_class)) class2 {
__init()8   void __init(){}
9 };
10 
11 class class3;
12 class [[clang::sycl_special_class]] class3 {
__init()13   void __init(){}
14 };
15 
16 class class4;
17 class __attribute__((sycl_special_class)) class4 {
__init()18   void __init(){}
19 };
20 
21 struct [[clang::sycl_special_class]] struct1 {
__initstruct122   void __init(){}
23 };
24 struct __attribute__((sycl_special_class)) struct2 {
__initstruct225   void __init(){}
26 };
27 
28 class __attribute__((sycl_special_class)) class5;
29 class class5 {
__init()30   void __init(){}
31 };
32 
33 struct __attribute__((sycl_special_class)) struct6 {
34   struct6();
35   bool operator==(const struct6 &);
36   struct6 &operator()();
37   ~struct6();
__initstruct638   void __init(){}
39 };
40 
41 // Must have one and only one __init method defined
42 class __attribute__((sycl_special_class)) class6 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
class6()43   class6() {}
44 };
45 class [[clang::sycl_special_class]] class7 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
46   void __init();
47 };
48 
49 class [[clang::sycl_special_class]] class8 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
50   void __init();
func()51   int func() {}
__init(int a)52   void __init(int a){}
53 };
54 
55 struct __attribute__((sycl_special_class)) struct3;
56 struct struct3 {}; // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
57 
58 // expected-error@+1{{'sycl_special_class' attribute must have one and only one '__init' method defined}}
59 struct __attribute__((sycl_special_class)) struct7 {
60   struct7();
61   bool operator==(const struct7 &);
62   struct7 &operator()();
63   ~struct7();
64 };
65 
66 // Only classes
67 [[clang::sycl_special_class]] int var1 = 0;       // expected-warning {{'sycl_special_class' attribute only applies to classes}}
68 __attribute__((sycl_special_class)) int var2 = 0; // expected-warning {{'sycl_special_class' attribute only applies to classes}}
69 
70 [[clang::sycl_special_class]] void foo1();       // expected-warning {{'sycl_special_class' attribute only applies to classes}}
71 __attribute__((sycl_special_class)) void foo2(); // expected-warning {{'sycl_special_class' attribute only applies to classes}}
72 
73 // Attribute takes no arguments
74 class [[clang::sycl_special_class(1)]] class9{};         // expected-error {{'sycl_special_class' attribute takes no arguments}}
75 class __attribute__((sycl_special_class(1))) class10 {}; // expected-error {{'sycl_special_class' attribute takes no arguments}}
76 
77 // __init method must be defined inside the CXXRecordDecl.
78 class [[clang::sycl_special_class]] class11 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
79   void __init();
80 };
__init()81 void class11::__init(){}
82 
83 class __attribute__((sycl_special_class)) class12 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
84   void __init();
85 };
__init()86 void class12::__init(){}
87 
88 struct [[clang::sycl_special_class]] struct4 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
89   void __init();
90 };
__init()91 void struct4::__init(){}
92 
93 struct __attribute__((sycl_special_class)) struct5 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
94   void __init();
95 };
__init()96 void struct5::__init(){}
97