llvm-project
348 строк · 21.1 Кб
1// RUN: sed -e "s@ATTR_USE@__arm_streaming@g" -e "s@ATTR_NAME@__arm_streaming@g" %s > %t
2// RUN: %clang_cc1 -fcxx-exceptions -fdeclspec -fexceptions -fsyntax-only -verify -std=c++11 -Wc++14-compat -Wc++14-extensions -Wc++17-extensions -triple aarch64-none-linux-gnu -target-feature +sme -x c++ %t
3// RUN: sed -e "s@ATTR_USE@__arm_inout\(\"za\"\)@g" -e "s@ATTR_NAME@__arm_inout@g" %s > %t
4// RUN: %clang_cc1 -fcxx-exceptions -fdeclspec -fexceptions -fsyntax-only -verify -std=c++11 -Wc++14-compat -Wc++14-extensions -Wc++17-extensions -triple aarch64-none-linux-gnu -target-feature +sme -x c++ %t
5
6// Need std::initializer_list
7namespace std {
8typedef decltype(sizeof(int)) size_t;
9
10// libc++'s implementation
11template <class _E>
12class initializer_list
13{
14const _E* __begin_;
15size_t __size_;
16
17initializer_list(const _E* __b, size_t __s)
18: __begin_(__b),
19__size_(__s)
20{}
21
22public:
23typedef _E value_type;
24typedef const _E& reference;
25typedef const _E& const_reference;
26typedef size_t size_type;
27
28typedef const _E* iterator;
29typedef const _E* const_iterator;
30
31initializer_list() : __begin_(nullptr), __size_(0) {}
32
33size_t size() const {return __size_;}
34const _E* begin() const {return __begin_;}
35const _E* end() const {return __begin_ + __size_;}
36};
37}
38
39
40// Declaration syntax checks
41ATTR_USE int before_attr; // expected-error {{'ATTR_NAME' only applies to function types}}
42int ATTR_USE between_attr; // expected-error {{'ATTR_NAME' only applies to function types}}
43const ATTR_USE int between_attr_2 = 0; // expected-error {{'ATTR_NAME' cannot appear here}}
44int after_attr ATTR_USE; // expected-error {{'ATTR_NAME' only applies to function types}}
45int * ATTR_USE ptr_attr; // expected-error {{'ATTR_NAME' only applies to function types}}
46int & ATTR_USE ref_attr = after_attr; // expected-error {{'ATTR_NAME' only applies to function types}}
47int && ATTR_USE rref_attr = 0; // expected-error {{'ATTR_NAME' only applies to function types}}
48int array_attr [1] ATTR_USE; // expected-error {{'ATTR_NAME' only applies to function types}}
49void fn_attr () ATTR_USE;
50void noexcept_fn_attr () noexcept ATTR_USE;
51struct MemberFnOrder {
52virtual void f() const volatile && noexcept ATTR_USE final = 0;
53};
54struct ATTR_USE struct_attr; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
55class ATTR_USE class_attr {}; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
56union ATTR_USE union_attr; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
57enum ATTR_USE E { }; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
58namespace test_misplacement {
59ATTR_USE struct struct_attr2; // expected-error {{misplaced 'ATTR_NAME'}}
60ATTR_USE class class_attr2; // expected-error {{misplaced 'ATTR_NAME'}}
61ATTR_USE union union_attr2; // expected-error {{misplaced 'ATTR_NAME'}}
62ATTR_USE enum E2 { }; // expected-error {{misplaced 'ATTR_NAME'}}
63}
64
65// Checks attributes placed at wrong syntactic locations of class specifiers.
66class ATTR_USE ATTR_USE // expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}
67attr_after_class_name_decl ATTR_USE ATTR_USE; // expected-error {{'ATTR_NAME' cannot appear here}} \
68expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}
69
70class ATTR_USE ATTR_USE // expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}
71attr_after_class_name_definition ATTR_USE ATTR_USE ATTR_USE{}; // expected-error {{'ATTR_NAME' cannot appear here}} \
72expected-error 3 {{'ATTR_NAME' only applies to non-K&R-style functions}}
73
74class ATTR_USE c {}; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
75class c ATTR_USE ATTR_USE x; // expected-error 2 {{'ATTR_NAME' only applies to function types}}
76class c ATTR_USE ATTR_USE y ATTR_USE ATTR_USE; // expected-error 4 {{'ATTR_NAME' only applies to function types}}
77class c final [(int){0}];
78
79class base {};
80class ATTR_USE ATTR_USE final_class // expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}
81ATTR_USE alignas(float) final // expected-error {{'ATTR_NAME' cannot appear here}} \
82expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
83ATTR_USE alignas(float) ATTR_USE alignas(float): base{}; // expected-error {{'ATTR_NAME' cannot appear here}}
84
85class ATTR_USE ATTR_USE final_class_another // expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}
86ATTR_USE ATTR_USE alignas(16) final // expected-error {{'ATTR_NAME' cannot appear here}} \
87expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}
88ATTR_USE ATTR_USE alignas(16) ATTR_USE{}; // expected-error {{'ATTR_NAME' cannot appear here}}
89
90class after_class_close {} ATTR_USE; // expected-error {{'ATTR_NAME' cannot appear here, place it after "class" to apply it to the type declaration}}
91
92class C {};
93
94ATTR_USE struct with_init_declarators {} init_declarator; // expected-error {{'ATTR_NAME' only applies to function types}}
95ATTR_USE struct no_init_declarators; // expected-error {{misplaced 'ATTR_NAME'}}
96template<typename> ATTR_USE struct no_init_declarators_template; // expected-error {{'ATTR_NAME' cannot appear here}}
97void fn_with_structs() {
98ATTR_USE struct with_init_declarators {} init_declarator; // expected-error {{'ATTR_NAME' only applies to function types}}
99ATTR_USE struct no_init_declarators; // expected-error {{'ATTR_NAME' cannot appear here}}
100}
101ATTR_USE; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
102struct ctordtor {
103ATTR_USE ctordtor ATTR_USE () ATTR_USE; // expected-error 2 {{'ATTR_NAME' cannot be applied to a declaration}}
104ctordtor (C) ATTR_USE;
105ATTR_USE ~ctordtor ATTR_USE () ATTR_USE; // expected-error 2 {{'ATTR_NAME' cannot be applied to a declaration}}
106};
107ATTR_USE ctordtor::ctordtor ATTR_USE () ATTR_USE {} // expected-error 2 {{'ATTR_NAME' cannot be applied to a declaration}}
108ATTR_USE ctordtor::ctordtor (C) ATTR_USE try {} catch (...) {} // expected-error {{'ATTR_NAME' cannot be applied to a declaration}}
109ATTR_USE ctordtor::~ctordtor ATTR_USE () ATTR_USE {} // expected-error 2 {{'ATTR_NAME' cannot be applied to a declaration}}
110extern "C++" ATTR_USE int extern_attr; // expected-error {{'ATTR_NAME' only applies to function types}}
111template <typename T> ATTR_USE void template_attr (); // expected-error {{'ATTR_NAME' cannot be applied to a declaration}}
112ATTR_USE ATTR_USE int ATTR_USE ATTR_USE multi_attr ATTR_USE ATTR_USE; // expected-error 6 {{'ATTR_NAME' only applies to function types}}
113
114int (paren_attr) ATTR_USE; // expected-error {{'ATTR_NAME' cannot appear here}}
115unsigned ATTR_USE int attr_in_decl_spec; // expected-error {{'ATTR_NAME' cannot appear here}}
116unsigned ATTR_USE int ATTR_USE const double_decl_spec = 0; // expected-error 2 {{'ATTR_NAME' cannot appear here}}
117class foo {
118void const_after_attr () ATTR_USE const; // expected-error {{expected ';'}}
119};
120extern "C++" ATTR_USE { } // expected-error {{'ATTR_NAME' cannot appear here}}
121ATTR_USE extern "C++" { } // expected-error {{'ATTR_NAME' cannot appear here}}
122ATTR_USE template <typename T> void before_template_attr (); // expected-error {{'ATTR_NAME' cannot appear here}}
123ATTR_USE namespace ns { int i; } // expected-error {{'ATTR_NAME' cannot appear here}}
124ATTR_USE static_assert(true, ""); //expected-error {{'ATTR_NAME' cannot appear here}}
125ATTR_USE asm(""); // expected-error {{'ATTR_NAME' cannot appear here}}
126
127ATTR_USE using ns::i; // expected-warning {{ISO C++}} \
128expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
129ATTR_USE using namespace ns; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
130namespace ATTR_USE ns2 {} // expected-warning {{attributes on a namespace declaration are a C++17 extension}} \
131expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
132
133using ATTR_USE alignas(4)ATTR_USE ns::i; // expected-warning 2 {{ISO C++}} \
134expected-error {{'ATTR_NAME' cannot appear here}} \
135expected-error {{'alignas' attribute only applies to variables, data members and tag types}} \
136expected-warning {{ISO C++}} \
137expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}
138using ATTR_USE alignas(4) ATTR_USE foobar = int; // expected-error {{'ATTR_NAME' cannot appear here}} \
139expected-error {{'alignas' attribute only applies to}} \
140expected-error 2 {{'ATTR_NAME' only applies to function types}}
141
142ATTR_USE using T = int; // expected-error {{'ATTR_NAME' cannot appear here}}
143using T ATTR_USE = int; // expected-error {{'ATTR_NAME' only applies to function types}}
144template<typename T> using U ATTR_USE = T; // expected-error {{'ATTR_NAME' only applies to function types}}
145using ns::i ATTR_USE; // expected-warning {{ISO C++}} \
146expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
147using ns::i ATTR_USE, ns::i ATTR_USE; // expected-warning 2 {{ISO C++}} \
148expected-warning {{use of multiple declarators in a single using declaration is a C++17 extension}} \
149expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}
150struct using_in_struct_base {
151typedef int i, j, k, l;
152};
153struct using_in_struct : using_in_struct_base {
154ATTR_USE using using_in_struct_base::i; // expected-warning {{ISO C++}} \
155expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
156using using_in_struct_base::j ATTR_USE; // expected-warning {{ISO C++}} \
157expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
158ATTR_USE using using_in_struct_base::k ATTR_USE, using_in_struct_base::l ATTR_USE; // expected-warning 3 {{ISO C++}} \
159expected-warning {{use of multiple declarators in a single using declaration is a C++17 extension}} \
160expected-error 4 {{'ATTR_NAME' only applies to non-K&R-style functions}}
161};
162using ATTR_USE ns::i; // expected-warning {{ISO C++}} \
163expected-error {{'ATTR_NAME' cannot appear here}} \
164expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
165using T ATTR_USE = int; // expected-error {{'ATTR_NAME' only applies to function types}}
166
167auto trailing() -> ATTR_USE const int; // expected-error {{'ATTR_NAME' cannot appear here}}
168auto trailing() -> const ATTR_USE int; // expected-error {{'ATTR_NAME' cannot appear here}}
169auto trailing() -> const int ATTR_USE; // expected-error {{'ATTR_NAME' only applies to function types}}
170auto trailing_2() -> struct struct_attr ATTR_USE; // expected-error {{'ATTR_NAME' only applies to function types}}
171
172namespace N {
173struct S {};
174};
175template<typename> struct Template {};
176
177// FIXME: Improve this diagnostic
178struct ATTR_USE N::S s; // expected-error {{'ATTR_NAME' cannot appear here}}
179struct ATTR_USE Template<int> t; // expected-error {{'ATTR_NAME' cannot appear here}}
180struct ATTR_USE ::template Template<int> u; // expected-error {{'ATTR_NAME' cannot appear here}}
181template struct ATTR_USE Template<char>; // expected-error {{'ATTR_NAME' cannot appear here}}
182template struct __attribute__((pure)) Template<std::size_t>; // We still allow GNU-style attributes here
183template <> struct ATTR_USE Template<void>; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
184
185enum ATTR_USE E1 {}; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
186enum ATTR_USE E2; // expected-error {{forbids forward references}} \
187expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
188enum ATTR_USE E1; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
189enum ATTR_USE E3 : int; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
190enum ATTR_USE { // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
191k_123 ATTR_USE = 123 // expected-warning {{attributes on an enumerator declaration are a C++17 extension}} \
192expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
193};
194enum ATTR_USE E1 e; // expected-error {{'ATTR_NAME' cannot appear here}}
195enum ATTR_USE class E4 { }; // expected-error {{'ATTR_NAME' cannot appear here}}
196enum struct ATTR_USE E5; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
197enum E6 {} ATTR_USE; // expected-error {{'ATTR_NAME' cannot appear here, place it after "enum" to apply it to the type declaration}}
198
199struct S {
200friend int f ATTR_USE (); // expected-error {{'ATTR_NAME' cannot appear here}} \
201expected-error {{'ATTR_NAME' cannot be applied to a declaration}}
202friend int f2 ATTR_USE () {} // expected-error {{'ATTR_NAME' cannot be applied to a declaration}}
203ATTR_USE friend int g(); // expected-error {{'ATTR_NAME' cannot appear here}}
204ATTR_USE friend int h() { // expected-error {{'ATTR_NAME' cannot be applied to a declaration}}
205}
206ATTR_USE friend int f3(), f4(), f5(); // expected-error {{'ATTR_NAME' cannot appear here}}
207friend int f6 ATTR_USE (), f7 ATTR_USE (), f8 ATTR_USE (); // expected-error3 {{'ATTR_NAME' cannot appear here}} \
208expected-error 3 {{'ATTR_NAME' cannot be applied to a declaration}}
209friend class ATTR_USE C; // expected-error {{'ATTR_NAME' cannot appear here}}
210ATTR_USE friend class D; // expected-error {{'ATTR_NAME' cannot appear here}}
211ATTR_USE friend int; // expected-error {{'ATTR_NAME' cannot appear here}}
212};
213template<typename T> void tmpl (T) {}
214template ATTR_USE void tmpl(char); // expected-error {{'ATTR_NAME' cannot appear here}}
215template void ATTR_USE tmpl(short); // expected-error {{'ATTR_NAME' only applies to function types}}
216
217// Statement tests
218void foo () {
219ATTR_USE ; // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
220ATTR_USE { } // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
221ATTR_USE if (0) { } // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
222ATTR_USE for (;;); // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
223ATTR_USE do { // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
224ATTR_USE continue; // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
225} while (0);
226ATTR_USE while (0); // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
227
228ATTR_USE switch (i) { // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
229ATTR_USE case 0: // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
230ATTR_USE default: // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
231ATTR_USE break; // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
232}
233
234ATTR_USE goto there; // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
235ATTR_USE there: // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
236
237ATTR_USE try { // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
238} ATTR_USE catch (...) { // expected-error {{'ATTR_NAME' cannot appear here}}
239}
240
241void bar ATTR_USE (ATTR_USE int i, ATTR_USE int j); // expected-error 2 {{'ATTR_NAME' only applies to function types}} \
242expected-error {{'ATTR_NAME' cannot be applied to a declaration}}
243using FuncType = void (ATTR_USE int); // expected-error {{'ATTR_NAME' only applies to function types}}
244void baz(ATTR_USE...); // expected-error {{expected parameter declarator}}
245
246ATTR_USE return; // expected-error {{'ATTR_NAME' cannot be applied to a statement}}
247}
248
249// Expression tests
250void bar () {
251new int[42]ATTR_USE[5]ATTR_USE{}; // expected-error {{'ATTR_NAME' only applies to function types}}
252}
253
254// Condition tests
255void baz () {
256if (ATTR_USE bool b = true) { // expected-error {{'ATTR_NAME' only applies to function types}}
257switch (ATTR_USE int n { 42 }) { // expected-error {{'ATTR_NAME' only applies to function types}}
258default:
259for (ATTR_USE int n = 0; ATTR_USE char b = n < 5; ++b) { // expected-error 2 {{'ATTR_NAME' only applies to function types}}
260}
261}
262}
263int x;
264// An attribute can be applied to an expression-statement, such as the first
265// statement in a for. But it can't be applied to a condition which is an
266// expression.
267for (ATTR_USE x = 0; ; ) {} // expected-error {{'ATTR_NAME' cannot appear here}}
268for (; ATTR_USE x < 5; ) {} // expected-error {{'ATTR_NAME' cannot appear here}}
269while (ATTR_USE bool k { false }) { // expected-error {{'ATTR_NAME' only applies to function types}}
270}
271while (ATTR_USE true) { // expected-error {{'ATTR_NAME' cannot appear here}}
272}
273do {
274} while (ATTR_USE false); // expected-error {{'ATTR_NAME' cannot appear here}}
275
276for (ATTR_USE int n : { 1, 2, 3 }) { // expected-error {{'ATTR_NAME' only applies to function types}}
277}
278}
279
280enum class __attribute__((visibility("hidden"))) SecretKeepers {
281one, /* rest are deprecated */ two, three
282};
283enum class ATTR_USE EvenMoreSecrets {}; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
284
285// Forbid attributes on decl specifiers.
286unsigned ATTR_USE static int ATTR_USE v1; // expected-error {{'ATTR_NAME' only applies to function types}} \
287expected-error {{'ATTR_NAME' cannot appear here}}
288typedef ATTR_USE unsigned long ATTR_USE v2; // expected-error {{'ATTR_NAME' only applies to function types}} \
289expected-error {{'ATTR_NAME' cannot appear here}}
290int ATTR_USE foo(int ATTR_USE x); // expected-error 2 {{'ATTR_NAME' only applies to function types}}
291
292ATTR_USE; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}
293
294class A {
295A(ATTR_USE int a); // expected-error {{'ATTR_NAME' only applies to function types}}
296};
297A::A(ATTR_USE int a) {} // expected-error {{'ATTR_NAME' only applies to function types}}
298
299template<typename T> struct TemplateStruct {};
300class FriendClassesWithAttributes {
301// We allow GNU-style attributes here
302template <class _Tp, class _Alloc> friend class __attribute__((__type_visibility__("default"))) vector;
303template <class _Tp, class _Alloc> friend class __declspec(code_seg("foo,whatever")) vector2;
304// But not C++11 ones
305template <class _Tp, class _Alloc> friend class ATTR_USE vector3; // expected-error {{'ATTR_NAME' cannot appear here}}
306
307// Also allowed
308friend struct __attribute__((__type_visibility__("default"))) TemplateStruct<FriendClassesWithAttributes>;
309friend struct __declspec(code_seg("foo,whatever")) TemplateStruct<FriendClassesWithAttributes>;
310friend struct ATTR_USE TemplateStruct<FriendClassesWithAttributes>; // expected-error {{'ATTR_NAME' cannot appear here}}
311};
312
313// Check ordering: C++11 attributes must appear before GNU attributes.
314class Ordering {
315void f1(
316int (ATTR_USE __attribute__(()) int n) // expected-error {{'ATTR_NAME' only applies to function types}}
317) {
318}
319
320void f2(
321int (*)(ATTR_USE __attribute__(()) int n) // expected-error {{'ATTR_NAME' only applies to function types}}
322) {
323}
324
325void f3(
326int (__attribute__(()) ATTR_USE int n) // expected-error {{'ATTR_NAME' cannot appear here}}
327) {
328}
329
330void f4(
331int (*)(__attribute__(()) ATTR_USE int n) // expected-error {{'ATTR_NAME' cannot appear here}}
332) {
333}
334};
335
336namespace base_specs {
337struct A {};
338struct B : ATTR_USE A {}; // expected-error {{'ATTR_NAME' cannot be applied to a base specifier}}
339struct C : ATTR_USE virtual A {}; // expected-error {{'ATTR_NAME' cannot be applied to a base specifier}}
340struct D : ATTR_USE public virtual A {}; // expected-error {{'ATTR_NAME' cannot be applied to a base specifier}}
341struct E : public ATTR_USE virtual A {}; // expected-error {{'ATTR_NAME' cannot appear here}} \
342expected-error {{'ATTR_NAME' cannot be applied to a base specifier}}
343struct F : virtual ATTR_USE public A {}; // expected-error {{'ATTR_NAME' cannot appear here}} \
344expected-error {{'ATTR_NAME' cannot be applied to a base specifier}}
345}
346
347namespace ATTR_USE ns_attr {}; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}} \
348expected-warning {{attributes on a namespace declaration are a C++17 extension}}
349