diff options
Diffstat (limited to 'gcc/testsuite/objc.dg/foreach-8.m')
-rw-r--r-- | gcc/testsuite/objc.dg/foreach-8.m | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/gcc/testsuite/objc.dg/foreach-8.m b/gcc/testsuite/objc.dg/foreach-8.m new file mode 100644 index 000000000..9a68e9ffb --- /dev/null +++ b/gcc/testsuite/objc.dg/foreach-8.m @@ -0,0 +1,51 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, December 2010. */ +/* { dg-options "-Wall" } */ +/* { dg-do compile } */ + +/* Test that fast enumeration loops where the iterating variable is declared + but not used do not generate warnings. */ + +/* +struct __objcFastEnumerationState +{ + unsigned long state; + id *itemsPtr; + unsigned long *mutationsPtr; + unsigned long extra[5]; +}; +*/ +@interface Object +{ + Class isa; +} +- (unsigned long)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state + objects:(id *)stackbuf + count:(unsigned int)len; +- (id) enumerator; +- (Class) classEnumerator; +@end + +unsigned int count_objects_in_collection (id collection) +{ + unsigned int count = 0; + + /* The following line should generate no warnings even with + -Wall. */ + for (id object in collection) + count++; + + return count; +} + +unsigned int count_objects_in_collection_2 (id collection) +{ + unsigned int count = 0; + id object; + + /* The following line should generate no warnings even with + -Wall. */ + for (object in collection) + count++; + + return count; +} |