aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/compilable/testexpression.d
blob: df491321d4821bc8824aab0a0b6e5d64d6529389 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

template TT(T...) { alias T TT; }

void TestOpAssign(Tx, Ux, ops)()
{
    foreach(T; Tx.x)
    foreach(U; Ux.x)
    foreach(op; ops.x)
    {
        T a = cast(T)1;
        mixin("a " ~ op ~ " cast(U)1;");
    }
}

void TestOpAssignAssign(Tx, Ux, ops)()
{
    foreach(T; Tx.x)
    foreach(U; Ux.x)
    foreach(op; ops.x)
    {
        T a = cast(T)1;
        U b = cast(U)1;
        T r;
        mixin("r = a " ~ op ~ " cast(U)1;");
    }
}

void TestOpAssignAuto(Tx, Ux, ops)()
{
    foreach(T; Tx.x)
    foreach(U; Ux.x)
    static if (U.sizeof <= T.sizeof)
    foreach(op; ops.x)
    {
        T a = cast(T)1;
        U b = cast(U)1;
        mixin("auto r = a " ~ op ~ " cast(U)1;");
    }
}

void TestOpAndAssign(Tx, Ux, ops)()
{
    foreach(T; Tx.x)
    foreach(U; Ux.x)
    static if (U.sizeof <= T.sizeof && T.sizeof >= 4)
    foreach(op; ops.x)
    {
        T a = cast(T)1;
        U b = cast(U)1;
        mixin("a = a " ~ op[0..$-1] ~ " cast(U)1;");
    }
}

struct boolean   { alias TT!(bool) x; }
struct integral  { alias TT!(byte, ubyte, short, ushort, int, uint, long, ulong) x; }
struct floating  { alias TT!(float, double, real) x; }

struct all       { alias TT!("+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>=", ">>>=") x; }
struct arith     { alias TT!("+=", "-=", "*=", "/=", "%=") x; }
struct bitwise   { alias TT!("&=", "|=", "^=") x; }
struct shift     { alias TT!("<<=", ">>=", ">>>=") x; }
struct addsub    { alias TT!("+=", "-=") x; }
struct muldivmod { alias TT!("*=", "/=", "%=") x; }
struct nomod     { alias TT!("+=", "-=", "*=", "/=") x; }

void OpAssignCases(alias X)()
{
    X!(boolean, boolean, bitwise)();

    X!(integral, boolean, all)();
    X!(integral, integral, all)();
    X!(integral, floating, arith)();

    X!(floating, boolean, arith)();
    X!(floating, integral, arith)();
    X!(floating, floating, arith)();
}

void OpReAssignCases(alias X)()
{
    X!(boolean, boolean, bitwise)();

    X!(integral, boolean, all)();
    X!(integral, integral, all)();

    X!(floating, boolean, arith)();
    X!(floating, integral, arith)();
    X!(floating, floating, arith)();
}

void main()
{
    OpAssignCases!TestOpAssign();
    OpAssignCases!TestOpAssignAssign(); // was once disabled due to bug 7436
    OpAssignCases!TestOpAssignAuto(); // https://issues.dlang.org/show_bug.cgi?id=5181
    OpReAssignCases!TestOpAndAssign();
}