[PATCH] D137550: [clangd] Fix the code action `RemoveUsingNamespace`
Tom Praschan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 9 11:05:28 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG82ca918b5755: [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/D137550/new/
https://reviews.llvm.org/D137550
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
@@ -249,6 +249,21 @@
ns::Foo foo;
foo + 10;
}
+ )cpp"},
+ {// Does not qualify user-defined literals
+ R"cpp(
+ namespace ns {
+ long double operator "" _w(long double);
+ }
+ using namespace n^s;
+ int main() { 1.5_w; }
+ )cpp",
+ R"cpp(
+ namespace ns {
+ long double operator "" _w(long double);
+ }
+
+ int main() { 1.5_w; }
)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,12 +155,23 @@
if (!visibleContext(T->getDeclContext())
->Equals(TargetDirective->getNominatedNamespace()))
return;
+ auto Kind = T->getDeclName().getNameKind();
// 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))
+ if (Kind == DeclarationName::CXXOperatorName)
+ return;
+ // Avoid adding qualifiers before user-defined literals, e.g.
+ // using namespace std;
+ // auto s = "foo"s; // Must not changed to auto s = "foo" std::s;
+ // FIXME: Add a using-directive for user-defined literals
+ // declared in an inline namespace, e.g.
+ // using namespace s^td;
+ // int main() { cout << "foo"s; }
+ // change to
+ // using namespace std::literals;
+ // int main() { std::cout << "foo"s; }
+ if (Kind == DeclarationName::NameKind::CXXLiteralOperatorName)
return;
}
SourceLocation Loc = Ref.NameLoc;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137550.474308.patch
Type: text/x-patch
Size: 2468 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221109/c783e596/attachment.bin>
More information about the cfe-commits
mailing list