with the following code (a boiled-down version of my original code)
#include
#include
template class A;
There is an error with your code:
template
auto diff(A const&y) const -> decltype(a-y.a)
{ return a-y.a; }
Here, A is a different type, so A cannot see it's a data member. Only A can see A.
Edit: that said, in your particular case, X and Y are both double, so I would naively expect that to compile. Note that in the best of cases, this construction should only compile when X and Y are the same, which may not be what you want.