xref: /aosp_15_r20/external/clang/test/Parser/cxx0x-attributes.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -Wc++14-compat -Wc++14-extensions -Wc++1z-extensions %s
2*67e74705SXin Li 
3*67e74705SXin Li // Need std::initializer_list
4*67e74705SXin Li namespace std {
5*67e74705SXin Li   typedef decltype(sizeof(int)) size_t;
6*67e74705SXin Li 
7*67e74705SXin Li   // libc++'s implementation
8*67e74705SXin Li   template <class _E>
9*67e74705SXin Li   class initializer_list
10*67e74705SXin Li   {
11*67e74705SXin Li     const _E* __begin_;
12*67e74705SXin Li     size_t    __size_;
13*67e74705SXin Li 
initializer_list(const _E * __b,size_t __s)14*67e74705SXin Li     initializer_list(const _E* __b, size_t __s)
15*67e74705SXin Li       : __begin_(__b),
16*67e74705SXin Li         __size_(__s)
17*67e74705SXin Li     {}
18*67e74705SXin Li 
19*67e74705SXin Li   public:
20*67e74705SXin Li     typedef _E        value_type;
21*67e74705SXin Li     typedef const _E& reference;
22*67e74705SXin Li     typedef const _E& const_reference;
23*67e74705SXin Li     typedef size_t    size_type;
24*67e74705SXin Li 
25*67e74705SXin Li     typedef const _E* iterator;
26*67e74705SXin Li     typedef const _E* const_iterator;
27*67e74705SXin Li 
initializer_list()28*67e74705SXin Li     initializer_list() : __begin_(nullptr), __size_(0) {}
29*67e74705SXin Li 
size() const30*67e74705SXin Li     size_t    size()  const {return __size_;}
begin() const31*67e74705SXin Li     const _E* begin() const {return __begin_;}
end() const32*67e74705SXin Li     const _E* end()   const {return __begin_ + __size_;}
33*67e74705SXin Li   };
34*67e74705SXin Li }
35*67e74705SXin Li 
36*67e74705SXin Li 
37*67e74705SXin Li // Declaration syntax checks
38*67e74705SXin Li [[]] int before_attr;
39*67e74705SXin Li int [[]] between_attr;
40*67e74705SXin Li const [[]] int between_attr_2 = 0; // expected-error {{an attribute list cannot appear here}}
41*67e74705SXin Li int after_attr [[]];
42*67e74705SXin Li int * [[]] ptr_attr;
43*67e74705SXin Li int & [[]] ref_attr = after_attr;
44*67e74705SXin Li int & [[unknown]] ref_attr_2 = after_attr; // expected-warning {{unknown attribute 'unknown' ignored}}
45*67e74705SXin Li int & [[noreturn]] ref_attr_3 = after_attr; // expected-error {{'noreturn' attribute cannot be applied to types}}
46*67e74705SXin Li int && [[]] rref_attr = 0;
47*67e74705SXin Li int array_attr [1] [[]];
48*67e74705SXin Li alignas(8) int aligned_attr;
49*67e74705SXin Li [[test::valid(for 42 [very] **** '+' symbols went on a trip and had a "good"_time; the end.)]] int garbage_attr; // expected-warning {{unknown attribute 'valid' ignored}}
50*67e74705SXin Li [[,,,static, class, namespace,, inline, constexpr, mutable,, bitand, bitor::compl(!.*_ Cx.!U^*R),,,]] int more_garbage_attr; // expected-warning {{unknown attribute 'static' ignored}} \
51*67e74705SXin Li     // expected-warning {{unknown attribute 'class' ignored}} \
52*67e74705SXin Li     // expected-warning {{unknown attribute 'namespace' ignored}} \
53*67e74705SXin Li     // expected-warning {{unknown attribute 'inline' ignored}} \
54*67e74705SXin Li     // expected-warning {{unknown attribute 'constexpr' ignored}} \
55*67e74705SXin Li     // expected-warning {{unknown attribute 'mutable' ignored}} \
56*67e74705SXin Li     // expected-warning {{unknown attribute 'bitand' ignored}} \
57*67e74705SXin Li     // expected-warning {{unknown attribute 'compl' ignored}}
58*67e74705SXin Li [[u8"invalid!"]] int invalid_string_attr; // expected-error {{expected ']'}}
59*67e74705SXin Li void fn_attr () [[]];
60*67e74705SXin Li void noexcept_fn_attr () noexcept [[]];
61*67e74705SXin Li struct MemberFnOrder {
62*67e74705SXin Li   virtual void f() const volatile && noexcept [[]] final = 0;
63*67e74705SXin Li };
64*67e74705SXin Li struct [[]] struct_attr;
65*67e74705SXin Li class [[]] class_attr {};
66*67e74705SXin Li union [[]] union_attr;
67*67e74705SXin Li 
68*67e74705SXin Li // Checks attributes placed at wrong syntactic locations of class specifiers.
69*67e74705SXin Li class [[]] [[]]
70*67e74705SXin Li   attr_after_class_name_decl [[]] [[]]; // expected-error {{an attribute list cannot appear here}}
71*67e74705SXin Li 
72*67e74705SXin Li class [[]] [[]]
73*67e74705SXin Li  attr_after_class_name_definition [[]] [[]] [[]]{}; // expected-error {{an attribute list cannot appear here}}
74*67e74705SXin Li 
75*67e74705SXin Li class [[]] c {};
76*67e74705SXin Li class c [[]] [[]] x;
77*67e74705SXin Li class c [[]] [[]] y [[]] [[]];
78*67e74705SXin Li class c final [(int){0}];
79*67e74705SXin Li 
80*67e74705SXin Li class base {};
81*67e74705SXin Li class [[]] [[]] final_class
82*67e74705SXin Li   alignas(float) [[]] final // expected-error {{an attribute list cannot appear here}}
83*67e74705SXin Li   alignas(float) [[]] [[]] alignas(float): base{}; // expected-error {{an attribute list cannot appear here}}
84*67e74705SXin Li 
85*67e74705SXin Li class [[]] [[]] final_class_another
86*67e74705SXin Li   [[]] [[]] alignas(16) final // expected-error {{an attribute list cannot appear here}}
87*67e74705SXin Li   [[]] [[]] alignas(16) [[]]{}; // expected-error {{an attribute list cannot appear here}}
88*67e74705SXin Li 
89*67e74705SXin Li // The diagnostics here don't matter much, this just shouldn't crash:
90*67e74705SXin Li class C final [[deprecated(l]] {}); // expected-error {{use of undeclared identifier}} expected-error {{expected ']'}} expected-error {{an attribute list cannot appear here}} expected-error {{expected unqualified-id}}
91*67e74705SXin Li class D final alignas ([l) {}]{}); // expected-error {{expected ',' or ']' in lambda capture list}} expected-error {{an attribute list cannot appear here}}
92*67e74705SXin Li 
93*67e74705SXin Li [[]] struct with_init_declarators {} init_declarator;
94*67e74705SXin Li [[]] struct no_init_declarators; // expected-error {{an attribute list cannot appear here}}
95*67e74705SXin Li template<typename> [[]] struct no_init_declarators_template; // expected-error {{an attribute list cannot appear here}}
96*67e74705SXin Li void fn_with_structs() {
97*67e74705SXin Li   [[]] struct with_init_declarators {} init_declarator;
98*67e74705SXin Li   [[]] struct no_init_declarators; // expected-error {{an attribute list cannot appear here}}
99*67e74705SXin Li }
100*67e74705SXin Li [[]];
101*67e74705SXin Li struct ctordtor {
102*67e74705SXin Li   [[]] ctordtor();
103*67e74705SXin Li   [[]] ~ctordtor();
104*67e74705SXin Li };
105*67e74705SXin Li [[]] ctordtor::ctordtor() {}
106*67e74705SXin Li [[]] ctordtor::~ctordtor() {}
107*67e74705SXin Li extern "C++" [[]] int extern_attr;
108*67e74705SXin Li template <typename T> [[]] void template_attr ();
109*67e74705SXin Li [[]] [[]] int [[]] [[]] multi_attr [[]] [[]];
110*67e74705SXin Li 
111*67e74705SXin Li int comma_attr [[,]];
112*67e74705SXin Li int scope_attr [[foo::]]; // expected-error {{expected identifier}}
113*67e74705SXin Li int (paren_attr) [[]]; // expected-error {{an attribute list cannot appear here}}
114*67e74705SXin Li unsigned [[]] int attr_in_decl_spec; // expected-error {{an attribute list cannot appear here}}
115*67e74705SXin Li unsigned [[]] int [[]] const double_decl_spec = 0; // expected-error 2{{an attribute list cannot appear here}}
116*67e74705SXin Li class foo {
117*67e74705SXin Li   void const_after_attr () [[]] const; // expected-error {{expected ';'}}
118*67e74705SXin Li };
119*67e74705SXin Li extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}}
120*67e74705SXin Li [[]] template <typename T> void before_template_attr (); // expected-error {{an attribute list cannot appear here}}
121*67e74705SXin Li [[]] namespace ns { int i; } // expected-error {{an attribute list cannot appear here}} expected-note {{declared here}}
122*67e74705SXin Li [[]] static_assert(true, ""); //expected-error {{an attribute list cannot appear here}}
123*67e74705SXin Li [[]] asm(""); // expected-error {{an attribute list cannot appear here}}
124*67e74705SXin Li 
125*67e74705SXin Li [[]] using ns::i; // expected-error {{an attribute list cannot appear here}}
126*67e74705SXin Li [[unknown]] using namespace ns; // expected-warning {{unknown attribute 'unknown' ignored}}
127*67e74705SXin Li [[noreturn]] using namespace ns; // expected-error {{'noreturn' attribute only applies to functions}}
128*67e74705SXin Li namespace [[]] ns2 {} // expected-warning {{attributes on a namespace declaration are incompatible with C++ standards before C++1z}}
129*67e74705SXin Li 
130*67e74705SXin Li using [[]] alignas(4) [[]] ns::i; // expected-error {{an attribute list cannot appear here}}
131*67e74705SXin Li using [[]] alignas(4) [[]] foobar = int; // expected-error {{an attribute list cannot appear here}} expected-error {{'alignas' attribute only applies to}}
132*67e74705SXin Li 
133*67e74705SXin Li void bad_attributes_in_do_while() {
134*67e74705SXin Li   do {} while (
135*67e74705SXin Li       [[ns::i); // expected-error {{expected ']'}} \
136*67e74705SXin Li                 // expected-note {{to match this '['}} \
137*67e74705SXin Li                 // expected-error {{expected expression}}
138*67e74705SXin Li   do {} while (
139*67e74705SXin Li       [[a]b ns::i); // expected-error {{expected ']'}} \
140*67e74705SXin Li                     // expected-note {{to match this '['}} \
141*67e74705SXin Li                     // expected-error {{expected expression}}
142*67e74705SXin Li   do {} while (
143*67e74705SXin Li       [[ab]ab] ns::i); // expected-error {{an attribute list cannot appear here}}
144*67e74705SXin Li   do {} while ( // expected-note {{to match this '('}}
145*67e74705SXin Li       alignas(4 ns::i; // expected-note {{to match this '('}}
146*67e74705SXin Li } // expected-error 2{{expected ')'}} expected-error {{expected expression}}
147*67e74705SXin Li 
148*67e74705SXin Li [[]] using T = int; // expected-error {{an attribute list cannot appear here}}
149*67e74705SXin Li using T [[]] = int; // ok
150*67e74705SXin Li template<typename T> using U [[]] = T;
151*67e74705SXin Li using ns::i [[]]; // expected-error {{an attribute list cannot appear here}}
152*67e74705SXin Li using [[]] ns::i; // expected-error {{an attribute list cannot appear here}}
153*67e74705SXin Li using T [[unknown]] = int; // expected-warning {{unknown attribute 'unknown' ignored}}
154*67e74705SXin Li using T [[noreturn]] = int; // expected-error {{'noreturn' attribute only applies to functions}}
155*67e74705SXin Li using V = int; // expected-note {{previous}}
156*67e74705SXin Li using V [[gnu::vector_size(16)]] = int; // expected-error {{redefinition with different types}}
157*67e74705SXin Li 
158*67e74705SXin Li auto trailing() -> [[]] const int; // expected-error {{an attribute list cannot appear here}}
159*67e74705SXin Li auto trailing() -> const [[]] int; // expected-error {{an attribute list cannot appear here}}
160*67e74705SXin Li auto trailing() -> const int [[]];
161*67e74705SXin Li auto trailing_2() -> struct struct_attr [[]];
162*67e74705SXin Li 
163*67e74705SXin Li namespace N {
164*67e74705SXin Li   struct S {};
165*67e74705SXin Li };
166*67e74705SXin Li template<typename> struct Template {};
167*67e74705SXin Li 
168*67e74705SXin Li // FIXME: Improve this diagnostic
169*67e74705SXin Li struct [[]] N::S s; // expected-error {{an attribute list cannot appear here}}
170*67e74705SXin Li struct [[]] Template<int> t; // expected-error {{an attribute list cannot appear here}}
171*67e74705SXin Li struct [[]] ::template Template<int> u; // expected-error {{an attribute list cannot appear here}}
172*67e74705SXin Li template struct [[]] Template<char>; // expected-error {{an attribute list cannot appear here}}
173*67e74705SXin Li template <> struct [[]] Template<void>;
174*67e74705SXin Li 
175*67e74705SXin Li enum [[]] E1 {};
176*67e74705SXin Li enum [[]] E2; // expected-error {{forbids forward references}}
177*67e74705SXin Li enum [[]] E1;
178*67e74705SXin Li enum [[]] E3 : int;
179*67e74705SXin Li enum [[]] {
180*67e74705SXin Li   k_123 [[]] = 123 // expected-warning {{attributes on an enumerator declaration are incompatible with C++ standards before C++1z}}
181*67e74705SXin Li };
182*67e74705SXin Li enum [[]] E1 e; // expected-error {{an attribute list cannot appear here}}
183*67e74705SXin Li enum [[]] class E4 { }; // expected-error {{an attribute list cannot appear here}}
184*67e74705SXin Li enum struct [[]] E5;
185*67e74705SXin Li 
186*67e74705SXin Li struct S {
187*67e74705SXin Li   friend int f [[]] (); // expected-FIXME{{an attribute list cannot appear here}}
188*67e74705SXin Li   friend int f1 [[noreturn]] (); //expected-error{{an attribute list cannot appear here}}
189*67e74705SXin Li   friend int f2 [[]] [[noreturn]] () {}
190*67e74705SXin Li   [[]] friend int g(); // expected-error{{an attribute list cannot appear here}}
191*67e74705SXin Li   [[]] friend int h() {
192*67e74705SXin Li   }
193*67e74705SXin Li   [[]] friend int f3(), f4(), f5(); // expected-error{{an attribute list cannot appear here}}
194*67e74705SXin Li   friend int f6 [[noreturn]] (), f7 [[noreturn]] (), f8 [[noreturn]] (); // expected-error3 {{an attribute list cannot appear here}}
195*67e74705SXin Li   friend class [[]] C; // expected-error{{an attribute list cannot appear here}}
196*67e74705SXin Li   [[]] friend class D; // expected-error{{an attribute list cannot appear here}}
197*67e74705SXin Li   [[]] friend int; // expected-error{{an attribute list cannot appear here}}
198*67e74705SXin Li };
199*67e74705SXin Li template<typename T> void tmpl(T) {}
200*67e74705SXin Li template void tmpl [[]] (int); // expected-FIXME {{an attribute list cannot appear here}}
201*67e74705SXin Li template [[]] void tmpl(char); // expected-error {{an attribute list cannot appear here}}
202*67e74705SXin Li template void [[]] tmpl(short);
203*67e74705SXin Li 
204*67e74705SXin Li // Argument tests
205*67e74705SXin Li alignas int aligned_no_params; // expected-error {{expected '('}}
206*67e74705SXin Li alignas(i) int aligned_nonconst; // expected-error {{'aligned' attribute requires integer constant}} expected-note {{read of non-const variable 'i'}}
207*67e74705SXin Li 
208*67e74705SXin Li // Statement tests
209*67e74705SXin Li void foo () {
210*67e74705SXin Li   [[]] ;
211*67e74705SXin Li   [[]] { }
212*67e74705SXin Li   [[]] if (0) { }
213*67e74705SXin Li   [[]] for (;;);
214*67e74705SXin Li   [[]] do {
215*67e74705SXin Li     [[]] continue;
216*67e74705SXin Li   } while (0);
217*67e74705SXin Li   [[]] while (0);
218*67e74705SXin Li 
219*67e74705SXin Li   [[]] switch (i) {
220*67e74705SXin Li     [[]] case 0:
221*67e74705SXin Li     [[]] default:
222*67e74705SXin Li       [[]] break;
223*67e74705SXin Li   }
224*67e74705SXin Li 
225*67e74705SXin Li   [[]] goto there;
226*67e74705SXin Li   [[]] there:
227*67e74705SXin Li 
228*67e74705SXin Li   [[]] try {
229*67e74705SXin Li   } [[]] catch (...) { // expected-error {{an attribute list cannot appear here}}
230*67e74705SXin Li   }
231*67e74705SXin Li   struct S { int arr[2]; } s;
232*67e74705SXin Li   (void)s.arr[ [] { return 0; }() ]; // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}}
233*67e74705SXin Li   int n = __builtin_offsetof(S, arr[ [] { return 0; }() ]); // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}}
234*67e74705SXin Li 
235*67e74705SXin Li   void bar [[noreturn]] ([[]] int i, [[]] int j);
236*67e74705SXin Li   using FuncType = void ([[]] int);
237*67e74705SXin Li   void baz([[]]...); // expected-error {{expected parameter declarator}}
238*67e74705SXin Li 
239*67e74705SXin Li   [[]] return;
240*67e74705SXin Li }
241*67e74705SXin Li 
242*67e74705SXin Li template<typename...Ts> void variadic() {
243*67e74705SXin Li   void bar [[noreturn...]] (); // expected-error {{attribute 'noreturn' cannot be used as an attribute pack}}
244*67e74705SXin Li }
245*67e74705SXin Li 
246*67e74705SXin Li // Expression tests
247*67e74705SXin Li void bar () {
248*67e74705SXin Li   // FIXME: GCC accepts [[gnu::noreturn]] on a lambda, even though it appertains
249*67e74705SXin Li   // to the operator()'s type, and GCC does not otherwise accept attributes
250*67e74705SXin Li   // applied to types. Use that to test this.
251*67e74705SXin Li   [] () [[gnu::noreturn]] { return; } (); // expected-warning {{attribute 'noreturn' ignored}} FIXME-error {{should not return}}
252*67e74705SXin Li   [] () [[gnu::noreturn]] { throw; } (); // expected-warning {{attribute 'noreturn' ignored}}
253*67e74705SXin Li   new int[42][[]][5][[]]{};
254*67e74705SXin Li }
255*67e74705SXin Li 
256*67e74705SXin Li // Condition tests
257*67e74705SXin Li void baz () {
258*67e74705SXin Li   if ([[unknown]] bool b = true) { // expected-warning {{unknown attribute 'unknown' ignored}}
259*67e74705SXin Li     switch ([[unknown]] int n { 42 }) { // expected-warning {{unknown attribute 'unknown' ignored}}
260*67e74705SXin Li     default:
261*67e74705SXin Li       for ([[unknown]] int n = 0; [[unknown]] char b = n < 5; ++b) { // expected-warning 2{{unknown attribute 'unknown' ignored}}
262*67e74705SXin Li       }
263*67e74705SXin Li     }
264*67e74705SXin Li   }
265*67e74705SXin Li   int x;
266*67e74705SXin Li   // An attribute can be applied to an expression-statement, such as the first
267*67e74705SXin Li   // statement in a for. But it can't be applied to a condition which is an
268*67e74705SXin Li   // expression.
269*67e74705SXin Li   for ([[]] x = 0; ; ) {} // expected-error {{an attribute list cannot appear here}}
270*67e74705SXin Li   for (; [[]] x < 5; ) {} // expected-error {{an attribute list cannot appear here}}
271*67e74705SXin Li   while ([[]] bool k { false }) {
272*67e74705SXin Li   }
273*67e74705SXin Li   while ([[]] true) { // expected-error {{an attribute list cannot appear here}}
274*67e74705SXin Li   }
275*67e74705SXin Li   do {
276*67e74705SXin Li   } while ([[]] false); // expected-error {{an attribute list cannot appear here}}
277*67e74705SXin Li 
278*67e74705SXin Li   for ([[unknown]] int n : { 1, 2, 3 }) { // expected-warning {{unknown attribute 'unknown' ignored}}
279*67e74705SXin Li   }
280*67e74705SXin Li }
281*67e74705SXin Li 
282*67e74705SXin Li enum class __attribute__((visibility("hidden"))) SecretKeepers {
283*67e74705SXin Li   one, /* rest are deprecated */ two, three
284*67e74705SXin Li };
285*67e74705SXin Li enum class [[]] EvenMoreSecrets {};
286*67e74705SXin Li 
287*67e74705SXin Li namespace arguments {
288*67e74705SXin Li   void f[[gnu::format(printf, 1, 2)]](const char*, ...);
289*67e74705SXin Li   void g() [[unknown::foo(ignore arguments for unknown attributes, even with symbols!)]]; // expected-warning {{unknown attribute 'foo' ignored}}
290*67e74705SXin Li   [[deprecated("with argument")]] int i;
291*67e74705SXin Li   // expected-warning@-1 {{use of the 'deprecated' attribute is a C++14 extension}}
292*67e74705SXin Li }
293*67e74705SXin Li 
294*67e74705SXin Li // Forbid attributes on decl specifiers.
295*67e74705SXin Li unsigned [[gnu::used]] static int [[gnu::unused]] v1; // expected-error {{'unused' attribute cannot be applied to types}} \
296*67e74705SXin Li            expected-error {{an attribute list cannot appear here}}
297*67e74705SXin Li typedef [[gnu::used]] unsigned long [[gnu::unused]] v2; // expected-error {{'unused' attribute cannot be applied to types}} \
298*67e74705SXin Li           expected-error {{an attribute list cannot appear here}}
299*67e74705SXin Li int [[carries_dependency]] foo(int [[carries_dependency]] x); // expected-error 2{{'carries_dependency' attribute cannot be applied to types}}
300*67e74705SXin Li 
301*67e74705SXin Li // Forbid [[gnu::...]] attributes on declarator chunks.
302*67e74705SXin Li int *[[gnu::unused]] v3; // expected-warning {{attribute 'unused' ignored}}
303*67e74705SXin Li int v4[2][[gnu::unused]]; // expected-warning {{attribute 'unused' ignored}}
304*67e74705SXin Li int v5()[[gnu::unused]]; // expected-warning {{attribute 'unused' ignored}}
305*67e74705SXin Li 
306*67e74705SXin Li [[attribute_declaration]]; // expected-warning {{unknown attribute 'attribute_declaration' ignored}}
307*67e74705SXin Li [[noreturn]]; // expected-error {{'noreturn' attribute only applies to functions}}
308*67e74705SXin Li [[carries_dependency]]; // expected-error {{'carries_dependency' attribute only applies to functions, methods, and parameters}}
309*67e74705SXin Li 
310*67e74705SXin Li class A {
311*67e74705SXin Li   A([[gnu::unused]] int a);
312*67e74705SXin Li };
313*67e74705SXin Li A::A([[gnu::unused]] int a) {}
314*67e74705SXin Li 
315*67e74705SXin Li namespace GccConst {
316*67e74705SXin Li   // GCC's tokenizer treats const and __const as the same token.
317*67e74705SXin Li   [[gnu::const]] int *f1();
318*67e74705SXin Li   [[gnu::__const]] int *f2();
319*67e74705SXin Li   [[gnu::__const__]] int *f3();
320*67e74705SXin Li   void f(const int *);
321*67e74705SXin Li   void g() { f(f1()); f(f2()); }
322*67e74705SXin Li   void h() { f(f3()); }
323*67e74705SXin Li }
324*67e74705SXin Li 
325*67e74705SXin Li namespace GccASan {
326*67e74705SXin Li   __attribute__((no_address_safety_analysis)) void f1();
327*67e74705SXin Li   __attribute__((no_sanitize_address)) void f2();
328*67e74705SXin Li   [[gnu::no_address_safety_analysis]] void f3();
329*67e74705SXin Li   [[gnu::no_sanitize_address]] void f4();
330*67e74705SXin Li }
331*67e74705SXin Li 
332*67e74705SXin Li namespace {
333*67e74705SXin Li   [[deprecated]] void bar();
334*67e74705SXin Li   // expected-warning@-1 {{use of the 'deprecated' attribute is a C++14 extension}}
335*67e74705SXin Li   [[deprecated("hello")]] void baz();
336*67e74705SXin Li   // expected-warning@-1 {{use of the 'deprecated' attribute is a C++14 extension}}
337*67e74705SXin Li   [[deprecated()]] void foo();
338*67e74705SXin Li   // expected-error@-1 {{parentheses must be omitted if 'deprecated' attribute's argument list is empty}}
339*67e74705SXin Li   [[gnu::deprecated()]] void quux();
340*67e74705SXin Li }
341*67e74705SXin Li 
342*67e74705SXin Li namespace {
343*67e74705SXin Li [[ // expected-error {{expected ']'}}
344*67e74705SXin Li #pragma pack(pop)
345*67e74705SXin Li deprecated
346*67e74705SXin Li ]] void bad();
347*67e74705SXin Li }
348*67e74705SXin Li 
349*67e74705SXin Li int fallthru(int n) {
350*67e74705SXin Li   switch (n) {
351*67e74705SXin Li   case 0:
352*67e74705SXin Li     n += 5;
353*67e74705SXin Li     [[fallthrough]]; // expected-warning {{use of the 'fallthrough' attribute is a C++1z extension}}
354*67e74705SXin Li   case 1:
355*67e74705SXin Li     n *= 2;
356*67e74705SXin Li     break;
357*67e74705SXin Li   }
358*67e74705SXin Li   return n;
359*67e74705SXin Li }
360*67e74705SXin Li 
361*67e74705SXin Li #define attr_name bitand
362*67e74705SXin Li #define attr_name_2(x) x
363*67e74705SXin Li #define attr_name_3(x, y) x##y
364*67e74705SXin Li [[attr_name, attr_name_2(bitor), attr_name_3(com, pl)]] int macro_attrs; // expected-warning {{unknown attribute 'compl' ignored}} \
365*67e74705SXin Li    expected-warning {{unknown attribute 'bitor' ignored}} \
366*67e74705SXin Li    expected-warning {{unknown attribute 'bitand' ignored}}
367