view gcc/testsuite/objc.dg/foreach-8.m @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 04ced10e8804
children
line wrap: on
line source

/* 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;
}