diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 59732962caac6..f81e03fe11d33 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -719,6 +719,10 @@ Bug Fixes in This Version - Clang now emits correct source location for code-coverage regions in `if constexpr` and `if consteval` branches. Fixes (`#54419 `_) +- Fix assertion failure when declaring a template friend function with + a constrained parameter in a template class that declares a class method + or lambda at different depth. + Fixes (`#75426 `_) - Fix an issue where clang cannot find conversion function with template parameter when instantiation of template class. Fixes (`#77583 `_) diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 7f20413c104e9..fc80515b45e35 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -223,6 +223,9 @@ Response HandleFunction(const FunctionDecl *Function, (!Pattern || !Pattern->getLexicalDeclContext()->isFileContext())) { return Response::ChangeDecl(Function->getLexicalDeclContext()); } + + if (ForConstraintInstantiation && Function->getFriendObjectKind()) + return Response::ChangeDecl(Function->getLexicalDeclContext()); return Response::UseNextDecl(Function); } diff --git a/clang/test/SemaTemplate/GH75426.cpp b/clang/test/SemaTemplate/GH75426.cpp new file mode 100644 index 0000000000000..faf70699f9c5f --- /dev/null +++ b/clang/test/SemaTemplate/GH75426.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s +// expected-no-diagnostics + +template concept C = true; + +struct A { + template void f(); +}; + +auto L = []{}; + +template +class Friends { + template friend void A::f(); + template friend void decltype(L)::operator()(); +};