beginning of the storage allocated for an array-new expression in
order to store the number of elements. */
tree cookie_size = NULL_TREE;
- tree placement_var;
+ tree placement_expr;
/* True if the function we are calling is a placement allocation
function. */
bool placement_allocation_fn_p;
alloc_fn = NULL_TREE;
/* If PLACEMENT is a simple pointer type, then copy it into
- PLACEMENT_VAR. */
+ PLACEMENT_EXPR. */
if (processing_template_decl
|| placement == NULL_TREE
|| TREE_CHAIN (placement) != NULL_TREE
|| TREE_CODE (TREE_TYPE (TREE_VALUE (placement))) != POINTER_TYPE)
- placement_var = NULL_TREE;
+ placement_expr = NULL_TREE;
else
{
- placement_var = get_temp_regvar (TREE_TYPE (TREE_VALUE (placement)),
- TREE_VALUE (placement));
- placement = tree_cons (NULL_TREE, placement_var, NULL_TREE);
+ placement_expr = save_expr (TREE_VALUE (placement));
+ placement = tree_cons (NULL_TREE, placement_expr, NULL_TREE);
}
/* Allocate the object. */
{
rval = build_nop (pointer_type, alloc_call);
if (placement != NULL)
- rval = avoid_placement_new_aliasing (rval, placement_var);
+ rval = avoid_placement_new_aliasing (rval, placement_expr);
return rval;
}
gcc_assert (!lvalue_p (rval));
if (placement != NULL)
- rval = avoid_placement_new_aliasing (rval, placement_var);
+ rval = avoid_placement_new_aliasing (rval, placement_expr);
return rval;
}
--- /dev/null
+// PR c++/33025
+// { dg-do run }
+// { dg-options "-O2" }
+
+typedef __SIZE_TYPE__ size_t;
+inline void *operator new (size_t, void *p) throw () { return p; }
+extern "C" void abort ();
+
+int
+main()
+{
+ const unsigned num = 10;
+ unsigned *data = new unsigned[2 * num];
+ unsigned *ptr = data;
+ for (unsigned i = 0; i < 2 * num; ++i)
+ (i % 2 == 0) ? new (ptr) unsigned (2) : new (ptr++) unsigned (1);
+ if (ptr - data != num)
+ abort ();
+ return 0;
+}