Author: Krisitan Erik Olsen
Date: 2026-08-19T08:22:36Z
New Revision: d558c8bd2dee85f128e047d712bb5cb9213f8868

URL: 
https://github.com/llvm/llvm-project/commit/d558c8bd2dee85f128e047d712bb5cb9213f8868
DIFF: 
https://github.com/llvm/llvm-project/commit/d558c8bd2dee85f128e047d712bb5cb9213f8868.diff

LOG: [Sema] Fix crash in DeclareAggregateDeductionGuideFromInitList for alias 
templates (#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

Added: 
    clang/test/SemaTemplate/gh206994.cpp

Modified: 
    clang/docs/ReleaseNotes.md
    clang/lib/Sema/SemaTemplateDeductionGuide.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 16911cf384ea3..2571149b02a12 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -510,6 +510,8 @@ features cannot lower the translation-unit ABI level;
 #### Miscellaneous Bug Fixes
 
 #### Miscellaneous Clang Crashes Fixed
+
+- Fixed a crash in CTAD for type alias templates when the aggregate deduction 
guide could not be resolved. (#GH206994)
 - Fixed a crash when instantiating an invalid dependent friend destructor 
declaration in a class template. (#GH210234)
 - Fixed an assertion failure in `-extract-api` when a documentation comment
   contains invalid UTF-8. (#GH212393)

diff  --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index 40c5a6181c51d..63d6759bc5490 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -1607,6 +1607,7 @@ CXXDeductionGuideDecl 
*Sema::DeclareAggregateDeductionGuideFromInitList(
       AggregateDeductionCandidates[Hash] = GD;
       return GD;
     }
+    return nullptr;
   }
 
   if (CXXRecordDecl *DefRecord =

diff  --git a/clang/test/SemaTemplate/gh206994.cpp 
b/clang/test/SemaTemplate/gh206994.cpp
new file mode 100644
index 0000000000000..6ef5f8e70dff1
--- /dev/null
+++ b/clang/test/SemaTemplate/gh206994.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -ferror-limit 19 -verify %s
+
+// Reduced from a fuzzer-generated crash report. Every line is needed
+// to trigger the specific error recovery state that causes the crash.
+
+__detail __detail:); // expected-error {{unknown type name '__detail'}} \
+                     // expected-error {{expected ';' after top level 
declarator}} \
+                     // expected-error {{expected unqualified-id}}
+template _Tptypename convertible_to_Tpcommon_reference_t_Tp_Up } // 
expected-error {{unknown type name '_Tptypename'; did you mean 'typename'?}} \
+  // expected-error {{expected a qualified name after 'typename'}} \
+  // expected-error {{variable cannot be defined in an explicit 
instantiation}} \
+  // expected-error {{expected ';' after top level declarator}} \
+  // expected-error {{extraneous closing brace}}
+requires0template // expected-error {{unknown type name 'requires0template'}}
+namespace ranges __iter_traits >; // expected-error {{expected 
unqualified-id}} \
+  // expected-error {{expected '{'}} \
+  // expected-error {{unknown type name '__iter_traits'}} \
+  // expected-error {{expected unqualified-id}}
+template  __iter_
diff _tremove_cvref_t_Tp rangesiter_swap0 // expected-error {{unknown type name 
'__iter_
diff _tremove_cvref_t_Tp'}} \
+  // expected-error {{expected ';' after top level declarator}}
+namespace detail { // expected-error {{variable cannot be defined in an 
explicit instantiation}}
+template < typename > struct 
diff erence_type_ // expected-error {{expected ';' after struct}} \
+  // expected-note {{'detail::
diff erence_type_' declared here}}
+}
+template < typename T > using 
diff erence_type = 
diff erence_type_< T >; // expected-error {{no template named '
diff erence_type_'; did you mean 'detail::
diff erence_type_'?}}
+namespace detail {
+template < typename T >
+struct 
diff erence_type_ :  T // expected-error {{expected '{' after base class list}}
+} 
diff erence_type alloc_limit = 4
+// expected-error@* {{too many errors emitted, stopping now}}


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

Reply via email to