[PATCH] D137550: [clangd] Fix the code action `RemoveUsingNamespace`
v1nh1shungry via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 7 06:52:44 PST 2022
v1nh1shungry created this revision.
v1nh1shungry added reviewers: tom-anders, sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
v1nh1shungry requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
Avoid adding qualifiers before user-defined literals
Repository:
rG LLVM Github Monorepo
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 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,14 @@
if (!visibleContext(T->getDeclContext())
->Equals(TargetDirective->getNominatedNamespace()))
return;
- // Avoid adding qualifiers before operators, e.g.
+ // Avoid adding qualifiers before operators
+ // and user-defined literals, e.g.
// using namespace std;
+ // auto s = "foo"s; // Must not changed to auto s = "foo" std::s;
// 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 (auto kind = T->getDeclName().getNameKind();
+ kind == DeclarationName::NameKind::CXXOperatorName ||
+ kind == DeclarationName::NameKind::CXXLiteralOperatorName)
return;
}
SourceLocation Loc = Ref.NameLoc;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137550.473652.patch
Type: text/x-patch
Size: 2105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221107/3b21a065/attachment.bin>
More information about the cfe-commits
mailing list