[change-namespace] Don't match a function call/ref multiple times.
authorEric Liu <ioeric@google.com>
Thu, 15 Mar 2018 14:45:02 +0000 (14:45 +0000)
committerEric Liu <ioeric@google.com>
Thu, 15 Mar 2018 14:45:02 +0000 (14:45 +0000)
commit9a54397f81c9882d9cd25bde666f4b0c50bf0654
treed5da805a01b5954ca3ff7c2e7cd9275e6545f113
parent69a4132f63e2aeea5ca3827f44996b1f376f3ac2
[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
clang-tools-extra/change-namespace/ChangeNamespace.cpp
clang-tools-extra/unittests/change-namespace/ChangeNamespaceTests.cpp