| 1 |
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94777 |
| 2 |
// { dg-additional-options "-funittest" } |
| 3 |
// { dg-do compile } |
| 4 |
|
| 5 |
void testVariadic(T)(int nargs, ...) |
| 6 |
{ |
| 7 |
import core.stdc.stdarg; |
| 8 |
foreach(i; 0 .. nargs) |
| 9 |
{ |
| 10 |
auto arg = va_arg!T(_argptr); |
| 11 |
static if (__traits(compiles, arg.value)) |
| 12 |
{ |
| 13 |
assert(arg.value == i); |
| 14 |
} |
| 15 |
else static if (__traits(compiles, arg[0])) |
| 16 |
{ |
| 17 |
foreach (value; arg) |
| 18 |
assert(value == i); |
| 19 |
} |
| 20 |
else |
| 21 |
{ |
| 22 |
assert(arg == T.init); |
| 23 |
} |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
/******************************************/ |
| 28 |
|
| 29 |
struct Postblit |
| 30 |
{ |
| 31 |
static int count = 0; |
| 32 |
int value; |
| 33 |
this(this) { count++; } |
| 34 |
} |
| 35 |
|
| 36 |
unittest |
| 37 |
{ |
| 38 |
auto a0 = Postblit(0); |
| 39 |
auto a1 = Postblit(1); |
| 40 |
auto a2 = Postblit(2); |
| 41 |
testVariadic!Postblit(3, a0, a1, a2); // { dg-error "cannot pass types with postblits or copy constructors as variadic arguments" } |
| 42 |
assert(Postblit.count == 3); |
| 43 |
} |
| 44 |
|
| 45 |
/******************************************/ |
| 46 |
|
| 47 |
struct CopyConstructor |
| 48 |
{ |
| 49 |
static int count = 0; |
| 50 |
int value; |
| 51 |
this(int v) { this.value = v; } |
| 52 |
this(ref typeof(this) other) { count++; this.value = other.value; } |
| 53 |
} |
| 54 |
|
| 55 |
unittest |
| 56 |
{ |
| 57 |
auto a0 = CopyConstructor(0); |
| 58 |
auto a1 = CopyConstructor(1); |
| 59 |
auto a2 = CopyConstructor(2); |
| 60 |
testVariadic!CopyConstructor(3, a0, a1, a2); // { dg-error "cannot pass types with postblits or copy constructors as variadic arguments" } |
| 61 |
assert(CopyConstructor.count == 3); |
| 62 |
} |