Make sure the program doesn't have a dereference of a non-pointer type.
This commit is contained in:
11
expr.cpp
11
expr.cpp
@@ -6305,8 +6305,17 @@ DereferenceExpr::GetType() const {
|
||||
|
||||
Expr *
|
||||
DereferenceExpr::TypeCheck() {
|
||||
if (expr == NULL)
|
||||
if (expr == NULL) {
|
||||
Assert(m->errorCount > 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dynamic_cast<const PointerType *>(expr->GetType()) == NULL) {
|
||||
Error(pos, "Illegal to dereference non-pointer type \"%s\".",
|
||||
expr->GetType()->GetString().c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
6
tests_errors/deref-4.ispc
Normal file
6
tests_errors/deref-4.ispc
Normal file
@@ -0,0 +1,6 @@
|
||||
// Illegal to dereference non-pointer type "float"
|
||||
|
||||
float func(float a) {
|
||||
*a = 0;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user