[clang] [Clang] fix generic lambda inside requires-clause of friend function template (PR #99813)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 21 09:33:14 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Zhikai Zeng (Backl1ght)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/99813.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+2)
- (modified) clang/lib/Sema/SemaTemplate.cpp (+1-4)
- (modified) clang/test/SemaTemplate/concepts-friends.cpp (+16)
``````````diff
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;
+ }
+};
+
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/99813
More information about the cfe-commits
mailing list