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