Why does the Gauss-Bonnet theorem seem to work for some square boundary identifications but not others? The Wikipedia article gives an interesting example of the Gauss-Bonnet theorem:

As an application, a torus has Euler characteristic 0, so its total curvature must also be zero. ... It is also possible to construct a torus by identifying opposite sides of a square, in which case the Riemannian metric on the torus is flat and has constant curvature 0, again resulting in total curvature 0.

But there are of course other ways of closing up the square by identifying points on its boundary. If we identify opposite sides with one pair's orientation flipped, we get the Klein bottle, which also has Euler characteristic 0. But if we flip both pair's orientations then we get the real projective plane, which has Euler characteristic 1. And if we identify the entire boundary together then we get the sphere, with Euler characteristic 2. These are all closed surfaces so the Gauss-Bonnet theorem would naively imply that their total curvature equals $2\pi$ times their Euler characteristic, but this only works for the torus and Klein bottle identifications, but not the real projective plane or sphere identifications. Why?
For concreteness, consider the manifold $M$, the closed square (or unit disk) quotiented by its boundary. I think that $M$ has the topological structure of $S^2$ but not the differential structure - i.e. it's homeomorphic but not diffeomorphic to $S^2$. Is this correct? But $M$ can't be an exotic sphere because they don't exist in two dimensions, so it must not be a differentiable manifold at all. If I'm correct, then the identification process means that $M$ is not actually differentiable at the point which is the identified boundary - it's perfectly homogenous as a topological manifold, but fails to be a differentiable manifold because there's one problematic point at which the Gaussian curvature is undefined. Similarly, I guess the identified-edge square is homeomorphic but not diffeomorphic to the real projective plane? Then are the squares with the torus and Klein bottle identifications differentiable at the identified edges and corners? If so, why are the torus- and Klein-bottle-identified squares differentiable at their boundary but not the RPP- and sphere-identified squares?
 A: When you join up the edges of the flat square to make a projective plane, what happens to its corners? Each corner gets identified with the opposite corner.
So at two points in the projective plane you have two corner bits of squares
identified. They may be flat, but round the corner, you have only $\pi$
worth of angle instead of $2\pi$. This means you can't extend the flat metric
to these corners, so the quotient isn't naturally a Riemannian manifold.
An easier illustration: consider the surface of a standard cube in $\Bbb R^3$.
Each face is flat. What about the edges? They aren't trouble, one can think
of each pair of adjacent faces as a $2\times1$ rectangle folded over, and
that has a flat metric. So if you remove the vertices, the surface of the
cube has a flat Riemannian metric all over it.
But those pesky vertices! If you make a little circuit about one of these,
in effect you're going through an angle of $3\pi/2$. If you parallel-transport a vector round the path, it come back turned through a right angle. This means
there's no way of extending this flat Riemannian metric to the vertex.
This works for every compact surface; you can express it as a simplicial complex,
and if you delete the vertices then you can put a flat metric on it. Alas
one can rarely extend it to the whole surface (certainly if it has nonzero
Euler characteristic).
A: There is a version of the Gauss-Bonnet formula that works for manifolds that are not smooth.
Gaussian curvature is a curvature density, and its integral over a region gives the total curvature in that region. There is also a notion of point curvature: if you have a bunch of angles summing to $\theta$ that meet at a point, the point curvature (also called the angular defect) there is defined to be $2\pi-\theta$. If you have a closed manifold that is smooth away from finitely many points, then the total curvature is defined to be the integral of the Gaussian curvature where it is defined, plus the sum of the point curvatures at the non-smooth points. Then the Gauss-Bonnet formula holds with this modified definition of total curvature.
To illustrate, consider the square with opposite edges identified with a flip. The curvature density is $0$ everywhere in the interior of the square. However, opposite vertices get identified, and at each pair of vertices, we only see $\pi/2+\pi/2=\pi$ total angle. This means the point curvature at each of the non-smooth points of the resulting surface is $2\pi-\pi=\pi$. So we can compute that the total curvature is $\pi+\pi=2\pi$, which indeed equals $2\pi\cdot\chi(\mathbb{RP}^2)$.
I don't know if this theorem can be made to apply to the square with the boundary collapsed to a point. However, there is another way to obtain $S^2$ from the square, by identifying edges in the following way:

There are three non-smooth points: the head of the single arrows, the head of the double arrows, and the common tail of all arrows. These points have curvature $3\pi/2$, $3\pi/2$, and $\pi$, respectively, and the total curvature $3\pi/2+3\pi/2+\pi=4\pi$. Here again, this agrees with $2\pi\cdot\chi(S^2)$.
