12. Given the quadratic function $f(x)$ satisfies $f(-1)=0$, and $x \leqslant f(x) \leqslant \frac{1}{2}\left(x^{2}+1\right)$ for all real numbers $x$. Then, the analytical expression of the function $f(x)$ is $\qquad$ 1.
12. $\frac{1}{4}(x+1)^{2}$.

Let $f(x)=a x^{2}+b x+c(a \neq 0)$.
From the given, when $x=1$, we have $f(1)=1$, that is,
$$
a+b+c=1 \text {. }
$$

Also, $f(-1)=0$, that is,
$$
a-b+c=0 \text {. }
$$

From equations (1) and (2), we get $a+c=b=\frac{1}{2}$.
Also, $f(x) \geqslant x$, that is, $a x^{2}+(b-1) x+c \geqslant 0$ for all real numbers $x$, which requires
$$
\left\{\begin{array}{l}
a>0, \\
(b-1)^{2}-4 a c \leqslant 0 .
\end{array}\right.
$$

Substituting $b=\frac{1}{2}$, we get
$$
a c \geqslant \frac{1}{16} \text {. }
$$

Also, $c=\frac{1}{2}-a$, so $a\left(\frac{1}{2}-a\right) \geqslant \frac{1}{16}$, which simplifies to $\left(a-\frac{1}{4}\right)^{2} \leqslant 0$.
Solving, we get $a=\frac{1}{4}$.
At this point, $f(x)=\frac{1}{4} x^{2}+\frac{1}{2} x+\frac{1}{4}=\frac{1}{4}(x+1)^{2}$.
Similarly, from $f(x) \leqslant \frac{1}{2}\left(x^{2}+1\right)$, solving gives $a=\frac{1}{4}$.
In summary, the function $f(x)$ is $\frac{1}{4}(x+1)^{2}$.