aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/runnable/staticforeach.d
blob: 6a9ac5deb2f8ed3f6fdcf5b25f8db5d7d7382e79 (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
// REQUIRED_ARGS:

/**********************************/
// https://issues.dlang.org/show_bug.cgi?id=19479

mixin template genInts19479a()
{
    static foreach (t; 0..1)
        int i = 5;
}

mixin template genInts19479b()
{
    static foreach (t; 0..2)
        mixin("int i" ~ cast(char)('0' + t) ~ " = 5;");
}

void test19479()
{
    {
        static foreach (t; 0..1)
            int i = 5;
        assert(i == 5);
    }
    {
        mixin genInts19479a!();
        assert(i == 5);
    }
    {
        static foreach (t; 0..2)
            mixin("int i" ~ cast(char)('0' + t) ~ " = 5;");
        assert(i0 == 5);
        assert(i1 == 5);
    }
    {
        mixin genInts19479b!();
        assert(i0 == 5);
        assert(i1 == 5);
    }
}

/**********************************/
// https://issues.dlang.org/show_bug.cgi?id=23192

alias AliasSeq(Args...) = Args;

struct S23192
{
    int x;
    int y;

    int fun()
    {
        static foreach (sym; AliasSeq!(S23192.x))
            int i = sym;

        static foreach (sym; AliasSeq!(this.y))
            int j = sym;

        return i + j;
    }
}

void test23192()
{
    assert(S23192(1, 2).fun() == 3);
    static assert(S23192(1, 2).fun() == 3);
}

void main()
{
    test19479();
    test23192();
}