Skip to content

Objective-C init method with return type id unable to return parent object type pointer #11665

@llvmbot

Description

@llvmbot
Bugzilla Link 11293
Resolution INVALID
Resolved on Nov 02, 2011 13:46
Version unspecified
OS All
Attachments Objective-C example showing that the init method with return type id is unable to return parent object type pointer
Reporter LLVM Bugzilla Contributor
CC @efriedma-quic

Extended Description

Objective-C init method with return type id unable to return parent object type pointer

id type can represent the pointer to any object

When an init method (with a return type "id") of a subclass returns a parent class pointer, the compiler throws a warning / error.

However when another method without the prefix "init" does the same no compilation error / warning is thrown.

Actual Behavior

When an init method (with a return type "id") of a subclass returns a parent class pointer, the compiler throws a warning / error

Expected Behavior

When an init method (with a return type "id") of a subclass returns a parent class pointer, the compiler should not throw a warning / error

Example (Sample Objective-C program explaining the problem)

Pls see the attached Objective-C program that explains the problem

Reference:

The Objective‐C Programming Language (Page 14)

Quoted from the document:

"In Objective-C, object identifiers are of a distinct data type: id. This type is the general type for any kind of object regardless of class and can be used for instances of a class and for class objects themselves."

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillainvalidResolved as invalid, i.e. not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions