xref: /aosp_15_r20/external/clang/test/SemaObjC/arc-system-header.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -fobjc-arc -isystem %S/Inputs %s -DNO_USE
2*67e74705SXin Li// RUN: %clang_cc1 -fobjc-arc -isystem %S/Inputs %s -verify
3*67e74705SXin Li
4*67e74705SXin Li#include <arc-system-header.h>
5*67e74705SXin Li
6*67e74705SXin Li#ifndef NO_USE
7*67e74705SXin Livoid test(id op, void *cp) {
8*67e74705SXin Li  cp = test0(op); // expected-error {{'test0' is unavailable in ARC}}
9*67e74705SXin Li  cp = *test1(&op); // expected-error {{'test1' is unavailable in ARC}}
10*67e74705SXin Li// [email protected]:1 {{inline function performs a conversion which is forbidden in ARC}}
11*67e74705SXin Li// [email protected]:5 {{inline function performs a conversion which is forbidden in ARC}}
12*67e74705SXin Li}
13*67e74705SXin Li
14*67e74705SXin Livoid test3(struct Test3 *p) {
15*67e74705SXin Li  p->field = 0; // expected-error {{'field' is unavailable in ARC}}
16*67e74705SXin Li                // [email protected]:14 {{declaration uses type that is ill-formed in ARC}}
17*67e74705SXin Li}
18*67e74705SXin Li
19*67e74705SXin Livoid test4(Test4 *p) {
20*67e74705SXin Li  p->field1 = 0; // expected-error {{'field1' is unavailable in ARC}}
21*67e74705SXin Li                 // [email protected]:19 {{declaration uses type that is ill-formed in ARC}}
22*67e74705SXin Li  p->field2 = 0;
23*67e74705SXin Li}
24*67e74705SXin Li
25*67e74705SXin Livoid test5(struct Test5 *p) {
26*67e74705SXin Li  p->field = 0; // expected-error {{'field' is unavailable in ARC}}
27*67e74705SXin Li                // [email protected]:25 {{field has non-trivial ownership qualification}}
28*67e74705SXin Li}
29*67e74705SXin Li
30*67e74705SXin Liid test6() {
31*67e74705SXin Li  // This is actually okay to use if declared in a system header.
32*67e74705SXin Li  id x;
33*67e74705SXin Li  x = (id) kMagicConstant;
34*67e74705SXin Li  x = (id) (x ? kMagicConstant : kMagicConstant);
35*67e74705SXin Li  x = (id) (x ? kMagicConstant : (void*) 0);
36*67e74705SXin Li
37*67e74705SXin Li  extern void test6_helper();
38*67e74705SXin Li  x = (id) (test6_helper(), kMagicConstant);
39*67e74705SXin Li}
40*67e74705SXin Li
41*67e74705SXin Livoid test7(Test7 *p) {
42*67e74705SXin Li  *p.prop = 0; // expected-error {{'prop' is unavailable in ARC}}
43*67e74705SXin Li  p.prop = 0; // expected-error {{'prop' is unavailable in ARC}}
44*67e74705SXin Li  *[p prop] = 0; // expected-error {{'prop' is unavailable in ARC}}
45*67e74705SXin Li  [p setProp: 0]; // expected-error {{'setProp:' is unavailable in ARC}}
46*67e74705SXin Li// [email protected]:41 4 {{declaration uses type that is ill-formed in ARC}}
47*67e74705SXin Li// [email protected]:41 2 {{property 'prop' is declared unavailable here}}
48*67e74705SXin Li}
49*67e74705SXin Li
50*67e74705SXin Liextern void doSomething(Test9 arg);
51*67e74705SXin Livoid test9() {
52*67e74705SXin Li    Test9 foo2 = {0, 0}; // expected-error {{'field' is unavailable in ARC}}
53*67e74705SXin Li                         // [email protected]:56 {{field has non-trivial ownership qualification}}
54*67e74705SXin Li    doSomething(foo2);
55*67e74705SXin Li}
56*67e74705SXin Li#endif
57*67e74705SXin Li
58*67e74705SXin Li// test8 in header
59