summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
diff options
context:
space:
mode:
authorAngel Garcia Gomez <angelgarcia@google.com>2015-09-11 10:02:07 +0000
committerAngel Garcia Gomez <angelgarcia@google.com>2015-09-11 10:02:07 +0000
commitbb9ca54bbe6050bfa8d111ee074f595c7fd02084 (patch)
treeb7f2b082318d40067405ccc17b9d6df22b33aea4 /clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
parentef3cf01d1ccb11271c5727c8d461dcad448f4ab8 (diff)
downloadbcm5719-llvm-bb9ca54bbe6050bfa8d111ee074f595c7fd02084.tar.gz
bcm5719-llvm-bb9ca54bbe6050bfa8d111ee074f595c7fd02084.zip
Another patch for modernize-loop-convert.
Summary: 1. Avoid converting loops that iterate over the size of a container and don't use its elements, as this would result in an unused-result warning. 2. Never capture the elements by value on lambdas, thus avoiding doing unnecessary copies and errors with non-copyable types. 3. The 'const auto &' instead of 'auto &' substitution on const containers now works on arrays and pseudoarrays as well. 4. The error about multiple replacements in the same macro call is now documented in the tests (not solved though). 5. Due to [1], I had to add a dummy usage of the range element (like "(void) *It;" or similars) on the tests that had empty loops. 6. I removed the braces from the CHECK comments. I think that there is no need for them, and they confuse vim. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D12734 llvm-svn: 247399
Diffstat (limited to 'clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h')
-rw-r--r--clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h33
1 files changed, 29 insertions, 4 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
index 2fda54e3488..5290b4752ef 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
@@ -197,14 +197,39 @@ private:
/// \brief The information needed to describe a valid convertible usage
/// of an array index or iterator.
struct Usage {
+ enum UsageKind {
+ // Regular usages of the loop index (the ones not specified below). Some
+ // examples:
+ // \code
+ // int X = 8 * Arr[i];
+ // ^~~~~~
+ // f(param1, param2, *It);
+ // ^~~
+ // if (Vec[i].SomeBool) {}
+ // ^~~~~~
+ // \endcode
+ UK_Default,
+ // Indicates whether this is an access to a member through the arrow
+ // operator on pointers or iterators.
+ UK_MemberThroughArrow,
+ // If the variable is being captured by a lambda, indicates whether the
+ // capture was done by value or by reference.
+ UK_CaptureByCopy,
+ UK_CaptureByRef
+ };
+ // The expression that is going to be converted. Null in case of lambda
+ // captures.
const Expr *Expression;
- bool IsArrow;
+
+ UsageKind Kind;
+
+ // Range that covers this usage.
SourceRange Range;
explicit Usage(const Expr *E)
- : Expression(E), IsArrow(false), Range(Expression->getSourceRange()) {}
- Usage(const Expr *E, bool IsArrow, SourceRange Range)
- : Expression(E), IsArrow(IsArrow), Range(std::move(Range)) {}
+ : Expression(E), Kind(UK_Default), Range(Expression->getSourceRange()) {}
+ Usage(const Expr *E, UsageKind Kind, SourceRange Range)
+ : Expression(E), Kind(Kind), Range(std::move(Range)) {}
};
/// \brief A class to encapsulate lowering of the tool's confidence level.
OpenPOWER on IntegriCloud