This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix action `RemoveUsingNamespace` for inline namespace
ClosedPublic

Authored by v1nh1shungry on Nov 15 2022, 5:41 AM.

Details

Summary

Existing version ignores symbols declared in an inline namespace ns
when removing using namespace ns

Diff Detail

Event Timeline

v1nh1shungry created this revision.Nov 15 2022, 5:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 15 2022, 5:41 AM
v1nh1shungry requested review of this revision.Nov 15 2022, 5:41 AM
v1nh1shungry added inline comments.Nov 15 2022, 5:50 AM
clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
212

We can replace printUsingNamespaceName with printNamespaceScope here so that we can get a::foobar() in the test.

However, it can sometimes cause redundancy such as in the 10th test.

And I don't know whether it is worth it. WDYT?

tom-anders added inline comments.Nov 15 2022, 11:09 AM
clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
212

Just making sure I understood this correctly:

If you replace printUsingNamespaceName with printNamespaceScope, then...

  • ...in the test you added it would result in a::foobar() instead of a::b::foobar() (which is better)
  • ... but in this test (which is the 10th test if I counted correctly):
namespace a::b { struct Foo {}; }
 using namespace a;
 using namespace a::[[b]];
 using namespace b;
 int main() { Foo F;}

what would be the result..? would you get a::Foo instead of a::b::Foo?

v1nh1shungry added inline comments.Nov 15 2022, 5:11 PM
clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
212

Sorry, I mean the next test. I read 10 from the inlay hint but I forgot the index starts from 0 :(

The test I want to mention:

namespace a::b { struct Foo {}; }
using namespace a;
using namespace a::b;
using namespace [[b]];
int main() { Foo F;}

We will get a::b::Foo in both the 10th and 11th tests. So in the 10th test, we don't get any benefits and don't sacrifice anything. In the 11th test, we get more redundancy than the existing version.

Apologize again for my mistake.

nridge added a subscriber: nridge.Nov 19 2022, 5:03 PM

A gentle ping? Sorry if it bothers you.

A gentle ping? Sorry if it bothers you.

Sorry! I thought you’d probably first wanted to address the remaining comments in https://reviews.llvm.org/D137817 because they might also affect this patch here..?

Oops! Thank you for your thoughtful consideration.

You're right, but I currently get stuck there and need more time. And I prefer to clear the existing patches simultaneously if you don't mind.

Or do you think I should merge the modification of this patch into there and give up this?

clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
212

FYI, we have a discussion left here.

tom-anders added inline comments.Nov 29 2022, 10:32 PM
clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
93
212

Ok I’d say let’s just go with printUsingNamespaceName here for now. When your other patch is merged as well, maybe we could have a look at this again.

address the comment's suggestion

v1nh1shungry marked an inline comment as done.Dec 12 2022, 9:30 AM

Sorry for the delay! And many thanks for reviewing and giving suggestions!

This revision is now accepted and ready to land.Dec 28 2022, 3:29 AM