[LLVMbugs] [Bug 11292] Objective-C - incompatible pointer type assignment not detected when used with init method

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Nov 2 18:15:06 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=11292

muthuveerappan.al at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |

--- Comment #2 from muthuveerappan.al at gmail.com 2011-11-02 20:15:06 CDT ---
Expected Behavior:
===========
The compiler should enforce that all init methods to have the return type as
"id". (see documentation) otherwise should throw a warning / error.

Enforcing this would mean that would mean that the init methods would no longer
return an parent class pointer type.

Actual Behavior:
============
Presently the compiler allows init methods to have the return type of the class
(class pointer type) that implements it.

Documentation:
===========
The Objective‐C Programming Language (Page 51)

"The return type of an initializer method should be id.
The return type should be id because id gives an indication that the class is
purposely not considered—that the class is unspecified and subject to change,
depending on context of invocation. For example, NSString provides the method
initWithFormat:. When sent to an instance of NSMutableString (a subclass of
NSString), however, the message returns an instance of NSMutableString, not
NSString."

Present Scenario:
===========
Assignment of a parent class pointer to a derived class pointer variable is
incorrect

This is currently being allowed in clang when the init method returns a parent
class pointer (as shown in example).

The problem would be solved if the compiler should enforce that all init
methods to have the return type as id. (see documentation) otherwise should
throw a warning / error.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list