public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94695] New: Implement -Wrange-loop-analysis
@ 2020-04-21 14:37 mpolacek at gcc dot gnu.org
  2020-04-21 14:37 ` [Bug c++/94695] " mpolacek at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-21 14:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94695

            Bug ID: 94695
           Summary: Implement -Wrange-loop-analysis
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

This options contains a sub-option -Wrange-loop-construct which warns about:

#include <string>
#include <vector>

int main()
{
    std::vector<std::string> lol;
    for (const auto it : lol) { }
}

<source>:7:21: warning: loop variable 'it' creates a copy from type 'const
std::__cxx11::basic_string<char>' [-Wrange-loop-construct]

    for (const auto it : lol) { }

                    ^

<source>:7:10: note: use reference type 'const std::__cxx11::basic_string<char>
&' to prevent copying

    for (const auto it : lol) { }

         ^~~~~~~~~~~~~~~

                    &

1 warning generated.

We should consider adding something like that, too, in GCC 11.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-05-10 10:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-21 14:37 [Bug c++/94695] New: Implement -Wrange-loop-analysis mpolacek at gcc dot gnu.org
2020-04-21 14:37 ` [Bug c++/94695] " mpolacek at gcc dot gnu.org
2020-09-22 16:28 ` mpolacek at gcc dot gnu.org
2020-09-29 23:03 ` cvs-commit at gcc dot gnu.org
2020-09-29 23:05 ` mpolacek at gcc dot gnu.org
2020-11-21 21:28 ` cvs-commit at gcc dot gnu.org
2020-11-21 21:30 ` mpolacek at gcc dot gnu.org
2021-05-10 10:03 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).