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

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


Author: cor3ntin
Date: 2024-07-11T17:58:15+02:00
New Revision: 0431c61f6b80b4ba34e36e7763c58edafcbbf1a9

URL: https://github.com/llvm/llvm-project/commit/0431c61f6b80b4ba34e36e7763c58edafcbbf1a9
DIFF: https://github.com/llvm/llvm-project/commit/0431c61f6b80b4ba34e36e7763c58edafcbbf1a9.diff

LOG: [Clang] Correctly recognize unexpanded packs in lambda template params (#98496)

Fixes #48937
Fixes #49099

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaLambda.cpp
    clang/test/SemaCXX/lambda-pack-expansion.cpp

Removed: 
    


################################################################################
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..601077e9f3334 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1380,6 +1380,8 @@ 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