/* Handle initialization things in C++.
- Copyright (C) 1987-2016 Free Software Foundation, Inc.
+ Copyright (C) 1987-2017 Free Software Foundation, Inc.
Contributed by Michael Tiemann (tiemann@cygnus.com)
This file is part of GCC.
#include "varasm.h"
#include "gimplify.h"
#include "c-family/c-ubsan.h"
+#include "intl.h"
static bool begin_init_stmts (tree *, tree *);
static tree finish_init_stmts (bool, tree, tree);
}
/* Strip redundant TARGET_EXPR so we don't need to remap it, and
so the aggregate init code below will see a CONSTRUCTOR. */
- if (init && SIMPLE_TARGET_EXPR_P (init))
+ bool simple_target = (init && SIMPLE_TARGET_EXPR_P (init));
+ if (simple_target)
init = TARGET_EXPR_INITIAL (init);
init = break_out_target_exprs (init);
+ if (simple_target && TREE_CODE (init) != CONSTRUCTOR)
+ /* Now put it back so C++17 copy elision works. */
+ init = get_target_expr (init);
}
current_class_ptr = save_ccp;
current_class_ref = save_ccr;
return init;
}
+/* Diagnose the flexible array MEMBER if its INITializer is non-null
+ and return true if so. Otherwise return false. */
+
+bool
+maybe_reject_flexarray_init (tree member, tree init)
+{
+ tree type = TREE_TYPE (member);
+
+ if (!init
+ || TREE_CODE (type) != ARRAY_TYPE
+ || TYPE_DOMAIN (type))
+ return false;
+
+ /* Point at the flexible array member declaration if it's initialized
+ in-class, and at the ctor if it's initialized in a ctor member
+ initializer list. */
+ location_t loc;
+ if (DECL_INITIAL (member) == init
+ || !current_function_decl
+ || DECL_DEFAULTED_FN (current_function_decl))
+ loc = DECL_SOURCE_LOCATION (member);
+ else
+ loc = DECL_SOURCE_LOCATION (current_function_decl);
+
+ error_at (loc, "initializer for flexible array member %q#D", member);
+ return true;
+}
+
/* Initialize MEMBER, a FIELD_DECL, with INIT, a TREE_LIST of
arguments. If TREE_LIST is void_type_node, an empty initializer
list was given; if NULL_TREE no initializer was given. */
{
if (init)
{
- if (TREE_CHAIN (init))
+ /* Check to make sure the member initializer is valid and
+ something like a CONSTRUCTOR in: T a[] = { 1, 2 } and
+ if it isn't, return early to avoid triggering another
+ error below. */
+ if (maybe_reject_flexarray_init (member, init))
+ return;
+
+ if (TREE_CODE (init) != TREE_LIST || TREE_CHAIN (init))
init = error_mark_node;
else
init = TREE_VALUE (init);
+
if (BRACE_ENCLOSED_INITIALIZER_P (init))
init = digest_init (type, init, tf_warning_or_error);
}
init = build_x_compound_expr_from_list (init, ELK_MEM_INIT,
tf_warning_or_error);
- if (init)
+ /* Reject a member initializer for a flexible array member. */
+ if (init && !maybe_reject_flexarray_init (member, init))
finish_expr_stmt (cp_build_modify_expr (input_location, decl,
INIT_EXPR, init,
tf_warning_or_error));
}
if (DECL_DEFAULTED_FN (current_function_decl)
- && ! DECL_INHERITED_CTOR_BASE (current_function_decl))
+ && ! DECL_INHERITED_CTOR (current_function_decl))
flags |= LOOKUP_DEFAULTED;
/* Sort the mem-initializers into the order in which the
if (arguments == error_mark_node)
continue;
+ /* Suppress access control when calling the inherited ctor. */
+ bool inherited_base = (DECL_INHERITED_CTOR (current_function_decl)
+ && flag_new_inheriting_ctors
+ && arguments);
+ if (inherited_base)
+ push_deferring_access_checks (dk_deferred);
+
if (arguments == NULL_TREE)
{
/* If these initializations are taking place in a copy constructor,
}
/* Initialize the base. */
- if (BINFO_VIRTUAL_P (subobject))
- construct_virtual_base (subobject, arguments);
- else
+ if (!BINFO_VIRTUAL_P (subobject))
{
tree base_addr;
tf_warning_or_error);
expand_cleanup_for_base (subobject, NULL_TREE);
}
+ else if (!ABSTRACT_CLASS_TYPE_P (current_class_type))
+ /* C++14 DR1658 Means we do not have to construct vbases of
+ abstract classes. */
+ construct_virtual_base (subobject, arguments);
+ else
+ /* When not constructing vbases of abstract classes, at least mark
+ the arguments expressions as read to avoid
+ -Wunused-but-set-parameter false positives. */
+ for (tree arg = arguments; arg; arg = TREE_CHAIN (arg))
+ mark_exp_read (TREE_VALUE (arg));
+
+ if (inherited_base)
+ pop_deferring_access_checks ();
}
in_base_initializer = 0;
TREE_READONLY (exp) = 0;
TREE_THIS_VOLATILE (exp) = 0;
- if (init && init != void_type_node
- && TREE_CODE (init) != TREE_LIST
- && !(TREE_CODE (init) == TARGET_EXPR
- && TARGET_EXPR_DIRECT_INIT_P (init))
- && !DIRECT_LIST_INIT_P (init))
- flags |= LOOKUP_ONLYCONVERTING;
-
if (TREE_CODE (type) == ARRAY_TYPE)
{
- tree itype;
+ tree itype = init ? TREE_TYPE (init) : NULL_TREE;
+ int from_array = 0;
- /* An array may not be initialized use the parenthesized
- initialization form -- unless the initializer is "()". */
- if (init && TREE_CODE (init) == TREE_LIST)
+ if (VAR_P (exp) && DECL_DECOMPOSITION_P (exp))
{
- if (complain & tf_error)
- error ("bad array initializer");
- return error_mark_node;
+ from_array = 1;
+ if (init && DECL_P (init)
+ && !(flags & LOOKUP_ONLYCONVERTING))
+ {
+ /* Wrap the initializer in a CONSTRUCTOR so that build_vec_init
+ recognizes it as direct-initialization. */
+ init = build_constructor_single (init_list_type_node,
+ NULL_TREE, init);
+ CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
+ }
+ }
+ else
+ {
+ /* An array may not be initialized use the parenthesized
+ initialization form -- unless the initializer is "()". */
+ if (init && TREE_CODE (init) == TREE_LIST)
+ {
+ if (complain & tf_error)
+ error ("bad array initializer");
+ return error_mark_node;
+ }
+ /* Must arrange to initialize each element of EXP
+ from elements of INIT. */
+ if (cv_qualified_p (type))
+ TREE_TYPE (exp) = cv_unqualified (type);
+ if (itype && cv_qualified_p (itype))
+ TREE_TYPE (init) = cv_unqualified (itype);
+ from_array = (itype && same_type_p (TREE_TYPE (init),
+ TREE_TYPE (exp)));
}
- /* Must arrange to initialize each element of EXP
- from elements of INIT. */
- itype = init ? TREE_TYPE (init) : NULL_TREE;
- if (cv_qualified_p (type))
- TREE_TYPE (exp) = cv_unqualified (type);
- if (itype && cv_qualified_p (itype))
- TREE_TYPE (init) = cv_unqualified (itype);
+
stmt_expr = build_vec_init (exp, NULL_TREE, init,
/*explicit_value_init_p=*/false,
- itype && same_type_p (TREE_TYPE (init),
- TREE_TYPE (exp)),
+ from_array,
complain);
TREE_READONLY (exp) = was_const;
TREE_THIS_VOLATILE (exp) = was_volatile;
return stmt_expr;
}
+ if (init && init != void_type_node
+ && TREE_CODE (init) != TREE_LIST
+ && !(TREE_CODE (init) == TARGET_EXPR
+ && TARGET_EXPR_DIRECT_INIT_P (init))
+ && !DIRECT_LIST_INIT_P (init))
+ flags |= LOOKUP_ONLYCONVERTING;
+
if ((VAR_P (exp) || TREE_CODE (exp) == PARM_DECL)
&& !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (type)))
/* Just know that we've seen something for this node. */
ctor_name = base_ctor_identifier;
rval = build_special_member_call (exp, ctor_name, &parms, binfo, flags,
complain);
- }
+ }
if (parms != NULL)
release_tree_vector (parms);
return;
}
+ /* List-initialization from {} becomes value-initialization for non-aggregate
+ classes with default constructors. Handle this here when we're
+ initializing a base, so protected access works. */
+ if (exp != true_exp && init && TREE_CODE (init) == TREE_LIST)
+ {
+ tree elt = TREE_VALUE (init);
+ if (DIRECT_LIST_INIT_P (elt)
+ && CONSTRUCTOR_ELTS (elt) == 0
+ && CLASSTYPE_NON_AGGREGATE (type)
+ && TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
+ init = void_type_node;
+ }
+
/* If an explicit -- but empty -- initializer list was present,
that's value-initialization. */
if (init == void_type_node)
If the access is to form a pointer to member, the
nested-name-specifier shall name the derived class
(or any class derived from that class). */
+ bool ok;
if (address_p && DECL_P (t)
&& DECL_NONSTATIC_MEMBER_P (t))
- perform_or_defer_access_check (TYPE_BINFO (type), t, t,
- complain);
+ ok = perform_or_defer_access_check (TYPE_BINFO (type), t, t,
+ complain);
else
- perform_or_defer_access_check (basebinfo, t, t,
- complain);
-
+ ok = perform_or_defer_access_check (basebinfo, t, t,
+ complain);
+ if (!ok)
+ return error_mark_node;
if (DECL_STATIC_FUNCTION_P (t))
return t;
member = t;
TREE_TYPE (member) = unknown_type_node;
}
else if (address_p && TREE_CODE (member) == FIELD_DECL)
- /* We need additional test besides the one in
- check_accessibility_of_qualified_id in case it is
- a pointer to non-static member. */
- perform_or_defer_access_check (TYPE_BINFO (type), member, member,
- complain);
+ {
+ /* We need additional test besides the one in
+ check_accessibility_of_qualified_id in case it is
+ a pointer to non-static member. */
+ if (!perform_or_defer_access_check (TYPE_BINFO (type), member, member,
+ complain))
+ return error_mark_node;
+ }
if (!address_p)
{
constant_value_1 (tree decl, bool strict_p, bool return_aggregate_cst_ok_p)
{
while (TREE_CODE (decl) == CONST_DECL
- || (strict_p
- ? decl_constant_var_p (decl)
- : (VAR_P (decl)
- && CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl)))))
+ || decl_constant_var_p (decl)
+ || (!strict_p && VAR_P (decl)
+ && CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl))))
{
tree init;
/* If DECL is a static data member in a template
&& TREE_CODE (init) == TREE_LIST
&& TREE_CHAIN (init) == NULL_TREE)
init = TREE_VALUE (init);
- /* Instantiate a non-dependent initializer. */
- init = instantiate_non_dependent_or_null (init);
+ /* Instantiate a non-dependent initializer for user variables. We
+ mustn't do this for the temporary for an array compound literal;
+ trying to instatiate the initializer will keep creating new
+ temporaries until we crash. Probably it's not useful to do it for
+ other artificial variables, either. */
+ if (!DECL_ARTIFICIAL (decl))
+ init = instantiate_non_dependent_or_null (init);
if (!init
|| !TREE_TYPE (init)
|| !TREE_CONSTANT (init)
to placement new is not checked since it's unknown what it might
point to. */
if (TREE_CODE (oper) == PARM_DECL
- || TREE_CODE (oper) == VAR_DECL
+ || VAR_P (oper)
|| TREE_CODE (oper) == COMPONENT_REF)
return;
{
tree op0 = oper;
while (TREE_CODE (op0 = TREE_OPERAND (op0, 0)) == COMPONENT_REF);
- if (TREE_CODE (op0) == VAR_DECL)
+ if (VAR_P (op0))
var_decl = op0;
oper = TREE_OPERAND (oper, 1);
}
if ((addr_expr || !POINTER_TYPE_P (TREE_TYPE (oper)))
- && (TREE_CODE (oper) == VAR_DECL
+ && (VAR_P (oper)
|| TREE_CODE (oper) == FIELD_DECL
|| TREE_CODE (oper) == PARM_DECL))
{
/* Treat members of unions and members of structs uniformly, even
though the size of a member of a union may be viewed as extending
to the end of the union itself (it is by __builtin_object_size). */
- if ((TREE_CODE (oper) == VAR_DECL || use_obj_size)
+ if ((VAR_P (oper) || use_obj_size)
&& DECL_SIZE_UNIT (oper)
&& tree_fits_uhwi_p (DECL_SIZE_UNIT (oper)))
{
&& warn_placement_new < 2)
return;
}
-
+
/* The size of the buffer can only be adjusted down but not up. */
gcc_checking_assert (0 <= adjust);
else if (nelts && CONSTANT_CLASS_P (nelts))
bytes_need = tree_to_uhwi (nelts)
* tree_to_uhwi (TYPE_SIZE_UNIT (type));
- else
+ else if (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type)))
bytes_need = tree_to_uhwi (TYPE_SIZE_UNIT (type));
+ else
+ {
+ /* The type is a VLA. */
+ return;
+ }
if (bytes_avail < bytes_need)
{
exact_size ?
"placement new constructing an object of type %qT "
"and size %qwu in a region of type %qT and size %qwi"
- : "placement new constructing an object of type %qT"
+ : "placement new constructing an object of type %qT "
"and size %qwu in a region of type %qT and size "
"at most %qwu",
type, bytes_need, TREE_TYPE (oper),
}
}
+/* True if alignof(T) > __STDCPP_DEFAULT_NEW_ALIGNMENT__. */
+
+bool
+type_has_new_extended_alignment (tree t)
+{
+ return (aligned_new_threshold
+ && TYPE_ALIGN_UNIT (t) > (unsigned)aligned_new_threshold);
+}
+
+/* Return the alignment we expect malloc to guarantee. This should just be
+ MALLOC_ABI_ALIGNMENT, but that macro defaults to only BITS_PER_WORD for some
+ reason, so don't let the threshold be smaller than max_align_t_align. */
+
+unsigned
+malloc_alignment ()
+{
+ return MAX (max_align_t_align(), MALLOC_ABI_ALIGNMENT);
+}
+
/* Generate code for a new-expression, including calling the "operator
new" function, initializing the object, and, if an exception occurs
during construction, cleaning up. The arguments are as for
tree alloc_fn;
tree cookie_expr, init_expr;
int nothrow, check_new;
- int use_java_new = 0;
/* If non-NULL, the number of extra bytes to allocate at the
beginning of the storage allocated for an array-new expression in
order to store the number of elements. */
{
if (complain & tf_warning_or_error)
{
- const char *msg;
- if (typedef_variant_p (orig_type))
- msg = ("non-constant array new length must be specified "
- "directly, not by typedef");
- else
- msg = ("non-constant array new length must be specified "
- "without parentheses around the type-id");
- pedwarn (EXPR_LOC_OR_LOC (outer_nelts, input_location),
- OPT_Wvla, msg);
+ pedwarn (EXPR_LOC_OR_LOC (outer_nelts, input_location), OPT_Wvla,
+ typedef_variant_p (orig_type)
+ ? G_("non-constant array new length must be specified "
+ "directly, not by typedef")
+ : G_("non-constant array new length must be specified "
+ "without parentheses around the type-id"));
}
else
return error_mark_node;
}
}
+ tree align_arg = NULL_TREE;
+ if (type_has_new_extended_alignment (elt_type))
+ align_arg = build_int_cst (align_type_node, TYPE_ALIGN_UNIT (elt_type));
+
alloc_fn = NULL_TREE;
/* If PLACEMENT is a single simple pointer type not passed by
bool member_new_p = false;
/* Allocate the object. */
- if (vec_safe_is_empty (*placement) && TYPE_FOR_JAVA (elt_type))
- {
- tree class_addr;
- tree class_decl;
- static const char alloc_name[] = "_Jv_AllocObject";
+ tree fnname;
+ tree fns;
- if (!MAYBE_CLASS_TYPE_P (elt_type))
- {
- error ("%qT isn%'t a valid Java class type", elt_type);
- return error_mark_node;
- }
+ fnname = cp_operator_id (array_p ? VEC_NEW_EXPR : NEW_EXPR);
- class_decl = build_java_class_ref (elt_type);
- if (class_decl == error_mark_node)
- return error_mark_node;
+ member_new_p = !globally_qualified_p
+ && CLASS_TYPE_P (elt_type)
+ && (array_p
+ ? TYPE_HAS_ARRAY_NEW_OPERATOR (elt_type)
+ : TYPE_HAS_NEW_OPERATOR (elt_type));
- use_java_new = 1;
- if (!get_global_value_if_present (get_identifier (alloc_name),
- &alloc_fn))
+ if (member_new_p)
+ {
+ /* Use a class-specific operator new. */
+ /* If a cookie is required, add some extra space. */
+ if (array_p && TYPE_VEC_NEW_USES_COOKIE (elt_type))
+ size = size_binop (PLUS_EXPR, size, cookie_size);
+ else
{
- if (complain & tf_error)
- error ("call to Java constructor with %qs undefined", alloc_name);
- return error_mark_node;
+ cookie_size = NULL_TREE;
+ /* No size arithmetic necessary, so the size check is
+ not needed. */
+ if (outer_nelts_check != NULL && inner_size == 1)
+ outer_nelts_check = NULL_TREE;
}
- else if (really_overloaded_fn (alloc_fn))
+ /* Perform the overflow check. */
+ tree errval = TYPE_MAX_VALUE (sizetype);
+ if (cxx_dialect >= cxx11 && flag_exceptions)
+ errval = throw_bad_array_new_length ();
+ if (outer_nelts_check != NULL_TREE)
+ size = fold_build3 (COND_EXPR, sizetype, outer_nelts_check,
+ size, errval);
+ /* Create the argument list. */
+ vec_safe_insert (*placement, 0, size);
+ /* Do name-lookup to find the appropriate operator. */
+ fns = lookup_fnfields (elt_type, fnname, /*protect=*/2);
+ if (fns == NULL_TREE)
{
- if (complain & tf_error)
- error ("%qD should never be overloaded", alloc_fn);
+ if (complain & tf_error)
+ error ("no suitable %qD found in class %qT", fnname, elt_type);
return error_mark_node;
}
- alloc_fn = OVL_CURRENT (alloc_fn);
- if (TREE_CODE (alloc_fn) != FUNCTION_DECL
- || TREE_CODE (TREE_TYPE (alloc_fn)) != FUNCTION_TYPE
- || !POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (alloc_fn))))
+ if (TREE_CODE (fns) == TREE_LIST)
{
if (complain & tf_error)
- error ("%qD is not a function returning a pointer", alloc_fn);
+ {
+ error ("request for member %qD is ambiguous", fnname);
+ print_candidates (fns);
+ }
return error_mark_node;
}
- class_addr = build1 (ADDR_EXPR, jclass_node, class_decl);
- alloc_call = cp_build_function_call_nary (alloc_fn, complain,
- class_addr, NULL_TREE);
- }
- else if (TYPE_FOR_JAVA (elt_type) && MAYBE_CLASS_TYPE_P (elt_type))
- {
- error ("Java class %q#T object allocated using placement new", elt_type);
- return error_mark_node;
+ tree dummy = build_dummy_object (elt_type);
+ alloc_call = NULL_TREE;
+ if (align_arg)
+ {
+ vec<tree, va_gc> *align_args
+ = vec_copy_and_insert (*placement, align_arg, 1);
+ alloc_call
+ = build_new_method_call (dummy, fns, &align_args,
+ /*conversion_path=*/NULL_TREE,
+ LOOKUP_NORMAL, &alloc_fn, tf_none);
+ /* If no matching function is found and the allocated object type
+ has new-extended alignment, the alignment argument is removed
+ from the argument list, and overload resolution is performed
+ again. */
+ if (alloc_call == error_mark_node)
+ alloc_call = NULL_TREE;
+ }
+ if (!alloc_call)
+ alloc_call = build_new_method_call (dummy, fns, placement,
+ /*conversion_path=*/NULL_TREE,
+ LOOKUP_NORMAL,
+ &alloc_fn, complain);
}
else
{
- tree fnname;
- tree fns;
-
- fnname = ansi_opname (array_p ? VEC_NEW_EXPR : NEW_EXPR);
-
- member_new_p = !globally_qualified_p
- && CLASS_TYPE_P (elt_type)
- && (array_p
- ? TYPE_HAS_ARRAY_NEW_OPERATOR (elt_type)
- : TYPE_HAS_NEW_OPERATOR (elt_type));
-
- if (member_new_p)
+ /* Use a global operator new. */
+ /* See if a cookie might be required. */
+ if (!(array_p && TYPE_VEC_NEW_USES_COOKIE (elt_type)))
{
- /* Use a class-specific operator new. */
- /* If a cookie is required, add some extra space. */
- if (array_p && TYPE_VEC_NEW_USES_COOKIE (elt_type))
- size = size_binop (PLUS_EXPR, size, cookie_size);
- else
- {
- cookie_size = NULL_TREE;
- /* No size arithmetic necessary, so the size check is
- not needed. */
- if (outer_nelts_check != NULL && inner_size == 1)
- outer_nelts_check = NULL_TREE;
- }
- /* Perform the overflow check. */
- tree errval = TYPE_MAX_VALUE (sizetype);
- if (cxx_dialect >= cxx11 && flag_exceptions)
- errval = throw_bad_array_new_length ();
- if (outer_nelts_check != NULL_TREE)
- size = fold_build3 (COND_EXPR, sizetype, outer_nelts_check,
- size, errval);
- /* Create the argument list. */
- vec_safe_insert (*placement, 0, size);
- /* Do name-lookup to find the appropriate operator. */
- fns = lookup_fnfields (elt_type, fnname, /*protect=*/2);
- if (fns == NULL_TREE)
- {
- if (complain & tf_error)
- error ("no suitable %qD found in class %qT", fnname, elt_type);
- return error_mark_node;
- }
- if (TREE_CODE (fns) == TREE_LIST)
- {
- if (complain & tf_error)
- {
- error ("request for member %qD is ambiguous", fnname);
- print_candidates (fns);
- }
- return error_mark_node;
- }
- alloc_call = build_new_method_call (build_dummy_object (elt_type),
- fns, placement,
- /*conversion_path=*/NULL_TREE,
- LOOKUP_NORMAL,
- &alloc_fn,
- complain);
+ cookie_size = NULL_TREE;
+ /* No size arithmetic necessary, so the size check is
+ not needed. */
+ if (outer_nelts_check != NULL && inner_size == 1)
+ outer_nelts_check = NULL_TREE;
}
- else
- {
- /* Use a global operator new. */
- /* See if a cookie might be required. */
- if (!(array_p && TYPE_VEC_NEW_USES_COOKIE (elt_type)))
- {
- cookie_size = NULL_TREE;
- /* No size arithmetic necessary, so the size check is
- not needed. */
- if (outer_nelts_check != NULL && inner_size == 1)
- outer_nelts_check = NULL_TREE;
- }
- alloc_call = build_operator_new_call (fnname, placement,
- &size, &cookie_size,
- outer_nelts_check,
- &alloc_fn, complain);
- }
+ alloc_call = build_operator_new_call (fnname, placement,
+ &size, &cookie_size,
+ align_arg, outer_nelts_check,
+ &alloc_fn, complain);
}
if (alloc_call == error_mark_node)
gcc_assert (alloc_fn != NULL_TREE);
+ /* Now, check to see if this function is actually a placement
+ allocation function. This can happen even when PLACEMENT is NULL
+ because we might have something like:
+
+ struct S { void* operator new (size_t, int i = 0); };
+
+ A call to `new S' will get this allocation function, even though
+ there is no explicit placement argument. If there is more than
+ one argument, or there are variable arguments, then this is a
+ placement allocation function. */
+ placement_allocation_fn_p
+ = (type_num_arguments (TREE_TYPE (alloc_fn)) > 1
+ || varargs_function_p (alloc_fn));
+
+ if (warn_aligned_new
+ && !placement_allocation_fn_p
+ && TYPE_ALIGN (elt_type) > malloc_alignment ()
+ && (warn_aligned_new > 1
+ || CP_DECL_CONTEXT (alloc_fn) == global_namespace)
+ && !aligned_allocation_fn_p (alloc_fn))
+ {
+ warning (OPT_Waligned_new_, "%<new%> of type %qT with extended "
+ "alignment %d", elt_type, TYPE_ALIGN_UNIT (elt_type));
+ inform (input_location, "uses %qD, which does not have an alignment "
+ "parameter", alloc_fn);
+ if (!aligned_new_threshold)
+ inform (input_location, "use %<-faligned-new%> to enable C++17 "
+ "over-aligned new support");
+ }
+
/* If we found a simple case of PLACEMENT_EXPR above, then copy it
into a temporary variable. */
if (!processing_template_decl
while (TREE_CODE (alloc_call) == COMPOUND_EXPR)
alloc_call = TREE_OPERAND (alloc_call, 1);
- /* Now, check to see if this function is actually a placement
- allocation function. This can happen even when PLACEMENT is NULL
- because we might have something like:
-
- struct S { void* operator new (size_t, int i = 0); };
-
- A call to `new S' will get this allocation function, even though
- there is no explicit placement argument. If there is more than
- one argument, or there are variable arguments, then this is a
- placement allocation function. */
- placement_allocation_fn_p
- = (type_num_arguments (TREE_TYPE (alloc_fn)) > 1
- || varargs_function_p (alloc_fn));
-
/* Preevaluate the placement args so that we don't reevaluate them for a
placement delete. */
if (placement_allocation_fn_p)
So check for a null exception spec on the op new we just called. */
nothrow = TYPE_NOTHROW_P (TREE_TYPE (alloc_fn));
- check_new = (flag_check_new || nothrow) && ! use_java_new;
+ check_new = (flag_check_new || nothrow);
if (cookie_size)
{
}
else if (explicit_value_init_p)
{
- /* Something like `new int()'. */
- tree val = build_value_init (type, complain);
+ /* Something like `new int()'. NO_CLEANUP is needed so
+ we don't try and build a (possibly ill-formed)
+ destructor. */
+ tree val = build_value_init (type, complain | tf_no_cleanup);
if (val == error_mark_node)
return error_mark_node;
init_expr = build2 (INIT_EXPR, type, init_expr, val);
init_expr = cp_build_modify_expr (input_location, init_expr,
INIT_EXPR, ie, complain);
}
- stable = stabilize_init (init_expr, &init_preeval_expr);
+ /* If the initializer uses C++14 aggregate NSDMI that refer to the
+ object being initialized, replace them now and don't try to
+ preevaluate. */
+ bool had_placeholder = false;
+ if (cxx_dialect >= cxx14
+ && !processing_template_decl
+ && TREE_CODE (init_expr) == INIT_EXPR)
+ TREE_OPERAND (init_expr, 1)
+ = replace_placeholders (TREE_OPERAND (init_expr, 1),
+ TREE_OPERAND (init_expr, 0),
+ &had_placeholder);
+ stable = (!had_placeholder
+ && stabilize_init (init_expr, &init_preeval_expr));
}
if (init_expr == error_mark_node)
unambiguous matching deallocation function can be found,
propagating the exception does not cause the object's memory to be
freed. */
- if (flag_exceptions && ! use_java_new)
+ if (flag_exceptions)
{
enum tree_code dcode = array_p ? VEC_DELETE_EXPR : DELETE_EXPR;
tree cleanup;
rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), init_preeval_expr, rval);
/* A new-expression is never an lvalue. */
- gcc_assert (!lvalue_p (rval));
+ gcc_assert (!obvalue_p (rval));
return convert (pointer_type, rval);
}
if (type == error_mark_node)
return error_mark_node;
- if (nelts == NULL_TREE && vec_safe_length (*init) == 1
+ if (nelts == NULL_TREE
/* Don't do auto deduction where it might affect mangling. */
&& (!processing_template_decl || at_function_scope_p ()))
{
tree auto_node = type_uses_auto (type);
if (auto_node)
{
- tree d_init = (**init)[0];
- d_init = resolve_nondeduced_context (d_init, complain);
+ tree d_init = NULL_TREE;
+ if (vec_safe_length (*init) == 1)
+ {
+ d_init = (**init)[0];
+ d_init = resolve_nondeduced_context (d_init, complain);
+ }
type = do_auto_deduction (type, d_init, auto_node);
}
}
orig_placement = make_tree_vector_copy (*placement);
orig_nelts = nelts;
if (*init)
- orig_init = make_tree_vector_copy (*init);
+ {
+ orig_init = make_tree_vector_copy (*init);
+ /* Also copy any CONSTRUCTORs in *init, since reshape_init and
+ digest_init clobber them in place. */
+ for (unsigned i = 0; i < orig_init->length(); ++i)
+ {
+ tree e = (**init)[i];
+ if (TREE_CODE (e) == CONSTRUCTOR)
+ (**init)[i] = copy_node (e);
+ }
+ }
make_args_non_dependent (*placement);
if (nelts)
return rval;
}
-
-/* Given a Java class, return a decl for the corresponding java.lang.Class. */
-
-tree
-build_java_class_ref (tree type)
-{
- tree name = NULL_TREE, class_decl;
- static tree CL_suffix = NULL_TREE;
- if (CL_suffix == NULL_TREE)
- CL_suffix = get_identifier("class$");
- if (jclass_node == NULL_TREE)
- {
- jclass_node = IDENTIFIER_GLOBAL_VALUE (get_identifier ("jclass"));
- if (jclass_node == NULL_TREE)
- {
- error ("call to Java constructor, while %<jclass%> undefined");
- return error_mark_node;
- }
- jclass_node = TREE_TYPE (jclass_node);
- }
-
- /* Mangle the class$ field. */
- {
- tree field;
- for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
- if (DECL_NAME (field) == CL_suffix)
- {
- mangle_decl (field);
- name = DECL_ASSEMBLER_NAME (field);
- break;
- }
- if (!field)
- {
- error ("can%'t find %<class$%> in %qT", type);
- return error_mark_node;
- }
- }
-
- class_decl = IDENTIFIER_GLOBAL_VALUE (name);
- if (class_decl == NULL_TREE)
- {
- class_decl = build_decl (input_location,
- VAR_DECL, name, TREE_TYPE (jclass_node));
- TREE_STATIC (class_decl) = 1;
- DECL_EXTERNAL (class_decl) = 1;
- TREE_PUBLIC (class_decl) = 1;
- DECL_ARTIFICIAL (class_decl) = 1;
- DECL_IGNORED_P (class_decl) = 1;
- pushdecl_top_level (class_decl);
- make_decl_rtl (class_decl);
- }
- return class_decl;
-}
\f
static tree
build_vec_delete_1 (tree base, tree maxindex, tree type,
vec_copy_assign_is_trivial (tree inner_elt_type, tree init)
{
tree fromtype = inner_elt_type;
- if (real_lvalue_p (init))
+ if (lvalue_p (init))
fromtype = cp_build_reference_type (fromtype, /*rval*/false);
return is_trivially_xible (MODIFY_EXPR, inner_elt_type, fromtype);
}
&& from_array != 2)
init = TARGET_EXPR_INITIAL (init);
+ bool direct_init = false;
+ if (from_array && init && BRACE_ENCLOSED_INITIALIZER_P (init)
+ && CONSTRUCTOR_NELTS (init) == 1)
+ {
+ tree elt = CONSTRUCTOR_ELT (init, 0)->value;
+ if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE)
+ {
+ direct_init = DIRECT_LIST_INIT_P (init);
+ init = elt;
+ }
+ }
+
/* If we have a braced-init-list, make sure that the array
is big enough for all the initializers. */
bool length_check = (init && TREE_CODE (init) == CONSTRUCTOR
finish_expr_stmt (one_init);
current_stmt_tree ()->stmts_are_full_exprs_p = 0;
- one_init = cp_build_unary_op (PREINCREMENT_EXPR, base, 0, complain);
+ one_init = cp_build_unary_op (PREINCREMENT_EXPR, base, false,
+ complain);
if (one_init == error_mark_node)
errors = true;
else
finish_expr_stmt (one_init);
- one_init = cp_build_unary_op (PREDECREMENT_EXPR, iterator, 0,
+ one_init = cp_build_unary_op (PREDECREMENT_EXPR, iterator, false,
complain);
if (one_init == error_mark_node)
errors = true;
tree to;
for_stmt = begin_for_stmt (NULL_TREE, NULL_TREE);
- finish_for_init_stmt (for_stmt);
+ finish_init_stmt (for_stmt);
finish_for_cond (build2 (GT_EXPR, boolean_type_node, iterator,
build_int_cst (TREE_TYPE (iterator), -1)),
for_stmt, false);
- elt_init = cp_build_unary_op (PREDECREMENT_EXPR, iterator, 0,
+ elt_init = cp_build_unary_op (PREDECREMENT_EXPR, iterator, false,
complain);
if (elt_init == error_mark_node)
errors = true;
from = build1 (INDIRECT_REF, itype, base2);
if (xvalue)
from = move (from);
+ if (direct_init)
+ from = build_tree_list (NULL_TREE, from);
}
else
from = NULL_TREE;
finish_expr_stmt (elt_init);
current_stmt_tree ()->stmts_are_full_exprs_p = 0;
- finish_expr_stmt (cp_build_unary_op (PREINCREMENT_EXPR, base, 0,
+ finish_expr_stmt (cp_build_unary_op (PREINCREMENT_EXPR, base, false,
complain));
if (base2)
- finish_expr_stmt (cp_build_unary_op (PREINCREMENT_EXPR, base2, 0,
+ finish_expr_stmt (cp_build_unary_op (PREINCREMENT_EXPR, base2, false,
complain));
finish_for_stmt (for_stmt);
vec<tree, va_gc> *vbases;
/* Run destructors for all virtual baseclasses. */
- if (CLASSTYPE_VBASECLASSES (current_class_type))
+ if (!ABSTRACT_CLASS_TYPE_P (current_class_type)
+ && CLASSTYPE_VBASECLASSES (current_class_type))
{
tree cond = (condition_conversion
(build2 (BIT_AND_EXPR, integer_type_node,