OSDN Git Service

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 /* { dg-do compile } */
3
4 #import "../objc-obj-c++-shared/Object1.h"
5 #import "../objc-obj-c++-shared/next-mapping.h"
6
7 /*
8 struct __objcFastEnumerationState
9 {
10   unsigned long state;
11   id            *itemsPtr;
12   unsigned long *mutationsPtr;
13   unsigned long extra[5];
14 };
15 */
16 @interface Object (NSFastEnumeration)
17 - (unsigned long)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state
18                                      objects:(id *)stackbuf 
19                                        count:(unsigned int)len;
20 - (id) enumerator;
21 - (Class) classEnumerator;
22 @end
23
24 int main (void)
25 {
26   id array = nil;
27   id object = nil;
28   id *invalid = 0;
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 (object in [object classEnumerator]) /* Ok */
46     ;
47
48   for (12 in array) /* { dg-error "invalid iterating variable in fast enumeration" } */
49     ;               /* { dg-error "iterating variable in fast enumeration is not an object" "" { target *-*-* } 48 } */
50
51   for (object in 12) /* { dg-error "collection in fast enumeration is not an object" } */
52     ;
53
54   for (object in invalid) /* { dg-error "collection in fast enumeration is not an object" } */
55     ;
56
57   for (invalid in [object enumerator]) /* { dg-error "iterating variable in fast enumeration is not an object" } */
58     ;
59
60   return 0;
61 }