[clang] [Clang] Support initializing array-typed structured bindings with direct-list-initialization (PR #102581)

via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 27 00:44:35 PDT 2024


================
@@ -198,4 +198,33 @@ namespace lambdas {
   }
 }
 
-// FIXME: by-value array copies
+namespace by_value_array_copy {
+  struct explicit_copy {
+    explicit_copy() = default; // expected-note 2{{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
+    explicit explicit_copy(const explicit_copy&) = default; // expected-note 2{{explicit constructor is not a candidate}}
+  };
+
+  constexpr int direct_initialization_for_elements() {
+    int arr[3]{1, 2, 3};
+    auto [a1, b1, c1](arr);
+    explicit_copy ec_arr[2];
+    auto [a2, b2](ec_arr);
+    arr[0]--;
+    return a1 + b1 + c1 + arr[0];
+  }
+  static_assert(direct_initialization_for_elements() == 6);
+
+  void copy_initialization_for_elements() {
----------------
cor3ntin wrote:

Can you add a test to check that the elements are correctly set to their value? (like you do above)

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


More information about the cfe-commits mailing list