maybe_push_decl (t);
/* Save the decltype away before reference collapse. */
hash_map_safe_put<hm_ggc> (decomp_type_table, t, eltype);
- eltype = cp_build_reference_type (eltype, !lvalue_p (init));
+ if (glvalue_p (init))
+ eltype = cp_build_reference_type (eltype, !lvalue_p (init));
TREE_TYPE (t) = eltype;
layout_decl (t, 0);
DECL_HAS_VALUE_EXPR_P (t) = 0;
}
/* Save the decltype away before reference collapse. */
hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);
- eltype = cp_build_reference_type (eltype, !lvalue_p (init));
+ if (glvalue_p (init))
+ eltype = cp_build_reference_type (eltype, !lvalue_p (init));
TREE_TYPE (v[i]) = eltype;
layout_decl (v[i], 0);
if (DECL_HAS_VALUE_EXPR_P (v[i]))
--- /dev/null
+// CWG3135 - constexpr structured bindings with prvalues from tuples
+// { dg-do compile { target c++14 } }
+// { dg-options "" }
+
+namespace std {
+ template <typename T> struct tuple_size;
+ template <int, typename> struct tuple_element;
+}
+
+struct A {
+ template <int I> constexpr int get () const { return I + 6; }
+};
+
+template <> struct std::tuple_size <A> { static const int value = 2; };
+template <int I> struct std::tuple_element <I, A> { using type = int; };
+template <> struct std::tuple_size <const A> { static const int value = 2; };
+template <int I> struct std::tuple_element <I, const A> { using type = const int; };
+
+constexpr A
+bar ()
+{
+ return A {};
+}
+
+template <int N>
+constexpr int
+foo ()
+{
+ constexpr auto [...i] = bar (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } }
+ // { dg-warning "structured binding declaration can be 'constexpr' only with" "" { target c++23_down } .-1 }
+ // { dg-warning "structured bindings only available with" "" { target c++14_down } .-2 }
+ return i...[0] + i...[1]; // { dg-warning "pack indexing only available with" "" { target c++23_down } }
+}
+
+static_assert (foo <42> () == 13);
foo (B a)
{
#pragma omp for collapse(2)
- for (auto [i, j, k] : a)
- for (int l = i; l < j; l += k) // { dg-error "initializer expression refers to iteration variable 'i'" }
- ; // { dg-error "condition expression refers to iteration variable 'j'" "" { target *-*-* } .-1 }
-} // { dg-error "increment expression refers to iteration variable 'k'" "" { target *-*-* } .-2 }
+ for (auto [i, j, k] : a) // { dg-error "initializer expression refers to iteration variable 'i'" }
+ for (int l = i; l < j; l += k) // { dg-error "condition expression refers to iteration variable 'j'" }
+ ; // { dg-error "increment expression refers to iteration variable 'k'" "" { target *-*-* } .-2 }
+}