llvm-project/clang/test/Sema/array-constraint.c
Steve Naroff 096dd942cf Removed Sema::VerifyConstantArrayType(). With the new Array/ConstantArray/VariableArray nodes, this
routine was causing more trouble than it was worth. Anders/Chris noticed that it could return an error code
without emiting a diagnostic (which results in an silent invalid decl, which should *never* happen). In addition,
this routine didn't work well for typedefs and field decls. Lastly, it didn't consider that initializers aren't
in place yet.

Added Type::getAsConstantArrayType(), Type::getAsVariableArrayType(), Type::getAsVariablyModifiedType(),
and Type::isVariablyModifiedType();

Modified Sema::ParseDeclarator() and Sema::ParseField() to use the new predicates. Also added a FIXME for
the initializer omission. Also added a missing test for "static" @ file scope.

llvm-svn: 41647
2007-08-31 17:20:07 +00:00

52 lines
1.3 KiB
C

// RUN: clang -parse-ast-check -pedantic %s
struct s;
struct s* t (struct s z[]) { // expected-error {{array has incomplete element type}}
return z;
}
void ff() {
struct s v, *p; // expected-error {{variable has incomplete type 'struct s'}}
p = &v;
}
void *k (void l[2]) { // expected-error {{array has incomplete element type}}
return l;
}
struct vari {
int a;
int b[];
};
struct vari *func(struct vari a[]) { // expected-error {{'struct vari' may not be used as an array element due to flexible array member}}
return a;
}
int foo[](void); // expected-error {{'foo' declared as array of functions}}
typedef int (*pfunc)(void);
pfunc xx(int f[](void)) { // expected-error {{'f' declared as array of functions}}
return f;
}
void check_size() {
float f;
int size_not_int[f]; // expected-error {{size of array has non-integer type 'float'}}
int negative_size[1-2]; // expected-error{{array size is negative}}
int zero_size[0]; // expected-warning{{zero size arrays are an extension}}
}
static int I;
typedef int TA[I]; // expected-error {{variable length array declared outside of any function}}
void strFunc(char *);
const char staticAry[] = "test";
int checkStaticAry() {
strFunc(staticAry); // expected-warning{{passing 'char const []' to 'char *' discards qualifiers}}
}