Clang attribute for designated initializers
| Originator: | jacopo | ||
| Number: | rdar://14256958 | Date Originated: | 25-Jun-2013 08:36 AM |
| Status: | Duplicate of 7386414 (Open) | Resolved: | |
| Product: | Developer Tools | Product Version: | 5.0 |
| Classification: | Feature (New) | Reproducible: | n/a |
This is a duplicate of rdar://14251519 but I think is a very nice addition so please forwarding to the Clang team for the next version of Clang!
Summary:
It would be nice be able to flag designated initializers using an __attribute__, and have Clang emit a warning whenever they're not properly used. This is especially important as the rules for designated initializers are easily missed and error-prone.
Example:
@interface FooClass: NSObject
- (id) initWithFoo:(id)foo __attribute__((designated_initializer));
@end
@implementation FooClass
{
id _foo;
}
- (id)initWithFoo:(id)foo_
{
self = [super init];
if(self) {
_foo = foo_;
}
return self;
}
@end
@interface BarClass: FooClass
- (id) initWithBar:(id)bar;
@end
@implementation BarClass
{
id _bar;
}
- (id) initWithBar:(id)bar_
{
self = [super init]; // Clang would complain that FooClass's designated initializer isn't called
if(self) {
_bar = bar_;
}
return self;
}
@end
Notes:
This is somewhat related to __attribute__((objc_requires_super)), as designated initializers should be called or reimplemented by subclasses designated initializers.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!