summaryrefslogtreecommitdiffstats
path: root/clang/lib/Tooling/Refactoring
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2017-10-16 10:37:42 +0000
committerHaojian Wu <hokein@google.com>2017-10-16 10:37:42 +0000
commit6f60ff84cd2b27f801df4809099f211ee04399b1 (patch)
tree6795194b986f704f6bd0b6867d986103c7202f30 /clang/lib/Tooling/Refactoring
parent68b285f69efce9d3669f0bf6c9fe0e89bd265e30 (diff)
downloadbcm5719-llvm-6f60ff84cd2b27f801df4809099f211ee04399b1.tar.gz
bcm5719-llvm-6f60ff84cd2b27f801df4809099f211ee04399b1.zip
[clang-rename] Add function unit tests.
Summary: Also contain a fix: * Fix a false positive of renaming a using shadow function declaration. Reviewers: ioeric Reviewed By: ioeric Subscribers: klimek, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D38882 llvm-svn: 315898
Diffstat (limited to 'clang/lib/Tooling/Refactoring')
-rw-r--r--clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp b/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
index 76a173f4b49..7f14dc2e0f5 100644
--- a/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ b/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
@@ -194,6 +194,12 @@ public:
bool VisitDeclRefExpr(const DeclRefExpr *Expr) {
const NamedDecl *Decl = Expr->getFoundDecl();
+ // Get the underlying declaration of the shadow declaration introduced by a
+ // using declaration.
+ if (auto* UsingShadow = llvm::dyn_cast<UsingShadowDecl>(Decl)) {
+ Decl = UsingShadow->getTargetDecl();
+ }
+
if (isInUSRSet(Decl)) {
RenameInfo Info = {Expr->getSourceRange().getBegin(),
Expr->getSourceRange().getEnd(),
@@ -452,6 +458,23 @@ createRenameAtomicChanges(llvm::ArrayRef<std::string> USRs,
RenameInfo.FromDecl,
NewName.startswith("::") ? NewName.str()
: ("::" + NewName).str());
+ } else {
+ // This fixes the case where type `T` is a parameter inside a function
+ // type (e.g. `std::function<void(T)>`) and the DeclContext of `T`
+ // becomes the translation unit. As a workaround, we simply use
+ // fully-qualified name here for all references whose `DeclContext` is
+ // the translation unit and ignore the possible existence of
+ // using-decls (in the global scope) that can shorten the replaced
+ // name.
+ llvm::StringRef ActualName = Lexer::getSourceText(
+ CharSourceRange::getTokenRange(
+ SourceRange(RenameInfo.Begin, RenameInfo.End)),
+ SM, TranslationUnitDecl->getASTContext().getLangOpts());
+ // Add the leading "::" back if the name written in the code contains
+ // it.
+ if (ActualName.startswith("::") && !NewName.startswith("::")) {
+ ReplacedName = "::" + NewName.str();
+ }
}
}
// If the NewName contains leading "::", add it back.
OpenPOWER on IntegriCloud