Constraint


virtual class    base;
     rand bit[2:0] addr;
     pure constraint addr_c;
     // constraint addr_c{addr inside{[3:5]};}  //works 
endclass


class    sub    extends  base;
     virtual constraint addr_c{addr inside{[3:5]};}//  virtual needed here similar to pure methods ?   
     rand int abc;
     function void tester();
       if(addr inside {[3:5]})begin 
       $displayh("value solved %0d",addr);
       end
     endfunction:tester
endclass


module tb();
  sub   c_h;
  initial
      begin 
        c_h = new();
        if(!c_h.randomize())begin 
         $display("randomization failed");
        end
       c_h.tester();
     end
endmodule

1] The normal constraints work fine but while using pure constraint i get following error may be still not supported in tool:-
** Error: testbench.sv(3): Missing ‘virtual’ keyword. ‘pure’ qualifier must be followed by ‘virtual’ qualifier.

2] Is it permissible for another subclass to inherits from abstract super class & add a different functionality for constraint?
Eg :- virtual constraint addr_c{addr ==2;} from sub_class_2

In reply to bl4ckp3rl :

Yes, this is a new construct from 1800-2017 and may not be supported by all tools yet. Please contact your tool vendor.

The only reason you would need this is if you needed a way for the bass class to control the constraint_mode in the extended class.

constraints are not virtual, but act as if they are because randomize() is virtual.