This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [objc-improvements] Warnings when compiling GNUStep
zlaski@apple.com (Ziemowit Laski) wrote on 02.09.03 in <FF2A40A7-DDA3-11D7-94DF-000393673036@apple.com>:
> they match up). However, in a few cases we're dealing with the idiom
>
> [[ClassName alloc] init...]
>
> in which case one _could_ make the argument that any method named
> 'alloc' should be treated
> specially by the compiler, i.e., as having a return type covariant with
> the receiver. What
> do you think? If we don't teach the compiler about 'alloc', then it is
> perfectly within
> its right to complain in this case also, unless we change foregoing to
> read
>
> [(ClassName *)[ClassName alloc] init...]
>
> which, I must admit, does have a slighty redundant flavor to it. :-(
> Of course, the
> slippery slope argument applies here (if we treat 'alloc' specially,
> then what about
> 'allocWithFoo:Bar:'?...)
Or [xxx initXXX...], which is often the same situation ...
... and which suggests a rule:
Iff calling a method on id, and this id is the return value of a method
call, and the method we want to call is supported by the receiver of
*that* method call, accept it. (alloc, init, new are examples of this
idiom.)
Sorry, not particularly elegant ...
MfG Kai