Added several type checks, especially for functions. Moved check for implicit
int return type. git-svn-id: svn://svn.cc65.org/cc65/trunk@3858 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
52c0c284da
commit
22d89f558e
1 changed files with 74 additions and 46 deletions
|
@ -849,7 +849,7 @@ static void ParseAnsiParamList (FuncDesc* F)
|
|||
|
||||
|
||||
|
||||
static FuncDesc* ParseFuncDecl (const DeclSpec* Spec)
|
||||
static FuncDesc* ParseFuncDecl (void)
|
||||
/* Parse the argument list of a function. */
|
||||
{
|
||||
unsigned Offs;
|
||||
|
@ -881,19 +881,6 @@ static FuncDesc* ParseFuncDecl (const DeclSpec* Spec)
|
|||
}
|
||||
}
|
||||
|
||||
/* Check for an implicit int return in the function */
|
||||
if ((Spec->Flags & DS_DEF_TYPE) != 0 &&
|
||||
Spec->Type[0].C == T_INT &&
|
||||
Spec->Type[1].C == T_END) {
|
||||
/* Function has an implicit int return. Output a warning if we don't
|
||||
* have the C89 standard enabled explicitly.
|
||||
*/
|
||||
if (IS_Get (&Standard) >= STD_C99) {
|
||||
Warning ("Implicit `int' return type is an obsolete feature");
|
||||
}
|
||||
F->Flags |= FD_OLDSTYLE_INTRET;
|
||||
}
|
||||
|
||||
/* Parse params */
|
||||
if ((F->Flags & FD_OLDSTYLE) == 0) {
|
||||
/* New style function */
|
||||
|
@ -1084,7 +1071,7 @@ static void Decl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
|||
NextToken ();
|
||||
|
||||
/* Parse the function declaration */
|
||||
F = ParseFuncDecl (Spec);
|
||||
F = ParseFuncDecl ();
|
||||
|
||||
/* Add the function type. Be sure to bounds check the type buffer */
|
||||
AddFuncTypeToDeclaration (D, F);
|
||||
|
@ -1160,6 +1147,46 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
|||
/* Fix any type qualifiers attached to an array type */
|
||||
FixArrayQualifiers (D->Type);
|
||||
|
||||
/* Check several things for function or function pointer types */
|
||||
if (IsTypeFunc (D->Type) || IsTypeFuncPtr (D->Type)) {
|
||||
|
||||
/* A function. Check the return type */
|
||||
Type* RetType = GetFuncReturn (D->Type);
|
||||
|
||||
/* Functions may not return functions or arrays */
|
||||
if (IsTypeFunc (RetType)) {
|
||||
Error ("Functions are not allowed to return functions");
|
||||
} else if (IsTypeArray (RetType)) {
|
||||
Error ("Functions are not allowed to return arrays");
|
||||
}
|
||||
|
||||
/* The return type must not be qualified */
|
||||
if (GetQualifier (RetType) != T_QUAL_NONE && RetType[1].C == T_END) {
|
||||
|
||||
if (GetType (RetType) == T_TYPE_VOID) {
|
||||
/* A qualified void type is always an error */
|
||||
Error ("function definition has qualified void return type");
|
||||
} else {
|
||||
/* For others, qualifiers are ignored */
|
||||
Warning ("type qualifiers ignored on function return type");
|
||||
RetType[0].C = UnqualifiedType (RetType[0].C);
|
||||
}
|
||||
}
|
||||
|
||||
/* Warn about an implicit int return in the function */
|
||||
if ((Spec->Flags & DS_DEF_TYPE) != 0 &&
|
||||
RetType[0].C == T_INT && RetType[1].C == T_END) {
|
||||
/* Function has an implicit int return. Output a warning if we don't
|
||||
* have the C89 standard enabled explicitly.
|
||||
*/
|
||||
if (IS_Get (&Standard) >= STD_C99) {
|
||||
Warning ("Implicit `int' return type is an obsolete feature");
|
||||
}
|
||||
GetFuncDesc (D->Type)->Flags |= FD_OLDSTYLE_INTRET;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Check the size of the generated type */
|
||||
if (!IsTypeFunc (D->Type) && !IsTypeVoid (D->Type)) {
|
||||
unsigned Size = SizeOf (D->Type);
|
||||
|
@ -1171,6 +1198,7 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue