OSDN Git Service

In gcc/:
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / foreach-7.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 @end
22
23 void function (void)
24 {
25   return;
26 }
27
28 id object_function (void)
29 {
30   return nil;
31 }
32
33 int main (void)
34 {
35   id array = nil;
36   id object = nil;
37
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" } */
40
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" } */
43
44   for (object_function () in nil) /* { dg-error "invalid iterating variable in fast enumeration" } */
45     ;
46
47   for ([object enumerator] in array) /* { dg-error "invalid iterating variable in fast enumeration" } */
48     ;
49
50   for (object = nil in array) /* { dg-error "invalid iterating variable in fast enumeration" } */
51     ;
52
53   for (id key, value in array) /* { dg-error "multiple iterating variables in fast enumeration" } */
54     ;
55
56   return 0;
57 }
58