https://github.com/Kristianerik created 
https://github.com/llvm/llvm-project/pull/207478

When a type alias template's aggregate deduction guide could not be
resolved, `DeclareAggregateDeductionGuideFromInitList` would fall
through to the `ClassTemplateDecl` code path, which unconditionally
casts the template's underlying decl to `CXXRecordDecl`. For alias
templates this is a `TypeAliasDecl`, causing an assertion failure
(or SIGSEGV in non-assertions builds).

The sibling function `DeclareImplicitDeductionGuides` handles this
correctly — it always returns after the alias template branch and
uses `dyn_cast_or_null` instead of `cast` for the non-alias path.
This patch adds the missing `return nullptr` to match that pattern.

Likely related to #176389 (same crash site, could not reproduce locally).

Fixes #206994

>From 6939cffdd1391a37363c695bfb073b3af99190ea Mon Sep 17 00:00:00 2001
From: Kristianerik <[email protected]>
Date: Fri, 3 Jul 2026 20:33:39 -0700
Subject: [PATCH] [Sema] Fix crash in
 DeclareAggregateDeductionGuideFromInitList for alias templates

---
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp   |  1 +
 .../SemaTemplate/ctad-alias-aggregate-crash.cpp | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 clang/test/SemaTemplate/ctad-alias-aggregate-crash.cpp

diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index fa740d5581e5f..ab8e6a3555d90 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -1606,6 +1606,7 @@ CXXDeductionGuideDecl 
*Sema::DeclareAggregateDeductionGuideFromInitList(
       AggregateDeductionCandidates[Hash] = GD;
       return GD;
     }
+    return nullptr;
   }
 
   if (CXXRecordDecl *DefRecord =
diff --git a/clang/test/SemaTemplate/ctad-alias-aggregate-crash.cpp 
b/clang/test/SemaTemplate/ctad-alias-aggregate-crash.cpp
new file mode 100644
index 0000000000000..e3cf256af86cb
--- /dev/null
+++ b/clang/test/SemaTemplate/ctad-alias-aggregate-crash.cpp
@@ -0,0 +1,17 @@
+// RUN: not %clang_cc1 -std=c++23 -fsyntax-only %s
+// Reduced from a fuzzer-generated crash report.
+// Ensure we don't crash when aggregate deduction guide resolution
+// fails for a type alias template during CTAD.
+__detail __detail:);
+template _Tptypename convertible_to_Tpcommon_reference_t_Tp_Up }
+requires0template
+namespace ranges __iter_traits >;
+template  __iter_diff_tremove_cvref_t_Tp rangesiter_swap0
+namespace detail {
+template < typename > struct difference_type_
+}
+template < typename T > using difference_type = difference_type_< T >;
+namespace detail {
+template < typename T >
+struct difference_type_ :  T
+} difference_type alloc_limit = 4

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to