Add error messages for structs containing nested undefined structs

This commit is contained in:
jbrodman
2014-05-27 15:50:53 -07:00
parent 68f62b1fc3
commit d3144da5eb
3 changed files with 46 additions and 11 deletions

View File

@@ -5143,9 +5143,18 @@ MemberExpr::create(Expr *e, const char *id, SourcePos p, SourcePos idpos,
exprType->GetString().c_str());
return NULL;
}
if (CastType<StructType>(exprType) != NULL)
if (CastType<StructType>(exprType) != NULL) {
const StructType *st = CastType<StructType>(exprType);
if (st->IsDefined()) {
return new StructMemberExpr(e, id, p, idpos, derefLValue);
}
else {
Error(p, "Member operator \"%s\" can't be applied to declared "
"struct \"%s\" containing an undefined struct type.", derefLValue ? "->" : ".",
exprType->GetString().c_str());
return NULL;
}
}
else if (CastType<VectorType>(exprType) != NULL)
return new VectorMemberExpr(e, id, p, idpos, derefLValue);
else if (CastType<UndefinedStructType>(exprType)) {
@@ -8708,6 +8717,12 @@ NewExpr::TypeCheck() {
"but not defined type \"%s\".", allocType->GetString().c_str());
return NULL;
}
const StructType *st = CastType<StructType>(allocType);
if (st != NULL && !st->IsDefined()) {
Error(pos, "Can't dynamically allocate storage for declared "
"type \"%s\" containing undefined member type.", allocType->GetString().c_str());
return NULL;
}
// Otherwise we only need to make sure that if we have an expression
// giving a number of elements to allocate that it can be converted to