d: Merge upstream dmd, druntime 26f049fb26, phobos 330d6a4fd.
[official-gcc.git] / gcc / testsuite / gdc.test / compilable / testfwdref.d
blobd5ad5fa3894e2e9b6a222570a5f125f415e5e4f0
1 // PERMUTE_ARGS:
2 // EXTRA_FILES: imports/fwdref9514.d imports/fwdref12201a.d
4 /***************************************************/
5 // https://issues.dlang.org/show_bug.cgi?id=6766
7 class Foo6766
9 this(int x) { }
10 void test(Foo6766 foo = new Foo6766(1)) { }
13 struct Bar6766
15 this(int x) { }
16 void test(Bar6766 bar = Bar6766(1)) { }
19 /***************************************************/
20 // https://issues.dlang.org/show_bug.cgi?id=8609
22 struct Tuple8609(T)
24 T arg;
27 // ----
29 struct Foo8609a
31 Bar8609a b;
33 struct Bar8609a
35 int x;
36 Tuple8609!(Foo8609a) spam() { return Tuple8609!(Foo8609a)(); }
39 // ----
41 struct Foo8609b
43 Bar8609b b;
45 struct Bar8609b
47 int x;
48 Tuple8609!(Foo8609b[1]) spam() { return Tuple8609!(Foo8609b[1])(); }
51 /***************************************************/
52 // https://issues.dlang.org/show_bug.cgi?id=8698
54 interface IRoot8698a {}
55 interface IClass8698a : IRoot8698a { }
56 struct Struct8698a { }
57 class Class8698a : IClass8698a { alias Struct8698a Value; }
58 void test8698a(Class8698a.Value) { }
59 //interface IRoot8698a {}
61 // ----
63 //interface IRoot8698b {}
64 interface IClass8698b : IRoot8698b { }
65 struct Struct8698b { }
66 class Class8698b : IClass8698b { alias Struct8698b Value; }
67 void test8698b(Class8698b.Value) { }
68 interface IRoot8698b {}
70 /***************************************************/
71 // https://issues.dlang.org/show_bug.cgi?id=9514
73 template TStructHelpers9514a()
75 void opEquals(Foo9514a)
77 auto n = FieldNames9514a!();
81 struct Foo9514a
83 mixin TStructHelpers9514a!();
86 import imports.fwdref9514 : find9514; // selective import without aliasing
88 template FieldNames9514a()
90 static if (find9514!`true`([1])) enum int FieldNames9514a = 1;
93 // ----
95 template TStructHelpers9514b()
97 void opEquals(Foo9514b)
99 auto n = FieldNames9514b!();
103 struct Foo9514b
105 mixin TStructHelpers9514b!();
108 import imports.fwdref9514 : foo9514 = find9514; // selective import with aliasing
110 template FieldNames9514b()
112 static if (foo9514!`true`([1])) enum int FieldNames9514b = 1;
115 /***************************************************/
116 // https://issues.dlang.org/show_bug.cgi?id=10015
118 struct S10015(T) { alias X = int; }
120 alias Y10015 = s10015.X;
121 S10015!int s10015;
123 /***************************************************/
124 // https://issues.dlang.org/show_bug.cgi?id=10101
126 int front10101(int);
128 mixin template reflectRange10101()
130 static if (is(typeof(this.front10101)))
132 int x;
136 struct S10101(R)
138 R r_;
140 typeof(r_.front10101) front10101() @property { return r_.front10101; }
142 mixin reflectRange10101;
145 void test10101()
147 S10101!(int) s;
150 /***************************************************/
151 // https://issues.dlang.org/show_bug.cgi?id=11019
153 class A11019
155 A11019 View() { return null; }
158 class B11019 : A11019
160 override D11019 View() { return null; }
163 class D11019 : B11019 {}
165 /***************************************************/
166 // https://issues.dlang.org/show_bug.cgi?id=11166
168 template Tup11166(T...) { alias Tup11166 = T; }
170 struct S11166a
172 enum S11166a a = S11166a(0);
173 enum S11166a b = S11166a(1);
175 this(long value) { }
177 long value;
179 // only triggered when private and a template instance.
180 private alias types = Tup11166!(a, b);
183 struct S11166b
185 enum S11166b a = S11166b(0);
186 enum S11166b b = S11166b(1);
188 // not at the last of members
189 alias types = Tup11166!(a, b);
191 this(long value) { }
193 long value;
196 /***************************************************/
197 // https://issues.dlang.org/show_bug.cgi?id=12152
199 class A12152
201 alias Y = B12152.X;
204 class B12152 : A12152
206 alias int X;
209 static assert(is(A12152.Y == int));
211 /***************************************************/
212 // https://issues.dlang.org/show_bug.cgi?id=12201
214 template T12201()
216 alias imports.fwdref12201a.FILE* FP;
219 struct S12201a
221 mixin T12201;
222 import imports.fwdref12201a;
225 union U12201
227 mixin T12201;
228 import imports.fwdref12201a;
231 class C12201
233 mixin T12201;
234 import imports.fwdref12201a;
237 interface I12201
239 mixin T12201;
240 import imports.fwdref12201a;
244 template TI12201()
246 mixin T12201;
247 import imports.fwdref12201a;
249 mixin template TM12201()
251 mixin T12201;
252 import imports.fwdref12201a;
254 struct S12201b
256 alias ti = TI12201!();
258 mixin TM12201;
261 /***************************************************/
262 // https://issues.dlang.org/show_bug.cgi?id=12531
264 struct Node12531(T)
266 T _val;
269 void test12531()
271 static struct Foo
273 Node12531!Foo* node;
277 /***************************************************/
278 // https://issues.dlang.org/show_bug.cgi?id=12543
280 class C12543;
281 static assert(C12543.sizeof == (void*).sizeof);
282 static assert(C12543.alignof == (void*).sizeof);
283 static assert(C12543.mangleof == "C10testfwdref6C12543");
285 /***************************************************/
286 // https://issues.dlang.org/show_bug.cgi?id=14010
288 enum E14010;
289 static assert(E14010.mangleof == "E10testfwdref6E14010");
291 struct S14010;
292 static assert(S14010.mangleof == "S10testfwdref6S14010");
294 /***************************************************/
295 // https://issues.dlang.org/show_bug.cgi?id=12983
297 alias I12983 = int;
298 class B12983(T) { alias MyC = C12983!string; }
300 class C12983(T) : B12983!float
302 void m() { f12983(0); }
305 alias MyB12983 = B12983!float;
307 void f12983();
308 void f12983(I12983);
310 /***************************************************/
311 // https://issues.dlang.org/show_bug.cgi?id=12984
313 class B12984a { alias MyD = D12984a!int; }
314 class C12984a : B12984a { }
316 class D12984a(T) { alias MyE = E12984a!float; }
317 class E12984a(T) : D12984a!int
319 void m()
321 auto c = new C12984a();
325 static assert(__traits(classInstanceSize, B12984a) == (void*).sizeof * 2);
326 static assert(__traits(classInstanceSize, C12984a) == (void*).sizeof * 2);
328 // ----
330 class B12984b { int b; alias MyD = D12984b!int; }
331 class C12984b : B12984b { int c; }
333 class D12984b(T) { int d; alias MyE = E12984b!float; }
334 class E12984b(T) : D12984b!int
336 int e;
337 void m()
339 auto c = new C12984b();
343 static assert(__traits(classInstanceSize, B12984b) == (void*).sizeof * 2 + int.sizeof);
344 static assert(__traits(classInstanceSize, C12984b) == (void*).sizeof * 2 + int.sizeof * 2);
346 /***************************************************/
347 // https://issues.dlang.org/show_bug.cgi?id=14390
349 class B14390a { alias MyD = D14390a!int; }
350 class C14390a : B14390a { void f(int) {} }
351 class D14390a(T) { alias MyE = E14390a!float; }
352 class E14390a(T) : D14390a!int { void m() { auto c = new C14390a(); } }
354 class B14390b { alias MyD = D14390b!int; }
355 class C14390b : B14390b { static struct S {} }
356 class D14390b(T) { alias MyE = E14390b!float; }
357 class E14390b(T) : D14390b!int { void m() { auto c = new C14390b(); } }
359 /***************************************************/
360 // https://issues.dlang.org/show_bug.cgi?id=13860
363 TEST_OUTPUT:
365 pure nothrow @nogc @safe void()
366 pure nothrow @nogc @safe void()
370 struct Foo13860(Bar...)
372 Bar bars;
373 auto baz(size_t d)() {}
374 pragma(msg, typeof(baz!0));
377 auto bar13860(S, R)(S s, R r)
379 pragma(msg, typeof(Foo13860!().baz!0));
382 void test13860()
384 int[] x;
385 int[] y;
386 x.bar13860(y);
389 /***************************************************/
390 // https://issues.dlang.org/show_bug.cgi?id=14083
392 class NBase14083
394 int foo(NA14083 a) { return 1; }
395 int foo(NB14083 a) { return 2; }
397 class NA14083 : NBase14083
399 int v;
400 this(int v) { this.v = v; }
402 class NB14083 : NBase14083
404 override int foo(NA14083 a) { return a.v; }
407 class TBase14083(T)
409 int foo(TA14083!T a) { return 1; }
410 int foo(TB14083!T a) { return 2; }
412 class TA14083(T) : TBase14083!T
414 T v;
415 this(T v) { this.v = v; }
417 class TB14083(T) : TBase14083!T
419 override int foo(TA14083!T a) { return a.v; }
422 static assert(
424 NA14083 na = new NA14083(10);
425 NB14083 nb = new NB14083();
426 assert(na.foo(na) == 1);
427 assert(na.foo(nb) == 2);
428 assert(nb.foo(na) == 10);
430 TA14083!int ta = new TA14083!int(10);
431 TB14083!int tb = new TB14083!int();
432 assert(ta.foo(ta) == 1);
433 assert(ta.foo(tb) == 2);
434 assert(tb.foo(ta) == 10);
436 return true;
437 }());
439 /***************************************************/
440 // https://issues.dlang.org/show_bug.cgi?id=14549
442 string foo14549(T)()
444 static if (T.tupleof.length >= 0)
445 return "";
448 class Frop14549
450 mixin(foo14549!(typeof(this)));
452 static if (__traits(compiles, undefined))
455 else
457 int bar = 0;
460 static if (!__traits(isVirtualMethod, this.bar)) {}
463 // ----
464 // regression case
466 template Mix14549()
468 mixin(code14549!(typeof(this)));
471 template code14549(T)
473 enum string code14549 =
474 q{ static if (!__traits(isVirtualMethod, "boo")) {} };
477 class Bar14549
479 mixin Mix14549;
480 int boo;
483 // ----
484 // https://issues.dlang.org/show_bug.cgi?id=14609
485 // regression case
487 interface Foo14609(T)
489 static if (is(T == int))
490 public int bar();
492 class Frop14609 : Foo14609!int
494 public int bar() { return 0; }
497 /***************************************************/
498 // test case 1, comes from Phobos
500 TEST_OUTPUT:
502 +alias Alias12540
503 +anySatisfy, T.length == 1
504 +isStaticArray
505 +T.stringof in StaticArrayTypeOf
506 -T.stringof in StaticArrayTypeOf
507 -isStaticArray
508 +hasElaborateCpCtor S == struct or else
509 -hasElaborateCpCtor S == struct or else
510 -anySatisfy, T.length == 1
511 -alias Alias12540
515 template anySatisfy15726x(alias F, T...)
517 //static if (T.length == 1)
519 pragma(msg, "+anySatisfy, T.length == 1");
520 enum anySatisfy15726x = F!(T[0]);
521 pragma(msg, "-anySatisfy, T.length == 1");
525 template StaticArrayTypeOf15726x(T)
527 alias X = T;
529 static if (is(X : E[n], E, size_t n))
531 //alias StaticArrayTypeOf15726x = X;
533 else
535 pragma(msg, "+T.stringof in StaticArrayTypeOf");
536 // Fixed: T.stringof (T == Class12540) should not invoke
537 // T.size() in ClassDeclaration.search().
538 static assert(0, T.stringof~" is not a static array type");
539 pragma(msg, "-T.stringof in StaticArrayTypeOf");
543 //enum bool isStaticArray(T) = is(StaticArrayTypeOf15726x!T);
544 template isStaticArray15726x(T)
546 pragma(msg, "+isStaticArray");
547 enum bool isStaticArray15726x = is(StaticArrayTypeOf15726x!T);
548 pragma(msg, "-isStaticArray");
551 template hasElaborateCpCtor15726x(S)
553 static if (isStaticArray15726x!S && S.length)
555 //pragma(msg, "X+");
556 enum bool hasElaborateCpCtor15726x =
557 hasElaborateCpCtor15726x!(typeof(S.init[0]));
558 //pragma(msg, "X-");
560 else
562 pragma(msg, "+hasElaborateCpCtor S == struct or else");
563 static if (is(S == struct))
565 enum bool hasElaborateCpCtor15726x = true;
566 //enum hasElaborateCpCtor15726x = hasMember!(S, "__postblit")
567 // || anySatisfy15726x!(.hasElaborateCpCtor15726x, FieldTypeTuple!S);
569 else
571 enum bool hasElaborateCpCtor15726x = false;
573 pragma(msg, "-hasElaborateCpCtor S == struct or else");
577 struct VariantN15726x(AllowedTypesParam...)
579 alias AllowedTypes = AllowedTypesParam;
581 static if (!AllowedTypes.length ||
582 anySatisfy15726x!(hasElaborateCpCtor15726x, AllowedTypes))
587 template Algebraic15726x(T)
589 alias Algebraic15726x = VariantN15726x!(T);
592 void test15726x()
594 static struct DummyScope
596 pragma(msg, "+alias Alias12540");
597 alias Alias12540 = Algebraic15726x!Class12540;
598 pragma(msg, "-alias Alias12540");
599 static class Class12540
601 Alias12540 entity;
606 /***************************************************/
607 // test case 2, comes from Phobos
609 struct RefCounted15726y(T)
611 struct RefCountedStore
613 struct Impl
615 T _payload;
617 Impl* _store;
619 RefCountedStore _refCounted;
621 this(this) {}
623 ~this()
625 _refCounted._store._payload.__xdtor();
629 struct RangeT15726y(A)
631 A[1] _outer_;
632 alias RC = RangeT15726y!(const(A));
635 struct Array15726y(T)
637 struct Payload
639 ~this();
642 alias Data = RefCounted15726y!(Payload);
643 Data _data;
645 alias Range = RangeT15726y!Array15726y;
648 void test15726y()
650 alias Range = RangeT15726y!(Array15726y!int);
651 Range r;
652 r = r; // opAssign
655 /***************************************************/
656 // https://issues.dlang.org/show_bug.cgi?id=15726
658 struct RC15726(T)
660 struct Impl
662 T _payload;
665 Impl* _store;
667 ~this()
669 destroy15726a(_store._payload);
673 // ----
675 struct Con15726a(T)
677 alias Stmt15726a = .Stmt15726a!T;
680 struct Stmt15726a(T)
682 alias Con15726a = .Con15726a!T;
684 RC15726!Payload data;
686 struct Payload
688 Con15726a con;
692 Con15726a!int x15726a;
694 void destroy15726a(T)(ref T obj) @trusted
696 auto buf = (cast(ubyte*)&obj)[0 .. T.sizeof];
699 // ----
701 struct Util15726b(C, S) {}
703 struct Con15726b(T)
705 alias Util15726b = .Util15726b!(Con15726b!T, Stmt15726b!T);
708 struct Stmt15726b(T)
710 struct Payload
712 Con15726b!T con;
715 RC15726!Payload data;
718 Con15726b!int x15726b;