Skip to content

Commit 40eca60

Browse files
Backl1ghtcor3ntin
andauthored
[Clang] fix generic lambda inside requires-clause of friend function template (#99813)
fixes #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. --------- Co-authored-by: cor3ntin <[email protected]>
1 parent 2704b80 commit 40eca60

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ Bug Fixes to C++ Support
290290
- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990).
291291
- Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025).
292292
- Correctly check constraints of explicit instantiations of member functions. (#GH46029)
293+
- Fixed an assertion failure about a constraint of a friend function template references to a value with greater
294+
template depth than the friend function template. (#GH98258)
293295

294296
Bug Fixes to AST Handling
295297
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,10 +1667,7 @@ class ConstraintRefersToContainingTemplateChecker
16671667
}
16681668

16691669
void CheckNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
1670-
assert(D->getDepth() <= TemplateDepth &&
1671-
"Nothing should reference a value below the actual template depth, "
1672-
"depth is likely wrong");
1673-
if (D->getDepth() != TemplateDepth)
1670+
if (D->getDepth() < TemplateDepth)
16741671
Result = true;
16751672

16761673
// Necessary because the type of the NTTP might be what refers to the parent
@@ -1694,10 +1691,7 @@ class ConstraintRefersToContainingTemplateChecker
16941691
using inherited::TransformTemplateTypeParmType;
16951692
QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
16961693
TemplateTypeParmTypeLoc TL, bool) {
1697-
assert(TL.getDecl()->getDepth() <= TemplateDepth &&
1698-
"Nothing should reference a value below the actual template depth, "
1699-
"depth is likely wrong");
1700-
if (TL.getDecl()->getDepth() != TemplateDepth)
1694+
if (TL.getDecl()->getDepth() < TemplateDepth)
17011695
Result = true;
17021696
return inherited::TransformTemplateTypeParmType(
17031697
TLB, TL,

clang/test/SemaTemplate/concepts-friends.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,3 +504,24 @@ template struct Z<int>;
504504
Y y(1);
505505

506506
}
507+
508+
namespace GH98258 {
509+
510+
struct S {
511+
template <typename U>
512+
friend void f() requires requires { []<typename V>(V){}; } {
513+
return;
514+
}
515+
516+
template <typename U>
517+
friend void f2() requires requires { [](auto){}; } {
518+
return;
519+
}
520+
521+
template <typename U>
522+
friend void f3() requires requires { []<int X>(){ return X; }; } {
523+
return;
524+
}
525+
};
526+
527+
}

0 commit comments

Comments
 (0)