@@ -9384,6 +9384,7 @@ cp_finish_decomp (tree decl, cp_decomp *
tree eltype = NULL_TREE;
unsigned HOST_WIDE_INT eltscnt = 0;
+ bool tuple_p = false;
if (TREE_CODE (type) == ARRAY_TYPE)
{
tree nelts;
@@ -9535,6 +9536,7 @@ cp_finish_decomp (tree decl, cp_decomp *
of the individual variables. If those will be read, we'll mark
the underlying decl as read at that point. */
DECL_READ_P (decl) = save_read;
+ tuple_p = true;
}
else if (TREE_CODE (type) == UNION_TYPE)
{
@@ -9607,14 +9609,25 @@ cp_finish_decomp (tree decl, cp_decomp *
}
if (processing_template_decl)
{
+ /* For non-dependent structured bindings using std::tuple_size
+ and std::tuple_element, remember that in third operand of
+ the DECL_VALUE_EXPR ARRAY_REF for finish_decltype_type purposes. */
for (unsigned int i = 0; i < count; i++)
if (!DECL_HAS_VALUE_EXPR_P (v[i]))
{
tree a = build_nt (ARRAY_REF, decl, size_int (i),
- NULL_TREE, NULL_TREE);
+ tuple_p ? size_zero_node : NULL_TREE,
+ NULL_TREE);
SET_DECL_VALUE_EXPR (v[i], a);
DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
}
+ else
+ {
+ tree vexpr = DECL_VALUE_EXPR (v[i]);
+ gcc_checking_assert (TREE_CODE (vexpr) == ARRAY_REF
+ && TREE_OPERAND (vexpr, 0) == decl);
+ TREE_OPERAND (vexpr, 2) = tuple_p ? size_zero_node : NULL_TREE;
+ }
}
}
@@ -11804,7 +11804,22 @@ finish_decltype_type (tree expr, bool id
access expression). */
if (DECL_DECOMPOSITION_P (expr))
{
- if (DECL_HAS_VALUE_EXPR_P (expr))
+ bool non_tuple_p = DECL_HAS_VALUE_EXPR_P (expr);
+ if (non_tuple_p && ptds.saved)
+ {
+ /* cp_finish_decl sets DECL_VALUE_EXPR on all
+ DECL_DECOMPOSITION_P decls, not just ones for
+ array, struct, vector, complex etc. subobject proxies.
+ The ARRAY_REFs for the tuple cases are marked with
+ non-NULL third argument. */
+ tree vexpr = DECL_VALUE_EXPR (expr);
+ if (TREE_CODE (vexpr) == ARRAY_REF
+ && DECL_P (TREE_OPERAND (vexpr, 0))
+ && DECL_DECOMPOSITION_P (TREE_OPERAND (vexpr, 0))
+ && TREE_OPERAND (vexpr, 2) == size_zero_node)
+ non_tuple_p = false;
+ }
+ if (non_tuple_p)
/* Expr is an array or struct subobject proxy, handle
bit-fields properly. */
return unlowered_expr_type (expr);
@@ -0,0 +1,63 @@
+// PR c++/92687
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+namespace std {
+ template<typename T> struct tuple_size;
+ template<int, typename> struct tuple_element;
+}
+
+struct A {
+ int i;
+ template <int I> int& get() { return i; }
+};
+
+template<> struct std::tuple_size<A> { static const int value = 2; };
+template<int I> struct std::tuple_element<I,A> { using type = int; };
+
+template<typename T>
+struct is_reference {
+ static const bool value = false;
+};
+
+template<typename T>
+struct is_reference<T&>
+{
+ static const bool value = true;
+};
+
+template<typename T>
+struct is_reference<T&&>
+{
+ static const bool value = true;
+};
+
+template<int N>
+void
+foo ()
+{
+ auto [x, y] = A {}; // { dg-warning "structured bindings only available with" "" { target c++14_down } }
+ static_assert (!is_reference<decltype (x)>::value, "");
+}
+
+void
+bar ()
+{
+ auto [x, y] = A {}; // { dg-warning "structured bindings only available with" "" { target c++14_down } }
+ static_assert (!is_reference<decltype (x)>::value, "");
+}
+
+template<typename T>
+void
+baz ()
+{
+ auto [x, y] = T {}; // { dg-warning "structured bindings only available with" "" { target c++14_down } }
+ static_assert (!is_reference<decltype (x)>::value, "");
+}
+
+void
+qux ()
+{
+ foo<0> ();
+ baz<A> ();
+}