gcc/testsuite:
[official-gcc.git] / gcc / testsuite / objc.dg / foreach-7.m
blob5da940f620ee7ef84aef16ca47880f526d5a0143
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 void function (void)
25   return;
28 id object_function (void)
30   return nil;
33 int main (void)
35   id array = nil;
36   id object = nil;
38   for (typedef int my_typedef in array) /* { dg-error "declaration of non-variable" } */
39     ; /* { dg-error "iterating variable in fast enumeration is not an object" } */
41   for (function () in nil) /* { dg-error "invalid iterating variable in fast enumeration" } */
42     ; /* { dg-error "iterating variable in fast enumeration is not an object" } */
44   for (object_function () in nil) /* { dg-error "invalid iterating variable in fast enumeration" } */
45     ;
47   for ([object enumerator] in array) /* { dg-error "invalid iterating variable in fast enumeration" } */
48     ;
50   for (object = nil in array) /* { dg-error "invalid iterating variable in fast enumeration" } */
51     ;
53   for (id key, value in array) /* { dg-error "multiple iterating variables in fast enumeration" } */
54     ;
56   return 0;