| 1 |
/* |
| 2 |
RUN_OUTPUT: |
| 3 |
--- |
| 4 |
Success |
| 5 |
--- |
| 6 |
*/ |
| 7 |
import core.stdc.stdio : printf; |
| 8 |
|
| 9 |
//------------------------------------------------------------------------------ |
| 10 |
|
| 11 |
T enforce7452(T, string file = __FILE__, size_t line = __LINE__) |
| 12 |
(T value, lazy const(char)[] msg = null) @safe pure |
| 13 |
{ |
| 14 |
if (!value) |
| 15 |
throw new Exception(msg ? msg.idup : "Enforcement failed", file, line); |
| 16 |
return value; |
| 17 |
} |
| 18 |
|
| 19 |
int f7452()(int x) |
| 20 |
{ |
| 21 |
enforce7452(x > 0); |
| 22 |
return x; |
| 23 |
} |
| 24 |
void g7452() @safe pure |
| 25 |
{ |
| 26 |
assert(4 == f7452(4)); |
| 27 |
} |
| 28 |
|
| 29 |
//------------------------------------------------------------------------------ |
| 30 |
|
| 31 |
void e7452b(int, lazy int) pure nothrow @safe {} |
| 32 |
int f7452b()(int x) |
| 33 |
{ |
| 34 |
e7452b(x, 0); |
| 35 |
return x; |
| 36 |
} |
| 37 |
void g7452b() pure nothrow @safe |
| 38 |
{ |
| 39 |
assert(4 == f7452b(4)); |
| 40 |
} |
| 41 |
|
| 42 |
//------------------------------------------------------------------------------ |
| 43 |
|
| 44 |
int f7452c()(int x) |
| 45 |
{ |
| 46 |
auto y = function int() { return 0; }; |
| 47 |
return x; |
| 48 |
} |
| 49 |
void g7452c() pure nothrow @safe |
| 50 |
{ |
| 51 |
assert(4 == f7452c(4)); |
| 52 |
} |
| 53 |
|
| 54 |
//------------------------------------------------------------------------------ |
| 55 |
|
| 56 |
auto f6332a()() { return 1; } |
| 57 |
int f6332b()() { return 1; } |
| 58 |
|
| 59 |
alias f6332a!() F6332a; |
| 60 |
|
| 61 |
void g6332() pure nothrow @safe |
| 62 |
{ |
| 63 |
auto x = f6332b(); |
| 64 |
auto y = f6332a(); |
| 65 |
assert(x == y); |
| 66 |
} |
| 67 |
|
| 68 |
//------------------------------------------------------------------------------ |
| 69 |
|
| 70 |
int main() |
| 71 |
{ |
| 72 |
g7452(); |
| 73 |
g7452b(); |
| 74 |
g7452c(); |
| 75 |
g6332(); |
| 76 |
|
| 77 |
printf("Success\n"); |
| 78 |
return 0; |
| 79 |
} |