| 1 |
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94777 |
| 2 |
// { dg-additional-options "-fmain -funittest" } |
| 3 |
// { dg-do run } |
| 4 |
// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } |
| 5 |
|
| 6 |
void testVariadic(T)(int nargs, ...) |
| 7 |
{ |
| 8 |
import core.stdc.stdarg; |
| 9 |
foreach(i; 0 .. nargs) |
| 10 |
{ |
| 11 |
auto arg = va_arg!T(_argptr); |
| 12 |
static if (__traits(compiles, arg.value)) |
| 13 |
{ |
| 14 |
assert(arg.value == i); |
| 15 |
} |
| 16 |
else static if (__traits(compiles, arg[0])) |
| 17 |
{ |
| 18 |
foreach (value; arg) |
| 19 |
assert(value == i); |
| 20 |
} |
| 21 |
else |
| 22 |
{ |
| 23 |
assert(arg == T.init); |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
/******************************************/ |
| 29 |
|
| 30 |
struct Destructor |
| 31 |
{ |
| 32 |
static int count = 0; |
| 33 |
int value; |
| 34 |
~this() { count++; } |
| 35 |
} |
| 36 |
|
| 37 |
unittest |
| 38 |
{ |
| 39 |
{ |
| 40 |
auto a0 = Destructor(0); |
| 41 |
auto a1 = Destructor(1); |
| 42 |
auto a2 = Destructor(2); |
| 43 |
static assert(!__traits(compiles, testVariadic!Destructor(3, a0, a1, a2))); |
| 44 |
} |
| 45 |
assert(Destructor.count == 3); |
| 46 |
} |