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;
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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits