Merge pull request #705 from larsclausen/class_new_fix
Handle class new assignment to non-class variables
This commit is contained in:
commit
0a86773c5e
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
// Check that using the class new operator on a non-class variable results in an
|
||||
// error.
|
||||
|
||||
module test;
|
||||
|
||||
int i;
|
||||
|
||||
initial begin
|
||||
i = new;
|
||||
$display("FAILED");
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
// Check that using the class new operator on a dynamic array variable results
|
||||
// in an error.
|
||||
|
||||
module test;
|
||||
|
||||
int i[];
|
||||
|
||||
initial begin
|
||||
i = new;
|
||||
$display("FAILED");
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -499,6 +499,8 @@ sv_class_constructor_fail CE,-g2009 ivltests
|
|||
sv_class_empty_item normal,-g2009 ivltests
|
||||
sv_class_extends_scoped normal,-g2009 ivltests
|
||||
sv_class_localparam normal,-g2009 ivltests
|
||||
sv_class_new_fail1 CE,-g2009 ivltests
|
||||
sv_class_new_fail2 CE,-g2009 ivltests
|
||||
sv_class_new_init normal,-g2009 ivltests
|
||||
sv_class_in_module_decl normal,-g2009 ivltests
|
||||
sv_class_method_signed1 normal,-g2009 ivltests
|
||||
|
|
|
|||
Loading…
Reference in New Issue