A very good question.
As an observation, the derivatives at the end points are one-sided.
Indeed, reflection does not work if the function does not have the derivatives of odd order vanishing at the point. You can extend to the left of $a$ as a function of class $C^m$ if you can find a polynomial that has the prescribed derivatives at the point, up to order $m$. A $C^{\infty}$ is possible if you can find a $C^{\infty}$ function that has at $a$ matching derivatives with $f$ ( extend past $a$ with that function). This is possible indeed, due to the theorem of Borel on power series.
$\bf{Added:}$
The ideea : if $f$ is $C^{\infty}$ on $[a,b]$, $g$ is $C^{\infty}$ on $(-\infty, a]$, $h$ is $C^{\infty}$ on $[b, \infty)$, and $f$ and $g$ have all the derivative matching at $a$, $f$ and $h$ have all the derivatives matching at $b$, then $(f,g,h)$ provide an extension of $f$ to whole $\mathbb{R}$.