summaryrefslogtreecommitdiffstats
path: root/clang/lib/Tooling/Core/Lookup.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2016-11-25 16:02:49 +0000
committerEric Liu <ioeric@google.com>2016-11-25 16:02:49 +0000
commit6135581cdf5c6309614c47845a1d2f58f7bef595 (patch)
tree81aa14ebaadb629727632d6b1ae7f5425cd4a3e1 /clang/lib/Tooling/Core/Lookup.cpp
parent84b6f26eca491a756afe9b4e8025aaa1c63ad122 (diff)
downloadbcm5719-llvm-6135581cdf5c6309614c47845a1d2f58f7bef595.tar.gz
bcm5719-llvm-6135581cdf5c6309614c47845a1d2f58f7bef595.zip
Do not do raw name replacement when FromDecl is a class forward-declaration.
Summary: If the `FromDecl` is a class forward declaration, the reference is still considered as referring to the original definition given the nature of forward-declarations, so we can't do a raw name replacement in this case. Reviewers: bkramer Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D27132 llvm-svn: 287929
Diffstat (limited to 'clang/lib/Tooling/Core/Lookup.cpp')
-rw-r--r--clang/lib/Tooling/Core/Lookup.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/clang/lib/Tooling/Core/Lookup.cpp b/clang/lib/Tooling/Core/Lookup.cpp
index c7400fffbe5..6edf61b8050 100644
--- a/clang/lib/Tooling/Core/Lookup.cpp
+++ b/clang/lib/Tooling/Core/Lookup.cpp
@@ -13,6 +13,7 @@
#include "clang/Tooling/Core/Lookup.h"
#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
using namespace clang;
using namespace clang::tooling;
@@ -121,14 +122,20 @@ std::string tooling::replaceNestedName(const NestedNameSpecifier *Use,
"Expected fully-qualified name!");
// We can do a raw name replacement when we are not inside the namespace for
- // the original function and it is not in the global namespace. The
+ // the original class/function and it is not in the global namespace. The
// assumption is that outside the original namespace we must have a using
// statement that makes this work out and that other parts of this refactor
- // will automatically fix using statements to point to the new function
+ // will automatically fix using statements to point to the new class/function.
+ // However, if the `FromDecl` is a class forward declaration, the reference is
+ // still considered as referring to the original definition, so we can't do a
+ // raw name replacement in this case.
const bool class_name_only = !Use;
const bool in_global_namespace =
isa<TranslationUnitDecl>(FromDecl->getDeclContext());
- if (class_name_only && !in_global_namespace &&
+ const bool is_class_forward_decl =
+ isa<CXXRecordDecl>(FromDecl) &&
+ !cast<CXXRecordDecl>(FromDecl)->isCompleteDefinition();
+ if (class_name_only && !in_global_namespace && !is_class_forward_decl &&
!usingFromDifferentCanonicalNamespace(FromDecl->getDeclContext(),
UseContext)) {
auto Pos = ReplacementString.rfind("::");
OpenPOWER on IntegriCloud