From 8f78939bbf5706bec999fe2b2425eeea8f48f239 Mon Sep 17 00:00:00 2001 From: Nicola Pero Date: Mon, 1 Nov 2010 21:12:12 +0000 Subject: [PATCH] In gcc/objc/: 2010-11-01 Nicola Pero In gcc/objc/: 2010-11-01 Nicola Pero * objc-act.c (objc_maybe_build_component_ref): Warn about using deprecated properties. (objc_maybe_printable_name): Support PROPERTY_DECL. In gcc/testsuite/: 2010-11-01 Nicola Pero * objc.dg/property/at-property-deprecated-1.m: New. * obj-c++.dg/property/at-property-deprecated-1.mm: New. From-SVN: r166147 --- gcc/objc/ChangeLog | 6 +++ gcc/objc/objc-act.c | 10 +++++ gcc/testsuite/ChangeLog | 5 +++ .../property/at-property-deprecated-1.mm | 37 +++++++++++++++++++ .../property/at-property-deprecated-1.m | 37 +++++++++++++++++++ 5 files changed, 95 insertions(+) create mode 100644 gcc/testsuite/obj-c++.dg/property/at-property-deprecated-1.mm create mode 100644 gcc/testsuite/objc.dg/property/at-property-deprecated-1.m diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 5a7c85f5fc2..1e612916428 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,3 +1,9 @@ +2010-11-01 Nicola Pero + + * objc-act.c (objc_maybe_build_component_ref): Warn about using + deprecated properties. + (objc_maybe_printable_name): Support PROPERTY_DECL. + 2010-11-01 Nicola Pero Implemented Objective-C 2.0 property accessors. diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 00e2a4330a3..68639ce8356 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -1122,6 +1122,9 @@ objc_maybe_build_component_ref (tree object, tree property_ident) { tree expression; + if (TREE_DEPRECATED (x)) + warn_deprecated_use (x, NULL_TREE); + expression = build2 (PROPERTY_REF, TREE_TYPE(x), object, x); SET_EXPR_LOCATION (expression, input_location); TREE_SIDE_EFFECTS (expression) = 1; @@ -11224,6 +11227,13 @@ objc_maybe_printable_name (tree decl, int v ATTRIBUTE_UNUSED) case CLASS_METHOD_DECL: return IDENTIFIER_POINTER (DECL_NAME (decl)); break; + /* This happens when printing a deprecation warning for a + property. We may want to consider some sort of pretty + printing (eg, include the class name where it was declared + ?). */ + case PROPERTY_DECL: + return IDENTIFIER_POINTER (PROPERTY_NAME (decl)); + break; default: return NULL; break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ae4de13e2f5..ccace6fc17c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-11-01 Nicola Pero + + * objc.dg/property/at-property-deprecated-1.m: New. + * obj-c++.dg/property/at-property-deprecated-1.mm: New. + 2010-11-01 Nicola Pero Implemented Objective-C 2.0 property accessors. diff --git a/gcc/testsuite/obj-c++.dg/property/at-property-deprecated-1.mm b/gcc/testsuite/obj-c++.dg/property/at-property-deprecated-1.mm new file mode 100644 index 00000000000..1bcb28820a6 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/property/at-property-deprecated-1.mm @@ -0,0 +1,37 @@ +/* Contributed by Nicola Pero , October 2010. */ +/* { dg-do compile } */ + +/* Test that properties can be deprecated. */ + +#include +#include +#include + +@interface MyRootClass +{ + Class isa; + int a; +} +@property int a __attribute__((deprecated)); ++ (id) initialize; ++ (id) alloc; +- (id) init; +@end + +@implementation MyRootClass ++ (id) initialize { return self; } ++ (id) alloc { return class_createInstance (self, 0); } +- (id) init { return self; } +@synthesize a; +@end + +int main (void) +{ + MyRootClass *object = [[MyRootClass alloc] init]; + + object.a = 40; /* { dg-warning ".a. is deprecated .declared at " } */ + if (object.a != 40) /* { dg-warning ".a. is deprecated .declared at " } */ + abort (); + + return (0); +} diff --git a/gcc/testsuite/objc.dg/property/at-property-deprecated-1.m b/gcc/testsuite/objc.dg/property/at-property-deprecated-1.m new file mode 100644 index 00000000000..c38854ff38d --- /dev/null +++ b/gcc/testsuite/objc.dg/property/at-property-deprecated-1.m @@ -0,0 +1,37 @@ +/* Contributed by Nicola Pero , October 2010. */ +/* { dg-do compile } */ + +/* Test that properties can be deprecated. */ + +#include +#include +#include + +@interface MyRootClass +{ + Class isa; + int a; +} +@property int a __attribute__((deprecated)); ++ (id) initialize; ++ (id) alloc; +- (id) init; +@end + +@implementation MyRootClass ++ (id) initialize { return self; } ++ (id) alloc { return class_createInstance (self, 0); } +- (id) init { return self; } +@synthesize a; +@end + +int main (void) +{ + MyRootClass *object = [[MyRootClass alloc] init]; + + object.a = 40; /* { dg-warning ".a. is deprecated .declared at " } */ + if (object.a != 40) /* { dg-warning ".a. is deprecated .declared at " } */ + abort (); + + return 0; +} -- 2.30.2