How to clear out or flush the arduino serial buffer

I got the same error and fixed by changing following code

void HardwareSerial::flushRX()
{
_rx_buffer->head = _rx_buffer->tail;
}

with

void HardwareSerial::flushRX()
{
  _rx_buffer_head = _rx_buffer_tail;
}

But the problem is that even if this is not returning any errors, the Serial input is not getting flushed. :expressionless: