Luminescence, electron spin resonance (ESR), optical absorption, conductivity, and composition data are measured on doped and compensated hydrogenated amorphous silicon. In material singly doped with boron or phosphorus, a variety of experiments indicates the introduction of a large defect density (up to 1018 cm-3) of the dangling-bond type. Compensation increases the luminescence efficiency, but the luminescence peak shifts strongly to lower energy. Compensation reduces the ESR resonance at g=2.0055, but a broad resonance characteristic of a hole trap remains. We deduce that compensation reduces the dangling-bond density, but introduces a new band of localized states above the valence-band edge. We associate these new states with boron-phosphorus complexes whose origin is a chemical interaction occurring during deposition. Changes in the dangling-bond density with doping and compensation lead us to propose an autocompensation mechanism of defect formation. Also reported is the first observation of a metastable light-induced ESR signal in a-Si: H.