[clang] 6e6c506 - [Concepts] Traverse the instantiation chain for parameter injection inside a constraint scope (#79568)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 26 23:42:56 PST 2024
Author: Younan Zhang
Date: 2024-01-27T15:42:52+08:00
New Revision: 6e6c506f3caeafc25925b811b9cd205e2e213dd6
URL: https://github.com/llvm/llvm-project/commit/6e6c506f3caeafc25925b811b9cd205e2e213dd6
DIFF: https://github.com/llvm/llvm-project/commit/6e6c506f3caeafc25925b811b9cd205e2e213dd6.diff
LOG: [Concepts] Traverse the instantiation chain for parameter injection inside a constraint scope (#79568)
We preserve the trailing requires-expression during the lambda
expression transformation. In order to get those referenced parameters
inside a requires-expression properly resolved to the instantiated
decls, we intended to inject these 'original' `ParmVarDecls` to the
current instantiaion scope, at `Sema::SetupConstraintScope`.
The previous approach seems to overlook nested instantiation chains,
leading to the crash within a nested lambda followed by a requires
clause.
This fixes https://github.com/llvm/llvm-project/issues/73418.
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaConcept.cpp
clang/test/SemaTemplate/concepts-lambda.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5330cd9caad801..ff755ff281ffb2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -119,6 +119,9 @@ Bug Fixes to C++ Support
parameter where we did an incorrect specialization of the initialization of
the default parameter.
Fixes (`#68490 <https://github.com/llvm/llvm-project/issues/68490>`_)
+- Fixed a bug where variables referenced by requires-clauses inside
+ nested generic lambdas were not properly injected into the constraint scope.
+ (`#73418 <https://github.com/llvm/llvm-project/issues/73418>`_)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index acfc00f4125407..88fc846c89e42c 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -612,8 +612,12 @@ bool Sema::SetupConstraintScope(
// If this is a member function, make sure we get the parameters that
// reference the original primary template.
- if (const auto *FromMemTempl =
- PrimaryTemplate->getInstantiatedFromMemberTemplate()) {
+ // We walk up the instantiated template chain so that nested lambdas get
+ // handled properly.
+ for (FunctionTemplateDecl *FromMemTempl =
+ PrimaryTemplate->getInstantiatedFromMemberTemplate();
+ FromMemTempl;
+ FromMemTempl = FromMemTempl->getInstantiatedFromMemberTemplate()) {
if (addInstantiatedParametersToScope(FD, FromMemTempl->getTemplatedDecl(),
Scope, MLTAL))
return true;
diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp b/clang/test/SemaTemplate/concepts-lambda.cpp
index 7e431529427dff..0b7580f91043c7 100644
--- a/clang/test/SemaTemplate/concepts-lambda.cpp
+++ b/clang/test/SemaTemplate/concepts-lambda.cpp
@@ -149,3 +149,21 @@ void foo() {
auto caller = make_caller.operator()<&S1::f1>();
}
} // namespace ReturnTypeRequirementInLambda
+
+namespace GH73418 {
+void foo() {
+ int x;
+ [&x](auto) {
+ return [](auto y) {
+ return [](auto obj, auto... params)
+ requires requires {
+ sizeof...(params);
+ [](auto... pack) {
+ return sizeof...(pack);
+ }(params...);
+ }
+ { return false; }(y);
+ }(x);
+ }(x);
+}
+} // namespace GH73418
More information about the cfe-commits
mailing list