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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
// REQUIRED_ARGS:
/*
TEST_OUTPUT:
---
foo1 ulong function(return ref int* delegate() return p) ref return
foo2 int function(return ref int delegate() p) ref
foo3 int function(ref inout(int*) p) ref
foo4 int function(return ref inout(int*) p) ref
---
*/
import core.stdc.stdio;
/********************************************/
struct SS
{
ref ulong foo1(return ref int* delegate() return p) return;
ref int foo2(return ref int delegate() p);
ref int foo3(inout ref int* p);
ref int foo4(return inout ref int* p);
}
pragma(msg, "foo1 ", typeof(&SS.foo1));
pragma(msg, "foo2 ", typeof(&SS.foo2));
pragma(msg, "foo3 ", typeof(&SS.foo3));
pragma(msg, "foo4 ", typeof(&SS.foo4));
void test3()
{
version (none)
{
import std.stdio;
writeln(SS.foo1.mangleof);
writeln(SS.foo2.mangleof);
writeln(SS.foo3.mangleof);
writeln(SS.foo4.mangleof);
writeln(typeof(SS.foo1).stringof);
writeln(typeof(SS.foo2).stringof);
writeln(typeof(SS.foo3).stringof);
writeln(typeof(SS.foo4).stringof);
}
version (all)
{
// Test scope mangling
assert(SS.foo1.mangleof == "_D10testscope22SS4foo1MFNcNjNkKDFNjZPiZm");
assert(SS.foo2.mangleof == "_D10testscope22SS4foo2MFNcNkKDFZiZi");
assert(SS.foo3.mangleof == "_D10testscope22SS4foo3MFNcKNgPiZi");
assert(SS.foo4.mangleof == "_D10testscope22SS4foo4MFNcNkKNgPiZi");
// Test scope pretty-printing
assert(typeof(SS.foo1).stringof == "ref ulong(return ref int* delegate() return p) return");
assert(typeof(SS.foo2).stringof == "ref int(return ref int delegate() p)");
assert(typeof(SS.foo3).stringof == "ref int(ref inout(int*) p)");
assert(typeof(SS.foo4).stringof == "ref int(return ref inout(int*) p)");
}
}
/********************************************/
ref int foo(return ref int x)
{
return x;
}
struct S
{
int x;
ref S bar() return
{
return this;
}
}
ref T foo2(T)(ref T x)
{
return x;
}
void test4()
{
int x;
foo2(x);
}
/********************************************/
ref int foo(return ref int x, ref int y)
{
return x;
}
ref int bar()
{
int x;
static int y = 7;
return foo(y, x);
}
void test5()
{
int x = bar();
assert(x == 7);
}
/********************************************/
struct S6
{
int x = 8;
ref int bar() return
{
return x;
}
}
void test6()
{
S6 s;
int b = s.bar();
assert(b == 8);
}
/********************************************/
class C
{
int x;
ref int foo(return ref int x) { return x; }
ref int bar() return { return x; }
}
class D : C
{
override ref int foo(ref int x) { static int y; return y; }
override ref int bar() { static int y; return y; }
}
void test7()
{
}
/********************************************/
struct S8(T)
{
int x;
ref int bar() // infer 'return'
{
return x;
}
}
ref int test8a(return ref S8!int s)
{
return s.bar();
}
void test8()
{
}
/********************************************/
char[] foo9(return out char[4] buf)
{
return buf[0 .. 1];
}
/********************************************/
struct S10
{
int x;
ref inout(int) foo() inout return
{
return x;
}
}
/********************************************/
struct RC
{
this(this) { }
}
struct S11
{
@disable this(this);
void remove()
{
_ptr[0] = _ptr[1];
}
RC* _ptr;
}
void test11()
{
S11 ary;
}
/********************************************/
int[10] a12;
int* foo12()
{
foreach (ref x; a12)
return &x;
return null;
}
/********************************************/
struct FullCaseEntry
{
dchar[3] seq;
ubyte n, size;// n number in batch, size - size of batch
ubyte entry_len;
@property auto value() const @trusted pure nothrow @nogc return
{
return seq[0..entry_len];
}
}
/********************************************/
class C12
{
void member() scope { }
}
/********************************************/
void main()
{
test3();
test4();
test5();
test6();
test7();
test8();
test11();
printf("Success\n");
}
|