[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`
Tom Praschan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 6 08:32:31 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf5a2ef80fa47: [clangd] Fix the code action `RemoveUsingNamespace` (authored by v1nh1shungry, committed by tom-anders).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137494/new/
https://reviews.llvm.org/D137494
Files:
clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -226,6 +226,29 @@
int main() {
std::vector V;
}
+ )cpp"},
+ {// Does not qualify operators declared in a non-class context
+ R"cpp(
+ namespace ns {
+ struct Foo {};
+ void operator+(const Foo &, int) {}
+ }
+ using namespace n^s;
+ int main() {
+ Foo foo;
+ foo + 10;
+ }
+ )cpp",
+ R"cpp(
+ namespace ns {
+ struct Foo {};
+ void operator+(const Foo &, int) {}
+ }
+
+ int main() {
+ ns::Foo foo;
+ foo + 10;
+ }
)cpp"}};
for (auto C : Cases)
EXPECT_EQ(C.second, apply(C.first)) << C.first;
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@
if (!visibleContext(T->getDeclContext())
->Equals(TargetDirective->getNominatedNamespace()))
return;
+ // Avoid adding qualifiers before operators, e.g.
+ // using namespace std;
+ // cout << "foo"; // Must not changed to std::cout std:: << "foo"
+ // FIXME: User-defined literals are not handled
+ if (T->isInIdentifierNamespace(
+ Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+ return;
}
SourceLocation Loc = Ref.NameLoc;
if (Loc.isMacroID()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137494.473501.patch
Type: text/x-patch
Size: 1883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221106/b4501c5a/attachment.bin>
More information about the cfe-commits
mailing list