In Pugh's Real Mathematical Analysis there is an exercise, marked with three stars (which denotes that the author doesn't know the answer), whether there exist a nonsmooth function $f : \mathbb{R} \to \mathbb{R}$ such that $f^2$ and $f^3$ are both smooth.
My question is not strictly about this exercise, but rather about cases when we weaken the hypotheses when only one of $f^2$ and $f^3$ are smooth.
The fact that the exercise comes with this hypotheses suggest we should be able to find those functions. For the case when $f^2$ need to be smooth we have a function $f(x) = x$ if $x$ is rational and $-x$ if $x$ is irrational, but what about the case when $f^3$ needs to be smooth?