| 1 |
/* TEST_OUTPUT: |
| 2 |
--- |
| 3 |
fail_compilation/placenew.d(23): Error: PlacementExpression `3` is an rvalue, but must be an lvalue |
| 4 |
fail_compilation/placenew.d(28): Error: undefined identifier `x` |
| 5 |
fail_compilation/placenew.d(36): Error: `new ( i )` PlacementExpression cannot be evaluated at compile time |
| 6 |
fail_compilation/placenew.d(39): called from here: `xxx()` |
| 7 |
fail_compilation/placenew.d(39): while evaluating: `static assert(xxx() == 1)` |
| 8 |
fail_compilation/placenew.d(48): Error: new placement size 24 must be >= object size 40 |
| 9 |
fail_compilation/placenew.d(54): Error: placement new cannot be used with associative arrays |
| 10 |
fail_compilation/placenew.d(67): Error: new placement size 4 must be >= class object size $?:32=16|64=24$ |
| 11 |
fail_compilation/placenew.d(77): Error: `@safe` function `test7` cannot use placement `new` is not allowed in a `@safe` function |
| 12 |
--- |
| 13 |
*/ |
| 14 |
|
| 15 |
void test0() |
| 16 |
{ |
| 17 |
int i; |
| 18 |
int* pi = new (i) int; |
| 19 |
} |
| 20 |
|
| 21 |
void test1() |
| 22 |
{ |
| 23 |
int* pi = new (3) int; |
| 24 |
} |
| 25 |
|
| 26 |
void test2() |
| 27 |
{ |
| 28 |
int* px = new (x) int; |
| 29 |
} |
| 30 |
|
| 31 |
void test3() |
| 32 |
{ |
| 33 |
int xxx() |
| 34 |
{ |
| 35 |
int i; |
| 36 |
int* pi = new (i) int(1); |
| 37 |
return 1; |
| 38 |
} |
| 39 |
static assert(xxx() == 1); |
| 40 |
} |
| 41 |
|
| 42 |
struct S { int[6] a; } |
| 43 |
struct T { int[10] a; } |
| 44 |
|
| 45 |
void test4() |
| 46 |
{ |
| 47 |
S s; |
| 48 |
new (s) T(); |
| 49 |
} |
| 50 |
|
| 51 |
void test5() |
| 52 |
{ |
| 53 |
T p; |
| 54 |
auto aa = new(p) int[int*]; |
| 55 |
} |
| 56 |
|
| 57 |
/*************************************************/ |
| 58 |
|
| 59 |
class C6 |
| 60 |
{ |
| 61 |
int i, j; |
| 62 |
} |
| 63 |
|
| 64 |
int test6() |
| 65 |
{ |
| 66 |
int k; |
| 67 |
C6 c = new(k) C6; |
| 68 |
return c.j; |
| 69 |
} |
| 70 |
|
| 71 |
/*************************************************/ |
| 72 |
|
| 73 |
@safe |
| 74 |
void test7() |
| 75 |
{ |
| 76 |
int i; |
| 77 |
int* p = new(i) int; |
| 78 |
} |
| 79 |
|
| 80 |
/*************************************************/ |