Initializing localparam based on Type parameter

I have a parameterized class with a type - parameter .
Within the parameterized class I have a localparam which I need to initialize based on the type - parameter during specialization


module   top_tb ;

    class  C #( type T = int )  ;

   `ifndef M1 

      localparam  STR  =  $sformatf( "C#(%0s)" , $typename( int ) ) ;
   
   `else

      localparam  STR  =  $sformatf( "C#(%0s)" , $typename( type( T ) )  ) ;
   
   `endif

      function  new() ;
        $display(" STR  is  %0s " , STR );
      endfunction

    endclass 

    C #( int ) c_int ;
    
    C #( bit signed [31:0] ) c_bits_31_0 ;  

    C #( bit  [31:0] ) c_bit_31_0 ;
  
      initial  begin 

                c_int  =  new() ;
           
	   c_bits_31_0  =  new() ;

            c_bit_31_0  =  new() ;
 
      end 

    endmodule


I observe issue with it across simulators .
**ONLY 1 of the major 3 Simulators ( Running with Licensed ones at work ) run this code .
**

However I am not here to discuss simulator issues , I am here to ask if there is a way around the limitation of $typename ??

As per SV LRM Section 20.6.1 :: $typename can be used as elaboration time constant

So Code is Legal as per LRM .

From a strict LRM perspective $typename removes the sign i.e


 $typename( bit signed [1:0] )  should  give  Output  as  bit [1:0] 
 $typename( bit [1:0] )         should  give  Output  as  bit [1:0]
 

How do I overcome this during initialization of the localparam ?

For the following ::


    C #( bit signed [1:0] ) c_bits_1_0 ;
    C #( bit [1:0] ) c_bit_1_0 ;

I  want  localparam  to  have different values  as  these  are  2  different  Specializations  !!

In reply to TC_2017:

A couple of issues with your question

  • The rule about revealing signedness only applies to the default. Both types
    bit [1:0]
    and
    bit unsigned [1:0]
    should show up as
    bit [1:0]
    , and both
    int
    as well as
    int signed
    should show up as
    int
    .

type(T) should just be
T

  • From section 11.2.1 Constant expressions in the LRM, it is not clear that both
    $sformatf
    and
    $typename
    are allowed in constant expressions. That is something we are working to correct in the next revision of the LRM.
  • Does STR really need to be a
    localparam
    ? Would a
    const string
    work for you?