1 /* 2 TEST_OUTPUT: 3 --- 4 fail_compilation/fail10102.d(48): Error: variable fail10102.main.m default construction is disabled for type NotNull!(int*) 5 fail_compilation/fail10102.d(49): Error: variable fail10102.main.a default construction is disabled for type NotNull!(int*)[3] 6 fail_compilation/fail10102.d(50): Error: default construction is disabled for type NotNull!(int*) 7 fail_compilation/fail10102.d(51): Error: field `S.m` must be initialized because it has no default constructor 8 --- 9 */ 10 NotNull(T)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 main()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 } 53