TAxis::SetRange(…) and TAxis::SetRangeUser(…) are supposed to just set the viewing range, as according to the documentation in ROOT: TAxis Class Reference
.
However, for h1 as a TH1F,
h1->GetXaxis()->SetRangeUser(1000,10000);
TF1 * fit = new TF1("fit","[0]*x",500,15000);
h1->Fit(fit,"","",500,15000);
Will not fit between the range 500,15000, but instead will fit between the range 1000,10000 (with no errors or warnings), even though from the documentation it is quite clear this should not happen.
The fitting range is taken from the fit command if the range given to the fit command is smaller than SetRange, but otherwise the maximum range of the fit allowed is restricted to the range given by SetRange/SetRangeUser, rather than the full range of the histogram
Ah ok, that makes sense in that case, because when you do SetRange on a histogram, it is just like this histogram is a new one restricted to the new range. I am not surprised that the fit command is not able to extend its fitting range outside the range applied on the histogram. @moneta can confirm.
A warning should probably be shown if one tries to fit outside this range then (or ideally just fixed so that the viewing range does not affect the fitting range), or at a minimum the documentation should mention it (since as is the documentation says it only affects the viewing range).