[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Parser / attributes.c
blobc73505d9f547d87d9841021d7ff969dcfb427791
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic -std=c99 -Wno-strict-prototypes
3 int __attribute__(()) x;
5 __inline void __attribute__((__always_inline__, __nodebug__))
6 foo(void) {
10 __attribute__(()) y; // expected-error {{type specifier missing, defaults to 'int'}}
12 // PR2796
13 int (__attribute__(()) *z)(long y);
16 void f1(__attribute__(()) int x);
18 int f2(y, __attribute__(()) x); // expected-error {{expected identifier}}
20 // This is parsed as a normal argument list (with two args that are implicit
21 // int) because the __attribute__ is a declspec.
22 void f3(__attribute__(()) x, // expected-error {{type specifier missing, defaults to 'int'}}
23 y); // expected-error {{type specifier missing, defaults to 'int'}}
25 void f4(__attribute__(())); // expected-error {{expected parameter declarator}}
28 // This is ok, the __attribute__ applies to the pointer.
29 int baz(int (__attribute__(()) *x)(long y));
31 void g1(void (*f1)(__attribute__(()) int x));
32 void g2(int (*f2)(y, __attribute__(()) x)); // expected-error {{expected identifier}}
33 void g3(void (*f3)(__attribute__(()) x, int y)); // expected-error {{type specifier missing, defaults to 'int'}}
34 void g4(void (*f4)(__attribute__(()))); // expected-error {{expected parameter declarator}}
37 void (*h1)(void (*f1)(__attribute__(()) int x));
38 void (*h2)(int (*f2)(y, __attribute__(()) x)); // expected-error {{expected identifier}}
40 void (*h3)(void (*f3)(__attribute__(()) x)); // expected-error {{type specifier missing, defaults to 'int'}}
41 void (*h4)(void (*f4)(__attribute__(()))); // expected-error {{expected parameter declarator}}
43 int foo42(void) {
44 int x, __attribute__((unused)) y, z;
45 return 0;
48 void __attribute__((noreturn)) d0(void), __attribute__((noreturn)) d1(void);
50 void d2(void) __attribute__((noreturn)), d3(void) __attribute__((noreturn));
53 // PR6287
54 void __attribute__((returns_twice)) returns_twice_test(void);
56 int aligned(int);
57 int __attribute__((vec_type_hint(char, aligned(16) )) missing_rparen_1; // expected-error 2{{expected ')'}} expected-note {{to match}} expected-warning {{does not declare anything}}
58 int __attribute__((mode(x aligned(16) )) missing_rparen_2; // expected-error 2{{expected ')'}}
59 int __attribute__((format(printf, 0 aligned(16) )) missing_rparen_3; // expected-error 2{{expected ')'}}
63 int testFundef1(int *a) __attribute__((nonnull(1))) { // \
64 // expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}}
65 return *a;
68 // noreturn is lifted to type qualifier
69 void testFundef2(void) __attribute__((noreturn)) { // \
70 // expected-warning {{GCC does not allow 'noreturn' attribute in this position on a function definition}}
71 testFundef2();
74 int testFundef3(int *a) __attribute__((nonnull(1), // \
75 // expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}}
76 pure)) { // \
77 // expected-warning {{GCC does not allow 'pure' attribute in this position on a function definition}}
78 return *a;
81 int testFundef4(int *a) __attribute__((nonnull(1))) // \
82 // expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}}
83 __attribute((pure)) { // \
84 // expected-warning {{GCC does not allow 'pure' attribute in this position on a function definition}}
85 return *a;
88 // GCC allows these
89 void testFundef5(void) __attribute__(()) { }
91 __attribute__((pure)) int testFundef6(int a) { return a; }
93 void deprecatedTestFun(void) __attribute__((deprecated()));
95 struct s {
96 int a;
99 // This test ensure compatibility with parsing GNU-style attributes
100 // where the attribute is on a separate line from the elaborated type
101 // specifier.
102 struct s
103 __attribute__((used)) bar;
105 // Ensure that attributes must be separated by a comma (PR38352).
106 __attribute__((const const)) int PR38352(void); // expected-error {{expected ')'}}
107 // Also ensure that we accept spurious commas.
108 __attribute__((,,,const)) int PR38352_1(void);
109 __attribute__((const,,,)) int PR38352_2(void);
110 __attribute__((const,,,const)) int PR38352_3(void);
111 __attribute__((,,,const,,,const,,,)) int PR38352_4(void);
113 // Test that we allow attributes on free-standing decl-specifier-seqs.
114 // GCC appears to allow this.
115 __attribute__(()) struct t;
116 void f5() {
117 __attribute__(()) struct t;