Fix bogus warnings (noticed by Chris) with array-constraints.c.

Remove bogus type conversions in Sema::GetTypeForDeclarator(). This commit
only deals with the array types (DeclaratorCheck::Array), though the
rest of this routine should be reviewed. Given the complexity of C declarators,
I don't want to change the entire routine now (will discuss with Chris tomorrow).

llvm-svn: 41443
This commit is contained in:
Steve Naroff 2007-08-26 14:38:38 +00:00
parent f6dcc9df7e
commit 5f90ca9904
3 changed files with 18 additions and 6 deletions

View File

@ -170,23 +170,19 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
if (T->isIncompleteType()) {
Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_incomplete_type,
T.getAsString());
T = Context.IntTy;
} else if (T->isFunctionType()) {
Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_functions,
D.getIdentifier()->getName());
T = Context.getPointerType(T);
} else if (const ReferenceType *RT = T->getAsReferenceType()) {
// C++ 8.3.2p4: There shall be no ... arrays of references ...
Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_references,
D.getIdentifier()->getName());
T = RT->getReferenceeType();
} else if (const RecordType *EltTy = T->getAsRecordType()) {
// If the element type is a struct or union that contains a variadic
// array, reject it: C99 6.7.2.1p2.
if (EltTy->getDecl()->hasFlexibleArrayMember()) {
Diag(DeclType.Loc, diag::err_flexible_array_in_array,
T.getAsString());
T = Context.IntTy;
}
}
T = Context.getArrayType(T, ASM, ATI.TypeQuals,

View File

@ -210,7 +210,7 @@
35260CA40C7F75C000D66CE9 /* ExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ExprCXX.cpp; path = AST/ExprCXX.cpp; sourceTree = "<group>"; };
84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = "<group>"; };
84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = "<group>"; };
8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = "<group>"; };
DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = "<group>"; };
DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };

View File

@ -1,4 +1,4 @@
// RUN: clang -parse-ast-check %s
// RUN: clang -parse-ast-check -pedantic %s
struct s;
struct s* t (struct s z[]) { // expected-error {{array has incomplete element type}}
@ -9,3 +9,19 @@ void *k (void l[2]) { // expected-error {{array has incomplete element
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;
}