diff options
| author | Angel Garcia Gomez <angelgarcia@google.com> | 2015-11-06 14:04:12 +0000 |
|---|---|---|
| committer | Angel Garcia Gomez <angelgarcia@google.com> | 2015-11-06 14:04:12 +0000 |
| commit | 7e1d4ae937b2c9947d2daf8a5064885d8127e5bf (patch) | |
| tree | a690fb9d5ddba7743026a37e066e72c9a36e96ed /clang-tools-extra/clang-tidy/modernize | |
| parent | 712229ec59b71e3bba342ac5848625ce200bb4a6 (diff) | |
| download | bcm5719-llvm-7e1d4ae937b2c9947d2daf8a5064885d8127e5bf.tar.gz bcm5719-llvm-7e1d4ae937b2c9947d2daf8a5064885d8127e5bf.zip | |
Avoid naming conflicts with the old index in modernize-loop-convert.
Summary: The old index declaration is going to be removed anyway, so we can reuse its name if it is the best candidate for the new index.
Reviewers: klimek
Subscribers: cfe-commits, alexfh
Differential Revision: http://reviews.llvm.org/D14437
llvm-svn: 252303
Diffstat (limited to 'clang-tools-extra/clang-tidy/modernize')
| -rw-r--r-- | clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp index f1fd078fa01..1f2b40da977 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp @@ -820,14 +820,14 @@ std::string VariableNamer::createIndexName() { if (Len > 1 && ContainerName.endswith(Style == NS_UpperCase ? "S" : "s")) { IteratorName = ContainerName.substr(0, Len - 1); // E.g.: (auto thing : things) - if (!declarationExists(IteratorName)) + if (!declarationExists(IteratorName) || IteratorName == OldIndex->getName()) return IteratorName; } if (Len > 2 && ContainerName.endswith(Style == NS_UpperCase ? "S_" : "s_")) { IteratorName = ContainerName.substr(0, Len - 2); // E.g.: (auto thing : things_) - if (!declarationExists(IteratorName)) + if (!declarationExists(IteratorName) || IteratorName == OldIndex->getName()) return IteratorName; } @@ -849,12 +849,12 @@ std::string VariableNamer::createIndexName() { IteratorName = AppendWithStyle(ContainerName, OldIndex->getName()); // E.g.: (auto container_i : container) - if (!declarationExists(IteratorName)) + if (!declarationExists(IteratorName) || IteratorName == OldIndex->getName()) return IteratorName; IteratorName = AppendWithStyle(ContainerName, Elem); // E.g.: (auto container_elem : container) - if (!declarationExists(IteratorName)) + if (!declarationExists(IteratorName) || IteratorName == OldIndex->getName()) return IteratorName; // Someone defeated my naming scheme... @@ -875,7 +875,8 @@ std::string VariableNamer::createIndexName() { int Attempt = 0; do { IteratorName = GiveMeName + std::to_string(Attempt++); - } while (declarationExists(IteratorName)); + } while (declarationExists(IteratorName) || + IteratorName == OldIndex->getName()); return IteratorName; } |

