The messages for two of the warnings are misleading:
- warn_for_range_const_reference_copy suggests that the initialization of the loop variable results in a copy. But that's not always true, we just know that some conversion happens, potentially invoking a constructor or conversion operator. The constructor might copy, as in the example that lead to this message [1], but it might also not. However, the constructed object is bound to a reference, which is potentially misleading, so we rewrite the message to emphasize that. We also make sure that we print the reference type into the warning message to clarify that this warning only appears when operator* returns a reference.
- warn_for_range_variable_always_copy suggests that a reference type loop variable initialized from a temporary "is always a copy". But we don't know this, the range might just return temporary objects which aren't copies of anything. (Assuming RVO a copy constructor might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
I'd like to change this name to reflect the changed diagnostic.