Does $f(x) = 1 $ belong to the Hilbert space of the infinitely-deep square well? Let the square well be on the interval $(0,\pi )$. It is generally postulated that the wave function of this system should vanish at the end points, i.e., $g(0)= g(\pi) = 0$.
The function $f(x) \equiv 1 $ does not satisfy this condition. But it can be expanded in terms of the eigenstates $\{\sin n x \}$, 
$$ f(x)  = \frac{4}{\pi} \left(\sin x + \frac{1}{3}\sin 3x  +  \frac{1}{5}\sin 5 x + \ldots \right) .$$ 
Therefore, it should belong to the Hilbert space spanned by the eigenstates, right? 
On the other hand, by the expansion, this state has infinite energy, which makes it like an invalid state.  
 A: Generally, the Hilbert space for the infinite square well is taken as 
$$
L_2([0,\pi]) = \left\{f:[0,\pi]\to \mathbb C \ \middle| \ |f|^2 \text{ is Lebesgue integrable, } \int_0^\pi|f(x)|^2\mathrm dx<\infty\right\},
$$
so the answer is yes.
On the other hand, your function doesn't satisfy the conditions we require of the set of physical states in the well, nor does it belong to the domain of the hamiltonian, both of which are strict subsets of the Hilbert space.
It is an uncomfortable fact that some* configurations in QM involving infinite-dimensional Hilbert spaces give rise to states which live in the Hilbert space of the problem but which we're unwilling to consider as physical states. This is an unfortunate consequence of the fact that we like the closed-under-infinite-superpositions property of Hilbert spaces, but the conditions we like to impose on states to call them 'physical' are not closed under those infinite superpositions. So, you know, ugh. But it is what it is, and we just do our best to keep things as well-labelled as we can.
*actually, by "some", I mean all configurations in QM involving infinite-dimensional Hilbert spaces. This behaviour is generic and it appears everywhere - examples are easy to come up with.
