nridge created this revision. Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov. Herald added a project: clang.
This is mostly a workaround for https://bugs.llvm.org/show_bug.cgi?id=42914. Once that is fixed, the handling in VisitDeducedTyped() should be sufficient. Fixes https://github.com/clangd/clangd/issues/242 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D72119 Files: clang-tools-extra/clangd/FindTarget.cpp clang-tools-extra/clangd/unittests/XRefsTests.cpp Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -495,6 +495,16 @@ void test(unique_ptr<S<T>>& V) { V->fo^o(); } + )cpp", + + R"cpp(// Class template argument deduction + template <typename T> + struct [[Test]] { + Test(T); + }; + void foo() { + T^est a(5); + } )cpp"}; for (const char *Test : Tests) { Annotations T(Test); @@ -513,6 +523,7 @@ // FIXME: Auto-completion in a template requires disabling delayed template // parsing. TU.ExtraArgs.push_back("-fno-delayed-template-parsing"); + TU.ExtraArgs.push_back("-std=c++17"); auto AST = TU.build(); ASSERT_TRUE(AST.getDiagnostics().empty()) Index: clang-tools-extra/clangd/FindTarget.cpp =================================================================== --- clang-tools-extra/clangd/FindTarget.cpp +++ clang-tools-extra/clangd/FindTarget.cpp @@ -315,6 +315,12 @@ // TypeLoc never has a deduced type. https://llvm.org/PR42914 Outer.add(DT->getDeducedType(), Flags | Rel::Underlying); } + void VisitDeducedTemplateSpecializationType( + const DeducedTemplateSpecializationType *DTST) { + if (auto *TD = DTST->getTemplateName().getAsTemplateDecl()) { + Outer.add(TD->getTemplatedDecl(), Flags | Rel::TemplatePattern); + } + } void VisitTypedefType(const TypedefType *TT) { Outer.add(TT->getDecl(), Flags); }
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -495,6 +495,16 @@ void test(unique_ptr<S<T>>& V) { V->fo^o(); } + )cpp", + + R"cpp(// Class template argument deduction + template <typename T> + struct [[Test]] { + Test(T); + }; + void foo() { + T^est a(5); + } )cpp"}; for (const char *Test : Tests) { Annotations T(Test); @@ -513,6 +523,7 @@ // FIXME: Auto-completion in a template requires disabling delayed template // parsing. TU.ExtraArgs.push_back("-fno-delayed-template-parsing"); + TU.ExtraArgs.push_back("-std=c++17"); auto AST = TU.build(); ASSERT_TRUE(AST.getDiagnostics().empty()) Index: clang-tools-extra/clangd/FindTarget.cpp =================================================================== --- clang-tools-extra/clangd/FindTarget.cpp +++ clang-tools-extra/clangd/FindTarget.cpp @@ -315,6 +315,12 @@ // TypeLoc never has a deduced type. https://llvm.org/PR42914 Outer.add(DT->getDeducedType(), Flags | Rel::Underlying); } + void VisitDeducedTemplateSpecializationType( + const DeducedTemplateSpecializationType *DTST) { + if (auto *TD = DTST->getTemplateName().getAsTemplateDecl()) { + Outer.add(TD->getTemplatedDecl(), Flags | Rel::TemplatePattern); + } + } void VisitTypedefType(const TypedefType *TT) { Outer.add(TT->getDecl(), Flags); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits