Debian Codegraph @

gcc/testsuite/objc.dg/attributes/method-nonnull-1.m

raw
1 /* Contributed by Nicola Pero <[email protected]>, May 2011. */
2 /* { dg-do compile } */
3 /* { dg-options "-Wall" } */
4 /* { dg-additional-options "-Wno-objc-root-class" } */
5
6 #include <objc/objc.h>
7 #include <stdlib.h>
8
9 @interface MyArray
10 {
11 Class isa;
12 }
13 + (void) addObject: (id)object __attribute__ ((nonnull));
14 - (void) addObject: (id)object __attribute__ ((nonnull));
15
16 + (void) insertObject: (id)object atIndex: (size_t)index __attribute__ ((nonnull (1)));
17 - (void) insertObject: (id)object atIndex: (size_t)index __attribute__ ((nonnull (1)));
18
19 + (void) insertObject: (id)object atIndex: (size_t)index andObject: (id)anotherObject atIndex: (size_t)anotherIndex __attribute__ ((nonnull (1, 3)));
20 - (void) insertObject: (id)object atIndex: (size_t)index andObject: (id)anotherObject atIndex: (size_t)anotherIndex __attribute__ ((nonnull (1, 3)));
21
22 /* Test the behavior with invalid code. */
23 + (void) removeObject: (id)object __attribute__ ((nonnull (0))); /* { dg-warning "does not refer to a function parameter" } */
24 - (void) removeObject: (id)object __attribute__ ((nonnull (0))); /* { dg-warning "does not refer to a function parameter" } */
25
26 + (void) removeObject: (id)object __attribute__ ((nonnull (2))); /* { dg-warning "exceeds the number of function parameters 3" } */
27 - (void) removeObject: (id)object __attribute__ ((nonnull (2))); /* { dg-warning "exceeds the number of function parameters 3" } */
28
29 + (void) removeObjectAtIndex: (size_t)object __attribute__ ((nonnull (1))); /* { dg-warning "refers to parameter type .size_t." } */
30 - (void) removeObjectAtIndex: (size_t)object __attribute__ ((nonnull (1))); /* { dg-warning "refers to parameter type .size_t." } */
31
32 + (void) removeObject: (id)object __attribute__ ((nonnull (MyArray))); /* { dg-warning "is invalid" } */
33 - (void) removeObject: (id)object __attribute__ ((nonnull (MyArray))); /* { dg-warning "is invalid" } */
34 @end
35
36 void test (MyArray *object)
37 {
38 [object addObject: object];
39 [object addObject: nil]; /* { dg-warning "\\\[-Wnonnull" } */
40
41 [object insertObject: object atIndex: 4];
42 [object insertObject: nil atIndex: 4]; /* { dg-warning "\\\[-Wnonnull" } */
43
44 [object insertObject: object atIndex: 2 andObject: object atIndex: 3];
45 [object insertObject: nil atIndex: 2 andObject: object atIndex: 3]; /* { dg-warning "\\\[-Wnonnull" } */
46 [object insertObject: object atIndex: 2 andObject: nil atIndex: 3]; /* { dg-warning "\\\[-Wnonnull" } */
47 }