[Sema] Add support for flexible array members in Obj-C.
authorVolodymyr Sapsai <vsapsai@apple.com>
Mon, 23 Oct 2017 22:01:41 +0000 (22:01 +0000)
committerVolodymyr Sapsai <vsapsai@apple.com>
Mon, 23 Oct 2017 22:01:41 +0000 (22:01 +0000)
commit30680e943735ae8f008af0513e85725f3d6cfee6
treed68cf0759aa37b19934fdf9cb41bfe53f64f2a07
parent7e55e68852834a1b246116db3a90a793d26df703
[Sema] Add support for flexible array members in Obj-C.

Allow Obj-C ivars with incomplete array type but only as the last ivar.
Also add a requirement for ivars that contain a flexible array member to
be at the end of class too. It is possible to add in a subclass another
ivar at the end but we'll emit a warning in this case. Also we'll emit a
warning if a variable sized ivar is declared in class extension or in
implementation because subclasses won't know they should avoid adding
new ivars.

In ARC incomplete array objects are treated as __unsafe_unretained so
require them to be marked as such.

Prohibit synthesizing ivars with flexible array members because order of
synthesized ivars is not obvious and tricky to control. Spelling out
ivar explicitly gives control to developers and helps to avoid surprises
with unexpected ivar ordering.

For C and C++ changed diagnostic to tell explicitly a field is not the
last one and point to the next field. It is not as useful as in Obj-C
but it is an improvement and it is consistent with Obj-C. For C for
unions emit more specific err_flexible_array_union instead of generic
err_field_incomplete.

rdar://problem/21054495

Reviewers: rjmccall, theraven

Reviewed By: rjmccall

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D38773

llvm-svn: 316381
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/lib/Sema/SemaObjCProperty.cpp
clang/test/Sema/transparent-union.c
clang/test/SemaCXX/flexible-array-test.cpp
clang/test/SemaObjC/flexible-array-arc.m [new file with mode: 0644]
clang/test/SemaObjC/flexible-array.m [new file with mode: 0644]
clang/test/SemaObjC/ivar-sem-check-1.m
clang/test/SemaObjCXX/flexible-array.mm [new file with mode: 0644]