Clang attribute for designated initializers

Originator:nicolas.bouilleaud
Number:rdar://14251519 Date Originated:2013-06-24
Status:Duplicate/7386414/Open Resolved:
Product:Developer Tools Product Version:5.0
Classification:Feature (new) Reproducible:n/a
 
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!