Use 'auto const&' for iterators whose deref operator return a const var

This patch fixes PR15601.
- Added check for whether the loop variable and the initializer have the same
type.
- Added tests.