[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Sema / attr-retain.c
blobc8d9c8195637ae2a6dcf3dc0e20e18c80bcb49b6
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -Wunused-function
3 /// We allow 'retain' on non-ELF targets because 'retain' is often used together
4 /// with 'used'. 'used' has GC root semantics on macOS and Windows. We want
5 /// users to just write retain,used and don't need to dispatch on binary formats.
7 extern char test1[] __attribute__((retain)); // expected-warning {{'retain' attribute ignored on a non-definition declaration}}
8 extern const char test2[] __attribute__((retain)); // expected-warning {{'retain' attribute ignored on a non-definition declaration}}
9 const char test3[] __attribute__((retain)) = "";
11 struct __attribute__((retain)) s { // expected-warning {{'retain' attribute only applies to variables with non-local storage, functions, and Objective-C methods}}
14 void foo(void) {
15 static int a __attribute__((retain));
16 int b __attribute__((retain)); // expected-warning {{'retain' attribute only applies to variables with non-local storage, functions, and Objective-C methods}}
17 (void)a;
18 (void)b;
21 __attribute__((retain,used)) static void f0(void) {}
22 __attribute__((retain)) static void f1(void) {} // expected-warning {{unused function 'f1'}}
23 __attribute__((retain)) void f2(void) {}
25 /// Test attribute merging.
26 int tentative;
27 int tentative __attribute__((retain));
28 extern int tentative;
29 int tentative = 0;