summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/change-namespace
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2018-03-15 14:45:02 +0000
committerEric Liu <ioeric@google.com>2018-03-15 14:45:02 +0000
commit9a54397f81c9882d9cd25bde666f4b0c50bf0654 (patch)
treed5da805a01b5954ca3ff7c2e7cd9275e6545f113 /clang-tools-extra/change-namespace
parent69a4132f63e2aeea5ca3827f44996b1f376f3ac2 (diff)
downloadbcm5719-llvm-9a54397f81c9882d9cd25bde666f4b0c50bf0654.tar.gz
bcm5719-llvm-9a54397f81c9882d9cd25bde666f4b0c50bf0654.zip
[change-namespace] Don't match a function call/ref multiple times.
Summary: Previously, the matcher matches a function call/ref multiple times, one for each decl ancestor. This might cause problems. For example, in the following case, `func()` would be matched once (with namespace context) before using decl is seen and once after using decl is seeing, which would result in different conflicting replacements as the first match would replace `func` with "ns::func" as it doesn't know about the using decl. ``` namespace x { namespace { using ::ns::func; void f() { func(); } } } ``` Switching from `hasDescendant` matching to `hasAncestor` matching solves the problem. Reviewers: hokein Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44517 llvm-svn: 327629
Diffstat (limited to 'clang-tools-extra/change-namespace')
-rw-r--r--clang-tools-extra/change-namespace/ChangeNamespace.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/clang-tools-extra/change-namespace/ChangeNamespace.cpp b/clang-tools-extra/change-namespace/ChangeNamespace.cpp
index 68adada9948..35c321aed79 100644
--- a/clang-tools-extra/change-namespace/ChangeNamespace.cpp
+++ b/clang-tools-extra/change-namespace/ChangeNamespace.cpp
@@ -478,13 +478,13 @@ void ChangeNamespaceTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
hasAncestor(namespaceDecl(isAnonymous())),
hasAncestor(cxxRecordDecl()))),
hasParent(namespaceDecl()));
- Finder->addMatcher(decl(forEachDescendant(expr(anyOf(
- callExpr(callee(FuncMatcher)).bind("call"),
- declRefExpr(to(FuncMatcher.bind("func_decl")))
- .bind("func_ref")))),
- IsInMovedNs, unless(isImplicit()))
- .bind("dc"),
- this);
+ Finder->addMatcher(
+ expr(allOf(hasAncestor(decl().bind("dc")), IsInMovedNs,
+ unless(hasAncestor(isImplicit())),
+ anyOf(callExpr(callee(FuncMatcher)).bind("call"),
+ declRefExpr(to(FuncMatcher.bind("func_decl")))
+ .bind("func_ref")))),
+ this);
auto GlobalVarMatcher = varDecl(
hasGlobalStorage(), hasParent(namespaceDecl()),
OpenPOWER on IntegriCloud