Skip to content

Commit 231c5f2

Browse files
cor3ntingithub-actions[bot]
authored andcommitted
Automerge: [Clang] Fix a crash when using ctad with a template template parameter. (#161488)
This fixes the crash reported in #130604. It does not try to improve diagnostics or resolve CWG3003 (this will be explored separately). Fixes #130604
2 parents e676b70 + 2daa2f1 commit 231c5f2

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ Bug Fixes to C++ Support
437437
- Fix the result of `__builtin_is_implicit_lifetime` for types with a user-provided constructor. (#GH160610)
438438
- Correctly deduce return types in ``decltype`` expressions. (#GH160497) (#GH56652) (#GH116319) (#GH161196)
439439
- Fixed a crash in the pre-C++23 warning for attributes before a lambda declarator (#GH161070).
440+
- Fix a crash when attempting to deduce a deduction guide from a non deducible template template parameter. (#130604)
440441

441442
Bug Fixes to AST Handling
442443
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplateDeductionGuide.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,10 +1428,13 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
14281428
DeclareImplicitDeductionGuidesForTypeAlias(*this, AliasTemplate, Loc);
14291429
return;
14301430
}
1431-
if (CXXRecordDecl *DefRecord =
1432-
cast<CXXRecordDecl>(Template->getTemplatedDecl())->getDefinition()) {
1431+
CXXRecordDecl *DefRecord =
1432+
dyn_cast_or_null<CXXRecordDecl>(Template->getTemplatedDecl());
1433+
if (!DefRecord)
1434+
return;
1435+
if (const CXXRecordDecl *Definition = DefRecord->getDefinition()) {
14331436
if (TemplateDecl *DescribedTemplate =
1434-
DefRecord->getDescribedClassTemplate())
1437+
Definition->getDescribedClassTemplate())
14351438
Template = DescribedTemplate;
14361439
}
14371440

clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,3 +586,18 @@ Baz a{};
586586
static_assert(__is_same(decltype(a), A<A<int>>));
587587

588588
} // namespace GH133132
589+
590+
namespace GH130604 {
591+
template <typename T> struct A {
592+
A(T);
593+
};
594+
595+
template <typename T, template <typename> class TT = A> using Alias = TT<T>; // #gh130604-alias
596+
template <typename T> using Alias2 = Alias<T>;
597+
598+
Alias2 a(42);
599+
// expected-error@-1 {{no viable constructor or deduction guide for deduction of template arguments of 'Alias2'}}
600+
Alias b(42);
601+
// expected-error@-1 {{alias template 'Alias' requires template arguments; argument deduction only allowed for class templates or alias template}}
602+
// expected-note@#gh130604-alias {{template is declared here}}
603+
}

0 commit comments

Comments
 (0)