Symmetry-protected topological phases and quantum anomalies