[clang] 4c3514f - [clang] Fix a "!CodeSynthesisContexts.empty()" assertion failure when constructing aggregate deduction guides. (#89227)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 18 06:46:39 PDT 2024
Author: Haojian Wu
Date: 2024-04-18T15:46:35+02:00
New Revision: 4c3514fa53cc39db5de4dbbca9a54977159f24e8
URL: https://github.com/llvm/llvm-project/commit/4c3514fa53cc39db5de4dbbca9a54977159f24e8
DIFF: https://github.com/llvm/llvm-project/commit/4c3514fa53cc39db5de4dbbca9a54977159f24e8.diff
LOG: [clang] Fix a "!CodeSynthesisContexts.empty()" assertion failure when constructing aggregate deduction guides. (#89227)
We were missing to push an record to the instantiation stack in
`DeclareAggregateDeductionGuideForTypeAlias`. This patch fixes that.
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 f4b6e1ceb6f023..d4976f9d0d11d8 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -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.
diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index b71cd46f884d63..6f04264a655ad5 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -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
More information about the cfe-commits
mailing list