Skip to content

Commit

Permalink
[Clang] fix generic lambda inside requires-clause of friend function …
Browse files Browse the repository at this point in the history
…template (llvm#99813)

fixes llvm#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]>
  • Loading branch information
2 people authored and dmpolukhin committed Sep 2, 2024
1 parent 76ea67b commit b42f43f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
10 changes: 2 additions & 8 deletions clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions clang/test/SemaTemplate/concepts-friends.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,3 +504,24 @@ 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;
}

template <typename U>
friend void f3() requires requires { []<int X>(){ return X; }; } {
return;
}
};

}

0 comments on commit b42f43f

Please sign in to comment.