Handle class new assignment to non-class variables
Using a class new operator on a non-class variable should result in an error. At the moment when using a class new operator on a dynamic array or queue will result in an segmentation fault. This is because the implementation assumes that the left hand side is of a class type. Add a check in the class new operator implementation that the type of the left hand side is a class. Report an error if it is not. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
e7b700f48e
commit
eeed05d9cd
13
elab_expr.cc
13
elab_expr.cc
|
|
@ -6594,14 +6594,21 @@ NetExpr* PENewClass::elaborate_expr_constructor_(Design*des, NetScope*scope,
|
|||
NetExpr* PENewClass::elaborate_expr(Design*des, NetScope*scope,
|
||||
ivl_type_t ntype, unsigned flags) const
|
||||
{
|
||||
NetExpr*obj = new NetENew(ntype);
|
||||
obj->set_line(*this);
|
||||
|
||||
// Find the constructor for the class. If there is no
|
||||
// constructor then the result of this expression is the
|
||||
// allocation alone.
|
||||
const netclass_t*ctype = dynamic_cast<const netclass_t*> (ntype);
|
||||
|
||||
if (!ctype) {
|
||||
cerr << get_fileline() << ": error: class new not allowed here. "
|
||||
<< "Left-hand side is not of class type." << endl;
|
||||
des->errors++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
NetExpr*obj = new NetENew(ntype);
|
||||
obj->set_line(*this);
|
||||
|
||||
obj = elaborate_expr_constructor_(des, scope, ctype, obj, flags);
|
||||
return obj;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue