diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 829a759ca4a0b..7b759cfd17119 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -192,6 +192,8 @@ Bug Fixes to C++ Support - Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667), (#GH99877). - Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions. +- Fix mismatch of noexecpt in friend function declaration by copying template instantiated parameters to + current local scope.(#GH101330). Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index f93cd113988ae..2ffea99a49378 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4698,7 +4698,22 @@ void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation, // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. Sema::ContextRAII savedContext(*this, Decl); + + FunctionDecl *Source = Proto->getExtProtoInfo().ExceptionSpec.SourceTemplate; + FunctionTemplateDecl *SourceTemplate = Source->getDescribedFunctionTemplate(); + llvm::SmallDenseMap InstTemplateParams; + if (CurrentInstantiationScope && SourceTemplate) + if (TemplateParameterList *TPL = SourceTemplate->getTemplateParameters()) + for (NamedDecl *TemplateParam : *TPL) + if (auto *Found = + CurrentInstantiationScope->findInstantiationOf(TemplateParam)) + if (auto *InstTemplateParam = Found->dyn_cast()) + InstTemplateParams[TemplateParam] = InstTemplateParam; + LocalInstantiationScope Scope(*this); + for (auto [TemplateParam, InstTemplateParam] : InstTemplateParams) { + Scope.InstantiatedLocal(TemplateParam, InstTemplateParam); + } MultiLevelTemplateArgumentList TemplateArgs = getTemplateInstantiationArgs(Decl, Decl->getLexicalDeclContext(), diff --git a/clang/test/SemaCXX/pr101330.cpp b/clang/test/SemaCXX/pr101330.cpp new file mode 100644 index 0000000000000..3d42bd5635562 --- /dev/null +++ b/clang/test/SemaCXX/pr101330.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// expected-no-diagnostics + +template +struct C { + template + friend void func(const C &m) noexcept(N == 0); +}; + +template +void func(const C &m) noexcept(N == 0) {} + +int main() { + C t; + return 0; +}