This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Objective-C : Do not accept an object as parameter to a method



With this simple patch compiler checks whether (and raise error if required) an object
is used as parameter to a method or not. Because it is not a good idea in Objective-C.

2002-06-26 Devang Patel <dpatel@apple.com>

* objc/objc-act.c (adjust_type_for_id_default): Do not allow an object
as parameter.
testsuite:
* objc.dg/param-1.m: New test.


Index: objc-act.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.137
diff -c -3 -p -r1.137 objc-act.c
*** objc-act.c 11 Jun 2002 23:11:34 -0000 1.137
--- objc-act.c 26 Jun 2002 23:48:49 -0000
*************** adjust_type_for_id_default (type)
*** 4460,4465 ****
--- 4463,4472 ----
chain;
chain = TREE_CHAIN (chain))
{
+ if (TREE_CODE (TREE_VALUE (chain)) == RECORD_TYPE
+ && !(TREE_VALUE (type)
+ && TREE_CODE (TREE_VALUE (type)) == INDIRECT_REF))
+ error ("can not use an object as parameter to a method\n");
if (!is_objc_type_qualifier (TREE_VALUE (chain)))
return type;
}

*** /dev/null Thu Aug 30 13:30:55 2001
--- param-1.m Wed Jun 26 16:35:46 2002
***************
*** 0 ****
--- 1,20 ----
+ /* Test if compiler detects object as an parameter to a method
+ or not. It is not valid. */
+ /* { dg-do compile } */
+
+ @interface foo
+ @end
+
+ @implementation foo
+ @end
+
+ @interface bar
+ -(void) my_method:(foo) my_param; /* { dg-error "can not use an object as parameter to a method" } */
+ @end
+
+ @implementation bar
+ -(void) my_method:(foo) my_param /* { dg-error "can not use an object as parameter to a method" } */
+ {
+ }
+ @end
+



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]