Executing a pop_back() function call on empty queue

When calling a pop_back() function on an empty queue, the simulation doesnt fail


module GRG_queue1;

  typedef struct {
    string        txt    ;
    byte unsigned b      ;
    int           array[];
  } T;
  
  typedef enum {
                HELLO,
                UNKNOWN,
                RESET, 
                SET
    } wire_state_t;
  

  T q[$];
  
  wire_state_t wire_q[$];
  int test_q[$];
  
  wire_state_t map_q[];
  
  
  initial begin
    q.push_back('{"abc", 123, '{4, 5, 6}});
    q.push_back('{"def", 156, '{9, 8, 7}});
    $display("%p", q);
    
    $display("wire_q: %s", wire_q.pop_back());
    $display("wire_q: %s", wire_q.pop_back());
    $display("wire_q: %s", wire_q.pop_back());
    $display("wire_q: %s", wire_q.pop_back());
    $display("wire_q: %s", wire_q.pop_back());
    
    $display("map_q: %s", map_q[0]);
    
    $display("wire_q size: %d", wire_q.size());
    
    $display("test_q: %d", test_q[0]);
    
    
  end

endmodule

Output:__

wire_q: HELLO
wire_q: HELLO
wire_q: HELLO
wire_q: HELLO
wire_q: HELLO
map_q: HELLO
wire_q size: 0
test_q: 0

From the LRM:

7.10.2.5 Pop_back()
The prototype of the pop_back() method is as follows:
function element_t pop_back();
The pop_back() method removes and returns the last element of the queue.
If this method is called on an empty queue:
— Its return value shall be the same as that obtained by attempting to read a nonexistent array element
of the same type as the queue’s elements (as described in Table 7-1 in 7.4.6);
— It shall have no effect on the queue and may cause a warning to be issued.

Based on the LRM, everything is working correctly. You may get a warning message, but a warning isn’t required.

In reply to cgales:

What is the use-case for sending the default value. In other languages, we receive a null-object access

Table 7-1 describes the return types/values when there are no elements available. In some cases, you will get null-objects. For other types, you will get default values.