https://github.com/Iasonaskrpr created https://github.com/llvm/llvm-project/pull/181890
This PR fixes #181603 The logic added in #125266 failed to account for cases where a function template is instantiated from a friend definition that is not a TSK_ExplicitSpecialization. In these scenarios the find_if search on the primary template redeclaration chain would fail because the definition is hidden within the lexical context of the class. Updated the assertion logic to check if the function is a friend object and isThisDeclarationADefinition() returns true before asserting. ICE is fixed and all clang tests pass >From 29dedf125fd495aa19c4148529a95a6f4970d264 Mon Sep 17 00:00:00 2001 From: Iasonaskrpr <[email protected]> Date: Tue, 17 Feb 2026 21:29:33 +0200 Subject: [PATCH] Resolved ICE --- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index e74c41517ecbf..b7d6e786f4616 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -5894,14 +5894,18 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, return cast<FunctionTemplateDecl>(RTD) ->isCompatibleWithDefinition(); }); - assert(It != Primary->redecls().end() && - "Should't get here without a definition"); - if (FunctionDecl *Def = cast<FunctionTemplateDecl>(*It) - ->getTemplatedDecl() - ->getDefinition()) - DC = Def->getLexicalDeclContext(); - else - DC = (*It)->getLexicalDeclContext(); + if (It != Primary->redecls().end()) { + if (FunctionDecl *Def = cast<FunctionTemplateDecl>(*It) + ->getTemplatedDecl() + ->getDefinition()) + DC = Def->getLexicalDeclContext(); + else + DC = (*It)->getLexicalDeclContext(); + } else { + assert((Function->getFriendObjectKind() != Decl::FOK_None && + Function->isThisDeclarationADefinition()) && + "Should't get here without a definition"); + } Innermost.emplace(Function->getTemplateSpecializationArgs()->asArray()); } MultiLevelTemplateArgumentList TemplateArgs = getTemplateInstantiationArgs( _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
