Navigation Menu

Skip to content

Commit

Permalink
[clang-rename] Better renaming the typedef decl.
Browse files Browse the repository at this point in the history
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

llvm-svn: 373440
  • Loading branch information
hokein committed Oct 2, 2019
1 parent e503256 commit fbd134f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
Expand Up @@ -98,7 +98,17 @@ class RecursiveSymbolVisitor
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) {
Expand Down
8 changes: 8 additions & 0 deletions clang/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

0 comments on commit fbd134f

Please sign in to comment.