Suppose a person is learning about the teachings of the Catholicism, and dies before that person has reached a conclusion whether he or she would like to join the Church. According to the teachings of the Catholic Church, what would happen to this person in terms of salvation? Now suppose that person leans toward accepting Catholicism, what would happen instead?
Catechism of The Catholic Church has direct Answer for your question:
Such a baptism is called Baptism of desire. But for this to be valid, their conversion should be accompanied by internal act of perfect love and contrition by which their soul is cleansed of all sin.
It is also to be noted that the ordinary magisterium of the Church has openly taught the three-fold Baptism (water, desire and blood) since the earliest days of the Church, and never has this teaching ever been condemned by the Catholic Church.