  We prove the Adler-Bardeen theorem in a large class of general gauge
theories, including nonrenormalizable ones. We assume that the gauge symmetries
are general covariance, local Lorentz symmetry and Abelian and non-Abelian
Yang-Mills symmetries, and that the local functionals of vanishing ghost number
satisfy a variant of the Kluberg-Stern--Zuber conjecture. We show that if the
gauge anomalies are trivial at one loop, for every truncation of the theory
there exists a subtraction scheme where they manifestly vanish to all orders,
within the truncation. Outside the truncation the cancellation of gauge
anomalies can be enforced by fine-tuning local counterterms. The framework of
the proof is worked out by combining a recently formulated chiral dimensional
regularization with a gauge invariant higher-derivative regularization. If the
higher-derivative regularizing terms are placed well beyond the truncation, and
the energy scale $\Lambda$ associated with them is kept fixed, the theory is
super-renormalizable and has the property that, once the gauge anomalies are
cancelled at one loop, they manifestly vanish from two loops onwards by simple
power counting. When the $\Lambda$ divergences are subtracted away and
$\Lambda$ is sent to infinity, the anomaly cancellation survives in a manifest
form within the truncation and in a nonmanifest form outside. The standard
model coupled to quantum gravity satisfies all the assumptions, so it is free
of gauge anomalies to all orders.
