Author: antangelo Date: 2024-01-12T09:02:01-05:00 New Revision: 45568135cbb31bb3b345a8355134970742248120
URL: https://github.com/llvm/llvm-project/commit/45568135cbb31bb3b345a8355134970742248120 DIFF: https://github.com/llvm/llvm-project/commit/45568135cbb31bb3b345a8355134970742248120.diff LOG: [Sema] Use lexical DC for friend functions when getting constraint instantiation args (#77552) Fixes a crash where the template argument depth computed in the semantic context for a friend FunctionDecl with a constrained parameter is compared against arguments in the lexical context for the purpose of checking if the constraint depends on enclosing template parameters. Since getTemplateInstantiationArgs in this case follows the semantic DC for friend FunctionDecls, the resulting depth is incorrect and trips an assertion. Fixes #75426 Added: clang/test/SemaTemplate/GH75426.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaTemplateInstantiate.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4aba054e252af2..10e426a30d98f9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -723,6 +723,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 <https://github.com/llvm/llvm-project/issues/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 diff erent depth. + Fixes (`#75426 <https://github.com/llvm/llvm-project/issues/75426>`_) - Fix an issue where clang cannot find conversion function with template parameter when instantiation of template class. Fixes (`#77583 <https://github.com/llvm/llvm-project/issues/77583>`_) diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 7f20413c104e97..fc80515b45e35b 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 00000000000000..faf70699f9c5f0 --- /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<typename T> concept C = true; + +struct A { + template<C T> void f(); +}; + +auto L = []<C T>{}; + +template<typename X> +class Friends { + template<C T> friend void A::f(); + template<C T> friend void decltype(L)::operator()(); +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits