| 1 |
/* Test basic Objective-C foreach syntax. This tests warnings and errors. */ |
| 2 |
/* |
| 3 |
{ dg-options "-ftrack-macro-expansion=0" } |
| 4 |
{ dg-do compile } |
| 5 |
*/ |
| 6 |
|
| 7 |
#import "../objc-obj-c++-shared/TestsuiteObject.h" |
| 8 |
#import <objc/objc.h> |
| 9 |
#undef nil |
| 10 |
#define nil ((id)0) |
| 11 |
/* |
| 12 |
struct __objcFastEnumerationState |
| 13 |
{ |
| 14 |
unsigned long state; |
| 15 |
id *itemsPtr; |
| 16 |
unsigned long *mutationsPtr; |
| 17 |
unsigned long extra[5]; |
| 18 |
}; |
| 19 |
*/ |
| 20 |
@interface TestsuiteObject (NSFastEnumeration) |
| 21 |
- (unsigned long)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state |
| 22 |
objects:(id *)stackbuf |
| 23 |
count:(unsigned int)len; |
| 24 |
- (id) enumerator; |
| 25 |
@end |
| 26 |
|
| 27 |
void function (void) |
| 28 |
{ |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
id object_function (void) |
| 33 |
{ |
| 34 |
return nil; |
| 35 |
} |
| 36 |
|
| 37 |
int main (void) |
| 38 |
{ |
| 39 |
id array = nil; |
| 40 |
id object = nil; |
| 41 |
|
| 42 |
for (typedef int my_typedef in array) |
| 43 |
; /* { dg-error "iterating variable in fast enumeration is not an object" "" { target *-*-* } .-1 } */ |
| 44 |
|
| 45 |
for (function () in nil) /* { dg-error "invalid iterating variable in fast enumeration" } */ |
| 46 |
; /* { dg-error "iterating variable in fast enumeration is not an object" "" { target *-*-* } .-1 } */ |
| 47 |
|
| 48 |
for (object_function () in nil) /* { dg-error "invalid iterating variable in fast enumeration" } */ |
| 49 |
; |
| 50 |
|
| 51 |
for ([object enumerator] in array) /* { dg-error "invalid iterating variable in fast enumeration" } */ |
| 52 |
; |
| 53 |
|
| 54 |
for (object = nil in array) /* { dg-error "invalid iterating variable in fast enumeration" } */ |
| 55 |
; |
| 56 |
|
| 57 |
for (id key, value in array) /* { dg-error "multiple iterating variables in fast enumeration" } */ |
| 58 |
; |
| 59 |
|
| 60 |
return 0; |
| 61 |
} |
| 62 |
|