St. Thomas Aquinas
“A distinction must be made among sinners: some are secret; others are notorious… Therefore Holy Communion ought not to be given to open sinners when they ask for it… But if they be not open sinners, but occult, the Holy Communion should not be denied them if they ask for it. For since every Christian, from the fact that he is baptized, is admitted to the Lord’s table, he may not be robbed of his right, except from some open cause… Nevertheless a priest who has knowledge of the crime can privately warn the secret sinner, or warn all openly in public, from approaching the Lord’s table, until they have repented of their sins and have been reconciled to the Church; because after repentance and reconciliation, Communion must not be refused even to public sinners, especially in the hour of death.”
Source: St. Thomas Aquinas, Summa Theologica