diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b1ddfa070318b..c6ee1e282a008 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -437,6 +437,7 @@ Bug Fixes to C++ Support - Fix the result of `__builtin_is_implicit_lifetime` for types with a user-provided constructor. (#GH160610) - Correctly deduce return types in ``decltype`` expressions. (#GH160497) (#GH56652) (#GH116319) (#GH161196) - Fixed a crash in the pre-C++23 warning for attributes before a lambda declarator (#GH161070). +- Fix a crash when attempting to deduce a deduction guide from a non deducible template template parameter. (#130604) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp index 3d54d1eb4373a..fe673eac8fcfa 100644 --- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp +++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp @@ -1428,10 +1428,13 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template, DeclareImplicitDeductionGuidesForTypeAlias(*this, AliasTemplate, Loc); return; } - if (CXXRecordDecl *DefRecord = - cast(Template->getTemplatedDecl())->getDefinition()) { + CXXRecordDecl *DefRecord = + dyn_cast_or_null(Template->getTemplatedDecl()); + if (!DefRecord) + return; + if (const CXXRecordDecl *Definition = DefRecord->getDefinition()) { if (TemplateDecl *DescribedTemplate = - DefRecord->getDescribedClassTemplate()) + Definition->getDescribedClassTemplate()) Template = DescribedTemplate; } diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp index 2f1817d0ca7eb..fd1a5c01233d5 100644 --- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp +++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp @@ -586,3 +586,18 @@ Baz a{}; static_assert(__is_same(decltype(a), A>)); } // namespace GH133132 + +namespace GH130604 { +template struct A { + A(T); +}; + +template class TT = A> using Alias = TT; // #gh130604-alias +template using Alias2 = Alias; + +Alias2 a(42); +// expected-error@-1 {{no viable constructor or deduction guide for deduction of template arguments of 'Alias2'}} +Alias b(42); +// expected-error@-1 {{alias template 'Alias' requires template arguments; argument deduction only allowed for class templates or alias template}} +// expected-note@#gh130604-alias {{template is declared here}} +}