In the book Quantum Mechanics (Volume I) by Galindo & Pascual, they define the domain of the QM momentum operator on the Hilbert space $\mathcal{H}=L^2(\mathbb{R})$ as \begin{equation*} D(P)=\Biggl\{\psi\in\mathcal{H}: \psi\text{ absolutely continuous,} \int_{-\infty}^\infty\!dx\,\Biggl\lvert\frac{d\psi(x)}{dx}\Biggr\rvert^2<\infty\Biggr\} \end{equation*} and the momentum operator $P$ by $$(P\psi)(x)=-i\frac{d\psi(x)}{dx}.$$ They go on to prove that $P$ is densely defined and symmetric. To prove that $P$ is self-adjoint, they attempt to show that $D(P^\dagger)\subseteq D(P)$. Here are the next couple of lines of the proof:
... consider a function $\psi\in D(P^\dagger)$ and define $\psi_1=P^\dagger\psi$; then $$\langle\psi|P|\varphi\rangle=\langle\psi_1|\varphi\rangle,\quad\forall\varphi\in D(P)$$ can be rewritten as \begin{equation*} \begin{split} \langle\psi|P|\varphi\rangle &=\int_{-\infty}^\infty\!dx\,\psi_1^*(x)\varphi(x)\\ &=i\int_{-\infty}^\infty\!dx\Biggl[\frac{d}{dx} \Biggl(i\int_0^x\!dt\,\psi_1(t)+c\Biggr)^*\Biggr]\varphi(x), \end{split} \end{equation*} where $c$ is an arbitrary constant. Choosing $\varphi\in C^\infty_0$, integrating by parts, and taking into account that $\varphi$ is zero outside a finite interval, we obtain \begin{equation}\tag{2.16} \int_{-\infty}^\infty\!dx\Biggl(\psi(x)-i\int_0^x\!dt\,\psi_1(t)-c\Biggr)^* \Biggl(-i\frac{d\varphi(x)}{dx}\Biggr)=0,\quad\forall\varphi\in C^\infty_0. \end{equation}
[So far, this seems OK to me. It is the next statement that I don't follow:]
Since $C^\infty_0$ is dense in $L^2(\mathbb{R})$, the first factor of the integrand in (2.16) must be a constant and hence, with a convenient choice $c_0$ for $c$, we can write almost everywhere \begin{equation}\tag{2.17} \psi(x)=c_0+i\int_0^x\!dt\,\psi_1(t), \end{equation} [and it goes on from there]
I want to concentrate on the validity of going from (2.16) to (2.17). I understand that, with total lack of rigor, if we have $$\int h\varphi'=0\quad\forall\varphi\in C^\infty_0$$ we'd like to do an integration by parts and write $$\int h'\varphi=\int h\varphi'=0\quad\forall\varphi\in C^\infty_0$$ from which we would get that $h'=0$ almost everywhere hence $h=c$ almost everywhere. But I don't see how to apply that here since I don't know that $\psi$ is differentiable a.e. or even a.e. on a compact interval.
It even looks like a version of the DuBois-Raymond theorem from variational calculus, but I only know that for continuous functions on a compact interval, so it would seem to not apply here.
So, my questions are:
how do you get from (2.16) to (2.17)?
what element of $L^2(\mathbb{R})$ would they be talking about when they say that $C^\infty_0$ is dense in $L^2(\mathbb{R})$?