summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.dg/pr94777c.d
blob: 9b725c052c37c4ed930505b313b379d0a4fce7dd (plain)
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
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94777
// { dg-additional-options "-funittest" }
// { dg-do compile }

void testVariadic(T)(int nargs, ...)
{
    import core.stdc.stdarg;
    foreach(i; 0 .. nargs)
    {
        auto arg = va_arg!T(_argptr);
        static if (__traits(compiles, arg.value))
        {
            assert(arg.value == i);
        }
        else static if (__traits(compiles, arg[0]))
        {
            foreach (value; arg)
                assert(value == i);
        }
        else
        {
            assert(arg == T.init);
        }
    }
}

/******************************************/

struct Postblit
{
    static int count = 0;
    int value;
    this(this) { count++; }
}

unittest
{
    auto a0 = Postblit(0);
    auto a1 = Postblit(1);
    auto a2 = Postblit(2);
    testVariadic!Postblit(3, a0, a1, a2); // { dg-error "cannot pass types with postblits or copy constructors as variadic arguments" }
    assert(Postblit.count == 3);
}

/******************************************/

struct CopyConstructor 
{
    static int count = 0;
    int value;
    this(int v) { this.value = v; }
    this(ref typeof(this) other) { count++; this.value = other.value; }
}

unittest
{
    auto a0 = CopyConstructor(0);
    auto a1 = CopyConstructor(1);
    auto a2 = CopyConstructor(2);
    testVariadic!CopyConstructor(3, a0, a1, a2); // { dg-error "cannot pass types with postblits or copy constructors as variadic arguments" }
    assert(CopyConstructor.count == 3);
}