Saint Thomas Aquinas, Summa Theologica, on The Sacraments, Question 68 - Of Those Who Receive Baptism, Second Article - Whether a Man Can Be Saved without Baptism?
"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 wish to be baptized: which clearly indicates contempt of the sacraments, in regard to those who have the use of 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 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 grace he prayed for."
(The council fathers at Trent placed the Summa theologiae on the altar during their deliberations.)