A function in $C_0^2$ is twice continuously differentiable and has compact support. If you have an explicit function $f(x)$, you can check if it is in $C_0^2$ by differentiating it twice and making sure that $f''(x)$ is also continuous. Furthermore, you need to be sure that your function is nonzero only on a compact set.
In your example, the function is a polynomial, so it is infinitely differentiable and therefore trivially in $C^2$, however unless the domain is restricted it does not have compact support (the values for which it is nonzero are unbounded).
Furthermore, one cannot arbitrarily restrict the domain and expect the function to continue to be differentiable, indeed if the domain is restricted at points where $f(x)$ is nonzero the function will no longer even be continuous. A common argument used when compact support is needed is to multiply the function by an appropriate bump function.