objc-act.c (adjust_type_for_id_default): Do not allow an object as parameter.
authorDevang Patel <dpatel@apple.com>
Tue, 2 Jul 2002 23:06:04 +0000 (16:06 -0700)
committerDevang Patel <dpatel@gcc.gnu.org>
Tue, 2 Jul 2002 23:06:04 +0000 (16:06 -0700)
      * objc/objc-act.c (adjust_type_for_id_default): Do not allow an
        object as parameter. Prevent something like 'NSObject' to be
        used as the type for a method argument.

      testsuite:
      * objc.dg/param-1.m: New test.

From-SVN: r55197

gcc/ChangeLog
gcc/objc/objc-act.c
gcc/testsuite/ChangeLog
gcc/testsuite/objc.dg/param-1.m [new file with mode: 0644]

index 8dae99bae5e18af0f6ba91159e7d06989dba0253..ef5cd4bbde8daa5aa4c0dd2b22dacd7da43cf7ee 100644 (file)
@@ -1,3 +1,9 @@
+
+2002-07-02 Devang Patel <dpatel@apple.com
+       * objc/objc-act.c (adjust_type_for_id_default): Do not allow an
+         object as parameter. Prevent something like 'NSObject' to be
+         used as the type for a method argument.
+
 2002-07-03  Neil Booth  <neil@daikokuya.co.uk>
 
        * cpptrad.c: Update comment.
index c0db5993d5641d55076bcb1f4b8d2dfee0ebbf21..e8f97ac4bcbe419a0f18d3d9c72efef1642ee35a 100644 (file)
@@ -4465,6 +4465,10 @@ adjust_type_for_id_default (type)
        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;
     }
index 62ce01d600ed7966d73e8fd8c74a9b5d29ab4d54..16cc4791d8784dabf4a4e8d93e3371c956c25143 100644 (file)
@@ -1,3 +1,6 @@
+2002-07-02 Devang Patel <dpatel@apple.com>
+       * objc.dg/param-1.m: New test.
+
 2002-07-03  Neil Booth  <neil@daikokuya.co.uk>
 
        * gcc.dg/cpp/trad/directive.c: Add test.
diff --git a/gcc/testsuite/objc.dg/param-1.m b/gcc/testsuite/objc.dg/param-1.m
new file mode 100644 (file)
index 0000000..e796a3b
--- /dev/null
@@ -0,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
+