St. Thomas Aquinas
Summa, Article 1, Part III, Q. 68:
"I answer that, the sacrament of Baptism may be wanting to someone in two ways. First, both in reality and in desire; as is the case with those who neither are baptized, nor wished to be baptized: which clearly indicates contempt of the sacrament, in regard to those who have the use of the free will. Consequently those to whom Baptism is wanting thus, cannot obtain salvation: since neither sacramentally nor mentally are they incorporated in Christ, through Whom alone can salvation be obtained.
"Secondly, the sacrament of Baptism may be wanting to anyone in reality but not in desire: for instance, when a man wishes to be baptized, but by some ill-chance he is forestalled by death before receiving Baptism. And such a man can obtain salvation without being actually baptized, on account of his desire for Baptism, which desire is the outcome of faith that worketh by charity, whereby God, Whose power is not yet tied to visible sacraments, sanctifies man inwardly. Hence Ambrose says of Valentinian, who died while yet a catechumen: 'I lost him whom I was to regenerate: but he did not lose the graces he prayed for.' "