[clang] [Clang] Correctly recognize unexpanded packs in lambda template params (PR #98496)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 11 08:21:47 PDT 2024


https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/98496

Fixes #48937

>From 27c49b8c204202bf8928e1b2c6fe4c33c012c049 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Thu, 11 Jul 2024 17:12:35 +0200
Subject: [PATCH] [Clang] Correctly recognize unexpanded packs in lambda
 template params

Fixes #48937
---
 clang/docs/ReleaseNotes.rst                  |  4 +++-
 clang/lib/Sema/SemaLambda.cpp                |  1 +
 clang/test/SemaCXX/lambda-pack-expansion.cpp | 21 ++++++++++++++++++++
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6adf57da42e65..c6a2237113ace 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -103,7 +103,7 @@ ABI Changes in This Version
   ifuncs. Its purpose was to preserve backwards compatibility when the ".ifunc"
   suffix got removed from the name mangling. The alias interacts badly with
   GlobalOpt (see the issue #96197).
-  
+
 - Fixed Microsoft name mangling for auto non-type template arguments of pointer
   type for MSVC 1920+. This change resolves incompatibilities with code compiled
   by MSVC 1920+ but will introduce incompatibilities with code compiled by
@@ -1024,6 +1024,8 @@ Bug Fixes to C++ Support
 - Fixed a bug where references to lambda capture inside a ``noexcept`` specifier were not correctly
   instantiated. (#GH95735).
 - Fixed a CTAD substitution bug involving type aliases that reference outer template parameters. (#GH94614).
+- Clang now correctly handles unexpanded packs in the template parameter list of a generic lambda expression
+  (#GH48937)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 4b19296e8a23a..7b93e5df25b36 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1380,6 +1380,7 @@ void Sema::ActOnLambdaClosureParameters(
     AddTemplateParametersToLambdaCallOperator(LSI->CallOperator, LSI->Lambda,
                                               TemplateParams);
     LSI->Lambda->setLambdaIsGeneric(true);
+    LSI->ContainsUnexpandedParameterPack |= TemplateParams->containsUnexpandedParameterPack();
   }
   LSI->AfterParameterList = true;
 }
diff --git a/clang/test/SemaCXX/lambda-pack-expansion.cpp b/clang/test/SemaCXX/lambda-pack-expansion.cpp
index e3e968e2704ed..221d1d01a06ae 100644
--- a/clang/test/SemaCXX/lambda-pack-expansion.cpp
+++ b/clang/test/SemaCXX/lambda-pack-expansion.cpp
@@ -20,3 +20,24 @@ void foo() {
   take_by_ref(x);
 }
 }
+
+namespace GH48937 {
+
+template <typename... Ts>
+consteval int f(Ts... ts) {
+  return ([]<Ts a = 42>(){ return a;}, ...)();
+}
+
+static_assert(f(0, 42) == 42);
+
+template <typename Ts>
+int g(Ts ts) {
+  return ([]<Ts a = 42>(){ return a;}, ...)();  // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
+}
+
+template <typename... Ts>
+int h(Ts... ts) {
+  return ([]<Ts a = 42>(){ return a;})();  // expected-error {{expression contains unexpanded parameter pack 'Ts'}}
+}
+
+}



More information about the cfe-commits mailing list