If $f$ is $C^{\infty}$ and $f^2$ is analytic, then $f$ is analytic Assume that $f:\mathbb{C}^n\rightarrow \mathbb{C}$ is a $C^{\infty}$ function such that $f^2$ is (complex) analytic. Then one can show that $f$ is analytic. (Note: Liviu Nicolaescu and Alexandre Eremenko have given elegant proofs of this below; my own proof involved the Weierstrass preparation theorem.) 
Now, when we consider the question for functions in some quasi-analytic Denjoy-Carleman class these proofs don't carry over: 
Question: If $f^2$ is a function in some quasi-analytic Denjoy-Carleman class, then $f$ is quasi-analytic belonging to the same class?
Weierstrass preparation theorem doesn't hold, for $n\geq2$, in quasi-analytic Denjoy-Carleman classes, and it is an open problem whether a $C^\infty$ function that belongs to a quasi-analytic Denjoy-Carleman class along every line belongs to that class. This is part of the difficulty of this problem for $n\geq2$.
Another open question in Denjoy-Carleman classes is about whether ideals are closed. For principal ideals this is related to solving for $f$ in $gf=h$, where $g$ and $h$ are known to belong to the Denjoy-Carleman class. The ideal generated by $g$ would not be closed if we can find a smooth $f$ that doesn't belong to the class such that it gets pushed into the class by the multiplication by $g$. In this way, the question above is about understanding whether a smooth function, not in the class, can be pushed into the class by multiplying by itself. If the square appears composed with $f$ on the other side then it is known to occur. This is, $f(x^2)$ may be in a quasi-analytic Denjoy-Carleman class while $f$ is not.
Note: I put in the tags model-theory and o-minimal because people that work in those areas sometimes have also worked with quasi-analytic functions enough to maybe have an idea for proving it. Subject classification in mathematics doesn't play the same role for exposition than for finding proofs.
Note: Joris' theorem states that if $f^2$ and $f^3$ are smooth functions then $f$ is smooth. This holds for several variables functions. Also, for the quasianalytic case, in the case of one variable, it is again easy to show that if $f$ is smooth and $f^2$ and $f^3$ belong to some quasianalytic Denjoy-Carlmenan class, then $f$ also belong to the same class. For several variables ... who know!? The problem with just $f^2$ is also a subproblem steaming form asking if Joris' theorem is true for quasianalytic DC classes.
 A: Here is a simple proof for complex-analytic case.
If restrictions of $f$ on all complex lines are analytic, then $f$ is analytic.
This reduces the problem to the case $n=1$. Now $f^2$ is analytic so near every point, so
it has a representation $f^2(z)=(z-a)^mg(z),$ where $g(a)\neq 0$. If $m$ is even,
we obtain analyticity of $f$. If $m$ is odd, $f$ cannot be $C^\infty$; some derivative blows up.
The argument also works for real-analytic, as a real-analytic function extends to complex
analytic in some complex neighborhood.
EDIT. This proof extends to quasianalytic functions of $DC$ (Denjoy-Carleman) class. One needs two facts:


*

*If $f\in DC$ and $f(a)=0$ then $f(x)=(x-a)g(x)$ with $g\in DC$. The proof is based
on the formula 
$$g(x)=\int_0^1f'(tx)dt.$$
By induction, this gives $f(x)=(x-a)^mg(x)$, for every $f\in DC$ and every $a$,
with some non-negative integer $m$ and $g\in DC$, $g(a)\neq 0$.

*If $f\in DC$ and $F$ is analytic on the range of $f$, then $F\circ f\in DC$. This follows from the great theorem of E. M. Dyn'kin (J.d'Analyse 60 (1993)) that characterizes
$DC$ in terms of pseudoanalytic extension to a complex semi-neighborhood of a real interval.
In the proof above, $F$ is a branch of the square root.
Validity of facts 1 and 2 was explained to me by MO user fedja.  
