[clang] [Sema] Preserve ContainsUnexpandedParameterPack in TransformLambdaExpr (PR #86265)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 18 04:25:37 PDT 2024


================
@@ -23,3 +23,104 @@ namespace PR41576 {
   }
   static_assert(f(3, 4) == 6); // expected-note {{instantiation}}
 }
+
+namespace PR85667 {
+
+template <class T>
+struct identity {
+  using type = T;
+};
+
+template <class = void> void f() {
+
+  static_assert([]<class... Is>(Is... x) {
+    return ([I(x)] {
+      return I;
+    }() + ...);
+  }(1, 2) == 3);
+
+  static_assert([]<class... Is>(Is... x) {
+    return ([](auto y = Is()) { return y + 1; } + ...);
+  }(0, 0, 0) == 3);
+
+  []<class... Is>() {
+    return ([]() noexcept(Is()) { return 0; }() + ...);
+  }.template operator()<int, int>();
+
+  static_assert(__is_same(decltype([]<class... Is>() {
+                            return ([]() -> decltype(Is()) { return {}; }(),
+                                    ...);
+                          }.template operator()<int, char>()),
+                          char));
+
+  []<class... Is>() {
+    return ([]<class... Ts>() -> decltype(Is()) { return Ts(); }() + ...);
+    // expected-error at -1 {{unexpanded parameter pack 'Ts'}}
+  }.template operator()<int, int>();
+
+  // Note that GCC and EDG reject this case currently.
+  // GCC says the fold expression "has no unexpanded parameter packs", while
+  // EDG says the constraint is not allowed on a non-template function.
+  // MSVC is happy with it.
+  []<class... Is>() {
+    ([]()
+       requires(Is())
+     {},
+     ...);
+  }.template operator()<bool, bool>();
+
+  // https://github.com/llvm/llvm-project/issues/56852
+  []<class... Is>(Is...) {
+    ([] {
+      using T = identity<Is>::type;
+    }(), ...);
+  }(1, 2);
+
+  [](auto ...y) {
+    ([y] { }(), ...);
+  }();
+
+  [](auto ...x) {
+    ([&](auto ...y) {
+      ([x..., y] { }(), ...);
+    })(1);
+  }(2, 'b');
+
+#if 0
+  // https://github.com/llvm/llvm-project/issues/18873
+  [](auto ...x) { // #1
+    ([&](auto ...y) {  // #2
+      ([x, y] { }(), ...); // #3
+    })(1, 'a');  // #4
+  }(2, 'b');  // #5
+
----------------
zyn0217 wrote:

I'm unsure if it's feasible to sneak in these tests, though they still crash for a different reason after this patch. @cor3ntin lmk what you think.

https://github.com/llvm/llvm-project/pull/86265


More information about the cfe-commits mailing list