OSDN Git Service

Backported from mainline
[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/TestsuiteObject.h"
5 #import <objc/objc.h>
6 #undef  nil
7 #define nil ((id)0)
8 /*
9 struct __objcFastEnumerationState
10 {
11   unsigned long state;
12   id            *itemsPtr;
13   unsigned long *mutationsPtr;
14   unsigned long extra[5];
15 };
16 */
17 @interface TestsuiteObject (NSFastEnumeration)
18 - (unsigned long)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state
19                                      objects:(id *)stackbuf 
20                                        count:(unsigned int)len;
21 - (id) enumerator;
22 @end
23
24 void function (void)
25 {
26   return;
27 }
28
29 id object_function (void)
30 {
31   return nil;
32 }
33
34 int main (void)
35 {
36   id array = nil;
37   id object = nil;
38
39   for (typedef int my_typedef in array) /* { dg-error "declaration of non-variable" } */
40     ;                                   /* { dg-error "iterating variable in fast enumeration is not an object" "" { target *-*-* } 39 } */
41
42   for (function () in nil) /* { dg-error "invalid iterating variable in fast enumeration" } */
43     ;                      /* { dg-error "iterating variable in fast enumeration is not an object" "" { target *-*-* } 42 } */
44
45   for (object_function () in nil) /* { dg-error "invalid iterating variable in fast enumeration" } */
46     ;
47
48   for ([object enumerator] in array) /* { dg-error "invalid iterating variable in fast enumeration" } */
49     ;
50
51   for (object = nil in array) /* { dg-error "invalid iterating variable in fast enumeration" } */
52     ;
53
54   for (id key, value in array) /* { dg-error "multiple iterating variables in fast enumeration" } */
55     ;
56
57   return 0;
58 }
59