reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
  229
  230
  231
  232
  233
  234
  235
  236
  237
  238
  239
  240
  241
  242
  243
  244
  245
  246
  247
  248
  249
  250
  251
  252
  253
  254
  255
  256
  257
  258
  259
  260
  261
  262
  263
  264
  265
  266
  267
  268
  269
  270
  271
  272
  273
  274
  275
  276
  277
  278
  279
  280
  281
  282
  283
  284
  285
  286
  287
  288
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s

// # Flexible array member.
// ## Instance variables only in interface.
@interface LastIvar {
  char flexible[];
}
@end

@interface NotLastIvar {
  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
  int last; // expected-note {{next instance variable declaration is here}}
}
@end

// ## Instance variables in implementation.
@interface LastIvarInImpl
@end
@implementation LastIvarInImpl {
  char flexible[]; // expected-warning {{field 'flexible' with variable sized type 'char []' is not visible to subclasses and can conflict with their instance variables}}
}
@end

@interface NotLastIvarInImpl
@end
@implementation NotLastIvarInImpl {
  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
  // expected-warning@-1 {{field 'flexible' with variable sized type 'char []' is not visible to subclasses and can conflict with their instance variables}}
  int last; // expected-note {{next instance variable declaration is here}}
}
@end

@implementation NotLastIvarInImplWithoutInterface { // expected-warning {{cannot find interface declaration for 'NotLastIvarInImplWithoutInterface'}}
  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
  // expected-warning@-1 {{field 'flexible' with variable sized type 'char []' is not visible to subclasses and can conflict with their instance variables}}
  int last; // expected-note {{next instance variable declaration is here}}
}
@end

@interface LastIvarInClass_OtherIvarInImpl {
  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
}
@end
@implementation LastIvarInClass_OtherIvarInImpl {
  int last; // expected-note {{next instance variable declaration is here}}
}
@end

// ## Non-instance variables in implementation.
@interface LastIvarInClass_UnrelatedVarInImpl {
  char flexible[];
}
@end
@implementation LastIvarInClass_UnrelatedVarInImpl
int nonIvar;
@end

// ## Instance variables in class extension.
@interface LastIvarInExtension
@end
@interface LastIvarInExtension() {
  char flexible[]; // expected-warning {{field 'flexible' with variable sized type 'char []' is not visible to subclasses and can conflict with their instance variables}}
}
@end

@interface NotLastIvarInExtension
@end
@interface NotLastIvarInExtension() {
  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
  // expected-warning@-1 {{field 'flexible' with variable sized type 'char []' is not visible to subclasses and can conflict with their instance variables}}
  int last; // expected-note {{next instance variable declaration is here}}
}
@end

@interface LastIvarInClass_OtherIvarInExtension {
  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
}
@end
@interface LastIvarInClass_OtherIvarInExtension() {
  int last; // expected-note {{next instance variable declaration is here}}
}
@end

@interface LastIvarInExtension_OtherIvarInExtension
@end
@interface LastIvarInExtension_OtherIvarInExtension() {
  int last; // expected-note {{next instance variable declaration is here}}
}
@end
@interface LastIvarInExtension_OtherIvarInExtension()
// Extension without ivars to test we see through such extensions.
@end
@interface LastIvarInExtension_OtherIvarInExtension() {
  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
  // expected-warning@-1 {{field 'flexible' with variable sized type 'char []' is not visible to subclasses and can conflict with their instance variables}}
}
@end

@interface LastIvarInExtension_OtherIvarInImpl
@end
@interface LastIvarInExtension_OtherIvarInImpl() {
  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
  // expected-warning@-1 {{field 'flexible' with variable sized type 'char []' is not visible to subclasses and can conflict with their instance variables}}
}
@end
@implementation LastIvarInExtension_OtherIvarInImpl {
  int last; // expected-note {{next instance variable declaration is here}}
}
@end

// ## Instance variables in named categories.
@interface IvarInNamedCategory
@end
@interface IvarInNamedCategory(Category) {
  char flexible[]; // expected-error {{instance variables may not be placed in categories}}
}
@end

// ## Synthesized instance variable.
@interface LastIvarAndProperty {
  char _flexible[];
}
@property char flexible[]; // expected-error {{property cannot have array or function type 'char []'}}
@end

// ## Synthesize other instance variables.
@interface LastIvar_ExplicitlyNamedPropertyBackingIvarPreceding {
  int _elementsCount;
  char flexible[];
}
@property int count;
@end
@implementation LastIvar_ExplicitlyNamedPropertyBackingIvarPreceding
@synthesize count = _elementsCount;
@end

@interface LastIvar_ImplicitlyNamedPropertyBackingIvarPreceding {
  int count;
  char flexible[];
}
@property int count;
@end
@implementation LastIvar_ImplicitlyNamedPropertyBackingIvarPreceding
@synthesize count;
@end

@interface NotLastIvar_ExplicitlyNamedPropertyBackingIvarLast {
  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
}
@property int count;
@end
@implementation NotLastIvar_ExplicitlyNamedPropertyBackingIvarLast
@synthesize count = _elementsCount; // expected-note {{next synthesized instance variable is here}}
@end

@interface NotLastIvar_ImplicitlyNamedPropertyBackingIvarLast {
  char flexible[]; // expected-error {{flexible array member 'flexible' with type 'char []' is not at the end of class}}
}
@property int count; // expected-note {{next synthesized instance variable is here}}
@end
@implementation NotLastIvar_ImplicitlyNamedPropertyBackingIvarLast
// Test auto-synthesize.
//@synthesize count;
@end


// # Variable sized types.
struct Packet {
  unsigned int size;
  char data[];
};

// ## Instance variables only in interface.
@interface LastStructIvar {
  struct Packet flexible;
}
@end

@interface NotLastStructIvar {
  struct Packet flexible; // expected-error {{field 'flexible' with variable sized type 'struct Packet' is not at the end of class}}
  int last; // expected-note {{next instance variable declaration is here}}
}
@end

// ## Instance variables in implementation.
@interface LastStructIvarInImpl
@end
@implementation LastStructIvarInImpl {
  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}}
}
@end

@interface NotLastStructIvarInImpl
@end
@implementation NotLastStructIvarInImpl {
  struct Packet flexible; // expected-error {{field 'flexible' with variable sized type 'struct Packet' is not at the end of class}}
  // expected-warning@-1 {{field 'flexible' with variable sized type 'struct Packet' is not visible to subclasses and can conflict with their instance variables}}
  int last; // expected-note {{next instance variable declaration is here}}
}
@end

@interface LastStructIvarInClass_OtherIvarInImpl {
  struct Packet flexible; // expected-error {{field 'flexible' with variable sized type 'struct Packet' is not at the end of class}}
}
@end
@implementation LastStructIvarInClass_OtherIvarInImpl {
  int last; // expected-note {{next instance variable declaration is here}}
}
@end

// ## Synthesized instance variable.
@interface LastSynthesizeStructIvar
@property int first;
@property struct Packet flexible; // expected-error {{synthesized property with variable size type 'struct Packet' requires an existing instance variable}}
@end
@implementation LastSynthesizeStructIvar
@end

@interface NotLastSynthesizeStructIvar
@property struct Packet flexible; // expected-error {{synthesized property with variable size type 'struct Packet' requires an existing instance variable}}
@property int last;
@end
@implementation NotLastSynthesizeStructIvar
@end

@interface LastStructIvarWithExistingIvarAndSynthesizedProperty {
  struct Packet _flexible;
}
@property struct Packet flexible;
@end
@implementation LastStructIvarWithExistingIvarAndSynthesizedProperty
@end


// # Subclasses.
@interface FlexibleArrayMemberBase {
  char flexible[]; // expected-note6 {{'flexible' declared here}}
}
@end

@interface NoIvarAdditions : FlexibleArrayMemberBase
@end
@implementation NoIvarAdditions
@end

@interface AddedIvarInInterface : FlexibleArrayMemberBase {
  int last; // expected-warning {{field 'last' can overwrite instance variable 'flexible' with variable sized type 'char []' in superclass 'FlexibleArrayMemberBase'}}
}
@end

@interface AddedIvarInImplementation : FlexibleArrayMemberBase
@end
@implementation AddedIvarInImplementation {
  int last; // expected-warning {{field 'last' can overwrite instance variable 'flexible' with variable sized type 'char []' in superclass 'FlexibleArrayMemberBase'}}
}
@end

@interface AddedIvarInExtension : FlexibleArrayMemberBase
@end
@interface AddedIvarInExtension() {
  int last; // expected-warning {{field 'last' can overwrite instance variable 'flexible' with variable sized type 'char []' in superclass 'FlexibleArrayMemberBase'}}
}
@end

@interface SynthesizedIvar : FlexibleArrayMemberBase
@property int count;
@end
@implementation SynthesizedIvar
@synthesize count; // expected-warning {{field 'count' can overwrite instance variable 'flexible' with variable sized type 'char []' in superclass 'FlexibleArrayMemberBase'}}
@end

@interface WarnInSubclassOnlyOnce : FlexibleArrayMemberBase {
  int last; // expected-warning {{field 'last' can overwrite instance variable 'flexible' with variable sized type 'char []' in superclass 'FlexibleArrayMemberBase'}}
}
@end
@interface WarnInSubclassOnlyOnce() {
  int laster;
}
@end
@implementation WarnInSubclassOnlyOnce {
  int lastest;
}
@end

@interface AddedIvarInSubSubClass : NoIvarAdditions {
  int last; // expected-warning {{field 'last' can overwrite instance variable 'flexible' with variable sized type 'char []' in superclass 'FlexibleArrayMemberBase'}}
}
@end