https://github.com/skadewdl3 updated https://github.com/llvm/llvm-project/pull/210610
>From 28cd7775fba49e938db8f79d1ce8c55adbeebccb Mon Sep 17 00:00:00 2001 From: Soham Karandikar <[email protected]> Date: Sun, 19 Jul 2026 21:55:54 +0530 Subject: [PATCH 1/3] Added a check for `NameInfo` actually containing a valid destructor name --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index c2e90624b8a6e..30ddad02f63c2 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3287,7 +3287,10 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( TrailingRequiresClause); Method->setRangeEnd(Constructor->getEndLoc()); } else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) { - Method = CXXDestructorDecl::Create( + if (NameInfo.getName().getNameKind() != DeclarationName::NameKind::CXXDestructorName) { + return nullptr; + } + Method = CXXDestructorDecl::Create( SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo, Destructor->UsesFPIntrin(), Destructor->isInlineSpecified(), false, Destructor->getConstexprKind(), TrailingRequiresClause); >From 7bb6ae3f23d571d3a20e9966568c6890ed0f0563 Mon Sep 17 00:00:00 2001 From: Soham Karandikar <[email protected]> Date: Mon, 20 Jul 2026 00:48:41 +0530 Subject: [PATCH 2/3] Simplified if-statement, ran clang-format --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 30ddad02f63c2..df559711f1674 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3287,10 +3287,11 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( TrailingRequiresClause); Method->setRangeEnd(Constructor->getEndLoc()); } else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) { - if (NameInfo.getName().getNameKind() != DeclarationName::NameKind::CXXDestructorName) { - return nullptr; - } - Method = CXXDestructorDecl::Create( + if (NameInfo.getName().getNameKind() != + DeclarationName::NameKind::CXXDestructorName) + return nullptr; + + Method = CXXDestructorDecl::Create( SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo, Destructor->UsesFPIntrin(), Destructor->isInlineSpecified(), false, Destructor->getConstexprKind(), TrailingRequiresClause); >From b532607410ae8af37e8f7c5c99aeb62b05c432d3 Mon Sep 17 00:00:00 2001 From: Soham Karandikar <[email protected]> Date: Thu, 23 Jul 2026 00:05:12 -0500 Subject: [PATCH 3/3] Moved empty `DeclarationNameInfo` check after template instantiaion, added lit test --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 9 +++++---- clang/test/SemaTemplate/friend.cpp | 13 +++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index df559711f1674..cff4f17d35bfc 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3271,6 +3271,11 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( DeclarationNameInfo NameInfo = SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs); + // Check if the substitution of template args failed + // leading to an empty DeclarationNameInfo. + if (!NameInfo.getName()) + return nullptr; + if (FunctionRewriteKind != RewriteKind::None) adjustForRewrite(FunctionRewriteKind, D, T, TInfo, NameInfo); @@ -3287,10 +3292,6 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( TrailingRequiresClause); Method->setRangeEnd(Constructor->getEndLoc()); } else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) { - if (NameInfo.getName().getNameKind() != - DeclarationName::NameKind::CXXDestructorName) - return nullptr; - Method = CXXDestructorDecl::Create( SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo, Destructor->UsesFPIntrin(), Destructor->isInlineSpecified(), false, diff --git a/clang/test/SemaTemplate/friend.cpp b/clang/test/SemaTemplate/friend.cpp index aef2faced6a96..6aca7ad90a127 100644 --- a/clang/test/SemaTemplate/friend.cpp +++ b/clang/test/SemaTemplate/friend.cpp @@ -180,3 +180,16 @@ namespace InstQualifier1 { }; } } // namespace InstQualifier1 + +namespace invalid_function_name_in_template_instantiation { + template <typename T> + struct D { + friend T::S::~ffl_fusion(); // expected-error {{no type named 'ffl_fusion'}} + }; + + struct Q { + struct S { ~S(); }; + }; + + template struct D<Q>; // expected-note {{in instantiation of template class}} +} // namespace invalid_function_name_in_template_instantiation _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
