Debian Codegraph @

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

raw
1 /* Contributed by Nicola Pero <[email protected]>, October 2010. */
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 /* Ensure a compatible definition of nil. */
9 #include "../../objc-obj-c++-shared/objc-test-suite-types.h"
10
11 @interface NSArray
12 {
13 Class isa;
14 }
15 + (id) arrayWithObject: (id)object __attribute__ ((sentinel)); /* { dg-warning "attribute only applies to variadic functions" } */
16 + (id) arrayWithObjects: (id)firstObject, ... __attribute__ ((sentinel));
17
18 - (id) initWithObject: (id)object __attribute__ ((sentinel)); /* { dg-warning "attribute only applies to variadic functions" } */
19 - (id) initWithObjects: (id)firstObject, ... __attribute__ ((sentinel));
20 @end
21
22 void test (id object)
23 {
24 NSArray *array;
25
26 array = [NSArray arrayWithObject: object];
27 array = [NSArray arrayWithObjects: object, nil];
28 array = [NSArray arrayWithObjects: object, object, nil];
29 array = [NSArray arrayWithObjects: object]; /* { dg-warning "not enough variable arguments" } */
30 array = [NSArray arrayWithObjects: object, object]; /* { dg-warning "missing sentinel" } */
31
32 [array initWithObject: object];
33 [array initWithObjects: object, nil];
34 [array initWithObjects: object, object, nil];
35 [array initWithObjects: object]; /* { dg-warning "not enough variable arguments" } */
36 [array initWithObjects: object, object]; /* { dg-warning "missing sentinel" } */
37 }