| 1 |
|
| 2 |
extern(C) int printf(const char*, ...); |
| 3 |
|
| 4 |
/*********************************************************/ |
| 5 |
|
| 6 |
int sum(int[] xx ...) |
| 7 |
{ |
| 8 |
int s; |
| 9 |
|
| 10 |
foreach (int x; xx) |
| 11 |
s += x; |
| 12 |
return s; |
| 13 |
} |
| 14 |
|
| 15 |
void test1() |
| 16 |
{ |
| 17 |
static int[3] a = [5, 8, 10]; |
| 18 |
int[] b = a; |
| 19 |
int i; |
| 20 |
|
| 21 |
i = sum(); |
| 22 |
assert(i == 0); |
| 23 |
i = sum(10); |
| 24 |
assert(i == 10); |
| 25 |
i = sum(10, 20); |
| 26 |
assert(i == 30); |
| 27 |
i = sum(11, 22, 34); |
| 28 |
assert(i == 67); |
| 29 |
i = sum(a); |
| 30 |
assert(i == 23); |
| 31 |
i = sum(b); |
| 32 |
assert(i == 23); |
| 33 |
printf("%d\n", sum()); |
| 34 |
} |
| 35 |
|
| 36 |
/*********************************************************/ |
| 37 |
|
| 38 |
int sum2(int[3] xx ...) |
| 39 |
{ |
| 40 |
int s; |
| 41 |
|
| 42 |
foreach (int x; xx) |
| 43 |
s += x; |
| 44 |
return s; |
| 45 |
} |
| 46 |
|
| 47 |
void test2() |
| 48 |
{ |
| 49 |
static int[3] a = [5, 8, 10]; |
| 50 |
int i; |
| 51 |
|
| 52 |
i = sum2(11, 22, 34); |
| 53 |
assert(i == 67); |
| 54 |
i = sum2(a); |
| 55 |
assert(i == 23); |
| 56 |
printf("%d\n", i); |
| 57 |
} |
| 58 |
|
| 59 |
/*********************************************************/ |
| 60 |
|
| 61 |
int[4] bb3 = [5,6,7,8]; |
| 62 |
|
| 63 |
int sum3(int[] xx = bb3 ...) |
| 64 |
{ |
| 65 |
int s; |
| 66 |
|
| 67 |
foreach (int x; xx) |
| 68 |
s += x; |
| 69 |
return s; |
| 70 |
} |
| 71 |
|
| 72 |
void test3() |
| 73 |
{ |
| 74 |
static int[3] a = [5, 8, 10]; |
| 75 |
int i; |
| 76 |
|
| 77 |
i = sum3(11, 22, 34); |
| 78 |
assert(i == 67); |
| 79 |
i = sum3(a); |
| 80 |
assert(i == 23); |
| 81 |
i = sum3(); |
| 82 |
assert(i == 26); |
| 83 |
printf("%d\n", i); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
/*********************************************************/ |
| 88 |
|
| 89 |
|
| 90 |
void bug1993(int[][] y...) |
| 91 |
{ |
| 92 |
} |
| 93 |
void test5() |
| 94 |
{ |
| 95 |
bug1993(null); |
| 96 |
bug1993(null, null); |
| 97 |
bug1993([0], null); |
| 98 |
bug1993([0], [0]); |
| 99 |
bug1993(null, [0]); |
| 100 |
} |
| 101 |
|
| 102 |
/*********************************************************/ |
| 103 |
|
| 104 |
int main() |
| 105 |
{ |
| 106 |
test1(); |
| 107 |
test2(); |
| 108 |
test3(); |
| 109 |
test5(); |
| 110 |
|
| 111 |
printf("Success\n"); |
| 112 |
return 0; |
| 113 |
} |