From 4fd4f57ef9212c847ee05e034aed3bf7c59cb3cc Mon Sep 17 00:00:00 2001 From: zebullax Date: Tue, 11 Nov 2025 11:24:11 +0900 Subject: [PATCH] Check against subst failure ouside of imm context (#206) Signed-off-by: zebullax --- clang/lib/AST/ExprConstantMeta.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/clang/lib/AST/ExprConstantMeta.cpp b/clang/lib/AST/ExprConstantMeta.cpp index 78d0e8ad2125..2a1b752589b0 100644 --- a/clang/lib/AST/ExprConstantMeta.cpp +++ b/clang/lib/AST/ExprConstantMeta.cpp @@ -2985,17 +2985,21 @@ bool substitute(APValue &Result, ASTContext &C, MetaActions &Meta, const_cast(TSpecDecl->getTypeForDecl())); //C.recordCachedSubstitution(SubstitutionHash, RV); return SetAndSucceed(Result, RV); - } else if (auto *TATD = dyn_cast(TDecl)) { + } + if (auto *TATD = dyn_cast(TDecl)) { TArgs.clear(); expandTemplateArgPacks(ExpandedTArgs, TArgs); QualType QT = Meta.Substitute(TATD, TArgs, Range.getBegin()); - assert(!QT.isNull() && "substitution failed after validating arguments?"); - + if(QT.isNull()) { + // substitution failed after validating arguments + return true; + } APValue RV = makeReflection(QT); //C.recordCachedSubstitution(SubstitutionHash, RV); return SetAndSucceed(Result, makeReflection(QT)); - } else if (auto *FTD = dyn_cast(TDecl)) { + } + if (auto *FTD = dyn_cast(TDecl)) { FunctionDecl *Spec = Meta.Substitute(FTD, ExpandedTArgs, Range.getBegin()); assert(Spec && "substitution failed after validating arguments?"); @@ -3007,7 +3011,8 @@ bool substitute(APValue &Result, ASTContext &C, MetaActions &Meta, APValue RV = makeReflection(Spec); //C.recordCachedSubstitution(SubstitutionHash, RV); return SetAndSucceed(Result, RV); - } else if (auto *VTD = dyn_cast(TDecl)) { + } + if (auto *VTD = dyn_cast(TDecl)) { TArgs.clear(); expandTemplateArgPacks(ExpandedTArgs, TArgs); @@ -3017,7 +3022,8 @@ bool substitute(APValue &Result, ASTContext &C, MetaActions &Meta, APValue RV = makeReflection(Spec); //C.recordCachedSubstitution(SubstitutionHash, RV); return SetAndSucceed(Result, makeReflection(Spec)); - } else if (auto *CD = dyn_cast(TDecl)) { + } + if (auto *CD = dyn_cast(TDecl)) { TArgs.clear(); expandTemplateArgPacks(ExpandedTArgs, TArgs);