/
deprecate1.d
1303 lines (1034 loc) · 21.1 KB
/
deprecate1.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// REQUIRED_ARGS: -d
// PERMUTE_ARGS: -dw
// Test cases using deprecated features
module deprecate1;
import core.stdc.stdio : printf;
import std.traits;
import std.math : isNaN;
/**************************************
volatile
**************************************/
void test5a(int *j)
{
int i;
volatile i = *j;
volatile i = *j;
}
void test5()
{
int x;
test5a(&x);
}
// from test23
static int i2 = 1;
void test2()
{
volatile { int i2 = 2; }
assert(i2 == 1);
}
// bug 1200. Other tests in test42.d
void foo6e() {
volatile debug {}
}
/**************************************
octal literals
**************************************/
void test10()
{
int b = 0b_1_1__1_0_0_0_1_0_1_0_1_0_;
assert(b == 3626);
b = 0_1_2_3_4_;
printf("b = %d\n", b);
assert(b == 668);
}
/**************************************
typedef
**************************************/
template func19( T )
{
typedef T function () fp = &erf;
T erf()
{
printf("erf()\n");
return T.init;
}
}
alias func19!( int ) F19;
F19.fp tc;
void test19()
{
printf("tc = %p\n", tc);
assert(tc() == 0);
}
/**************************************/
// http://www.digitalmars.com/d/archives/digitalmars/D/bugs/578.html
typedef void* T60;
class A60
{
int List[T60][int][uint];
void GetMsgHandler(T60 h,uint Msg)
{
assert(Msg in List[h][0]); //Offending line
}
}
void test60()
{
}
/**************************************/
// http://www.digitalmars.com/d/archives/digitalmars/D/bugs/576.html
typedef ulong[3] BBB59;
template A59()
{
void foo(BBB59 a)
{
printf("A.foo\n");
bar(a);
}
}
struct B59
{
mixin A59!();
void bar(BBB59 a)
{
printf("B.bar\n");
}
}
void test59()
{
ulong[3] aa;
BBB59 a;
B59 b;
b.foo(a);
}
/***************************************/
// From variadic.d
template foo33(TA...)
{
const TA[0] foo33=0;
}
template bar33(TA...)
{
const TA[0..1][0] bar33=TA[0..1][0].init;
}
void test33()
{
typedef int dummy33=0;
typedef int myint=3;
assert(foo33!(int)==0);
assert(bar33!(int)==int.init);
assert(bar33!(myint)==myint.init);
assert(foo33!(int,dummy33)==0);
assert(bar33!(int,dummy33)==int.init);
assert(bar33!(myint,dummy33)==myint.init);
}
/***************************************/
// Bug 875 ICE(glue.c)
void test41()
{
double bongos(int flux, string soup)
{
return 0.0;
}
auto foo = mk_future(& bongos, 99, "soup"[]);
}
int mk_future(A, B...)(A cmd, B args)
{
typedef ReturnType!(A) TReturn;
typedef ParameterTypeTuple!(A) TParams;
typedef B TArgs;
alias Foo41!(TReturn, TParams, TArgs) TFoo;
return 0;
}
class Foo41(A, B, C) {
this(A delegate(B), C)
{
}
}
// Typedef tests from test4.d
/* ================================ */
void test4_test26()
{
typedef int foo = cast(foo)3;
foo x;
assert(x == cast(foo)3);
typedef int bar = 4;
bar y;
assert(y == cast(bar)4);
}
/* ================================ */
struct Foo28
{
int a;
int b = 7;
}
void test4_test28()
{
version (all)
{
int a;
int b = 1;
typedef int t = 2;
t c;
t d = cast(t)3;
assert(int.init == 0);
assert(a.init == 0);
assert(b.init == 0);
assert(t.init == cast(t)2);
assert(c.init == cast(t)2);
printf("d.init = %d\n", d.init);
assert(d.init == cast(t)2);
assert(Foo28.a.init == 0);
assert(Foo28.b.init == 0);
}
else
{
int a;
int b = 1;
typedef int t = 2;
t c;
t d = cast(t)3;
assert(int.init == 0);
assert(a.init == 0);
assert(b.init == 1);
assert(t.init == cast(t)2);
assert(c.init == cast(t)2);
printf("d.init = %d\n", d.init);
assert(d.init == cast(t)3);
assert(Foo28.a.init == 0);
assert(Foo28.b.init == 7);
}
}
// from template4.d test 4
void template4_test4()
{
typedef char Typedef;
static if (is(Typedef Char == typedef))
{
static if (is(Char == char))
{ }
else static assert(0);
}
else static assert(0);
}
// from structlit
typedef int myint10 = 4;
struct S10
{
int i;
union
{ int x = 2;
int y;
}
int j = 3;
myint10 k;
}
void structlit_test10()
{
S10 s = S10( 1 );
assert(s.i == 1);
assert(s.x == 2);
assert(s.y == 2);
assert(s.j == 3);
assert(s.k == 4);
static S10 t = S10( 1 );
assert(t.i == 1);
assert(t.x == 2);
assert(t.y == 2);
assert(t.j == 3);
assert(t.k == 4);
S10 u = S10( 1, 5 );
assert(u.i == 1);
assert(u.x == 5);
assert(u.y == 5);
assert(u.j == 3);
assert(u.k == 4);
static S10 v = S10( 1, 6 );
assert(v.i == 1);
assert(v.x == 6);
assert(v.y == 6);
assert(v.j == 3);
assert(v.k == 4);
}
/******************************************/
void test15_test1()
{
int i;
bool[] b = new bool[10];
for (i = 0; i < 10; i++)
assert(b[i] == false);
typedef bool tbit = true;
tbit[] tb = new tbit[63];
for (i = 0; i < 63; i++)
assert(tb[i] == true);
}
void test15_test2()
{
int i;
byte[] b = new byte[10];
for (i = 0; i < 10; i++)
{ //printf("b[%d] = %d\n", i, b[i]);
assert(b[i] == 0);
}
typedef byte tbyte = 0x23;
tbyte[] tb = new tbyte[63];
for (i = 0; i < 63; i++)
assert(tb[i] == 0x23);
}
void test15_test3()
{
int i;
ushort[] b = new ushort[10];
for (i = 0; i < 10; i++)
{ //printf("b[%d] = %d\n", i, b[i]);
assert(b[i] == 0);
}
typedef ushort tushort = 0x2345;
tushort[] tb = new tushort[63];
for (i = 0; i < 63; i++)
assert(tb[i] == 0x2345);
}
void test15_test4()
{
int i;
float[] b = new float[10];
for (i = 0; i < 10; i++)
{ //printf("b[%d] = %d\n", i, b[i]);
assert(isNaN(b[i]));
}
typedef float tfloat = 0.0;
tfloat[] tb = new tfloat[63];
for (i = 0; i < 63; i++)
assert(tb[i] == cast(tfloat)0.0);
}
/************************************/
// failed to compile on DMD0.050, only with typedef (alias was OK)
typedef int[int] T11;
T11 a11;
void test15_test11()
{
1 in a11;
}
/************************************/
// ICE(cgelem.c) on 0.050, alias was OK.
struct A12
{
int x;
int y;
int x1;
int x2;
}
typedef A12 B12;
template V12(T)
{
T buf;
T get()
{
return buf;
}
}
alias V12!(B12) foo12;
void test15_test12()
{
B12 b = foo12.get();
}
/************************************/
// test15_test13. Failed to compile DMD0.050, OK with alias.
typedef int[] T13;
static T13 a13=[1,2,3];
/************************************************/
// Failed to compile DMD0.050, OK with alias.
typedef int foo3;
foo3 [foo3] list3;
void testaa_test3()
{
list3[cast(foo3)5] = cast(foo3)2;
foo3 x = list3.keys[0]; // This line fails.
assert(x == cast(foo3)5);
}
/*****************************************/
void test20_test32()
{
typedef int Type = 12;
static Type[5] var = [0:1, 3:2];
assert(var[0] == 1);
assert(var[1] == 12);
assert(var[2] == 12);
assert(var[3] == 2);
assert(var[4] == 12);
}
/**************************************/
class A2
{
T opCast(T)()
{
auto s = T.stringof;
printf("A.opCast!(%.*s)\n", s.length, s.ptr);
return T.init;
}
}
void opover2_test2()
{
auto a = new A2();
auto x = cast(int)a;
assert(x == 0);
typedef int myint_BUG6712 = 7;
auto y = cast(myint_BUG6712)a;
assert(y == 7);
}
/**************************************/
// http://www.digitalmars.com/d/archives/10750.html
// test12.d, test7(). ICE(constfold.c)
version(none) // This contains an incredibly nasty cast
{
template base7( T )
{
void errfunc() { throw new Exception("no init"); }
typedef T safeptr = cast(T)&errfunc; // Nasty cast
}
alias int function(int) mfp;
alias base7!(mfp) I_V_fp;
}
typedef bool antibool = 1;
antibool[8] z21 = [ cast(antibool) 0, ];
void test12_test21()
{
assert(z21[7]);
}
/**************************************/
// test12.d, test41.
// Might be related to this:
// http://www.digitalmars.com/d/archives/digitalmars/D/INVALID_HANDLE_VALUE_const_55633.html
typedef void* H41;
const H41 INVALID_H41_VALUE = cast(H41)-1;
/*******************************************/
struct Ranged(T)
{
T value, min, max, range;
}
typedef Ranged!(float) Degree = {0f, 0f, 360f, 360f};
void test28_test5()
{
static Degree a;
assert(a.value == 0f);
assert(a.min == 0f);
assert(a.max == 360f);
assert(a.range == 360f);
}
/*******************************************/
void test28_test6()
{
struct Foo
{
void foo() { }
}
typedef Foo Bar;
Bar a;
a.foo();
}
/*******************************************/
typedef uint socket_t = -1u;
class Socket
{
socket_t sock;
void accept()
{
socket_t newsock;
}
}
void test28_test16()
{
}
/*******************************************/
typedef int Xint = 42;
void test28_test56()
{
Xint[3][] x = new Xint[3][4];
foreach(Xint[3] i; x) {
foreach (Xint j; i)
assert(j == 42);
}
}
void test28_test57()
{
Xint[3][] x = new Xint[3][4];
x.length = 200;
assert(x.length == 200);
foreach(Xint[3] i; x) {
foreach (Xint j; i)
assert(j == 42);
}
}
/******************************************/
// from runnable/traits.d
typedef int traits_myint;
static assert(__traits(isArithmetic, traits_myint) == true);
static assert(__traits(isScalar, traits_myint) == true);
static assert(__traits(isIntegral, traits_myint) == true);
mixin template Members6674()
{
static int i1;
static int i2;
static int i3; //comment out to make func2 visible
static int i4; //comment out to make func1 visible
}
class Test6674
{
mixin Members6674;
typedef void function() func1;
typedef bool function() func2;
}
static assert([__traits(allMembers,Test6674)] == [
"i1","i2","i3","i4",
"func1","func2",
"toString","toHash","opCmp","opEquals","Monitor","factory"]);
/***************************************************/
// Bug 1523. typedef only.
struct BaseStruct {
int n;
char c;
}
typedef BaseStruct MyStruct26;
void myFunction(MyStruct26) {}
void test42_test26()
{
myFunction(MyStruct26(0, 'x'));
}
/***************************************************/
// typedef only
class Foo30
{
int i;
}
typedef Foo30 Bar30;
void test42_test30()
{
Bar30 testBar = new Bar30();
auto j = testBar.i;
}
/***************************************************/
// test55. bug 1767
class DebugInfo
{
typedef int CVHeaderType ;
enum anon:CVHeaderType{ CV_NONE, CV_DOS, CV_NT, CV_DBG }
}
/***************************************************/
void test42_test102()
{
typedef const(char)[] A;
A stripl(A s)
{
uint i;
return s[i .. $];
}
}
/***************************************************/
// test42.d test107(). segfault 2.020
class foo107 {}
typedef foo107 bar107;
void x107()
{
bar107 a = new bar107();
bar107 b = new bar107();
bool c = (a == b);
}
/***************************************************/
// Bug 3668. segfault regression 2.032.
void test42_test167()
{
typedef byte[] Foo;
Foo bar;
foreach(value; bar){}
}
// Bug 190. Test42.d, test 225.
typedef int avocado;
void eat(avocado x225 = .x225);
avocado x225;
/***************************************************/
typedef ireal BUG3919;
alias typeof(BUG3919.init*BUG3919.init) ICE3919;
alias typeof(BUG3919.init/BUG3919.init) ICE3920;
/*****************************************/
// rejectsvalid 0.100. typedef only.
void testswitch_test18()
{
enum E { a, b }
typedef E F;
F i = E.a;
final switch (i)
{
case E.a:
case E.b:
break;
}
}
/************************************/
void testconst_test7()
{
typedef void *HANDLE;
const HANDLE INVALID_HANDLE_VALUE = cast(HANDLE)-1;
}
/************************************/
void testconst_test67()
{
typedef char mychar;
alias immutable(mychar)[] mystring;
mystring s = cast(mystring)"hello";
mychar c = s[0];
}
/************************************/
void testconst_test71()
{
string s = "hello world";
char c = s[0];
typedef char mychar;
alias immutable(mychar)[] mystring;
mystring t = cast(mystring)("hello world");
mychar d = t[0];
}
/************************************/
class foo86 { }
typedef shared foo86 Y86;
void testconst_test86()
{
pragma(msg, Y86);
shared(Y86) x = new Y86;
}
/************************************/
class Class19 : Throwable
{
this() { super(""); }
}
typedef Class19 Alias19;
void testdstress_test19()
{
try{
throw new Alias19();
}catch{
return;
}
assert(0);
}
/************************************/
public static const uint U20 = (cast(uint)(-1)) >>> 2;
typedef uint myType20;
public static const myType20 T20 = (cast(myType20)(-1)) >>> 2;
void testdstress_test20()
{
assert(U20 == 0x3FFFFFFF);
assert(T20 == 0x3FFFFFFF);
}
/******************************************************/
class ABC { }
typedef ABC DEF;
TypeInfo foo()
{
ABC c;
return typeid(DEF);
}
void testtypeid_test1()
{
TypeInfo ti = foo();
TypeInfo_Typedef td = cast(TypeInfo_Typedef)ti;
assert(td);
ti = td.base;
TypeInfo_Class tc = cast(TypeInfo_Class)ti;
assert(tc);
printf("%.*s\n", tc.info.name.length, tc.info.name.ptr);
assert(tc.info.name == "deprecate1.ABC");
}
/******************************************************/
union MyUnion5{
int i;
byte b;
}
typedef MyUnion5* Foo5;
void testtypeid_test5()
{
TypeInfo ti = typeid(Foo5);
assert(!(ti is null));
assert(ti.tsize==(Foo5).sizeof);
assert(ti.toString()=="deprecate1.Foo5");
}
/***********************************/
// test8.d test13()
typedef void *HWND;
const HWND hWnd = cast(HWND)(null);
/***********************************/
typedef int* IP;
void test8_test21()
{
int i = 5;
IP ip = cast(IP) &i;
assert(*ip == 5);
}
/***********************************/
// http://www.digitalmars.com/d/archives/7812.html
typedef int delegate() DG;
class A23 {
int foo() { return 7; }
DG pfoo() { return &this.foo; } //this is ok
}
void test8_test23()
{
int i;
A23 a = new A23;
DG dg = &a.foo;
i = dg();
assert(i == 7);
DG dg2 = a.pfoo();
i = dg2();
assert(i == 7);
}
/***********************************/
// test8 test29()
typedef int[] tint;
void Set( ref tint array, int newLength )
{
array.length= newLength;
}
/***********************************/
struct V41 { int x; }
typedef V41 W41 = { 3 };
class Node41
{
W41 v;
}
void test8_test41()
{
Node41 n = new Node41;
printf("n.v.x == %d\n", n.v.x);
assert(n.v.x == 3);
}
/***********************************/
// http://www.digitalmars.com/d/archives/digitalmars/D/bugs/1801.html
// test8 test47. ICE(e2ir.c)
typedef string Qwert47;
string yuiop47(Qwert47 asdfg)
{
return asdfg[4..6];
}
/***********************************/
void test22_test28()
{
typedef cdouble Y;
Y five = cast(Y) (4.0i + 0.4);
}
/*******************************************/
// Bug 184
struct vegetarian
{
carrots areYummy;
}
typedef ptrdiff_t carrots;
void test23_test35()
{
assert(vegetarian.sizeof == ptrdiff_t.sizeof);
}
/*******************************************/
// bug 185
void test23_test36()
{
typedef double type = 5.0;
type t;
assert (t == type.init);
type[] ts = new type[10];
ts.length = 20;
foreach (i; ts)
{
assert(i == cast(type)5.0);
}
}
/*******************************************/
typedef int Int1;
typedef int Int2;
int show(Int1 v)
{
printf("Int1: %d", v);
return 1;
}
int show(Int2 v) {
printf("Int2: %d", v);
return 2;
}
int show(int i) {
printf("int: %d", i);
return 3;
}
int show(long l) {
printf("long: %d", l);
return 4;
}
int show(uint u) {
printf("uint: %d", u);
return 5;
}
void test23_test49()
{ int i;
Int1 value1 = 42;
Int2 value2 = 69;
i = show(value1 + value2);
assert(i == 3);
i = show(value2 + value1);
assert(i == 3);
i = show(2 * value1);
assert(i == 3);