aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-parser.c6
-rw-r--r--gcc/objc/ChangeLog5
-rw-r--r--gcc/objc/objc-act.c12
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/objc.dg/foreach-8.m51
6 files changed, 81 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c2d40f1..b6269f7 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2010-12-06 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ * c-parser.c (c_parser_for_statement): Use c_fully_fold() instead
+ of c_process_expr_stmt() for the iterating and collection
+ expressions of an Objective-C fast enumeration loop.
+
2010-12-06 Jakub Jelinek <jakub@redhat.com>
PR debug/45997
diff --git a/gcc/c-parser.c b/gcc/c-parser.c
index f2d5e5b..62eb1e7 100644
--- a/gcc/c-parser.c
+++ b/gcc/c-parser.c
@@ -4812,8 +4812,7 @@ c_parser_for_statement (c_parser *parser)
is_foreach_statement = true;
if (! lvalue_p (init_expression))
c_parser_error (parser, "invalid iterating variable in fast enumeration");
- object_expression = c_process_expr_stmt (loc, init_expression);
-
+ object_expression = c_fully_fold (init_expression, false, NULL);
}
else
{
@@ -4854,7 +4853,8 @@ c_parser_for_statement (c_parser *parser)
else
{
if (is_foreach_statement)
- collection_expression = c_process_expr_stmt (loc, c_parser_expression (parser).value);
+ collection_expression = c_fully_fold (c_parser_expression (parser).value,
+ false, NULL);
else
incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
}
diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog
index 99df784..f3001e5 100644
--- a/gcc/objc/ChangeLog
+++ b/gcc/objc/ChangeLog
@@ -1,5 +1,10 @@
2010-12-06 Nicola Pero <nicola.pero@meta-innovation.com>
+ * objc-act.c (objc_finish_foreach_loop): Mark the
+ object_expression as used.
+
+2010-12-06 Nicola Pero <nicola.pero@meta-innovation.com>
+
* objc-act.c: Include c-family/c-objc.h.
* objc-lang.c: Same change.
* Make-lang.in (objc/objc-act.o): Depend on
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index 49e2442..f530556 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -13290,6 +13290,18 @@ objc_finish_foreach_loop (location_t location, tree object_expression, tree coll
/* type object; */
/* Done by c-parser.c. */
+ /* Disable warnings that 'object' is unused. For example the code
+
+ for (id object in collection)
+ i++;
+
+ which can be used to count how many objects there are in the
+ collection is fine and should generate no warnings even if
+ 'object' is technically unused. */
+ TREE_USED (object_expression) = 1;
+ if (DECL_P (object_expression))
+ DECL_READ_P (object_expression) = 1;
+
/* id __objc_foreach_collection */
objc_foreach_collection_decl = objc_create_temporary_var (objc_object_type, "__objc_foreach_collection");
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0aecee3..f278725 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2010-12-06 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ * objc.dg/foreach-8.m: New.
+
2010-12-06 Jakub Jelinek <jakub@redhat.com>
PR debug/45997
diff --git a/gcc/testsuite/objc.dg/foreach-8.m b/gcc/testsuite/objc.dg/foreach-8.m
new file mode 100644
index 0000000..9a68e9f
--- /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;
+}