This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG51df1a9ac96f: [clangd] Fix add-using tweak on declrefs with template arguments (authored by kadircet).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151303/new/ https://reviews.llvm.org/D151303 Files: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp Index: clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp +++ clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp @@ -498,6 +498,30 @@ switch(one::two::ee{}) { case ee_one:break; } } )cpp"}, + {R"cpp( +#include "test.hpp" +void foo() { + one::f^unc_temp<int>(); +})cpp", + R"cpp( +#include "test.hpp" +using one::func_temp; + +void foo() { + func_temp<int>(); +})cpp"}, + {R"cpp( +#include "test.hpp" +void foo() { + one::va^r_temp<int>; +})cpp", + R"cpp( +#include "test.hpp" +using one::var_temp; + +void foo() { + var_temp<int>; +})cpp"}, }; llvm::StringMap<std::string> EditedFiles; for (const auto &Case : Cases) { @@ -515,6 +539,8 @@ } using uu = two::cc; template<typename T> struct vec {}; +template <typename T> void func_temp(); +template <typename T> T var_temp(); })cpp"; // Typo correction is disabled in msvc-compatibility mode. ExtraArgs.push_back("-fno-ms-compatibility"); Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp =================================================================== --- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp +++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp @@ -288,11 +288,18 @@ if (Node == nullptr) return false; + // Closed range for the fully qualified name as spelled in source code. SourceRange SpelledNameRange; if (auto *D = Node->ASTNode.get<DeclRefExpr>()) { if (D->getDecl()->getIdentifier()) { QualifierToRemove = D->getQualifierLoc(); + // Use the name range rather than expr, as the latter can contain template + // arguments in the range. SpelledNameRange = D->getSourceRange(); + // Remove the template arguments from the name, as they shouldn't be + // spelled in the using declaration. + if (auto AngleLoc = D->getLAngleLoc(); AngleLoc.isValid()) + SpelledNameRange.setEnd(AngleLoc.getLocWithOffset(-1)); MustInsertAfterLoc = D->getDecl()->getBeginLoc(); } } else if (auto *T = Node->ASTNode.get<TypeLoc>()) {
Index: clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp +++ clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp @@ -498,6 +498,30 @@ switch(one::two::ee{}) { case ee_one:break; } } )cpp"}, + {R"cpp( +#include "test.hpp" +void foo() { + one::f^unc_temp<int>(); +})cpp", + R"cpp( +#include "test.hpp" +using one::func_temp; + +void foo() { + func_temp<int>(); +})cpp"}, + {R"cpp( +#include "test.hpp" +void foo() { + one::va^r_temp<int>; +})cpp", + R"cpp( +#include "test.hpp" +using one::var_temp; + +void foo() { + var_temp<int>; +})cpp"}, }; llvm::StringMap<std::string> EditedFiles; for (const auto &Case : Cases) { @@ -515,6 +539,8 @@ } using uu = two::cc; template<typename T> struct vec {}; +template <typename T> void func_temp(); +template <typename T> T var_temp(); })cpp"; // Typo correction is disabled in msvc-compatibility mode. ExtraArgs.push_back("-fno-ms-compatibility"); Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp =================================================================== --- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp +++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp @@ -288,11 +288,18 @@ if (Node == nullptr) return false; + // Closed range for the fully qualified name as spelled in source code. SourceRange SpelledNameRange; if (auto *D = Node->ASTNode.get<DeclRefExpr>()) { if (D->getDecl()->getIdentifier()) { QualifierToRemove = D->getQualifierLoc(); + // Use the name range rather than expr, as the latter can contain template + // arguments in the range. SpelledNameRange = D->getSourceRange(); + // Remove the template arguments from the name, as they shouldn't be + // spelled in the using declaration. + if (auto AngleLoc = D->getLAngleLoc(); AngleLoc.isValid()) + SpelledNameRange.setEnd(AngleLoc.getLocWithOffset(-1)); MustInsertAfterLoc = D->getDecl()->getBeginLoc(); } } else if (auto *T = Node->ASTNode.get<TypeLoc>()) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits