Author: Haojian Wu Date: 2024-04-02T15:18:38+02:00 New Revision: 0b9528d6bd0bfde5702b1ee5ed8a249d354434f1
URL: https://github.com/llvm/llvm-project/commit/0b9528d6bd0bfde5702b1ee5ed8a249d354434f1 DIFF: https://github.com/llvm/llvm-project/commit/0b9528d6bd0bfde5702b1ee5ed8a249d354434f1.diff LOG: [clang] CTAD: Track template template type parameters that referenced in the template arguments of the RHS. (#85405) Fixes https://github.com/llvm/llvm-project/issues/85385. The Finder was missing for this case, for the crash test, the template parameter TTP was incorrectly considered as not referenced/appeared in the template arguments of the right hand side of the alias template decl, thus the synthesized deduction decl doesn't contain this TTP in the template parameter list, but we have references in the declaration, thus it caused crashes. Added: Modified: clang/lib/Sema/SemaTemplate.cpp clang/test/SemaCXX/cxx20-ctad-type-alias.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index befec401c8eec3c..a2b8cc14ca764f1 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -2720,6 +2720,12 @@ SmallVector<unsigned> TemplateParamsReferencedInTemplateArgumentList( return true; } + bool TraverseTemplateName(TemplateName Template) { + if (auto *TD = Template.getAsTemplateDecl()) + MarkAppeared(TD); + return RecursiveASTVisitor::TraverseTemplateName(Template); + } + void MarkAppeared(NamedDecl *ND) { if (TemplateParams.contains(ND)) ReferencedTemplateParams.insert(ND); diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp index ce403285b0f5314..b71cd46f884d637 100644 --- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp +++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp @@ -259,3 +259,23 @@ using Bar2 = Foo<K>; // expected-error {{extraneous template parameter list in a Bar2 b = 1; // expected-error {{no viable constructor or deduction guide for deduction of template arguments}} } // namespace test19 + +// GH85385 +namespace test20 { +template <template <typename> typename T> +struct K {}; + +template <typename U> +class Foo {}; + +// Verify that template template type parameter TTP is referenced/used in the +// template arguments of the RHS. +template <template<typename> typename TTP> +using Bar = Foo<K<TTP>>; // expected-note {{candidate template ignored: could not match 'Foo<K<>>' against 'int'}} + +template <class T> +class Container {}; +Bar t = Foo<K<Container>>(); + +Bar s = 1; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of}} +} // namespace test20 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits