From c40da518998023c0190b1667bce7aab3c6099f66 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 2 Jul 2002 16:06:04 -0700 Subject: [PATCH] objc-act.c (adjust_type_for_id_default): Do not allow an object as parameter. * 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 | 6 ++++++ gcc/objc/objc-act.c | 4 ++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/objc.dg/param-1.m | 20 ++++++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/objc.dg/param-1.m diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8dae99bae5e..ef5cd4bbde8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ + +2002-07-02 Devang Patel * cpptrad.c: Update comment. diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index c0db5993d56..e8f97ac4bcb 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 62ce01d600e..16cc4791d87 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,6 @@ +2002-07-02 Devang Patel + * objc.dg/param-1.m: New test. + 2002-07-03 Neil Booth * 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 index 00000000000..e796a3b5107 --- /dev/null +++ b/gcc/testsuite/objc.dg/param-1.m @@ -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 + -- 2.30.2