]> git.ipfire.org Git - people/ms/gcc.git/blame - gcc/testsuite/gdc.test/fail_compilation/fail10102.d
d: Merge upstream dmd, druntime 4ca4140e58, phobos 454dff14d.
[people/ms/gcc.git] / gcc / testsuite / gdc.test / fail_compilation / fail10102.d
CommitLineData
b4c522fa
IB
1/*
2TEST_OUTPUT:
3---
8da8c7d3
IB
4fail_compilation/fail10102.d(48): Error: variable `fail10102.main.m` - default construction is disabled for type `NotNull!(int*)`
5fail_compilation/fail10102.d(49): Error: variable `fail10102.main.a` - default construction is disabled for type `NotNull!(int*)[3]`
5fee5ec3 6fail_compilation/fail10102.d(50): Error: default construction is disabled for type `NotNull!(int*)`
b4c522fa
IB
7fail_compilation/fail10102.d(51): Error: field `S.m` must be initialized because it has no default constructor
8---
9*/
10
11struct NotNull(T)
12{
13 T p;
14
15 alias p this;
16
17 this(T p)
18 {
19 assert(p != null, "pointer is null");
20 this.p = p;
21 }
22
23 @disable this();
24
25 NotNull opAssign(T p)
26 {
27 assert(p != null, "assigning null to NotNull");
28 this.p = p;
29 return this;
30 }
31}
32
33void main()
34{
35 struct S
36 {
37 NotNull!(int *) m;
38 // should fail: an explicit constructor must be required for S
39 }
40
41 int i;
42 NotNull!(int*) n = &i;
43 *n = 3;
44 assert(i == 3);
45 n = &i;
46 n += 1;
47
48 NotNull!(int*) m; // should fail
49 NotNull!(int*)[3] a; // should fail
50 auto b = new NotNull!(int*)[3]; // should fail
51 S s = S(); // should fail
52}