1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
3 // # Flexible array member.
4 // ## Instance variables only in interface.
10 @interface NotLastIvar {
11 char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char[]' is not at the end of class}}
12 int last; // expected-note {{next instance variable declaration is here}}
16 // ## Instance variables in implementation.
17 @interface LastIvarInImpl
19 @implementation LastIvarInImpl {
20 char flexible[]; // expected-warning {{field 'flexible' with variable sized type 'char[]' is not visible to subclasses and can conflict with their instance variables}}
24 @interface NotLastIvarInImpl
26 @implementation NotLastIvarInImpl {
27 char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char[]' is not at the end of class}}
28 // expected-warning@-1 {{field 'flexible' with variable sized type 'char[]' is not visible to subclasses and can conflict with their instance variables}}
29 int last; // expected-note {{next instance variable declaration is here}}
33 @implementation NotLastIvarInImplWithoutInterface { // expected-warning {{cannot find interface declaration for 'NotLastIvarInImplWithoutInterface'}}
34 char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char[]' is not at the end of class}}
35 // expected-warning@-1 {{field 'flexible' with variable sized type 'char[]' is not visible to subclasses and can conflict with their instance variables}}
36 int last; // expected-note {{next instance variable declaration is here}}
40 @interface LastIvarInClass_OtherIvarInImpl {
41 char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char[]' is not at the end of class}}
44 @implementation LastIvarInClass_OtherIvarInImpl {
45 int last; // expected-note {{next instance variable declaration is here}}
49 // ## Non-instance variables in implementation.
50 @interface LastIvarInClass_UnrelatedVarInImpl {
54 @implementation LastIvarInClass_UnrelatedVarInImpl
58 // ## Instance variables in class extension.
59 @interface LastIvarInExtension
61 @interface LastIvarInExtension() {
62 char flexible[]; // expected-warning {{field 'flexible' with variable sized type 'char[]' is not visible to subclasses and can conflict with their instance variables}}
66 @interface NotLastIvarInExtension
68 @interface NotLastIvarInExtension() {
69 char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char[]' is not at the end of class}}
70 // expected-warning@-1 {{field 'flexible' with variable sized type 'char[]' is not visible to subclasses and can conflict with their instance variables}}
71 int last; // expected-note {{next instance variable declaration is here}}
75 @interface LastIvarInClass_OtherIvarInExtension {
76 char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char[]' is not at the end of class}}
79 @interface LastIvarInClass_OtherIvarInExtension() {
80 int last; // expected-note {{next instance variable declaration is here}}
84 @interface LastIvarInExtension_OtherIvarInExtension
86 @interface LastIvarInExtension_OtherIvarInExtension() {
87 int last; // expected-note {{next instance variable declaration is here}}
90 @interface LastIvarInExtension_OtherIvarInExtension()
91 // Extension without ivars to test we see through such extensions.
93 @interface LastIvarInExtension_OtherIvarInExtension() {
94 char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char[]' is not at the end of class}}
95 // expected-warning@-1 {{field 'flexible' with variable sized type 'char[]' is not visible to subclasses and can conflict with their instance variables}}
99 @interface LastIvarInExtension_OtherIvarInImpl
101 @interface LastIvarInExtension_OtherIvarInImpl() {
102 char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char[]' is not at the end of class}}
103 // expected-warning@-1 {{field 'flexible' with variable sized type 'char[]' is not visible to subclasses and can conflict with their instance variables}}
106 @implementation LastIvarInExtension_OtherIvarInImpl {
107 int last; // expected-note {{next instance variable declaration is here}}
111 // ## Instance variables in named categories.
112 @interface IvarInNamedCategory
114 @interface IvarInNamedCategory(Category) {
115 char flexible[]; // expected-error {{instance variables may not be placed in categories}}
119 // ## Synthesized instance variable.
120 @interface LastIvarAndProperty {
123 @property char flexible[]; // expected-error {{property cannot have array or function type 'char[]'}}
126 // ## Synthesize other instance variables.
127 @interface LastIvar_ExplicitlyNamedPropertyBackingIvarPreceding {
133 @implementation LastIvar_ExplicitlyNamedPropertyBackingIvarPreceding
134 @synthesize count = _elementsCount;
137 @interface LastIvar_ImplicitlyNamedPropertyBackingIvarPreceding {
143 @implementation LastIvar_ImplicitlyNamedPropertyBackingIvarPreceding
147 @interface NotLastIvar_ExplicitlyNamedPropertyBackingIvarLast {
148 char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char[]' is not at the end of class}}
152 @implementation NotLastIvar_ExplicitlyNamedPropertyBackingIvarLast
153 @synthesize count = _elementsCount; // expected-note {{next synthesized instance variable is here}}
156 @interface NotLastIvar_ImplicitlyNamedPropertyBackingIvarLast {
157 char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char[]' is not at the end of class}}
159 @property int count; // expected-note {{next synthesized instance variable is here}}
161 @implementation NotLastIvar_ImplicitlyNamedPropertyBackingIvarLast
162 // Test auto-synthesize.
167 // # Variable sized types.
173 // ## Instance variables only in interface.
174 @interface LastStructIvar {
175 struct Packet flexible;
179 @interface NotLastStructIvar {
180 struct Packet flexible; // expected-error {{field 'flexible' with variable sized type 'struct Packet' is not at the end of class}}
181 int last; // expected-note {{next instance variable declaration is here}}
185 // ## Instance variables in implementation.
186 @interface LastStructIvarInImpl
188 @implementation LastStructIvarInImpl {
189 struct Packet flexible; // expected-warning {{field 'flexible' with variable sized type 'struct Packet' is not visible to subclasses and can conflict with their instance variables}}
193 @interface NotLastStructIvarInImpl
195 @implementation NotLastStructIvarInImpl {
196 struct Packet flexible; // expected-error {{field 'flexible' with variable sized type 'struct Packet' is not at the end of class}}
197 // expected-warning@-1 {{field 'flexible' with variable sized type 'struct Packet' is not visible to subclasses and can conflict with their instance variables}}
198 int last; // expected-note {{next instance variable declaration is here}}
202 @interface LastStructIvarInClass_OtherIvarInImpl {
203 struct Packet flexible; // expected-error {{field 'flexible' with variable sized type 'struct Packet' is not at the end of class}}
206 @implementation LastStructIvarInClass_OtherIvarInImpl {
207 int last; // expected-note {{next instance variable declaration is here}}
211 // ## Synthesized instance variable.
212 @interface LastSynthesizeStructIvar
214 @property struct Packet flexible; // expected-error {{synthesized property with variable size type 'struct Packet' requires an existing instance variable}}
216 @implementation LastSynthesizeStructIvar
219 @interface NotLastSynthesizeStructIvar
220 @property struct Packet flexible; // expected-error {{synthesized property with variable size type 'struct Packet' requires an existing instance variable}}
223 @implementation NotLastSynthesizeStructIvar
226 @interface LastStructIvarWithExistingIvarAndSynthesizedProperty {
227 struct Packet _flexible;
229 @property struct Packet flexible;
231 @implementation LastStructIvarWithExistingIvarAndSynthesizedProperty
236 @interface FlexibleArrayMemberBase {
237 char flexible[]; // expected-note6 {{'flexible' declared here}}
241 @interface NoIvarAdditions : FlexibleArrayMemberBase
243 @implementation NoIvarAdditions
246 @interface AddedIvarInInterface : FlexibleArrayMemberBase {
247 int last; // expected-warning {{field 'last' can overwrite instance variable 'flexible' with variable sized type 'char[]' in superclass 'FlexibleArrayMemberBase'}}
251 @interface AddedIvarInImplementation : FlexibleArrayMemberBase
253 @implementation AddedIvarInImplementation {
254 int last; // expected-warning {{field 'last' can overwrite instance variable 'flexible' with variable sized type 'char[]' in superclass 'FlexibleArrayMemberBase'}}
258 @interface AddedIvarInExtension : FlexibleArrayMemberBase
260 @interface AddedIvarInExtension() {
261 int last; // expected-warning {{field 'last' can overwrite instance variable 'flexible' with variable sized type 'char[]' in superclass 'FlexibleArrayMemberBase'}}
265 @interface SynthesizedIvar : FlexibleArrayMemberBase
268 @implementation SynthesizedIvar
269 @synthesize count; // expected-warning {{field 'count' can overwrite instance variable 'flexible' with variable sized type 'char[]' in superclass 'FlexibleArrayMemberBase'}}
272 @interface WarnInSubclassOnlyOnce : FlexibleArrayMemberBase {
273 int last; // expected-warning {{field 'last' can overwrite instance variable 'flexible' with variable sized type 'char[]' in superclass 'FlexibleArrayMemberBase'}}
276 @interface WarnInSubclassOnlyOnce() {
280 @implementation WarnInSubclassOnlyOnce {
285 @interface AddedIvarInSubSubClass : NoIvarAdditions {
286 int last; // expected-warning {{field 'last' can overwrite instance variable 'flexible' with variable sized type 'char[]' in superclass 'FlexibleArrayMemberBase'}}