| 1 |
// https://issues.dlang.org/show_bug.cgi?id=20998 |
| 2 |
/* |
| 3 |
REQUIRED_ARGS: -verrors=context |
| 4 |
TEST_OUTPUT: |
| 5 |
--- |
| 6 |
fail_compilation/test20998.d(76): Error: undefined identifier `invalid` |
| 7 |
X x = { invalid, 2, "asd" }; |
| 8 |
^ |
| 9 |
fail_compilation/test20998.d(76): Error: too many initializers for `X` with 2 fields |
| 10 |
X x = { invalid, 2, "asd" }; |
| 11 |
^ |
| 12 |
fail_compilation/test20998.d(83): Error: cannot implicitly convert expression `"a"` of type `string` to `int` |
| 13 |
X2 x2 = { ptr: null, "a", ptr: 2, 444 }; |
| 14 |
^ |
| 15 |
fail_compilation/test20998.d(83): Error: duplicate initializer for field `ptr` |
| 16 |
X2 x2 = { ptr: null, "a", ptr: 2, 444 }; |
| 17 |
^ |
| 18 |
fail_compilation/test20998.d(83): Error: too many initializers for `X2` with 3 fields |
| 19 |
X2 x2 = { ptr: null, "a", ptr: 2, 444 }; |
| 20 |
^ |
| 21 |
fail_compilation/test20998.d(90): Error: overlapping initialization for field `ptr` and `x` |
| 22 |
X3 x3 = { ptr: null, "a", ptr: 2, 444 }; |
| 23 |
^ |
| 24 |
fail_compilation/test20998.d(90): Error: cannot implicitly convert expression `"a"` of type `string` to `int` |
| 25 |
X3 x3 = { ptr: null, "a", ptr: 2, 444 }; |
| 26 |
^ |
| 27 |
fail_compilation/test20998.d(90): Error: duplicate initializer for field `ptr` |
| 28 |
X3 x3 = { ptr: null, "a", ptr: 2, 444 }; |
| 29 |
^ |
| 30 |
fail_compilation/test20998.d(90): Error: too many initializers for `X3` with 3 fields |
| 31 |
X3 x3 = { ptr: null, "a", ptr: 2, 444 }; |
| 32 |
^ |
| 33 |
fail_compilation/test20998.d(98): Error: field `X4.ptr` assigning to misaligned pointers is not allowed in a `@safe` function |
| 34 |
X4 x4 = { ptr: null, "a", 444, ptr: 2, true }; |
| 35 |
^ |
| 36 |
fail_compilation/test20998.d(98): Error: cannot implicitly convert expression `"a"` of type `string` to `int` |
| 37 |
X4 x4 = { ptr: null, "a", 444, ptr: 2, true }; |
| 38 |
^ |
| 39 |
fail_compilation/test20998.d(98): Error: too many initializers for `X4` with 2 fields |
| 40 |
X4 x4 = { ptr: null, "a", 444, ptr: 2, true }; |
| 41 |
^ |
| 42 |
fail_compilation/test20998.d(102): called from here: `test()` |
| 43 |
auto e = test(); |
| 44 |
^ |
| 45 |
fail_compilation/test20998.d(104): Error: cannot implicitly convert expression `1` of type `int` to `void*` |
| 46 |
X2 a5 = { ptr: 1, ptr: 2, ptr: 444, ptr: 555 }; |
| 47 |
^ |
| 48 |
fail_compilation/test20998.d(104): Error: duplicate initializer for field `ptr` |
| 49 |
X2 a5 = { ptr: 1, ptr: 2, ptr: 444, ptr: 555 }; |
| 50 |
^ |
| 51 |
fail_compilation/test20998.d(104): Error: duplicate initializer for field `ptr` |
| 52 |
X2 a5 = { ptr: 1, ptr: 2, ptr: 444, ptr: 555 }; |
| 53 |
^ |
| 54 |
fail_compilation/test20998.d(104): Error: too many initializers for `X2` with 3 fields |
| 55 |
X2 a5 = { ptr: 1, ptr: 2, ptr: 444, ptr: 555 }; |
| 56 |
^ |
| 57 |
fail_compilation/test20998.d(107): Error: too many initializers for `X2` with 3 fields |
| 58 |
X2 c6 = { null, 2, true, null }; |
| 59 |
^ |
| 60 |
fail_compilation/test20998.d(116): Error: cannot implicitly convert expression `1` of type `int` to `immutable(char*)` |
| 61 |
immutable Struct iStruct = {1, &ch}; |
| 62 |
^ |
| 63 |
fail_compilation/test20998.d(116): Error: too many initializers for `Struct` with 1 field |
| 64 |
immutable Struct iStruct = {1, &ch}; |
| 65 |
^ |
| 66 |
fail_compilation/test20998.d(120): called from here: `test2()` |
| 67 |
auto t = test2(); |
| 68 |
^ |
| 69 |
--- |
| 70 |
*/ |
| 71 |
|
| 72 |
struct X { |
| 73 |
void* ptr; |
| 74 |
int x; |
| 75 |
} |
| 76 |
X x = { invalid, 2, "asd" }; |
| 77 |
|
| 78 |
struct X2 { |
| 79 |
void* ptr; |
| 80 |
int x; |
| 81 |
bool y; |
| 82 |
} |
| 83 |
X2 x2 = { ptr: null, "a", ptr: 2, 444 }; |
| 84 |
|
| 85 |
union X3 { |
| 86 |
void* ptr; |
| 87 |
int x; |
| 88 |
bool y; |
| 89 |
} |
| 90 |
X3 x3 = { ptr: null, "a", ptr: 2, 444 }; |
| 91 |
|
| 92 |
int test() @safe |
| 93 |
{ |
| 94 |
align (1) struct X4 { |
| 95 |
void* ptr; |
| 96 |
int x; |
| 97 |
} |
| 98 |
X4 x4 = { ptr: null, "a", 444, ptr: 2, true }; |
| 99 |
return 0; |
| 100 |
} |
| 101 |
|
| 102 |
auto e = test(); |
| 103 |
|
| 104 |
X2 a5 = { ptr: 1, ptr: 2, ptr: 444, ptr: 555 }; |
| 105 |
X2 b5 = { ptr: null, y: true }; |
| 106 |
X2 c5 = { x: 2, true, ptr: null }; |
| 107 |
X2 c6 = { null, 2, true, null }; |
| 108 |
|
| 109 |
struct Struct { |
| 110 |
char* chptr; |
| 111 |
} |
| 112 |
|
| 113 |
int test2() |
| 114 |
{ |
| 115 |
char ch = 'd'; |
| 116 |
immutable Struct iStruct = {1, &ch}; |
| 117 |
return 0; |
| 118 |
} |
| 119 |
|
| 120 |
auto t = test2(); |