https://github.com/Backl1ght created https://github.com/llvm/llvm-project/pull/99813
fixes https://github.com/llvm/llvm-project/issues/98258 The cause is that the assertion "Nothing should reference a value below the actual template depth" is incorrect since we can have a generic lambda inside requires-clause of friend function template, and the generic lambda can reference to values with greater template depth. >From 4087cdd60a86a239dfea62344bb30e954d5cc662 Mon Sep 17 00:00:00 2001 From: Backl1ght <backlight....@gmail.com> Date: Sun, 21 Jul 2024 23:43:24 +0800 Subject: [PATCH] fix --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaTemplate.cpp | 5 +---- clang/test/SemaTemplate/concepts-friends.cpp | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4638b91b48f95..50da6d4556133 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1083,6 +1083,8 @@ Bug Fixes to C++ Support - Clang now diagnoses explicit object parameters in member pointers and other contexts where they should not appear. Fixes (#GH85992). - Fixed a crash-on-invalid bug involving extraneous template parameter with concept substitution. (#GH73885) +- 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 9d96201625389..c2dd5b04f1f70 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -1691,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 91b797034ed6c..9a77aad24f1cd 100644 --- a/clang/test/SemaTemplate/concepts-friends.cpp +++ b/clang/test/SemaTemplate/concepts-friends.cpp @@ -504,3 +504,19 @@ template struct Z<int>; Y y(1); } + +namespace GH98258 { + +struct S { + template <typename U> + friend void f() requires requires { []<typename V>(V){}; } { + return; + } + + template <typename U> + friend void f2() requires requires { [](auto){}; } { + return; + } +}; + +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits