We used getEnclosingNamespaceContext(), which calls getParent() rather
than getLexicalParent(), so we would end up adding the "using" line in
places that do not affect the cursor location, or just return an error
when declaration was in another file.
Details
- Reviewers
hokein - Commits
- rG910871532101: [clangd] Fix AddUsing tweak for out-of-line functions.
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
thanks.
clang-tools-extra/clangd/unittests/TweakTests.cpp | ||
---|---|---|
2673 | IIUC, before this patch, the using was added inside the above namespace foo, the code was still valid after applying the tweak. There is no enclosing namespace for foo::fun(), so we will insert the using at the first top-level decl. It seems that we will break the code if the one::two::ff decl is defined in the main file (not the test.hpp), e.g. // using one::two::ff will be inserted here, which is not valid namespace one { namespace two { void ff(); } } namespace foo { void fun(); } void foo::fun() {...} this case was working before the patch, and now is broken after this patch. It is not a common case, probably ok for now. |
clang-tools-extra/clangd/unittests/TweakTests.cpp | ||
---|---|---|
2673 | You are correct that this will not work. It is not a regression, however, since it was broken before too. Prior to this patch, the using would be inserted inside the namespace foo { }, so while the using statement would compile, it wouldn't affect the out-of-line definition of the function, meaning removing the qualifier would not work. The insertion point logic will have to change a little when we add the feature to remove all other full qualifiers for that name. I think it might be best to address these corner cases at that point, but I can also do it here if you prefer. |
clang-tools-extra/clangd/unittests/TweakTests.cpp | ||
---|---|---|
2673 |
hmm, that's interesting, the following code is compilable. namespace one { namespace two { void ff(); } } namespace foo { using one::two::ff; void fun(); } // namespace foo void foo::fun() { ff(); }
agree to defer it, this is something we should keep in mind. |
IIUC, before this patch, the using was added inside the above namespace foo, the code was still valid after applying the tweak.
There is no enclosing namespace for foo::fun(), so we will insert the using at the first top-level decl. It seems that we will break the code if the one::two::ff decl is defined in the main file (not the test.hpp), e.g.
this case was working before the patch, and now is broken after this patch. It is not a common case, probably ok for now.