1 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -verify -fopenmp -x c++ -std=c++14 -fms-extensions -Wno-pragma-pack -fexceptions -fcxx-exceptions %s
2 
3 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -verify -fopenmp-simd -x c++ -std=c++14 -fms-extensions -Wno-pragma-pack -fexceptions -fcxx-exceptions %s
4 
5 // expected-error@+1 {{expected an OpenMP directive}}
6 #pragma omp declare
7 
8 int foo();
9 
10 template <typename T>
11 T foofoo();
12 
13 #pragma omp declare variant                                  // expected-error {{expected '(' after 'declare variant'}}
14 #pragma omp declare variant(                                 // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
15 #pragma omp declare variant(foo                              // expected-error {{expected ')'}} expected-error {{expected 'match' clause on 'omp declare variant' directive}} expected-note {{to match this '('}}
16 #pragma omp declare variant(x)                               // expected-error {{use of undeclared identifier 'x'}}
17 #pragma omp declare variant(foo)                             // expected-error {{expected 'match' clause on 'omp declare variant' directive}}
18 #pragma omp declare variant(foofoo <int>)                    // expected-error {{expected 'match' clause on 'omp declare variant' directive}}
19 #pragma omp declare variant(foofoo <int>) xxx                // expected-error {{expected 'match' clause on 'omp declare variant' directive}}
20 #pragma omp declare variant(foofoo <int>) match              // expected-error {{expected '(' after 'match'}}
21 #pragma omp declare variant(foofoo <int>) match(             // expected-error {{expected context selector in 'match' clause on 'omp declare variant' directive}}
22 #pragma omp declare variant(foofoo <int>) match()            // expected-error {{expected context selector in 'match' clause on 'omp declare variant' directive}}
23 #pragma omp declare variant(foofoo <int>) match(xxx)         // expected-error {{expected '=' after 'xxx' context selector set name on 'omp declare variant' directive}}
24 #pragma omp declare variant(foofoo <int>) match(xxx =)       // expected-error {{expected '{' after '='}}
25 #pragma omp declare variant(foofoo <int>) match(xxx = yyy)   // expected-error {{expected '{' after '='}}
26 #pragma omp declare variant(foofoo <int>) match(xxx = yyy }) // expected-error {{expected '{' after '='}}
27 #pragma omp declare variant(foofoo <int>) match(xxx = {)     // expected-error {{expected '}'}} expected-note {{to match this '{'}}
28 #pragma omp declare variant(foofoo <int>) match(xxx = {})
29 #pragma omp declare variant(foofoo <int>) match(xxx = {vvv})
30 #pragma omp declare variant(foofoo <int>) match(xxx = {vvv} xxx) // expected-error {{expected ','}} expected-error {{expected '=' after 'xxx' context selector set name on 'omp declare variant' directive}}
31 #pragma omp declare variant(foofoo <int>) match(xxx = {vvv}) xxx // expected-warning {{extra tokens at the end of '#pragma omp declare variant' are ignored}}
32 #pragma omp declare variant(foofoo <int>) match(implementation={xxx}) // expected-warning {{unknown context selector in 'implementation' context selector set of 'omp declare variant' directive, ignored}}
33 #pragma omp declare variant(foofoo <int>) match(implementation={vendor}) // expected-error {{expected '(' after 'vendor'}} expected-error {{expected vendor identifier in 'vendor' context selector of 'implementation' selector set of 'omp declare variant' directive}} expected-error {{expected ')'}} expected-note {{to match this '('}}
34 #pragma omp declare variant(foofoo <int>) match(implementation={vendor(}) // expected-error {{expected vendor identifier in 'vendor' context selector of 'implementation' selector set of 'omp declare variant' directive}} expected-error {{expected ')'}} expected-note {{to match this '('}}
35 #pragma omp declare variant(foofoo <int>) match(implementation={vendor()}) // expected-error {{expected vendor identifier in 'vendor' context selector of 'implementation' selector set of 'omp declare variant' directive}}
36 int bar();
37 
38 #pragma omp declare variant                            // expected-error {{expected '(' after 'declare variant'}}
39 #pragma omp declare variant(                           // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
40 #pragma omp declare variant(foofoo <T>                 // expected-error {{expected ')'}} expected-error {{expected 'match' clause on 'omp declare variant' directive}} expected-note {{to match this '('}}
41 #pragma omp declare variant(x)                         // expected-error {{use of undeclared identifier 'x'}}
42 #pragma omp declare variant(foo)                       // expected-error {{expected 'match' clause on 'omp declare variant' directive}}
43 #pragma omp declare variant(foofoo)                    // expected-error {{expected 'match' clause on 'omp declare variant' directive}}
44 #pragma omp declare variant(foofoo <T>)                // expected-error {{expected 'match' clause on 'omp declare variant' directive}}
45 #pragma omp declare variant(foofoo <T>) xxx            // expected-error {{expected 'match' clause on 'omp declare variant' directive}}
46 #pragma omp declare variant(foofoo <T>) match          // expected-error {{expected '(' after 'match'}}
47 #pragma omp declare variant(foofoo <T>) match(         // expected-error {{expected context selector in 'match' clause on 'omp declare variant' directive}}
48 #pragma omp declare variant(foofoo <T>) match()        // expected-error {{expected context selector in 'match' clause on 'omp declare variant' directive}}
49 #pragma omp declare variant(foofoo <T>) match(xxx)     // expected-error {{expected '=' after 'xxx' context selector set name on 'omp declare variant' directive}}
50 #pragma omp declare variant(foofoo <T>) match(xxx =)   // expected-error {{expected '{' after '='}}
51 #pragma omp declare variant(foofoo <T>) match(xxx = {) // expected-error {{expected '}'}} expected-note {{to match this '{'}}
52 #pragma omp declare variant(foofoo <T>) match(xxx = {})
53 #pragma omp declare variant(foofoo <T>) match(xxx = {vvv})
54 #pragma omp declare variant(foofoo <T>) match(user = {score(<expr>) : condition(<expr>)})
55 #pragma omp declare variant(foofoo <T>) match(user = {score(<expr>) : condition(<expr>)})
56 #pragma omp declare variant(foofoo <T>) match(user = {condition(<expr>)})
57 #pragma omp declare variant(foofoo <T>) match(user = {condition(<expr>)})
58 #pragma omp declare variant(foofoo <T>) match(xxx = {vvv} xxx) // expected-error {{expected ','}} expected-error {{expected '=' after 'xxx' context selector set name on 'omp declare variant' directive}}
59 #pragma omp declare variant(foofoo <T>) match(xxx = {vvv}) xxx // expected-warning {{extra tokens at the end of '#pragma omp declare variant' are ignored}}
60 template <typename T>
61 T barbar();
62 
63 // expected-error@+2 {{'#pragma omp declare variant' can only be applied to functions}}
64 #pragma omp declare variant(barbar <int>) match(xxx = {})
65 int a;
66 // expected-error@+2 {{'#pragma omp declare variant' can only be applied to functions}}
67 #pragma omp declare variant(barbar <int>) match(xxx = {})
68 #pragma omp threadprivate(a)
69 int var;
70 #pragma omp threadprivate(var)
71 
72 // expected-error@+2 {{expected an OpenMP directive}} expected-error@+1 {{function declaration is expected after 'declare variant' directive}}
73 #pragma omp declare variant(barbar <int>) match(xxx = {})
74 #pragma omp declare
75 
76 // expected-error@+3 {{function declaration is expected after 'declare variant' directive}}
77 // expected-error@+1 {{function declaration is expected after 'declare variant' directive}}
78 #pragma omp declare variant(barbar <int>) match(xxx = {})
79 #pragma omp declare variant(barbar <int>) match(xxx = {})
80 #pragma options align = packed
81 int main();
82 
83 // expected-error@+3 {{function declaration is expected after 'declare variant' directive}}
84 // expected-error@+1 {{function declaration is expected after 'declare variant' directive}}
85 #pragma omp declare variant(barbar <int>) match(xxx = {})
86 #pragma omp declare variant(barbar <int>) match(xxx = {})
87 #pragma init_seg(compiler)
88 int main();
89 
90 // expected-error@+1 {{single declaration is expected after 'declare variant' directive}}
91 #pragma omp declare variant(barbar <int>) match(xxx = {})
92 int b, c;
93 
94 // expected-error@+1 {{'C' does not refer to a value}}
95 #pragma omp declare variant(C) match(xxx = {})
96 // expected-note@+1 {{declared here}}
97 template <class C>
98 void h(C *hp, C *hp2, C *hq, C *lin) {
99   b = 0;
100 }
101 
102 // expected-error@+1 {{variant in '#pragma omp declare variant' with type '<overloaded function type>' is incompatible with type 'void (*)(int *, int *, int *, int *)'}}
103 #pragma omp declare variant(barbar <int>) match(xxx = {})
104 template <>
105 void h(int *hp, int *hp2, int *hq, int *lin);
106 
107 int after_use_variant(void);
108 int after_use();
109 int bar() {
110   return after_use();
111 }
112 
113 // expected-warning@+1 {{'#pragma omp declare variant' cannot be applied for function after first usage; the original function might be used}}
114 #pragma omp declare variant(after_use_variant) match(xxx = {})
115 int after_use(void);
116 
117 int fn();
118 int fn(int);
119 #pragma omp declare variant(fn) match(xxx = {})
120 int overload(void);
121 
122 int fn1();
123 int fn1(int);
124 // expected-error@+1 {{variant in '#pragma omp declare variant' with type '<overloaded function type>' is incompatible with type 'int (*)(float)'}}
125 #pragma omp declare variant(fn1) match(xxx = {})
126 int overload1(float);
127 
128 int fn_constexpr_variant();
129 // expected-error@+2 {{'#pragma omp declare variant' does not support constexpr functions}}
130 #pragma omp declare variant(fn_constexpr_variant) match(xxx = {})
131 constexpr int fn_constexpr();
132 
133 constexpr int fn_constexpr_variant1();
134 // expected-error@+1 {{'#pragma omp declare variant' does not support constexpr functions}}
135 #pragma omp declare variant(fn_constexpr_variant1) match(xxx = {})
136 int fn_constexpr1();
137 
138 int fn_sc_variant();
139 // expected-error@+1 {{function with '#pragma omp declare variant' has a different storage class}}
140 #pragma omp declare variant(fn_sc_variant) match(xxx = {})
141 static int fn_sc();
142 
143 static int fn_sc_variant1();
144 // expected-error@+1 {{function with '#pragma omp declare variant' has a different storage class}}
145 #pragma omp declare variant(fn_sc_variant1) match(xxx = {})
146 int fn_sc1();
147 
148 int fn_inline_variant();
149 // expected-error@+1 {{function with '#pragma omp declare variant' has a different inline specification}}
150 #pragma omp declare variant(fn_inline_variant) match(xxx = {})
151 inline int fn_inline();
152 
153 inline int fn_inline_variant1();
154 // expected-error@+1 {{function with '#pragma omp declare variant' has a different inline specification}}
155 #pragma omp declare variant(fn_inline_variant1) match(xxx = {})
156 int fn_inline1();
157 
158 int fn_linkage_variant();
159 extern "C" {
160 // expected-error@+1 {{function with '#pragma omp declare variant' has a different linkage}}
161 #pragma omp declare variant(fn_linkage_variant) match(xxx = {})
162 int fn_linkage();
163 }
164 
165 extern "C" int fn_linkage_variant1();
166 // expected-error@+1 {{function with '#pragma omp declare variant' has a different linkage}}
167 #pragma omp declare variant(fn_linkage_variant1) match(xxx = {})
168 int fn_linkage1();
169 
170 auto fn_deduced_variant() { return 0; }
171 #pragma omp declare variant(fn_deduced_variant) match(xxx = {})
172 int fn_deduced();
173 
174 int fn_deduced_variant1();
175 #pragma omp declare variant(fn_deduced_variant1) match(xxx = {})
176 auto fn_deduced1() { return 0; }
177 
178 auto fn_deduced3() { return 0; }
179 // expected-warning@+1 {{'#pragma omp declare variant' cannot be applied to the function that was defined already; the original function might be used}}
180 #pragma omp declare variant(fn_deduced_variant1) match(xxx = {})
181 auto fn_deduced3();
182 
183 auto fn_deduced_variant2() { return 0; }
184 // expected-error@+1 {{variant in '#pragma omp declare variant' with type 'int ()' is incompatible with type 'float (*)()'}}
185 #pragma omp declare variant(fn_deduced_variant2) match(xxx = {})
186 float fn_deduced2();
187 
188 // expected-error@+1 {{exception specification in declaration does not match previous declaration}}
189 int fn_except_variant() noexcept(true);
190 // expected-note@+2 {{previous declaration is here}}
191 #pragma omp declare variant(fn_except_variant) match(xxx = {})
192 int fn_except() noexcept(false);
193 
194 // expected-error@+1 {{exception specification in declaration does not match previous declaration}}
195 int fn_except_variant1() noexcept(false);
196 // expected-note@+2 {{previous declaration is here}}
197 #pragma omp declare variant(fn_except_variant1) match(xxx = {})
198 int fn_except1() noexcept(true);
199 
200 struct SpecialFuncs {
201   void vd();
202   // expected-error@+2 {{'#pragma omp declare variant' does not support constructors}}
203 #pragma omp declare variant(SpecialFuncs::vd) match(xxx = {})
204   SpecialFuncs();
205   // expected-error@+2 {{'#pragma omp declare variant' does not support destructors}}
206 #pragma omp declare variant(SpecialFuncs::vd) match(xxx = {})
207   ~SpecialFuncs();
208 
209   void baz();
210   void bar();
211   void bar(int);
212 #pragma omp declare variant(SpecialFuncs::baz) match(xxx = {})
213 #pragma omp declare variant(SpecialFuncs::bar) match(xxx = {})
214   void foo1();
215   SpecialFuncs& foo(const SpecialFuncs&);
216   SpecialFuncs& bar(SpecialFuncs&&);
217   // expected-error@+2 {{'#pragma omp declare variant' does not support defaulted functions}}
218 #pragma omp declare variant(SpecialFuncs::foo) match(xxx = {})
219   SpecialFuncs& operator=(const SpecialFuncs&) = default;
220   // expected-error@+2 {{'#pragma omp declare variant' does not support deleted functions}}
221 #pragma omp declare variant(SpecialFuncs::bar) match(xxx = {})
222   SpecialFuncs& operator=(SpecialFuncs&&) = delete;
223 };
224 
225 namespace N {
226 // expected-error@+1 {{function declaration is expected after 'declare variant' directive}}
227 #pragma omp declare variant
228 } // namespace N
229 // expected-error@+1 {{function declaration is expected after 'declare variant' directive}}
230 #pragma omp declare variant
231 // expected-error@+1 {{function declaration is expected after 'declare variant' directive}}
232 #pragma omp declare variant
233