summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2019-10-02 09:50:46 +0000
committerHaojian Wu <hokein@google.com>2019-10-02 09:50:46 +0000
commit8a4696a6507c068d4451877725d5d618de4c6342 (patch)
tree9e4668ddb07b0ca716cb2b2ac807234c0e90825a
parent5ff48959823ef911d1f2eb805e0829ee07f1e570 (diff)
downloadclang-8a4696a6507c068d4451877725d5d618de4c6342.tar.gz
[clang-rename] Better renaming the typedef decl.
Summary: when renaming a typedef decl, we used to rename the underlying decl of the typedef, we should rename the typedef itself. Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68322 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373440 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h12
-rw-r--r--test/clang-rename/Typedef.cpp8
2 files changed, 19 insertions, 1 deletions
diff --git a/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h b/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
index cd230ea18b..c0f995d85c 100644
--- a/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
+++ b/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
@@ -98,7 +98,17 @@ public:
TypeBeginLoc, TypeEndLoc))
return false;
}
- return visit(Loc.getType()->getAsCXXRecordDecl(), TypeBeginLoc, TypeEndLoc);
+ if (const Type *TP = Loc.getTypePtr()) {
+ if (TP->getTypeClass() == clang::Type::Record)
+ return visit(TP->getAsCXXRecordDecl(), TypeBeginLoc, TypeEndLoc);
+ }
+ return true;
+ }
+
+ bool VisitTypedefTypeLoc(TypedefTypeLoc TL) {
+ const SourceLocation TypeEndLoc =
+ Lexer::getLocForEndOfToken(TL.getBeginLoc(), 0, SM, LangOpts);
+ return visit(TL.getTypedefNameDecl(), TL.getBeginLoc(), TypeEndLoc);
}
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
diff --git a/test/clang-rename/Typedef.cpp b/test/clang-rename/Typedef.cpp
new file mode 100644
index 0000000000..64d337fae2
--- /dev/null
+++ b/test/clang-rename/Typedef.cpp
@@ -0,0 +1,8 @@
+namespace std {
+class basic_string {};
+typedef basic_string string;
+} // namespace std
+
+std::string foo(); // // CHECK: std::new_string foo();
+
+// RUN: clang-rename -offset=93 -new-name=new_string %s -- | sed 's,//.*,,' | FileCheck %s