Commit 4ca5d2a7 by Nicola Pero Committed by Nicola Pero

In gcc/objc/: 2010-11-08 Nicola Pero <nicola.pero@meta-innovation.com>

In gcc/objc/:
2010-11-08  Nicola Pero  <nicola.pero@meta-innovation.com>

        * objc-act.c (lookup_property): When checking categories, also
        check the protocols attached to each.
        (objc_add_property_declaration): Determine the
        PROPERTY_SETTER_NAME and PROPERTY_GETTER_NAME here.  Tidied up
        error message.  Search for an existing property declaration with
        the same name which would be inherited from the class hiearchy,
        and produce an error if it has incompatible attributes.
        (check_methods): Changed second parameter.  If the method is a
        getter or setter for a property, do not warn if it is inherited as
        opposed to implemented directly in the class.
        (check_protocol): Updated calls to check_methods.
        (finish_class): Do not determine the PROPERTY_SETTER_NAME and
        PROPERTY_GETTER_NAME here; this is now done earlier, in
        objc_add_property_declaration.
        * objc-act.h (CLASS_NAME, CLASS_SUPER_NAME): Added comments.

In gcc/testsuite/:
2010-11-08  Nicola Pero  <nicola.pero@meta-innovation.com>

        * objc.dg/property/at-property-5.m: Updated test.       
        * objc.dg/property/at-property-16.m: New.
        * objc.dg/property/at-property-17.m: New.
        * objc.dg/property/at-property-18.m: New.
        * objc.dg/property/at-property-19.m: New.       
        * objc.dg/property/dotsyntax-12.m: New
        * objc.dg/protocol-inheritance-1.m: New.
        * objc.dg/protocol-inheritance-2.m: New.
        * obj-c++.dg/property/at-property-5.mm: Updated test.
        * obj-c++.dg/property/at-property-16.mm: New.
        * obj-c++.dg/property/at-property-17.mm: New.
        * obj-c++.dg/property/at-property-18.mm: New.
        * obj-c++.dg/property/at-property-19.mm: New.   
        * obj-c++.dg/protocol-inheritance-1.mm: New.
        * obj-c++.dg/protocol-inheritance-2.mm: New.
        * obj-c++.dg/property/dotsyntax-12.mm: New.

From-SVN: r166455
parent 9e115cec
2010-11-08 Nicola Pero <nicola.pero@meta-innovation.com>
* objc-act.c (lookup_property): When checking categories, also
check the protocols attached to each.
(objc_add_property_declaration): Determine the
PROPERTY_SETTER_NAME and PROPERTY_GETTER_NAME here. Tidied up
error message. Search for an existing property declaration with
the same name which would be inherited from the class hiearchy,
and produce an error if it has incompatible attributes.
(check_methods): Changed second parameter. If the method is a
getter or setter for a property, do not warn if it is inherited as
opposed to implemented directly in the class.
(check_protocol): Updated calls to check_methods.
(finish_class): Do not determine the PROPERTY_SETTER_NAME and
PROPERTY_GETTER_NAME here; this is now done earlier, in
objc_add_property_declaration.
* objc-act.h (CLASS_NAME, CLASS_SUPER_NAME): Added comments.
2010-11-06 Nicola Pero <nicola.pero@meta-innovation.com> 2010-11-06 Nicola Pero <nicola.pero@meta-innovation.com>
Fixed using the Objective-C 2.0 syntax with self and super. Fixed using the Objective-C 2.0 syntax with self and super.
......
...@@ -144,7 +144,10 @@ typedef enum objc_property_assign_semantics { ...@@ -144,7 +144,10 @@ typedef enum objc_property_assign_semantics {
/* CLASS_INTERFACE_TYPE, CLASS_IMPLEMENTATION_TYPE, /* CLASS_INTERFACE_TYPE, CLASS_IMPLEMENTATION_TYPE,
CATEGORY_INTERFACE_TYPE, CATEGORY_IMPLEMENTATION_TYPE, CATEGORY_INTERFACE_TYPE, CATEGORY_IMPLEMENTATION_TYPE,
PROTOCOL_INTERFACE_TYPE */ PROTOCOL_INTERFACE_TYPE */
/* CLASS_NAME is the name of the class. */
#define CLASS_NAME(CLASS) ((CLASS)->type.name) #define CLASS_NAME(CLASS) ((CLASS)->type.name)
/* CLASS_SUPER_NAME is the name of the superclass, or, in the case of
categories, it is the name of the category itself. */
#define CLASS_SUPER_NAME(CLASS) (TYPE_CHECK (CLASS)->type.context) #define CLASS_SUPER_NAME(CLASS) (TYPE_CHECK (CLASS)->type.context)
#define CLASS_IVARS(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 0) #define CLASS_IVARS(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 0)
#define CLASS_RAW_IVARS(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 1) #define CLASS_RAW_IVARS(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 1)
......
2010-11-08 Nicola Pero <nicola.pero@meta-innovation.com>
* objc.dg/property/at-property-5.m: Updated test.
* objc.dg/property/at-property-16.m: New.
* objc.dg/property/at-property-17.m: New.
* objc.dg/property/at-property-18.m: New.
* objc.dg/property/at-property-19.m: New.
* objc.dg/property/dotsyntax-12.m: New.
* objc.dg/protocol-inheritance-1.m: New.
* objc.dg/protocol-inheritance-2.m: New.
* obj-c++.dg/property/at-property-5.mm: Updated test.
* obj-c++.dg/property/at-property-16.mm: New.
* obj-c++.dg/property/at-property-17.mm: New.
* obj-c++.dg/property/at-property-18.mm: New.
* obj-c++.dg/property/at-property-19.mm: New.
* obj-c++.dg/protocol-inheritance-1.mm: New.
* obj-c++.dg/protocol-inheritance-2.mm: New.
* obj-c++.dg/property/dotsyntax-12.mm: New.
2010-11-08 Jason Merrill <jason@redhat.com> 2010-11-08 Jason Merrill <jason@redhat.com>
* g++.dg/expr/overflow1.C: New. * g++.dg/expr/overflow1.C: New.
......
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do compile } */
#include <objc/objc.h>
/* Test that if you have a property declared in a class and a
sub-class, the attributes match. */
@interface MyRootClass
{
Class isa;
}
@property (assign) id a;
@property (retain) id b;
@property int c;
@property (nonatomic) int d;
@property int e;
@property int f;
@property int g;
@property (readonly) int h;
@property (readonly,getter=getMe) int i;
@end
@interface MyClass : MyRootClass
@property (assign) id a;
@property (retain) id b;
@property int c;
@property (nonatomic) int d;
@property int e;
@property int f;
@property int g;
@property (readonly) int h;
@property (readonly,getter=getMe) int i;
@end
/* FIXME - there is a problem with the testuite in running the following test. The compiler generates the messages, but the testsuite still complains. */
@interface MyClass2 : MyRootClass
/* @property (retain) id a; */ /* dg-error "assign semantics attributes of property .a. conflict with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 13 */
/* @property (assign) id b; */ /* dg-error "assign semantics attributes of property .b. conflict with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 14 */
/* @property (nonatomic) int c; */ /* dg-error ".nonatomic. attribute of property .c. conflicts with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 15 */
/* @property int d; */ /* dg-error ".nonatomic. attribute of property .d. conflicts with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 16 */
/* @property (setter=setX:) int e; */ /* dg-error ".setter. attribute of property .e. conflicts with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 17 */
/* @property (getter=x) int f; */ /* dg-error ".getter. attribute of property .f. conflicts with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 18 */
/* @property (readonly) int g; */ /* dg-error ".readonly. attribute of property .g. conflicts with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 19 */
@property (readwrite) int h; /* Ok */
/* @property (readonly) int i; */ /* dg-error ".getter. attribute of property .i. conflicts with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 21 */
@end
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do compile } */
#include <objc/objc.h>
/* Test that if you have a property declared in a class, with
getters/setters in the superclass, there are no warnings. */
@interface MyRootClass
{
Class isa;
int myCount;
int myCount2;
int myCount3;
}
- (int)count;
- (void)setCount: (int)number;
- (int)count2;
- (void)setCount2: (int)number;
- (int)count3;
@end
@implementation MyRootClass
- (int) count
{
return myCount;
}
- (void) setCount: (int)number
{
myCount = number;
}
- (int) count2
{
return myCount2;
}
- (void) setCount2: (int)number
{
myCount2 = number;
}
- (int) count3
{
return myCount3;
}
@end
/* Try with a subclass. */
@interface MyClass : MyRootClass
@property int count;
@end
@implementation MyClass
@end /* No warnings. */
/* Try with a category. */
@interface MyRootClass (count)
@property int count;
@end
@implementation MyRootClass (count)
@end /* No warnings. */
/* Try with a category of a subclass. */
@interface MyClass2 : MyClass
@end
@implementation MyClass2
@end
@interface MyClass2 (count2)
@property int count2;
@end
@implementation MyClass2 (count2)
@end /* No warnings. */
/* Now, try with a category of a subclass, but with a missing setter,
which should generate a warning. */
@interface MyClass3 : MyClass
@end
@implementation MyClass3
@end
@interface MyClass3 (count3)
@property int count3;
@end
@implementation MyClass3 (count3)
@end /* { dg-warning "incomplete implementation" } */
/* { dg-warning "method definition for .-setCount3:. not found" "" { target *-*-* } 97 } */
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do compile } */
#include <objc/objc.h>
/* Test that if you have a property declared in a class and a
category, the attributes match. This is almost the same as
at-property-16.m, but for a category. It is a separate file
because it is difficult to test multiple messages for the same
line. */
@interface MyRootClass
{
Class isa;
}
@property (assign) id a;
@property (retain) id b;
@property int c;
@property (nonatomic) int d;
@property int e;
@property int f;
@property int g;
@property (readonly) int h;
@property (readonly,getter=getMe) int i;
@property (nonatomic) float j;
@end
/* FIXME - there is a problem with the testuite in running the following test. The compiler generates the messages, but the testsuite still complains. */
@interface MyRootClass (Category)
/*@property (retain) id a; */ /* dg-error "assign semantics attributes of property .a. conflict with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 16 */
/*@property (assign) id b; */ /* dg-error "assign semantics attributes of property .b. conflict with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 17 */
/*@property (nonatomic) int c; */ /* dg-error ".nonatomic. attribute of property .c. conflicts with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 18 */
/*@property int d; */ /* dg-error ".nonatomic. attribute of property .d. conflicts with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 19 */
/*@property (setter=setX:) int e; */ /* dg-error ".setter. attribute of property .e. conflicts with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 20 */
/*@property (getter=x) int f; */ /* dg-error ".getter. attribute of property .f. conflicts with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 21 */
/*@property (readonly) int g; */ /* dg-error ".readonly. attribute of property .g. conflicts with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 22 */
@property (readwrite) int h; /* Ok */
/*@property (readonly) int i; */ /* dg-error ".getter. attribute of property .i. conflicts with previous declaration" */
/* dg-message "originally specified here" "" { target *-*-* } 24 */
@property (nonatomic) float j; /* Ok */
@end
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */
/* { dg-do run } */
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
/* Test looking up a @property in a protocol of a category of a superclass. */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
@interface MyRootClass
{
Class isa;
int a;
}
+ (id) initialize;
+ (id) alloc;
- (id) init;
@end
@implementation MyRootClass
+ (id) initialize { return self; }
+ (id) alloc { return class_createInstance (self, 0); }
- (id) init { return self; }
@end
/* Use a different getter/setter, so that the only way to compile
object.count is to find the actual @property. */
@protocol count
@property (getter=number, setter=setNumber:) int count;
@end
@interface MySubClass : MyRootClass
- (int) testMe;
@end
@interface MySubClass (Category) <count>
@end
@implementation MySubClass (Category)
- (int) number
{
return a;
}
- (void) setNumber: (int)count
{
a = count;
}
@end
@implementation MySubClass
- (int) testMe
{
self.count = 400;
if (self.count != 400)
abort ();
return self.count;
}
@end
int main (void)
{
MySubClass *object = [[MySubClass alloc] init];
object.count = 44;
if (object.count != 44)
abort ();
if ([object testMe] != 400)
abort ();
return 0;
}
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
/* FIXME - there is a problem with the testuite in running the following test. The compiler /* FIXME - there is a problem with the testuite in running the following test. The compiler
generates the messages, but the testsuite still complains. */ generates the messages, but the testsuite still complains. */
/*@property (retain) id property_e;*/ /* dg-error "redeclaration of property .property_e." */ /*@property (retain) id property_e;*/ /* dg-error "redeclaration of property .property_e." */
/* dg-message "originally declared here" "" { target *-*-* } 26 */ /* dg-message "originally specified here" "" { target *-*-* } 26 */
@end @end
@property id test; /* { dg-error "misplaced .@property. Objective-C.. construct" } */ @property id test; /* { dg-error "misplaced .@property. Objective-C.. construct" } */
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do run } */
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
/* Test looking up a setter or getter which are in a protocol attached
to a category of a superclass. */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
static int c;
@interface MyRootClass
{
Class isa;
int a;
}
+ (id) initialize;
+ (id) alloc;
- (id) init;
@end
@implementation MyRootClass
+ (id) initialize { return self; }
+ (id) alloc { return class_createInstance (self, 0); }
- (id) init { return self; }
@end
@protocol count
- (int) count;
- (void) setCount: (int)count;
@end
@protocol classCount
+ (int) classCount;
+ (void) setClassCount: (int)count;
@end
@interface MyRootClass (Category) <count, classCount>
@end
@implementation MyRootClass (Category)
- (int) count
{
return a;
}
- (void) setCount: (int)count
{
a = count;
}
+ (int) classCount
{
return c;
}
+ (void) setClassCount: (int)count
{
c = count;
}
@end
@interface MySubClass : MyRootClass
+ (int) testMe;
- (int) testMe;
@end
@implementation MySubClass
- (int) testMe
{
self.count = 400;
if (self.count != 400)
abort ();
return self.count;
}
+ (int) testMe
{
self.classCount = 4000;
if (self.classCount != 4000)
abort ();
return self.classCount;
}
@end
int main (void)
{
MySubClass *object = [[MySubClass alloc] init];
object.count = 44;
if (object.count != 44)
abort ();
MySubClass.classCount = 40;
if (MySubClass.classCount != 40)
abort ();
if ([object testMe] != 400)
abort ();
if ([MySubClass testMe] != 4000)
abort ();
return 0;
}
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do compile } */
/* { dg-options "-Wno-protocol" } */
#include <objc/objc.h>
/* Test the -Wno-protocol flag. With this, at a class is accepted
(with no warnings) as conforming to a protocol even if some
protocol methods are implemented in the superclass. */
@protocol MyProtocol
- (int)method;
@end
@protocol MyProtocol2
- (int)method2;
@end
/* The superclass implements the method required by the protocol. */
@interface MyRootClass
{
Class isa;
}
- (int)method;
@end
@implementation MyRootClass
- (int)method
{
return 23;
}
@end
/* The subclass inherits the method (does not implement it directly)
but that still makes it conform to the protocol. No warnings. */
@interface MySubClass : MyRootClass <MyProtocol>
@end
@implementation MySubClass
@end /* No warnings here. */
/* The subclass instead does not inherit the method method2 (and does
not implement it directly) so it does not conform to the
protocol MyProtocol2. */
@interface MySubClass2 : MyRootClass <MyProtocol2>
@end
@implementation MySubClass2
@end /* Warnings here, below. */
/* { dg-warning "incomplete implementation of class .MySubClass2." "" { target *-*-* } 50 } */
/* { dg-warning "method definition for .\\-method2. not found" "" { target *-*-* } 50 } */
/* { dg-warning "class .MySubClass2. does not fully implement the .MyProtocol2. protocol" "" { target *-*-* } 50 } */
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do compile } */
#include <objc/objc.h>
/* Test standard warnings when a class conforms to a protocol but some
methods are implemented in the superclass. Use -Wno-protocol to
turn these off. */
@protocol MyProtocol
- (int)method;
@end
@protocol MyProtocol2
- (int)method2;
@end
/* The superclass implements the method required by the protocol. */
@interface MyRootClass
{
Class isa;
}
- (int)method;
@end
@implementation MyRootClass
- (int)method
{
return 23;
}
@end
/* The subclass inherits the method (does not implement it directly)
and unless -Wno-protocol is used, we emit a warning. */
@interface MySubClass : MyRootClass <MyProtocol>
@end
@implementation MySubClass
@end
/* { dg-warning "incomplete implementation of class .MySubClass." "" { target *-*-* } 39 } */
/* { dg-warning "method definition for .\\-method. not found" "" { target *-*-* } 39 } */
/* { dg-warning "class .MySubClass. does not fully implement the .MyProtocol. protocol" "" { target *-*-* } 39 } */
/* The subclass instead does not inherit the method method2 (and does
not implement it directly) so it does not conform to the
protocol MyProtocol2. */
@interface MySubClass2 : MyRootClass <MyProtocol2>
@end
@implementation MySubClass2
@end /* Warnings here, below. */
/* { dg-warning "incomplete implementation of class .MySubClass2." "" { target *-*-* } 53 } */
/* { dg-warning "method definition for .\\-method2. not found" "" { target *-*-* } 53 } */
/* { dg-warning "class .MySubClass2. does not fully implement the .MyProtocol2. protocol" "" { target *-*-* } 53 } */
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do compile } */
#include <objc/objc.h>
/* Test that if you have a property declared in a class and a
sub-class, the attributes match. */
@interface MyRootClass
{
Class isa;
}
@property (assign) id a;
@property (retain) id b;
@property int c;
@property (nonatomic) int d;
@property int e;
@property int f;
@property int g;
@property (readonly) int h;
@property (readonly,getter=getMe) int i;
@end
@interface MyClass : MyRootClass
@property (assign) id a;
@property (retain) id b;
@property int c;
@property (nonatomic) int d;
@property int e;
@property int f;
@property int g;
@property (readonly) int h;
@property (readonly,getter=getMe) int i;
@end
@interface MyClass2 : MyRootClass
@property (retain) id a; /* { dg-error "assign semantics attributes of property .a. conflict with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 13 } */
@property (assign) id b; /* { dg-error "assign semantics attributes of property .b. conflict with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 14 } */
@property (nonatomic) int c; /* { dg-error ".nonatomic. attribute of property .c. conflicts with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 15 } */
@property int d; /* { dg-error ".nonatomic. attribute of property .d. conflicts with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 16 } */
@property (setter=setX:) int e; /* { dg-error ".setter. attribute of property .e. conflicts with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 17 } */
@property (getter=x) int f; /* { dg-error ".getter. attribute of property .f. conflicts with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 18 } */
@property (readonly) int g; /* { dg-error ".readonly. attribute of property .g. conflicts with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 19 } */
@property (readwrite) int h; /* Ok */
@property (readonly) int i; /* { dg-error ".getter. attribute of property .i. conflicts with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 21 } */
@end
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do compile } */
#include <objc/objc.h>
/* Test that if you have a property declared in a class, with
getters/setters in the superclass, there are no warnings. */
@interface MyRootClass
{
Class isa;
int myCount;
int myCount2;
int myCount3;
}
- (int)count;
- (void)setCount: (int)number;
- (int)count2;
- (void)setCount2: (int)number;
- (int)count3;
@end
@implementation MyRootClass
- (int) count
{
return myCount;
}
- (void) setCount: (int)number
{
myCount = number;
}
- (int) count2
{
return myCount2;
}
- (void) setCount2: (int)number
{
myCount2 = number;
}
- (int) count3
{
return myCount3;
}
@end
/* Try with a subclass. */
@interface MyClass : MyRootClass
@property int count;
@end
@implementation MyClass
@end /* No warnings. */
/* Try with a category. */
@interface MyRootClass (count)
@property int count;
@end
@implementation MyRootClass (count)
@end /* No warnings. */
/* Try with a category of a subclass. */
@interface MyClass2 : MyClass
@end
@implementation MyClass2
@end
@interface MyClass2 (count2)
@property int count2;
@end
@implementation MyClass2 (count2)
@end /* No warnings. */
/* Now, try with a category of a subclass, but with a missing setter,
which should generate a warning. */
@interface MyClass3 : MyClass
@end
@implementation MyClass3
@end
@interface MyClass3 (count3)
@property int count3;
@end
@implementation MyClass3 (count3)
@end /* { dg-warning "incomplete implementation" } */
/* { dg-warning "method definition for .-setCount3:. not found" "" { target *-*-* } 97 } */
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do compile } */
#include <objc/objc.h>
/* Test that if you have a property declared in a class and a
category, the attributes match. This is almost the same as
at-property-16.m, but for a category. It is a separate file
because it is difficult to test multiple messages for the same
line. */
@interface MyRootClass
{
Class isa;
}
@property (assign) id a;
@property (retain) id b;
@property int c;
@property (nonatomic) int d;
@property int e;
@property int f;
@property int g;
@property (readonly) int h;
@property (readonly,getter=getMe) int i;
@property (nonatomic) float j;
@end
@interface MyRootClass (Category)
@property (retain) id a; /* { dg-error "assign semantics attributes of property .a. conflict with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 16 } */
@property (assign) id b; /* { dg-error "assign semantics attributes of property .b. conflict with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 17 } */
@property (nonatomic) int c; /* { dg-error ".nonatomic. attribute of property .c. conflicts with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 18 } */
@property int d; /* { dg-error ".nonatomic. attribute of property .d. conflicts with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 19 } */
@property (setter=setX:) int e; /* { dg-error ".setter. attribute of property .e. conflicts with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 20 } */
@property (getter=x) int f; /* { dg-error ".getter. attribute of property .f. conflicts with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 21 } */
@property (readonly) int g; /* { dg-error ".readonly. attribute of property .g. conflicts with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 22 } */
@property (readwrite) int h; /* Ok */
@property (readonly) int i; /* { dg-error ".getter. attribute of property .i. conflicts with previous declaration" } */
/* { dg-message "originally specified here" "" { target *-*-* } 24 } */
@property (nonatomic) float j; /* Ok */
@end
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */
/* { dg-do run } */
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
/* Test looking up a @property in a protocol of a category of a superclass. */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
@interface MyRootClass
{
Class isa;
int a;
}
+ (id) initialize;
+ (id) alloc;
- (id) init;
@end
@implementation MyRootClass
+ (id) initialize { return self; }
+ (id) alloc { return class_createInstance (self, 0); }
- (id) init { return self; }
@end
/* Use a different getter/setter, so that the only way to compile
object.count is to find the actual @property. */
@protocol count
@property (getter=number, setter=setNumber:) int count;
@end
@interface MySubClass : MyRootClass
- (int) testMe;
@end
@interface MySubClass (Category) <count>
@end
@implementation MySubClass (Category)
- (int) number
{
return a;
}
- (void) setNumber: (int)count
{
a = count;
}
@end
@implementation MySubClass
- (int) testMe
{
self.count = 400;
if (self.count != 400)
abort ();
return self.count;
}
@end
int main (void)
{
MySubClass *object = [[MySubClass alloc] init];
object.count = 44;
if (object.count != 44)
abort ();
if ([object testMe] != 400)
abort ();
return 0;
}
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
@property (retain) id property_g; @property (retain) id property_g;
@property (retain) id property_h; @property (retain) id property_h;
@property (retain) id property_e; /* { dg-error "redeclaration of property .property_e." } */ @property (retain) id property_e; /* { dg-error "redeclaration of property .property_e." } */
/* { dg-message "originally declared here" "" { target *-*-* } 26 } */ /* { dg-message "originally specified here" "" { target *-*-* } 26 } */
@end @end
@property id test; /* { dg-error "property declaration not in .interface or .protocol context" } */ @property id test; /* { dg-error "property declaration not in .interface or .protocol context" } */
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do run } */
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
/* Test looking up a setter or getter which are in a protocol attached
to a category of a superclass. */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
static int c;
@interface MyRootClass
{
Class isa;
int a;
}
+ (id) initialize;
+ (id) alloc;
- (id) init;
@end
@implementation MyRootClass
+ (id) initialize { return self; }
+ (id) alloc { return class_createInstance (self, 0); }
- (id) init { return self; }
@end
@protocol count
- (int) count;
- (void) setCount: (int)count;
@end
@protocol classCount
+ (int) classCount;
+ (void) setClassCount: (int)count;
@end
@interface MyRootClass (Category) <count, classCount>
@end
@implementation MyRootClass (Category)
- (int) count
{
return a;
}
- (void) setCount: (int)count
{
a = count;
}
+ (int) classCount
{
return c;
}
+ (void) setClassCount: (int)count
{
c = count;
}
@end
@interface MySubClass : MyRootClass
+ (int) testMe;
- (int) testMe;
@end
@implementation MySubClass
- (int) testMe
{
self.count = 400;
if (self.count != 400)
abort ();
return self.count;
}
+ (int) testMe
{
self.classCount = 4000;
if (self.classCount != 4000)
abort ();
return self.classCount;
}
@end
int main (void)
{
MySubClass *object = [[MySubClass alloc] init];
object.count = 44;
if (object.count != 44)
abort ();
MySubClass.classCount = 40;
if (MySubClass.classCount != 40)
abort ();
if ([object testMe] != 400)
abort ();
if ([MySubClass testMe] != 4000)
abort ();
return 0;
}
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do compile } */
/* { dg-options "-Wno-protocol" } */
#include <objc/objc.h>
/* Test the -Wno-protocol flag. With this, at a class is accepted
(with no warnings) as conforming to a protocol even if some
protocol methods are implemented in the superclass. */
@protocol MyProtocol
- (int)method;
@end
@protocol MyProtocol2
- (int)method2;
@end
/* The superclass implements the method required by the protocol. */
@interface MyRootClass
{
Class isa;
}
- (int)method;
@end
@implementation MyRootClass
- (int)method
{
return 23;
}
@end
/* The subclass inherits the method (does not implement it directly)
but that still makes it conform to the protocol. No warnings. */
@interface MySubClass : MyRootClass <MyProtocol>
@end
@implementation MySubClass
@end /* No warnings here. */
/* The subclass instead does not inherit the method method2 (and does
not implement it directly) so it does not conform to the
protocol MyProtocol2. */
@interface MySubClass2 : MyRootClass <MyProtocol2>
@end
@implementation MySubClass2
@end /* Warnings here, below. */
/* { dg-warning "incomplete implementation of class .MySubClass2." "" { target *-*-* } 50 } */
/* { dg-warning "method definition for .\\-method2. not found" "" { target *-*-* } 50 } */
/* { dg-warning "class .MySubClass2. does not fully implement the .MyProtocol2. protocol" "" { target *-*-* } 50 } */
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do compile } */
#include <objc/objc.h>
/* Test standard warnings when a class conforms to a protocol but some
methods are implemented in the superclass. Use -Wno-protocol to
turn these off. */
@protocol MyProtocol
- (int)method;
@end
@protocol MyProtocol2
- (int)method2;
@end
/* The superclass implements the method required by the protocol. */
@interface MyRootClass
{
Class isa;
}
- (int)method;
@end
@implementation MyRootClass
- (int)method
{
return 23;
}
@end
/* The subclass inherits the method (does not implement it directly)
and unless -Wno-protocol is used, we emit a warning. */
@interface MySubClass : MyRootClass <MyProtocol>
@end
@implementation MySubClass
@end
/* { dg-warning "incomplete implementation of class .MySubClass." "" { target *-*-* } 39 } */
/* { dg-warning "method definition for .\\-method. not found" "" { target *-*-* } 39 } */
/* { dg-warning "class .MySubClass. does not fully implement the .MyProtocol. protocol" "" { target *-*-* } 39 } */
/* The subclass instead does not inherit the method method2 (and does
not implement it directly) so it does not conform to the
protocol MyProtocol2. */
@interface MySubClass2 : MyRootClass <MyProtocol2>
@end
@implementation MySubClass2
@end /* Warnings here, below. */
/* { dg-warning "incomplete implementation of class .MySubClass2." "" { target *-*-* } 53 } */
/* { dg-warning "method definition for .\\-method2. not found" "" { target *-*-* } 53 } */
/* { dg-warning "class .MySubClass2. does not fully implement the .MyProtocol2. protocol" "" { target *-*-* } 53 } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment