From 5a2a6eb0503f631694426849a94ccb8355c7aad9 Mon Sep 17 00:00:00 2001 From: Nicola Pero Date: Sat, 13 Nov 2010 15:53:32 +0000 Subject: [PATCH] In gcc/objc/: 2010-11-13 Nicola Pero In gcc/objc/: 2010-11-13 Nicola Pero * objc-act.c (objc_get_protocol_qualified_type): detect cases where we are asked to attach a protocol to something which is not an Objective-C object type, and produce an error. In gcc/testsuite/: 2010-11-13 Nicola Pero * objc/compile/20060406-1.m: Fixed testcase not to try to qualify a pointer to an arbitrary C struct with an Objective-C protocol. Test various valid uses of typedef with Objective-C objects and protocols instead. * objc.dg/invalid-type-1.m: New. * obj-c++.dg/invalid-type-1.m: New. From-SVN: r166709 --- gcc/objc/ChangeLog | 6 +++ gcc/objc/objc-act.c | 17 ++++++- gcc/testsuite/ChangeLog | 10 ++++ gcc/testsuite/obj-c++.dg/invalid-type-1.mm | 25 ++++++++++ gcc/testsuite/objc.dg/invalid-type-1.m | 24 ++++++++++ gcc/testsuite/objc/compile/20060406-1.m | 56 +++++++++++++++++++--- 6 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/obj-c++.dg/invalid-type-1.mm create mode 100644 gcc/testsuite/objc.dg/invalid-type-1.m diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index f2f2a6a387f..41bc7969a03 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,3 +1,9 @@ +2010-11-13 Nicola Pero + + * objc-act.c (objc_get_protocol_qualified_type): detect cases + where we are asked to attach a protocol to something which is not + an Objective-C object type, and produce an error. + 2010-11-11 Nicola Pero * objc-act.c (objc_add_property_declaration): Check that the type diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 715623f379f..48b04ac9ef4 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -2530,7 +2530,22 @@ objc_get_protocol_qualified_type (tree interface, tree protocols) : xref_tag (RECORD_TYPE, type)); } else - return interface; + { + /* This case happens when we are given an 'interface' which + is not a valid class name. For example if a typedef was + used, and 'interface' really is the identifier of the + typedef, but when you resolve it you don't get an + Objective-C class, but something else, such as 'int'. + This is an error; protocols make no sense unless you use + them with Objective-C objects. */ + error_at (input_location, "only Objective-C object types can be qualified with a protocol"); + + /* Try to recover. Ignore the invalid class name, and treat + the object as an 'id' to silence further warnings about + the class. */ + type = objc_object_type; + is_ptr = true; + } } if (protocols) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bab3fe62ccf..e0d8dba672e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2010-11-13 Nicola Pero + + * objc/compile/20060406-1.m: Fixed testcase not to try to qualify + a pointer to an arbitrary C struct with an Objective-C protocol. + Test various valid uses of typedef with Objective-C objects and + protocols instead. + * objc.dg/invalid-type-1.m: New. + * obj-c++.dg/invalid-type-1.m: New. + 2010-11-13 Iain Sandoe * gcc.dg/darwin-segaddr.c: New test for multiple argument c/l switch. @@ -170,6 +179,7 @@ * gfortran.dg/proc_decl_24.f90: New. 2010-11-11 Nicola Pero + * objc.dg/property/at-property-20.m: New. * objc.dg/property/synthesize-8.m: New. * obj-c++.dg/property/at-property-20.m: New. diff --git a/gcc/testsuite/obj-c++.dg/invalid-type-1.mm b/gcc/testsuite/obj-c++.dg/invalid-type-1.mm new file mode 100644 index 00000000000..2d6ba68de1e --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/invalid-type-1.mm @@ -0,0 +1,25 @@ +/* Contributed by Nicola Pero , November 2010. */ +/* { dg-do compile } */ +#include + +typedef int Integer; + +@class MyClass; + +typedef MyClass AClass; + +@protocol MyProtocol +- (void) method; +@end + +Class class_object; /* This is fine. */ + +id object; /* This is fine. */ + +AClass *object1; /* This is fine. */ + +Integer *object2; /* { dg-error ".Integer. is not a template" } */ +/* { dg-error ".MyProtocol. was not declared in this scope" "" { target *-*-* } 21 } */ + +Integer *object3; /* { dg-error ".Integer. is not a template" } */ +/* { dg-error ".NonExistingProtocol. was not declared in this scope" "" { target *-*-* } 24 } */ diff --git a/gcc/testsuite/objc.dg/invalid-type-1.m b/gcc/testsuite/objc.dg/invalid-type-1.m new file mode 100644 index 00000000000..b8609f8c831 --- /dev/null +++ b/gcc/testsuite/objc.dg/invalid-type-1.m @@ -0,0 +1,24 @@ +/* Contributed by Nicola Pero , November 2010. */ +/* { dg-do compile } */ +#include + +typedef int Integer; + +@class MyClass; + +typedef MyClass AClass; + +@protocol MyProtocol +- (void) method; +@end + +Class class_object; /* This is fine. */ + +id object; /* This is fine. */ + +AClass *object1; /* This is fine. */ + +Integer *object2; /* { dg-error "only Objective-C object types can be qualified with a protocol" } */ + +Integer *object3; /* { dg-error "only Objective-C object types can be qualified with a protocol" } */ +/* { dg-error "cannot find protocol" "" { target *-*-* } 23 } */ diff --git a/gcc/testsuite/objc/compile/20060406-1.m b/gcc/testsuite/objc/compile/20060406-1.m index e4496bf6ede..62148902ac4 100644 --- a/gcc/testsuite/objc/compile/20060406-1.m +++ b/gcc/testsuite/objc/compile/20060406-1.m @@ -1,21 +1,65 @@ -typedef struct -{ - void *p; -} *S; +/* This test tests typedefs and protocol qualifiers. */ @protocol O - (unsigned)j; @end +@interface T +@end + + +/* First test. */ +typedef T *S; + @interface I -+ (unsigned char)T:(S[2])p v:(S)h; ++ (unsigned char)T:(S[2])p + v:(S)h; @end @implementation I -+ (unsigned char)T:(S[2])p v:(S)h ++ (unsigned char)T:(S[2])p + v:(S)h { p[0] = (S) 0; p[1] = (S) 0; return 0; } @end + + +/* Second test. */ +typedef T S1; + +@interface I1 ++ (unsigned char)T1:(S1*[2])p + v1:(S1*)h; +@end + +@implementation I1 ++ (unsigned char)T1:(S1*[2])p + v1:(S1*)h +{ + p[0] = (S1*) 0; + p[1] = (S1*) 0; + return 0; +} +@end + + +/* Third test. */ +typedef T S2; + +@interface I2 ++ (unsigned char)T1:(S2*[2])p + v1:(S2*)h; +@end + +@implementation I2 ++ (unsigned char)T1:(S2*[2])p + v1:(S2*)h +{ + p[0] = (S2*) 0; + p[1] = (S2*) 0; + return 0; +} +@end -- 2.30.2