diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 127b9541d5c5d8..5aedfc654e8dbb 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -290,6 +290,8 @@ Bug Fixes to C++ Support - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). - Correctly check constraints of explicit instantiations of member functions. (#GH46029) +- Fixed an assertion failure about a constraint of a friend function template references to a value with greater + template depth than the friend function template. (#GH98258) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 0afe6064bab185..992565701d40ca 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -1667,10 +1667,7 @@ class ConstraintRefersToContainingTemplateChecker } void CheckNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { - assert(D->getDepth() <= TemplateDepth && - "Nothing should reference a value below the actual template depth, " - "depth is likely wrong"); - if (D->getDepth() != TemplateDepth) + if (D->getDepth() < TemplateDepth) Result = true; // Necessary because the type of the NTTP might be what refers to the parent @@ -1694,10 +1691,7 @@ class ConstraintRefersToContainingTemplateChecker using inherited::TransformTemplateTypeParmType; QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) { - assert(TL.getDecl()->getDepth() <= TemplateDepth && - "Nothing should reference a value below the actual template depth, " - "depth is likely wrong"); - if (TL.getDecl()->getDepth() != TemplateDepth) + if (TL.getDecl()->getDepth() < TemplateDepth) Result = true; return inherited::TransformTemplateTypeParmType( TLB, TL, diff --git a/clang/test/SemaTemplate/concepts-friends.cpp b/clang/test/SemaTemplate/concepts-friends.cpp index 91b797034ed6cf..14b37d78d951dc 100644 --- a/clang/test/SemaTemplate/concepts-friends.cpp +++ b/clang/test/SemaTemplate/concepts-friends.cpp @@ -504,3 +504,24 @@ template struct Z; Y y(1); } + +namespace GH98258 { + +struct S { + template + friend void f() requires requires { [](V){}; } { + return; + } + + template + friend void f2() requires requires { [](auto){}; } { + return; + } + + template + friend void f3() requires requires { [](){ return X; }; } { + return; + } +}; + +}