5: CLASS_TYPE_P (in RECORD_TYPE and UNION_TYPE)
ENUM_FIXED_UNDERLYING_TYPE_P (in ENUMERAL_TYPE)
AUTO_IS_DECLTYPE (in TEMPLATE_TYPE_PARM)
+ REFERENCE_VLA_OK (in REFERENCE_TYPE)
6: TYPE_DEPENDENT_P_VALID
Usage of DECL_LANG_FLAG_?:
DECL_MEMBER_TEMPLATE_P (in TEMPLATE_DECL)
FUNCTION_PARAMETER_PACK_P (in PARM_DECL)
USING_DECL_TYPENAME_P (in USING_DECL)
+ DECL_VLA_CAPTURE_P (in FIELD_DECL)
2: DECL_THIS_EXTERN (in VAR_DECL or FUNCTION_DECL).
DECL_IMPLICIT_TYPEDEF_P (in a TYPE_DECL)
3: DECL_IN_AGGR_P.
&& (TREE_CODE (TREE_TYPE (TREE_OPERAND ((NODE), 0))) \
== REFERENCE_TYPE))
+/* True if NODE is a REFERENCE_TYPE which is OK to instantiate to be a
+ reference to VLA type, because it's used for VLA capture. */
+#define REFERENCE_VLA_OK(NODE) \
+ (TYPE_LANG_FLAG_5 (REFERENCE_TYPE_CHECK (NODE)))
+
#define NEW_EXPR_USE_GLOBAL(NODE) \
TREE_LANG_FLAG_0 (NEW_EXPR_CHECK (NODE))
#define DELETE_EXPR_USE_GLOBAL(NODE) \
#define DECL_THIS_STATIC(NODE) \
DECL_LANG_FLAG_6 (VAR_FUNCTION_OR_PARM_DECL_CHECK (NODE))
+/* Nonzero for FIELD_DECL node means that this field is a lambda capture
+ field for an array of runtime bound. */
+#define DECL_VLA_CAPTURE_P(NODE) \
+ DECL_LANG_FLAG_1 (FIELD_DECL_CHECK (NODE))
+
/* Nonzero for FIELD_DECL node means that this field is a base class
of the parent object, as opposed to a member field. */
#define DECL_FIELD_IS_BASE(NODE) \
if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE)
val = build_array_copy (val);
else if (DECL_NORMAL_CAPTURE_P (field)
+ && !DECL_VLA_CAPTURE_P (field)
&& TREE_CODE (TREE_TYPE (field)) != REFERENCE_TYPE)
{
/* "the entities that are captured by copy are used to
type = lambda_proxy_type (object);
- if (TREE_CODE (type) == RECORD_TYPE
- && TYPE_NAME (type) == NULL_TREE)
+ if (DECL_VLA_CAPTURE_P (member))
{
/* Rebuild the VLA type from the pointer and maxindex. */
tree field = next_initializable_field (TYPE_FIELDS (type));
tree max = build_simple_component_ref (object, field);
type = build_array_type (TREE_TYPE (TREE_TYPE (ptr)),
build_index_type (max));
- object = convert (build_reference_type (type), ptr);
- object = convert_from_reference (object);
+ type = build_reference_type (type);
+ REFERENCE_VLA_OK (type) = true;
+ object = convert (type, ptr);
}
var = build_decl (input_location, VAR_DECL, name, type);
vla_capture_type (tree array_type)
{
static tree ptr_id, max_id;
+ tree type = xref_tag (record_type, make_anon_name (), ts_current, false);
+ xref_basetypes (type, NULL_TREE);
+ type = begin_class_definition (type);
if (!ptr_id)
{
ptr_id = get_identifier ("ptr");
max_id = get_identifier ("max");
}
tree ptrtype = build_pointer_type (TREE_TYPE (array_type));
- tree field1 = build_decl (input_location, FIELD_DECL, ptr_id, ptrtype);
- tree field2 = build_decl (input_location, FIELD_DECL, max_id, sizetype);
- DECL_CHAIN (field2) = field1;
- tree type = make_node (RECORD_TYPE);
- finish_builtin_struct (type, "__cap", field2, NULL_TREE);
- TYPE_NAME (type) = NULL_TREE;
- return type;
+ tree field = build_decl (input_location, FIELD_DECL, ptr_id, ptrtype);
+ finish_member_declaration (field);
+ field = build_decl (input_location, FIELD_DECL, max_id, sizetype);
+ finish_member_declaration (field);
+ return finish_struct (type, NULL_TREE);
}
/* From an ID and INITIALIZER, create a capture (by reference if
{
char *buf;
tree type, member, name;
+ bool vla = false;
if (TREE_CODE (initializer) == TREE_LIST)
initializer = build_x_compound_expr_from_list (initializer, ELK_INIT,
type = lambda_capture_field_type (initializer, explicit_init_p);
if (array_of_runtime_bound_p (type))
{
+ vla = true;
if (!by_reference_p)
error ("array of runtime bound cannot be captured by copy, "
"only by reference");
maximum index, and then reconstruct the VLA for the proxy. */
tree elt = cp_build_array_ref (input_location, initializer,
integer_zero_node, tf_warning_or_error);
- tree ctype = vla_capture_type (type);
- tree ptr_field = next_initializable_field (TYPE_FIELDS (ctype));
- tree nelts_field = next_initializable_field (DECL_CHAIN (ptr_field));
- initializer = build_constructor_va (ctype, 2,
- ptr_field, build_address (elt),
- nelts_field, array_type_nelts (type));
- type = ctype;
+ initializer = build_constructor_va (init_list_type_node, 2,
+ NULL_TREE, build_address (elt),
+ NULL_TREE, array_type_nelts (type));
+ type = vla_capture_type (type);
}
else if (variably_modified_type_p (type, NULL_TREE))
{
/* Make member variable. */
member = build_lang_decl (FIELD_DECL, name, type);
+ DECL_VLA_CAPTURE_P (member) = vla;
if (!explicit_init_p)
/* Normal captures are invisible to name lookup but uses are replaced