gcc/testsuite:
[official-gcc.git] / gcc / testsuite / objc.dg / foreach-6.m
blobd368390cbcabfe8cff25091bc1d37e4402cb86d6
1 /* Test basic Objective-C foreach syntax.  This tests warnings and errors.  */
2 /* { dg-do compile } */
4 #import "../objc-obj-c++-shared/Object1.h"
5 #import "../objc-obj-c++-shared/next-mapping.h"
7 /*
8 struct __objcFastEnumerationState
10   unsigned long state;
11   id            *itemsPtr;
12   unsigned long *mutationsPtr;
13   unsigned long extra[5];
16 @interface Object (NSFastEnumeration)
17 - (unsigned long)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state
18                                      objects:(id *)stackbuf 
19                                        count:(unsigned int)len;
20 - (id) enumerator;
21 @end
23 int main (void)
25   id array = nil;
26   id object = nil;
28   for (object in array) /* Ok */
29     ;
31   for (object in nil) /* Ok */
32     ;
34   for (object in) /* { dg-error "missing collection in fast enumeration" } */
35     ;
37   for (object = nil in array) /* { dg-error "invalid iterating variable in fast enumeration" } */
38     ;
40   for (object in [object enumerator]) /* Ok */
41     ;
43   for (12 in array) /* { dg-error "invalid iterating variable in fast enumeration" } */
44     ; /* { dg-error "iterating variable in fast enumeration is not an object" } */
46   for (object in 12)
47     ; /* { dg-error "collection in fast enumeration is not an object" } */
49   return 0;