Author: hokein Date: Wed Oct 2 02:50:46 2019 New Revision: 373440 URL: http://llvm.org/viewvc/llvm-project?rev=373440&view=rev Log: [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 Added: cfe/trunk/test/clang-rename/Typedef.cpp Modified: cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h Modified: cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h?rev=373440&r1=373439&r2=373440&view=diff ============================================================================== --- cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h (original) +++ cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h Wed Oct 2 02:50:46 2019 @@ -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) { Added: cfe/trunk/test/clang-rename/Typedef.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/clang-rename/Typedef.cpp?rev=373440&view=auto ============================================================================== --- cfe/trunk/test/clang-rename/Typedef.cpp (added) +++ cfe/trunk/test/clang-rename/Typedef.cpp Wed Oct 2 02:50:46 2019 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits