[clang] [Clang] fix generic lambda inside requires-clause of friend function template (PR #99813)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 21 02:02:06 PDT 2024
https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/99813
>From 5d7f291e35930e07f52a7ac17a09f93690b64def Mon Sep 17 00:00:00 2001
From: Backl1ght <backlight.zzk at gmail.com>
Date: Sun, 21 Jul 2024 23:43:24 +0800
Subject: [PATCH 1/2] 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 4f1a916aad9d2b..b4ed5730f5af37 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -158,6 +158,8 @@ Bug Fixes to C++ Support
- Fixed a crash when an expression with a dependent ``__typeof__`` type is used as the operand of a unary operator. (#GH97646)
- Fixed a failed assertion when checking invalid delete operator declaration. (#GH96191)
+- 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 87b1f98bbe5ac9..e8b8bbe6d90547 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 91b797034ed6cf..9a77aad24f1cdb 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;
+ }
+};
+
+}
>From 558168eed0f3176376108534a2e949a8ad96505d Mon Sep 17 00:00:00 2001
From: Backl1ght <backlight.zzk at gmail.com>
Date: Sat, 27 Jul 2024 13:21:22 +0800
Subject: [PATCH 2/2] fix nttp
---
clang/lib/Sema/SemaTemplate.cpp | 5 +----
clang/test/SemaTemplate/concepts-friends.cpp | 5 +++++
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index e8b8bbe6d90547..cf183fb9b80867 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1664,10 +1664,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
diff --git a/clang/test/SemaTemplate/concepts-friends.cpp b/clang/test/SemaTemplate/concepts-friends.cpp
index 9a77aad24f1cdb..14b37d78d951dc 100644
--- a/clang/test/SemaTemplate/concepts-friends.cpp
+++ b/clang/test/SemaTemplate/concepts-friends.cpp
@@ -517,6 +517,11 @@ struct S {
friend void f2() requires requires { [](auto){}; } {
return;
}
+
+ template <typename U>
+ friend void f3() requires requires { []<int X>(){ return X; }; } {
+ return;
+ }
};
}
More information about the cfe-commits
mailing list