OSDN Git Service

In gcc/:
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / foreach-6.m
1 /* Test basic Objective-C foreach syntax.  This tests warnings and errors.  */
2 /* FIXME: Run this test with the NeXT runtime as well.  */
3 /* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */
4 /* { dg-do compile } */
5
6 #include <objc/objc.h>
7 #include <objc/Object.h>
8 extern void abort (void);
9 /*
10 struct __objcFastEnumerationState
11 {
12   unsigned long state;
13   id            *itemsPtr;
14   unsigned long *mutationsPtr;
15   unsigned long extra[5];
16 };
17 */
18 @interface Object (NSFastEnumeration)
19 - (unsigned long)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state
20                                      objects:(id *)stackbuf 
21                                        count:(unsigned int)len;
22 - (id) enumerator;
23 @end
24
25 int main (void)
26 {
27   id array = nil;
28   id object = nil;
29
30   for (object in array) /* Ok */
31     ;
32
33   for (object in nil) /* Ok */
34     ;
35
36   for (object in) /* { dg-error "missing collection in fast enumeration" } */
37     ;
38
39   for (object = nil in array) /* { dg-error "invalid iterating variable in fast enumeration" } */
40     ;
41
42   for (object in [object enumerator]) /* Ok */
43     ;
44
45   for (12 in array) /* { dg-error "invalid iterating variable in fast enumeration" } */
46     ; /* { dg-error "iterating variable in fast enumeration is not an object" } */
47
48   for (object in 12)
49     ; /* { dg-error "collection in fast enumeration is not an object" } */
50
51   return 0;
52 }