[PATCH] D75613: [Sema] Reword -Wrange-loop-analysis warning messages

Aaron Puchert via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 4 08:24:59 PST 2020


aaronpuchert created this revision.
aaronpuchert added reviewers: aaron.ballman, Mordante, rtrieu.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
aaronpuchert added a comment.

This addresses my earlier comment D73007#1853563 <https://reviews.llvm.org/D73007#1853563>.


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.
- 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.

[1] https://bugs.llvm.org/show_bug.cgi?id=32823


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75613

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaStmt.cpp
  clang/test/SemaCXX/warn-range-loop-analysis-trivially-copyable.cpp
  clang/test/SemaCXX/warn-range-loop-analysis.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75613.248179.patch
Type: text/x-patch
Size: 17637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200304/5c5b669e/attachment-0001.bin>


More information about the cfe-commits mailing list