summaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc.dg/foreach-8.m
blob: 9a68e9ffb0565459e3df766914fc2858478aeb58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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;
}