Skip to content

Assigning to self twice in init provokes spurious warning about not assigning at all #9466

@llvmbot

Description

@llvmbot
Bugzilla Link 9094
Resolution FIXED
Resolved on Feb 04, 2011 23:57
Version trunk
OS MacOS X
Attachments example
Reporter LLVM Bugzilla Contributor
CC @akyrtzi,@tkremenek

Extended Description

A common pattern in classes with multiple initializers (for example NSView with -initWithFrame: and -initWithCoder:) is to put the subclass's common initialization bits into a static function. If you structure this so that the common init can fail and return nil, then you can end up with something like this:

  • init;
    {
    if (!(self = [super init]))
    return nil;
    if (!(self = _commonInit(self)))
    return nil;

    return self;
    }

This provokes a warning about never having assigned self before returning it, which is not true:

double-assign-self.m:28:5: warning: Returning 'self' before setting it to the result of '[(super or self) init...]'

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions