What would happen if a manifest heretic were elected as Roman Pontiff, and he began to reign over the whole Church?
The answer is found in the history of the Church. Pope Silverius reigned in the 6th century as a valid and faithful Roman Pontiff. Vigilius desired to be Pope, so he promised the Roman emperor and empress that he would support their heresies and install a heretic in the See of Constantinople if they made him pope — which they did. But since Silverius was still the valid Pope, Vigilius was an antipope. And he promoted the heresies of the emperor and empress.
Then Silverius died and Vigilius was installed at Rome as the Roman Pontiff. He was accepted by the clergy and people of Rome, and by the body of Bishops in the world.
Bellarmine: “From this time neither error nor feigning of error was discovered in Vigilius, but rather, supreme constancy in the faith even to death, as it shall appear. For he received with the pontificate the strength of faith and he was changed from a weak chaff into the most solid rock.”
When a heretic is elected Pope, the prevenient grace of God, which no one can resist, immediately vanquishes all apostasy, heresy, schism, idolatry, sacrilege, and blasphemy from his person, and gives him the gift of truth and of a never failing faith.
No valid Roman Pontiff has ever taught grave error, nor failed in faith. No valid Pope has ever been an apostate or heretic or idolater.