tf_warning_or_error);
if (sz < 0)
return;
- if (sz == 0)
- {
- error_at (loc, "empty structured binding");
- return;
- }
n = sz;
tree auto_node = make_auto ();
tree decomp_type = cp_build_reference_type (auto_node, true);
= DECL_DECLARED_CONSTEXPR_P (range_decl);
if (DECL_DECLARED_CONSTEXPR_P (decl))
TREE_READONLY (decl) = 1;
- fit_decomposition_lang_decl (decl, NULL_TREE);
+ if (n)
+ fit_decomposition_lang_decl (decl, NULL_TREE);
pushdecl (decl);
cp_decomp this_decomp;
this_decomp.count = n;
DECL_NAME (decl) = for_range__identifier;
cp_finish_decl (decl, expansion_init,
/*is_constant_init*/false, NULL_TREE,
- LOOKUP_ONLYCONVERTING, &this_decomp);
+ LOOKUP_ONLYCONVERTING, n ? &this_decomp : NULL);
DECL_NAME (decl) = NULL_TREE;
}
int e = 42;
d[0] = 42;
template for (auto a : A {}) // { dg-warning "'template for' only available with" "" { target c++23_down } }
- ; // { dg-error "empty structured binding" "" { target *-*-* } .-1 }
+ ;
template for (int b : B {}) // { dg-warning "'template for' only available with" "" { target c++23_down } }
;
template for (int i : c) // { dg-warning "'template for' only available with" "" { target c++23_down } }
- ; // { dg-error "empty structured binding" "" { target *-*-* } .-1 }
+ ;
template for (int i : d) // { dg-warning "'template for' only available with" "" { target c++23_down } }
; // { dg-error "cannot decompose variable length array" "" { target *-*-* } .-1 }
template for (auto a : C {}) // { dg-warning "'template for' only available with" "" { target c++23_down } }
--- /dev/null
+// DR3048 - Empty destructuring expansion statements
+// { dg-do run { target c++11 } }
+// { dg-options "" }
+
+struct A {};
+
+int
+foo ()
+{
+ int c[0] = {};
+ int r = 0;
+ template for (auto a : A {}) // { dg-warning "'template for' only available with" "" { target c++23_down } }
+ ++r;
+ template for (int i : c) // { dg-warning "'template for' only available with" "" { target c++23_down } }
+ ++r;
+ return r;
+}
+
+int
+main ()
+{
+ if (foo () != 0)
+ __builtin_abort ();
+}
--- /dev/null
+// DR3048 - Empty destructuring expansion statements
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+struct A {};
+
+void
+foo ()
+{
+ static constexpr A b {};
+ template for (constexpr auto a : b) // { dg-warning "'template for' only available with" "" { target c++23_down } }
+ ;
+ A c {};
+ template for (constexpr auto a : c) // { dg-warning "'template for' only available with" "" { target c++23_down } }
+ ; // { dg-error "'c' is not a constant expression" "" { target *-*-* } .-1 }
+}