[cfe-dev] Flexible array members in ObjC classes
Volodymyr Sapsai via cfe-dev
cfe-dev at lists.llvm.org
Tue Oct 10 17:55:00 PDT 2017
On Sep 25, 2017, at 15:42, Volodymyr Sapsai via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>
> On Sep 22, 2017, at 01:06, David Chisnall <David.Chisnall at cl.cam.ac.uk <mailto:David.Chisnall at cl.cam.ac.uk>> wrote:
>>
>> On 22 Sep 2017, at 06:31, John McCall <rjmccall at apple.com <mailto:rjmccall at apple.com>> wrote:
>>>
>>>> Thanks everybody for their input. I plan to update the patch with different test cases so it's easier to discuss. But so far my summary is the following.
>>>>
>>>> For flexible array members we allow them only as the last ivar in @interface, with no ivars in @implementation. If it's not last, if it is in @implementation, if there are more ivars in @implementation - that's an error.
>>>>
>>>> For variable sized types (i.e. structs with last member a flexible array) we don't error but warn if we can detect more ivars after it (in @interface or in @implementation). If @implementation ivars end with variable sized ivar, no error or warning.
>>>>
>>>> For subclassing we don't error but warn if we can detect more ivars after a flexible array member or after a variable sized type member.
>>>
>>> I think most of this sounds reasonable. I would recommend being lax about whether the ivar is declared in the @interface vs. the @implementation, though.
>>
>> If nothing else, I’d recommend a warning if the ivar is in the @implementation, because that means that we can’t guarantee getting a warning for subclasses, but apart from that this looks like a sensible design. Thanks!
>>
>> David
>
> Added test cases to https://reviews.llvm.org/D38114 <https://reviews.llvm.org/D38114> Changes from my previous proposal:
> * Allow flexible array members and variable sized types in @implementation but it should be the last field. And there is still a warning in this case.
> * Error when variable sized type is not the last field (StructNotLastIVar, StructOtherIVarInImpl, StructNotLastIVarInImpl). Currently for C clang shows a warning that’s a GNU extension but by default GCC 7.2 rejects such code so I’m not sure it is worth supporting this extension for Objective-C.
>
> Volodymyr
Those who are interested, can follow the code review at https://reviews.llvm.org/D38773 <https://reviews.llvm.org/D38773>
Volodymyr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171010/bded7b64/attachment.html>
More information about the cfe-dev
mailing list