[PATCH] Add -Wrange-loop-analysis to warn when a range-based for-loop is creating a copy.
Richard Trieu
rtrieu at google.com
Mon Jun 16 22:18:42 PDT 2014
This warning will trigger on loop variables that make copies in a range-based for-loop. The three cases this warning catches are:
1) for (const Foo &x : Foos), where the range Foos does not return a copy. This warning will suggest using the non-reference type so the copy is obvious.
2) for (const Foo x : Foos), where the range Foos does return a reference, but is copied into x. This warning will suggest using the reference type to prevent a copy from being made.
3) for (const Bar &x : Foos), where Bar is constructed from Foo. In this case, suggest using the non-reference "const Bar" to indicate a copy is intended to be made, or "const Foo &" to prevent a copy from being made.
-Wrange-loop-analysis is being added as a sub-group to -Wloop-analysis. The previous warnings there are moved to -Wfor-loop-analysis. While the warnings are currently split along statement types, a finer grain division of warnings may be needed.
http://reviews.llvm.org/D4169
Files:
include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaStmt.cpp
test/SemaCXX/warn-range-loop-analysis.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4169.10476.patch
Type: text/x-patch
Size: 16628 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140617/4508a0a0/attachment.bin>
More information about the cfe-commits
mailing list