aaronpuchert added a comment.

As I wrote on the bug <https://bugs.llvm.org/show_bug.cgi?id=44556>, I think we 
should only suppress one of the warnings in templates (and maybe always):

  <source>:18:22: warning: loop variable '_' is always a copy because the range 
of type 'const Rng' does not return a reference [-Wrange-loop-analysis]
      for (const auto& _ : t)
                       ^
  <source>:26:5: note: in instantiation of function template specialization 
'f<Rng>' requested here
      f(Rng{});
      ^
  <source>:18:10: note: use non-reference type 'int'
      for (const auto& _ : t)
           ^~~~~~~~~~~~~~~

However, I think we shouldn't suppress the other:

  <source>:18:21: warning: loop variable '_' of type 'const X' creates a copy 
from type 'const X' [-Wrange-loop-analysis]
      for (const auto _ : t)
                      ^
  <source>:25:5: note: in instantiation of function template specialization 
'f<X [3]>' requested here
      f(array);
      ^
  <source>:18:10: note: use reference type 'const X &' to prevent copying
      for (const auto _ : t)
           ^~~~~~~~~~~~~~
                      &

This generates a bunch of unneeded non-trivial copies, and I think we want to 
warn about that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73007/new/

https://reviews.llvm.org/D73007



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to