From 0108771a510ae1d88eeef11360327a9a4ba66116 Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Mon, 26 Jan 2026 15:28:29 -0500 Subject: [PATCH] [Clang] Fix crash in CheckNonTypeTemplateParameterType with invalid type SubstAutoTypeSourceInfoDependent can return null when transforming an invalid type containing decltype(auto). Handle this case by returning QualType() to signal failure. Fixes #177545 --- clang/lib/Sema/SemaTemplate.cpp | 5 ++++- clang/test/SemaTemplate/deduction-crash.cpp | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 3497ff7856eed..24e26b930b072 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -1342,7 +1342,10 @@ QualType Sema::CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI, // - an identifier associated by name lookup with a non-type // template-parameter declared with a type that contains a // placeholder type (7.1.7.4), - TSI = SubstAutoTypeSourceInfoDependent(TSI); + TypeSourceInfo *NewTSI = SubstAutoTypeSourceInfoDependent(TSI); + if (!NewTSI) + return QualType(); + TSI = NewTSI; } return CheckNonTypeTemplateParameterType(TSI->getType(), Loc); diff --git a/clang/test/SemaTemplate/deduction-crash.cpp b/clang/test/SemaTemplate/deduction-crash.cpp index 99ca0b365ff6f..7c3e92af068e9 100644 --- a/clang/test/SemaTemplate/deduction-crash.cpp +++ b/clang/test/SemaTemplate/deduction-crash.cpp @@ -172,3 +172,8 @@ namespace PR51872_part1 { // expected-error@-1 {{no viable constructor or deduction guide for deduction of template arguments of 'T1'}} // expected-note@-7 {{candidate template ignored: could not match 'PR51872_part1::T1' against 'int'}} } + +namespace GH177545 { + template char> // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}} + struct T2; // expected-error@-1 {{function cannot return function type 'auto () volatile throw() -> decltype(auto)'}} +}