Debian Codegraph @

gcc/testsuite/obj-c++.dg/attributes/method-nonnull-1.mm

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 typedef __SIZE_TYPE__ my_size_t;
10
11 @interface MyArray
12 {
13 Class isa;
14 }
15 + (void) addObject: (id)object __attribute__ ((nonnull));
16 - (void) addObject: (id)object __attribute__ ((nonnull));
17
18 + (void) insertObject: (id)object atIndex: (size_t)index __attribute__ ((nonnull (1)));
19 - (void) insertObject: (id)object atIndex: (size_t)index __attribute__ ((nonnull (1)));
20
21 + (void) insertObject: (id)object atIndex: (size_t)index andObject: (id)anotherObject atIndex: (size_t)anotherIndex __attribute__ ((nonnull (1, 3)));
22 - (void) insertObject: (id)object atIndex: (size_t)index andObject: (id)anotherObject atIndex: (size_t)anotherIndex __attribute__ ((nonnull (1, 3)));
23
24 /* Test the behavior with invalid code. */
25 + (void) removeObject: (id)object __attribute__ ((nonnull (0))); /* { dg-warning "does not refer to a function parameter" } */
26 - (void) removeObject: (id)object __attribute__ ((nonnull (0))); /* { dg-warning "does not refer to a function parameter" } */
27
28 + (void) removeObject: (id)object __attribute__ ((nonnull (2))); /* { dg-warning "exceeds the number of function parameters 3" } */
29 - (void) removeObject: (id)object __attribute__ ((nonnull (2))); /* { dg-warning "exceeds the number of function parameters 3" } */
30
31 + (void) removeObjectAtIndex: (my_size_t)object __attribute__ ((nonnull (1))); /* { dg-warning "refers to parameter type .my_size_t." } */
32 - (void) removeObjectAtIndex: (my_size_t)object __attribute__ ((nonnull (1))); /* { dg-warning "refers to parameter type .my_size_t." } */
33
34 + (void) removeObject: (id)object __attribute__ ((nonnull (MyArray))); /* { dg-error "" } */
35 /* { dg-warning "attribute argument is invalid" "" { target *-*-* } .-1 } */
36 - (void) removeObject: (id)object __attribute__ ((nonnull (MyArray))); /* { dg-error "" } */
37 /* { dg-warning "attribute argument is invalid" "" { target *-*-* } .-1 } */
38 @end
39
40 void test (MyArray *object)
41 {
42 [object addObject: object];
43 [object addObject: nil]; /* { dg-warning "\\\[-Wnonnull" } */
44
45 [object insertObject: object atIndex: 4];
46 [object insertObject: nil atIndex: 4]; /* { dg-warning "\\\[-Wnonnull" } */
47
48 [object insertObject: object atIndex: 2 andObject: object atIndex: 3];
49 [object insertObject: nil atIndex: 2 andObject: object atIndex: 3]; /* { dg-warning "\\\[-Wnonnull" } */
50 [object insertObject: object atIndex: 2 andObject: nil atIndex: 3]; /* { dg-warning "\\\[-Wnonnull" } */
51 }