Debian Codegraph @

gcc/testsuite/gdc.test/runnable/variadic.d

raw
1 // TRANSFORM_OUTPUT: remove_lines("warning: vsprintf\(\) is often misused")
2
3 alias TypeTuple(T...) = T;
4
5 class A { }
6 class B : A { }
7 class C : B { }
8
9 /***************************************/
10
11 template Foo(int a, int b, int c)
12 {
13 const int Foo = 1;
14 }
15
16 template Foo(A...)
17 {
18 const int Foo = 2;
19 }
20
21 void test1()
22 {
23 int y = Foo!(1,2,3);
24 assert(y == 1);
25
26 y = Foo!(1,2);
27 assert(y == 2);
28
29 y = Foo!(1,2,3,4);
30 assert(y == 2);
31 }
32
33 /***************************************/
34
35 template Foo2(int a, int b, int c)
36 {
37 const int Foo2 = 1;
38 }
39
40 template Foo2(int a, int b, int c, A...)
41 {
42 const int Foo2 = 2;
43 }
44
45 void test2()
46 {
47 int y = Foo2!(1,2,3);
48 assert(y == 1);
49
50 y = Foo2!(1,2,3,4);
51 assert(y == 2);
52 }
53
54 /***************************************/
55
56 void bar3(int x, int y)
57 {
58 assert(x == 2);
59 assert(y == 3);
60 }
61
62 template Foo3(T, A...)
63 {
64 int Foo3(T t, A a)
65 {
66 assert(A.length == 2);
67 assert(a.length == 2);
68 bar3(a);
69 assert([a] == [2, 3]);
70 assert([cast(double)a] == [2.0, 3.0]);
71 assert(a[0] == 2);
72 assert(a[1] == 3);
73 assert(a[$ - 2] == 2);
74 assert(a[$ - 1] == 3);
75 static if (1 || a[6])
76 assert(1);
77 assert([a[]] == [2, 3]);
78 assert([a[0 .. $]] == [2, 3]);
79 assert([a[0 .. $ - 1]] == [2]);
80 return 3;
81 }
82 }
83
84 void test3()
85 {
86 int y = Foo3(1,2,3);
87 assert(y == 3);
88 }
89
90 /***************************************/
91
92
93 void foo4(A...)()
94 {
95 int[] ai;
96 int[] aa;
97
98 aa = null;
99 foreach (a; A)
100 {
101 aa ~= a;
102 }
103 assert(aa == [7,4,9]);
104
105 aa = null;
106 foreach (int a; A)
107 {
108 aa ~= a;
109 }
110 assert(aa == [7,4,9]);
111
112 ai = null;
113 aa = null;
114 foreach (int i, a; A)
115 {
116 ai ~= i;
117 aa ~= a;
118 }
119 assert(ai == [0,1,2]);
120 assert(aa == [7,4,9]);
121
122 ai = null;
123 aa = null;
124 foreach_reverse (uint i, a; A)
125 {
126 ai ~= i;
127 aa ~= a;
128 }
129 assert(ai == [2,1,0]);
130 assert(aa == [9,4,7]);
131
132 ai = null;
133 aa = null;
134 foreach_reverse (i, a; A)
135 {
136 ai ~= i;
137 aa ~= a;
138 }
139 assert(ai == [2,1,0]);
140 assert(aa == [9,4,7]);
141
142 ai = null;
143 aa = null;
144 foreach (int i, a; A)
145 {
146 ai ~= i;
147 aa ~= a;
148 if (i == 1)
149 break;
150 continue;
151 }
152 assert(ai == [0,1]);
153 assert(aa == [7,4]);
154 }
155
156 void test4()
157 {
158 foo4!(7,4,9)();
159 }
160
161 /***************************************/
162
163 int a12(TypeTuple!(int, int) t)
164 {
165 return t[0] + t[1];
166 }
167
168 int b12(TypeTuple!(TypeTuple!(int), TypeTuple!(int)) t)
169 {
170 return t[0] + t[1];
171 }
172
173 int c12(TypeTuple!(TypeTuple!(int), TypeTuple!(TypeTuple!(), int), TypeTuple!()) t)
174 {
175 return t[0] + t[1];
176 }
177
178 void test12()
179 {
180 assert(a12(1, 2) == 3);
181 assert(b12(1, 2) == 3);
182 assert(c12(1, 2) == 3);
183 }
184
185 /***************************************/
186
187
188 int plus13(TypeTuple!(int, long, float)[0 .. 2] t)
189 {
190 typeof(t)[0] e;
191 assert(typeid(typeof(e)) == typeid(int));
192 typeof(t)[1] f;
193 assert(typeid(typeof(f)) == typeid(long));
194 return t[0] + cast(int)t[1];
195 }
196
197 void test13()
198 {
199 assert(plus13(5, 6) == 11);
200 }
201
202 /***************************************/
203
204 int plus14(TypeTuple!(int, long, float)[0 .. $ - 1] t)
205 {
206 typeof(t)[$ - 2] e;
207 assert(typeid(typeof(e)) == typeid(int));
208 typeof(t)[1] f;
209 assert(typeid(typeof(f)) == typeid(long));
210 return t[0] + cast(int)t[1];
211 }
212
213 void test14()
214 {
215 assert(plus14(5, 6) == 11);
216 }
217
218 /***************************************/
219
220 void returnAndArgs(T, U...) (T delegate(U) dg)
221 {
222 static if (U.length == 0)
223 assert(dg() == 0);
224 else static if (U.length == 1)
225 assert(dg(false) == 1);
226 else
227 assert(dg(false, 63L) == 2);
228 }
229
230 void test24()
231 {
232 returnAndArgs(delegate int(){ return 0; });
233 returnAndArgs(delegate int(bool b){ return 1; });
234 returnAndArgs(delegate int(bool b, long c){ return 2; });
235 }
236
237 /***************************************/
238
239 void test28()
240 {
241 alias TypeTuple!(int, long, double) TL;
242
243 foreach (int i, T; TL)
244 {
245 switch (i)
246 {
247 case 0: assert(is(T == int)); break;
248 case 1: assert(is(T == long)); break;
249 case 2: assert(is(T == double)); break;
250 default:assert(0);
251 }
252 }
253 }
254
255 /***************************************/
256
257 template g32(alias B)
258 {
259 int g32 = 2;
260 }
261
262 int f32(A...)(A a)
263 {
264 return g32!(a);
265 }
266
267 void test32()
268 {
269 assert(f32(4) == 2);
270 }
271
272 /***************************************/
273
274 struct S34
275 {
276 int x;
277 long y;
278 double z;
279 }
280
281 void foo34(int x, long y, double z)
282 {
283 assert(x == 3);
284 assert(y == 8);
285 assert(z == 6.8);
286 }
287
288 void test34()
289 {
290 S34 s;
291
292 s.x = 3;
293 s.y = 8;
294 s.z = 6.8;
295 foo34(s.tupleof);
296 }
297
298 /***************************************/
299
300 alias TypeTuple!(int, long, double) TL35;
301
302 struct S35
303 {
304 TL35 tl;
305 }
306
307 void foo35(int x, long y, double z)
308 {
309 assert(x == 3);
310 assert(y == 8);
311 assert(z == 6.8);
312 }
313
314 void test35()
315 {
316 S35 s;
317
318 s.tl[0] = 3;
319 s.tl[1] = 8;
320 s.tl[2] = 6.8;
321 foo35(s.tupleof);
322 foo35(s.tl);
323 }
324
325 /***************************************/
326
327 alias TypeTuple!(int, long, double) TL36;
328
329 class C36
330 {
331 TL36 tl;
332 }
333
334 void foo36(int x, long y, double z)
335 {
336 assert(x == 3);
337 assert(y == 8);
338 assert(z == 6.8);
339 }
340
341 void test36()
342 {
343 C36 s = new C36;
344
345 s.tl[0] = 3;
346 s.tl[1] = 8;
347 s.tl[2] = 6.8;
348 foo36(s.tupleof);
349 foo36(s.tl);
350 }
351
352 /***************************************/
353
354
355 alias TypeTuple!(int, long, double) TL37;
356
357 class C37
358 {
359 TL37 tl;
360 }
361
362 void foo37(int x, long y, double z)
363 {
364 assert(x == 3);
365 assert(y == 8);
366 assert(z == 6.8);
367 }
368
369 void test37()
370 {
371 C37 s = new C37;
372
373 s.tl[0] = 3;
374 s.tl[1] = 8;
375 s.tl[2] = 6.8;
376 foo37(s.tupleof);
377
378 TL37 x;
379 assert(x[0] == 0);
380 x[0] = 3;
381 assert(x[0] == 3);
382 assert(x[1] == 0);
383 x[1] = 8;
384 x[2] = 6.8;
385 foo37(x);
386 }
387
388 /***************************************/
389
390 interface I38A { }
391 interface I38B { }
392
393 alias TypeTuple!(I38A, I38B) IL38;
394
395 class C38 : IL38
396 {
397 }
398
399 void test38()
400 {
401 auto c = new C38;
402 }
403
404 /***************************************/
405
406 void test39()
407 {
408 static const string a = "\x01";
409 static const char b = a[0];
410 static const string c = "test";
411 static assert(c[a[0]] == 'e');
412
413 alias TypeTuple!(ulong,uint,ushort,ubyte) tuple;
414 static assert(is(tuple[1] == uint));
415 static assert(is(tuple[a[0]] == uint));
416 }
417
418 /***************************************/
419
420 struct Foo45
421 {
422 static TypeTuple!(int) selements1;
423 TypeTuple!(int) elements1;
424 static TypeTuple!() selements0;
425 TypeTuple!() elements0;
426 }
427
428 void test45()
429 {
430 Foo45 foo;
431
432 static assert(Foo45.selements1.length == 1);
433 static assert(Foo45.elements1.length == 1);
434 static assert(Foo45.selements0.length == 0);
435 static assert(Foo45.elements0.length == 0);
436
437 static assert(foo.selements1.length == 1);
438 static assert(foo.elements1.length == 1);
439 static assert(foo.selements0.length == 0);
440 static assert(foo.elements0.length == 0);
441 }
442
443 /***************************************/
444
445 template Tuple46(E ...) { alias E Tuple46; }
446
447 alias Tuple46!(float, float, 3) TP46;
448 alias TP46[1..$] TQ46;
449
450 void test46()
451 {
452 TQ46[0] f = TQ46[1];
453 assert(is(typeof(f) == float));
454 assert(f == 3);
455 }
456
457 /***************************************/
458
459 template Foo47(T, Args...)
460 {
461 void bar(Args args, T t)
462 {
463 }
464 }
465
466 void test47()
467 {
468 alias Foo47!(int) aFoo;
469 }
470
471 /***************************************/
472
473 template Tuple48(E...)
474 {
475 alias E Tuple48;
476 }
477
478 void VarArg48(T...)(T args)
479 {
480 }
481
482 void test48()
483 {
484 VarArg48( );
485 VarArg48( Tuple48!(1,2,3) );
486 VarArg48( Tuple48!() );
487 }
488
489 /***************************************/
490
491 alias TypeTuple!(int, long) TX49;
492
493 void foo49(TX49 t)
494 {
495 TX49 s;
496 s = t;
497 assert(s[0] == 1);
498 assert(s[1] == 2);
499 }
500
501 void test49()
502 {
503 foo49(1, 2);
504 }
505
506 /***************************************/
507
508 void foo51(U...)(int t, U u)
509 {
510 assert(t == 1);
511 assert(u[0] == 2);
512 assert(u[1] == 3);
513 }
514
515 void bar51(U...)(U u, int t)
516 {
517 assert(u[0] == 1);
518 assert(u[1] == 2);
519 assert(t == 3);
520 }
521
522 void abc51(U...)(int s, U u, int t)
523 {
524 assert(s == 1);
525 assert(u[0] == 2);
526 assert(u[1] == 3);
527 assert(t == 4);
528 }
529
530 void test51()
531 {
532 foo51(1, 2, 3);
533 bar51(1, 2, 3);
534 bar51!(int, int)(1, 2, 3);
535 abc51(1,2,3,4);
536 }
537
538 /***************************************/
539
540 string to55(U, V)(V s) { return "he"; }
541
542 private S wyda(S, T...)(T args)
543 {
544 S result;
545 foreach (i, arg; args)
546 {
547 result ~= to55!(S)(args[i]);
548 }
549 return result;
550 }
551
552 string giba(U...)(U args)
553 {
554 return wyda!(string, U)(args);
555 }
556
557 void test55()
558 {
559 assert(giba(42, ' ', 1.5, ": xyz") == "hehehehe");
560 }
561
562 /***************************************/
563
564 private template implicitlyConverts(U, V)
565 {
566 enum bool implicitlyConverts = V.sizeof >= U.sizeof
567 && is(typeof({U s; V t = s;}()));
568 }
569
570 T to56(T, S)(S s)
571 if (!implicitlyConverts!(S, T) /*&& isSomeString!(T)
572 && isSomeString!(S)*/)
573 {
574 return T.init;
575 }
576
577 void test56()
578 {
579 auto x = to56!(int)("4");
580 assert(x == 0);
581 assert(!implicitlyConverts!(const(char)[], string));
582 assert(implicitlyConverts!(string, const(char)[]));
583 }
584
585 /***************************************/
586
587 struct A57(B...) {}
588
589 void test57()
590 {
591 alias A57!(int, float) X;
592 static if (!is(X Y == A57!(Z), Z...))
593 {
594 static assert(false);
595 }
596 }
597
598 /***************************************/
599
600 struct A58(B...) {}
601
602 void test58()
603 {
604 alias A58!(int, float) X;
605 static if (!is(X Y == A58!(Z), Z...))
606 {
607 static assert(false);
608 }
609 }
610
611 /***************************************/
612
613 struct Tuple59(T...)
614 {
615 T field;
616 }
617
618 template reduce(fun...)
619 {
620 alias Reduce!(fun).reduce reduce;
621 }
622
623 template Reduce(fun...)
624 {
625 Tuple59!(double, double)
626 reduce(Range)(Range r)
627 {
628 typeof(Tuple59!(double,double).field)[0] y;
629 typeof(typeof(return).field)[0] x;
630 Tuple59!(double, double) s;
631 return s;
632 }
633 }
634
635 void test59()
636 {
637 double[] a = [ 3.0, 4, 7, 11, 3, 2, 5 ];
638 static double sum(double a, double b) {return a + b;}
639 auto r = reduce!((a, b) { return a + b; },
640 (a, b) { return a + b; })(a);
641 }
642
643 /***************************************/
644
645 template tuple60(T...)
646 {
647 alias T tuple60;
648 }
649
650 template Foo60(S : void delegate(tuple60!(int))) {}
651 template Foo60(S : void delegate(tuple60!(int, int))) {}
652
653 alias Foo60!(void delegate(int)) Bar60;
654
655 void test60()
656 {
657 }
658
659 /***************************************/
660
661 template TypeTuple61(TList...){
662 alias TList TypeTuple61;
663 }
664 template List61(lst...) { alias lst list; }
665 alias TypeTuple61!(List61!(void)) A61;
666 alias TypeTuple61!(A61[0].list) B61;
667
668 void test61()
669 {
670 }
671
672 /***************************************/
673
674 template Tuple63(T...){
675 alias T Tuple63;
676 }
677 // https://issues.dlang.org/show_bug.cgi?id=3336
678 static assert(!is(int[ Tuple63!(int, int) ]));
679
680 void test63()
681 {
682 }
683
684 /***************************************/
685
686 template Tuple1411(T ...) { alias T Tuple1411; }
687
688 void test1411()
689 {
690 int delegate(ref Tuple1411!(int, char[], real)) dg; // (*)
691 int f(ref int a, ref char[] b, ref real c) { return 77; }
692 dg = &f;
693 }
694
695 /***************************************/
696 // https://issues.dlang.org/show_bug.cgi?id=4444
697
698 void test4444()
699 {
700 alias TypeTuple!(1) index;
701 auto arr = new int[4];
702 auto x = arr[index]; // error
703 }
704
705 /***************************************/
706 // https://issues.dlang.org/show_bug.cgi?id=13864
707
708 struct Tuple13864(T...)
709 {
710 T expand;
711 alias expand this;
712 }
713 auto tuple13864(T...)(T args)
714 {
715 return Tuple13864!T(args);
716 }
717
718 void test13864()
719 {
720 int[] x = [2,3,4];
721 auto y = x[tuple13864(0).expand];
722 assert(y == 2);
723 }
724
725 /***************************************/
726 // https://issues.dlang.org/show_bug.cgi?id=4884
727
728 struct A4884(T...)
729 {
730 void foo(T) {}
731 void bar(bool, T) {}
732 }
733
734 void test4884()
735 {
736 auto a1 = A4884!(int)();
737 auto a2 = A4884!(int, long)();
738 }
739
740 /***************************************/
741 // https://issues.dlang.org/show_bug.cgi?id=4920
742
743 struct Test4920(parameters_...)
744 {
745 alias parameters_ parameters;
746 }
747
748 void test4920()
749 {
750 Test4920!(10, 20, 30) test;
751 static assert(typeof(test).parameters[1] == 20); // okay
752 static assert( test .parameters[1] == 20); // (7)
753 }
754
755 /***************************************/
756 // https://issues.dlang.org/show_bug.cgi?id=4940
757
758 template Tuple4940(T...)
759 {
760 alias T Tuple4940;
761 }
762
763 struct S4940
764 {
765 Tuple4940!(int, int) x;
766 this(int) { }
767 }
768
769 void test4940()
770 {
771 auto w = S4940(0).x;
772 }
773
774 //----
775
776 struct S4940add
777 {
778 string s;
779 long x;
780 }
781
782 ref S4940add get4940add(return ref S4940add s){ return s; }
783
784 void test4940add()
785 {
786 S4940add s;
787 get4940add(s).tupleof[1] = 20;
788 assert(s.x == 20);
789 }
790
791 /***************************************/
792 // https://issues.dlang.org/show_bug.cgi?id=6530
793
794 struct S6530
795 {
796 int a, b, c;
797 }
798
799 struct HasPostblit6530
800 {
801 this(this) {} // Bug goes away without this.
802 }
803
804 auto toRandomAccessTuple6530(T...)(T input, HasPostblit6530 hasPostblit)
805 {
806 return S6530(1, 2, 3);
807 }
808
809 void doStuff6530(T...)(T args)
810 {
811 HasPostblit6530 hasPostblit;
812
813 // Bug goes away without the .tupleof.
814 auto foo = toRandomAccessTuple6530(args, hasPostblit).tupleof;
815 }
816
817 void test6530()
818 {
819 doStuff6530(1, 2, 3);
820 }
821
822 /***************************************/
823
824 import core.stdc.stdarg;
825
826 extern(C)
827 void func9495(int a, string format, ...)
828 {
829 va_list ap;
830 va_start(ap, format);
831 auto a1 = va_arg!int(ap);
832 auto a2 = va_arg!int(ap);
833 auto a3 = va_arg!int(ap);
834 assert(a1 == 0x11111111);
835 assert(a2 == 0x22222222);
836 assert(a3 == 0x33333333);
837 va_end(ap);
838 }
839
840 void test9495()
841 {
842 func9495(0, "", 0x11111111, 0x22222222, 0x33333333);
843 }
844
845 /***************************************/
846
847 void copya(int a, string format, ...)
848 {
849 va_list ap;
850 va_start(ap, format);
851
852 va_list ap2;
853 va_copy(ap2, ap);
854
855 auto a1 = va_arg!int(ap);
856 auto a2 = va_arg!int(ap);
857 auto a3 = va_arg!int(ap);
858
859 assert(a1 == 0x11111111);
860 assert(a2 == 0x22222222);
861 assert(a3 == 0x33333333);
862
863 auto b1 = va_arg!int(ap2);
864 auto b2 = va_arg!int(ap2);
865 auto b3 = va_arg!int(ap2);
866
867 assert(b1 == 0x11111111);
868 assert(b2 == 0x22222222);
869 assert(b3 == 0x33333333);
870
871 va_end(ap);
872 va_end(ap2);
873 }
874
875 void testCopy()
876 {
877 copya(0, "", 0x11111111, 0x22222222, 0x33333333);
878 }
879
880 /***************************************/
881 // https://issues.dlang.org/show_bug.cgi?id=6700
882
883 template bug6700(TList ...) {
884 const int bug6700 = 2;
885 }
886 TypeTuple!(int, long) TT6700;
887
888 static assert(bug6700!( (TT6700[1..$]) )==2);
889
890 /***************************************/
891 // https://issues.dlang.org/show_bug.cgi?id=6966
892
893 template X6966(T...)
894 {
895 alias const(T[0]) X6966;
896 }
897 static assert(is(X6966!(int) == const(int)));
898 static assert(is(X6966!(int, 0) == const(int)));
899
900 /***************************************/
901 // https://issues.dlang.org/show_bug.cgi?id=7233
902
903 struct Foo7233 { int x, y; }
904 Foo7233[] front7233(Foo7233[][] a)
905 {
906 return a[0];
907 }
908
909 class Bar7233 { int x, y; }
910 Bar7233[] front7233(Bar7233[][] a)
911 {
912 return a[0];
913 }
914
915 void test7233()
916 {
917 Foo7233[][] b1 = [[Foo7233()]];
918 auto xy1 = b1.front7233[0].tupleof;
919
920 Bar7233[][] b2 = [[new Bar7233()]];
921 auto xy2 = b2.front7233[0].tupleof;
922 }
923
924 /***************************************/
925 // https://issues.dlang.org/show_bug.cgi?id=7263
926
927 template TypeTuple7263(T...){ alias T TypeTuple7263; }
928
929 struct tuple7263
930 {
931 TypeTuple7263!(int, int) field;
932 alias field this;
933 }
934
935 auto front7263(T)(ref T arr){ return arr[0]; }
936
937 void test7263()
938 {
939 auto bars = [tuple7263(0, 0), tuple7263(1, 1)];
940 auto spam1 = bars.front7263[1];
941 auto spam2 = bars.front7263[1..2];
942 }
943
944 /***************************************/
945 // https://issues.dlang.org/show_bug.cgi?id=8244
946
947 TypeTuple!(int,int)[] x8244;
948 static assert(is(typeof(x8244) == TypeTuple!(int, int)));
949
950 /***************************************/
951 // https://issues.dlang.org/show_bug.cgi?id=9017
952
953 template X9017(Args...)
954 {
955 static if(__traits(compiles, { enum e = Args; }))
956 enum e = Args;
957 }
958 alias X9017!0 x9017;
959 static assert(x9017.e[0] == 0);
960
961 void test9017()
962 {
963 enum tup1 = TypeTuple!(11, 22);
964 enum tup2 = TypeTuple!("one", "two");
965 static assert(tup1 == TypeTuple!(11, 22));
966 static assert(tup2 == TypeTuple!("one", "two"));
967 static assert(tup1[0] == 11 && tup1[1] == 22);
968 static assert(tup2[0] == "one" && tup2[1] == "two");
969
970 shared const tup3 = TypeTuple!(10, 3.14);
971 immutable tup4 = TypeTuple!("a", [1,2]);
972 static assert(is(typeof(tup3[0]) == shared const int));
973 static assert(is(typeof(tup3[1]) == shared const double));
974 static assert(is(typeof(tup4[0]) == immutable string));
975 static assert(is(typeof(tup4[1]) == immutable int[]));
976 }
977
978 /***************************************/
979 // https://issues.dlang.org/show_bug.cgi?id=10279
980
981 void foo10279(int[][] strs...) @trusted { }
982 void bar10279() @safe { foo10279(); }
983
984 /***************************************/
985 // https://issues.dlang.org/show_bug.cgi?id=13508
986
987 struct S13508
988 {
989 this(T)(T[] t...) {}
990 }
991
992 template make13508(T)
993 {
994 T make13508(Args...)(Args args)
995 {
996 return T(args);
997 }
998 }
999
1000 void test13508() @safe @nogc
1001 {
1002 S13508 s = make13508!S13508(5);
1003 }
1004
1005 /***************************************/
1006 // https://issues.dlang.org/show_bug.cgi?id=14395
1007
1008 int v2u14395(uint[1] ar...)
1009 {
1010 return ar[0];
1011 }
1012
1013 void print14395(int size = v2u14395(7))
1014 {
1015 assert(size == 7);
1016 }
1017
1018 void test14395()
1019 {
1020 print14395();
1021 }
1022
1023 /***************************************/
1024 // https://issues.dlang.org/show_bug.cgi?id=10414
1025
1026 void foo10414(void delegate()[] ...) { }
1027
1028 void bar10414() { }
1029
1030 void test10414()
1031 {
1032 foo10414
1033 (
1034 { bar10414(); },
1035 { bar10414(); },
1036 );
1037 }
1038
1039 /***************************************/
1040
1041 import core.stdc.stdarg;
1042
1043 struct S14179
1044 {
1045 const(char)* filename;
1046 uint linnum;
1047 uint charnum;
1048 }
1049
1050 extern(C++) const(char)* func14179(S14179 x, const(char)* string, ...)
1051 {
1052 return string;
1053 }
1054
1055 void test14179()
1056 {
1057 const(char)* s = "hello";
1058 assert(func14179(S14179(), s) == s);
1059 }
1060
1061 /***************************************/
1062 // https://issues.dlang.org/show_bug.cgi?id=10722
1063
1064 struct S10722
1065 {
1066 int x;
1067 }
1068
1069 template GetSomething10722(S...)
1070 {
1071 alias GetSomething = int;
1072 }
1073
1074 void test10722()
1075 {
1076 alias X10722 = GetSomething10722!(S10722.tupleof[0]);
1077 }
1078
1079 /***************************************/
1080
1081 void testx15417(ulong c1, ...)
1082 {
1083 check(c1, _argptr, _arguments);
1084 }
1085
1086 class C15417
1087 {
1088 private void method ()
1089 {
1090 void test1 (ulong c1, ...)
1091 {
1092 check(c1, _argptr, _arguments);
1093 }
1094
1095 void test2 (ulong c1, ...)
1096 {
1097 va_list ap;
1098 va_start(ap, c1);
1099
1100 check(c1, ap, _arguments);
1101 }
1102
1103 testx15417(4242UL, char.init);
1104 test1(4242UL, char.init);
1105 test2(4242UL, char.init);
1106 }
1107 }
1108
1109 void check (ulong c1, va_list arglist, TypeInfo[] ti)
1110 {
1111 assert(ti.length == 1);
1112 assert(ti[0].toString() == "char");
1113 assert(char.init == va_arg!(char)(arglist));
1114 }
1115
1116 void test15417()
1117 {
1118 auto c = new C15417;
1119 c.method;
1120 }
1121
1122
1123 /***************************************/
1124 // https://issues.dlang.org/show_bug.cgi?id=21425
1125
1126 import core.stdc.stdarg;
1127 import core.stdc.stdio;
1128
1129 extern(C) void f5(int dummy, ...)
1130 {
1131 va_list ap;
1132
1133 va_start(ap, dummy);
1134 int x = va_arg!int(ap);
1135 assert(x == 5);
1136 va_end(ap);
1137
1138 va_start(ap, dummy);
1139 int y = va_arg!int(ap);
1140 assert(y == 5);
1141 va_end(ap);
1142 }
1143
1144 void test21425()
1145 {
1146 f5(0, 5);
1147 }
1148
1149 /*********************************************/
1150 // https://issues.dlang.org/show_bug.cgi?id=23409
1151
1152 import core.stdc.string;
1153
1154 void printf10(const(char)* fmt, ...){
1155 char[30] s;
1156 for(int i = 0; i < 10; i++){
1157 va_list args;
1158 va_start(args, fmt);
1159 vsprintf(s.ptr, fmt, args);
1160 va_end(args);
1161 assert(strcmp(s.ptr, "Hello world\n") == 0);
1162 }
1163 }
1164
1165 void test23409()
1166 {
1167 printf10("Hello %s\n".ptr, "world".ptr);
1168 }
1169
1170 /***************************************/
1171
1172 int main()
1173 {
1174 test1();
1175 test2();
1176 test3();
1177 test4();
1178 test12();
1179 test13();
1180 test14();
1181 test24();
1182 test28();
1183 test32();
1184 test34();
1185 test35();
1186 test36();
1187 test37();
1188 test38();
1189 test39();
1190 test45();
1191 test46();
1192 test47();
1193 test48();
1194 test49();
1195 test51();
1196 test55();
1197 test56();
1198 test57();
1199 test58();
1200 test59();
1201 test60();
1202 test61();
1203 test63();
1204 test1411();
1205 test4444();
1206 test13864();
1207 test4884();
1208 test4920();
1209 test4940();
1210 test4940add();
1211 test6530();
1212 test7233();
1213 test7263();
1214 test9017();
1215 test14395();
1216 test10414();
1217 test9495();
1218 testCopy();
1219 test14179();
1220 test15417();
1221 test21425();
1222 test23409();
1223
1224 return 0;
1225 }