Let $f:\mathbb R\to\mathbb R$ with $$f(x)=\cos\left(\frac1x\right)\quad\text{for}\quad x\neq0,$$ $$f(x)=0\quad\text{for}\quad x=0.$$
I want to show that there exists a function $F:\mathbb R\to\mathbb R$ such that $F$ is differentiable on $\mathbb R$ and $$\forall_{x_0\in\mathbb R}\,\left[\frac{\mathrm d}{\mathrm dx}F(x)\right]_{x=x_0}=f(x_0),$$ i.e. that $f$ has a primitive.
However, if we simply integrate every term in the Taylor series of $f$ on $\mathbb R\setminus\{0\}$, we arrive at a function $F$ which has a discontinuity at $x=0$ (no matter how we define $F(0)$), namely $$F(x)=\sum_{k=0}^\infty\frac{(-1)^kx^{1-2k}}{(2k)!(1-2k)},\quad x\neq0$$ with $$\lim_{x\to0+}F(x)=\frac\pi2,\qquad\lim_{x\to0-}F(x)=-\frac\pi2,$$ which would mean that $F$ cannot be a primitive of $f$.
Is there maybe another way to show this, e.g. by using the identity $$f(x)=\frac{\exp\left(\frac{\mathrm i}{x}\right)}{2}+\frac{\exp\left(-\frac{\mathrm i}{x}\right)}{2}$$ for all $x\neq0$ and proving that $\exp(\pm\mathrm i/x)$ has a primitive? This however seems to lead to the same problems.
Let$$g(x)=\begin{cases}-x^2\sin\left(\frac1x\right)&\text{ if }x\neq0\\0&\text{ if }x=0.\end{cases}$$Then $g$ is differentiable and$$g'(x)=\begin{cases}f(x)-2x\sin\left(\frac1x\right)&\text{ if }x\neq0\\0&\text{ if }x=0.\end{cases}$$But the function$$h(x)=\begin{cases}2x\sin\left(\frac1x\right)&\text{ if }x\neq0\\0&\text{ if }x=0\end{cases}$$is continuous and therefore it has a primitive $H$. So, $g+H$ is a primitive of $f$.