summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
diff options
context:
space:
mode:
authorAngel Garcia Gomez <angelgarcia@google.com>2015-09-24 15:29:46 +0000
committerAngel Garcia Gomez <angelgarcia@google.com>2015-09-24 15:29:46 +0000
commitbd432b2d04b2aa0a42ec6c222e898baed339980e (patch)
treeaba763b9e901f17ae90ae321f1265f6fbf4cf99d /clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
parentbf37cdec28108097ef7d0bc3e8baebd1ce5b475d (diff)
downloadbcm5719-llvm-bd432b2d04b2aa0a42ec6c222e898baed339980e.tar.gz
bcm5719-llvm-bd432b2d04b2aa0a42ec6c222e898baed339980e.zip
Remove dangling parenthesis.
Summary: Remove parenthesis surrounding the new loop index. Reviewers: klimek Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D13133 llvm-svn: 248507
Diffstat (limited to 'clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 56074f683ea..a476f6c92c1 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -472,11 +472,21 @@ void LoopConvertCheck::doConversion(
// variable.
for (const auto &Usage : Usages) {
std::string ReplaceText;
+ SourceRange Range = Usage.Range;
if (Usage.Expression) {
// If this is an access to a member through the arrow operator, after
// the replacement it must be accessed through the '.' operator.
ReplaceText = Usage.Kind == Usage::UK_MemberThroughArrow ? VarName + "."
: VarName;
+ auto Parents = Context->getParents(*Usage.Expression);
+ if (Parents.size() == 1) {
+ if (const auto *Paren = Parents[0].get<ParenExpr>()) {
+ // Usage.Expression will be replaced with the new index variable,
+ // and parenthesis around a simple DeclRefExpr can always be
+ // removed.
+ Range = Paren->getSourceRange();
+ }
+ }
} else {
// The Usage expression is only null in case of lambda captures (which
// are VarDecl). If the index is captured by value, add '&' to capture
@@ -486,7 +496,7 @@ void LoopConvertCheck::doConversion(
}
TUInfo->getReplacedVars().insert(std::make_pair(Loop, IndexVar));
Diag << FixItHint::CreateReplacement(
- CharSourceRange::getTokenRange(Usage.Range), ReplaceText);
+ CharSourceRange::getTokenRange(Range), ReplaceText);
}
}
OpenPOWER on IntegriCloud