No phone gets updates forever. The truth is that you are never *guaranteed* any version update. Bug fixes and security updates, sure, but you get the device with the OS installed and the warranty from the manufacturer that it will work as advertised.
The truth is that Flagship devices generally do get at least one version update, depending where the launch is in the OS release cycle. The only promise you get is from Google to update Nexus devices as long as the hardware supports it. That's been historically 2 versions.
Now, I've got 4 years old phones running Kit Kat because of the development community and the extended support for older devices. The likelihood of having developer support for new OS versions on old devices is directly proportional to the popularity of those devices. The more people who have them, the more likely developers will update them. That means the higher end phones of any manufacturer line.
As for the S4, S5, M8, etc., you can reasonably expect the manufacturer to do what's in the best interest of the company and its stockholders. If that means customer retention by offering OS updates on older models, they'll do it. But, the longer old phones are in service, the few new phones get sold.