summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/runnable/warning1.d
blob: 537088e97cc3261b581830459a6951b5f1c7b982 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// REQUIRED_ARGS: -w
// PERMUTE_ARGS:

extern(C) int printf(const char*, ...);

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

class F { }
int foo()
{
    scope F f = new F(); // comment out and warning goes away
    return 0;
}

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

int foo2()
{
    try
    {
        return 0;
    }
    finally { }
}

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

private int getNthInt(A...)(uint index, A args)
{
    foreach (i, arg; args)
    {
        static if (is(typeof(arg) : long) || is(typeof(arg) : ulong))
        {
            if (i != index) continue;
            return cast(int)(arg);
        }
        else
        {
            if (i == index) break;
        }
    }
    throw new Error("int expected");
}

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

class Foo2 {
    int foo() {
        synchronized(this){
            return 8;
        }
    }
}

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

void mainX()
{
    int i=0;
    printf("This number is zero: ");
    goto inloop;
    for(; i<10; i++) {              // this is line 7
        printf("This number is nonzero: ");
inloop:
        printf("%d\n", i);
    }
}

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

string foo3(int bar)
{
    switch (bar)
    {
        case 1:
            return "1";
        case 2:
            return "2";
        default:
            return "3";
    }
}


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

int foo4()
{
    int i;
    for (;; ++i)
    {
        if (i == 10) return 0;
    }
}

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

int foo5()
{
    do {
        if (false)
            return 1;
    } while (true);
}

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

nothrow int foo6()
{
    int x = 2;
    try
    {
    }
    catch(Exception e)
    {
        x = 4;
        throw new Exception("xxx");
    }
    return x;
}

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

template TypeTuple(T...) { alias T TypeTuple; }
void test6518()
{
    switch(2)
    {
        foreach(v; TypeTuple!(1, 2, 3))
            case v: break;
        default: assert(0);
    }
}

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

bool test7232()
{
    scope(failure) return false;
    return true;
}

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

struct S9332
{
    this(S9332)
    {
//      while (1) { }
        assert(0, "unreachable?");
    }
}

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

class C13201
{
    void foo()
    {
        synchronized(this)
        {
            assert(0);
        }
    }
}

void test13201a()
{
    auto c = new C13201();
    synchronized(c)
    {
        assert(0);
    }
}

void test13201b()
{
    struct S { ~this() {} }

    S s;
    assert(0);
}

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

void main()
{
}