Theoretical investigation of the Humphreys–Davidson limit at high and low metallicity