Skip to content

Commit

Permalink
[clang] Fix a "!CodeSynthesisContexts.empty()" assertion failure when…
Browse files Browse the repository at this point in the history
… constructing aggregate deduction guides. (llvm#89227)

We were missing to push an record to the instantiation stack in
`DeclareAggregateDeductionGuideForTypeAlias`. This patch fixes that.
  • Loading branch information
hokein authored Apr 18, 2024
1 parent 73e7f2f commit 4c3514f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3044,6 +3044,11 @@ FunctionTemplateDecl *DeclareAggregateDeductionGuideForTypeAlias(
return nullptr;

LocalInstantiationScope Scope(SemaRef);
Sema::InstantiatingTemplate BuildingDeductionGuides(
SemaRef, AliasTemplate->getLocation(), RHSDeductionGuide,
Sema::InstantiatingTemplate::BuildingDeductionGuidesTag{});
if (BuildingDeductionGuides.isInvalid())
return nullptr;

// Build a new template parameter list for the synthesized aggregate deduction
// guide by transforming the one from RHSDeductionGuide.
Expand Down
10 changes: 10 additions & 0 deletions clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,13 @@ Bar t = Foo<K<Container>>();

Bar s = 1; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of}}
} // namespace test20

namespace test21 {
template <typename T, unsigned N>
struct Array { const T member[N]; };
template <unsigned N>
using String = Array<char, N>;

// Verify no crash on constructing the aggregate deduction guides.
String s("hello");
} // namespace test21

0 comments on commit 4c3514f

Please sign in to comment.