| 1 |
/* |
| 2 |
REQUIRED_ARGS: -preview=rvaluerefparam |
| 3 |
PERMUTE_ARGS: |
| 4 |
EXTRA_FILES: imports/testmangle.d |
| 5 |
TEST_OUTPUT: |
| 6 |
--- |
| 7 |
func |
| 8 |
double |
| 9 |
All good 1 |
| 10 |
All good 2 |
| 11 |
All good 3 |
| 12 |
_D7imports10testmangle12detectMangleFPSQBlQBg6DetectZQq |
| 13 |
_D7imports10testmangle__T10DetectTmplTiZQpFNaNbNiNfZv |
| 14 |
true |
| 15 |
false |
| 16 |
uint |
| 17 |
int[] |
| 18 |
int[] |
| 19 |
const(K5886) |
| 20 |
4 ; const(K5886) |
| 21 |
8 ; const(K5886) |
| 22 |
K5886 |
| 23 |
immutable(K5886) |
| 24 |
4 ; K5886 |
| 25 |
4 ; immutable(K5886) |
| 26 |
1 ; K5886 |
| 27 |
2 ; const(K5886) |
| 28 |
3 ; immutable(K5886) |
| 29 |
8 ; K5886 |
| 30 |
9 ; const(K5886) |
| 31 |
10 ; immutable(K5886) |
| 32 |
> U = int, N:$?:64=ulong = 3LU|32=uint = 3u$ |
| 33 |
K=string, V=int |
| 34 |
K=char, V=string |
| 35 |
T = SA, E = int, dim = $?:64=5LU|32=5u$ |
| 36 |
T = DA, E = int |
| 37 |
T = AA, K = string, V = int |
| 38 |
pure nothrow @nogc @safe void(int t) |
| 39 |
pure nothrow @nogc @safe void(int t) |
| 40 |
T = byte |
| 41 |
T = char |
| 42 |
--- |
| 43 |
|
| 44 |
RUN_OUTPUT: |
| 45 |
--- |
| 46 |
typeof(T)=double typeof(S)=int |
| 47 |
typeof(T)=double typeof(S)=int |
| 48 |
typeof(T)=float typeof(S)=int |
| 49 |
Success |
| 50 |
--- |
| 51 |
*/ |
| 52 |
|
| 53 |
module breaker; |
| 54 |
|
| 55 |
import core.stdc.stdio, core.vararg; |
| 56 |
|
| 57 |
/**********************************/ |
| 58 |
|
| 59 |
U foo(T, U)(U i) |
| 60 |
{ |
| 61 |
return i + 1; |
| 62 |
} |
| 63 |
|
| 64 |
int foo(T)(int i) |
| 65 |
{ |
| 66 |
return i + 2; |
| 67 |
} |
| 68 |
|
| 69 |
void test1() |
| 70 |
{ |
| 71 |
auto i = foo!(int)(2L); |
| 72 |
// assert(i == 4); // now returns 3 |
| 73 |
} |
| 74 |
|
| 75 |
/**********************************/ |
| 76 |
|
| 77 |
U foo2(T, U)(U i) |
| 78 |
{ |
| 79 |
return i + 1; |
| 80 |
} |
| 81 |
|
| 82 |
void test2() |
| 83 |
{ |
| 84 |
auto i = foo2!(int)(2L); |
| 85 |
assert(i == 3); |
| 86 |
} |
| 87 |
|
| 88 |
/**********************************/ |
| 89 |
|
| 90 |
class Foo3 |
| 91 |
{ |
| 92 |
T bar(T,U)(U u) |
| 93 |
{ |
| 94 |
return cast(T)u; |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
void test3() |
| 99 |
{ |
| 100 |
Foo3 foo = new Foo3; |
| 101 |
int i = foo.bar!(int)(1.0); |
| 102 |
assert(i == 1); |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
/**********************************/ |
| 107 |
|
| 108 |
T* begin4(T)(T[] a) { return a.ptr; } |
| 109 |
|
| 110 |
void copy4(string pred = "", Ranges...)(Ranges rs) |
| 111 |
{ |
| 112 |
alias rs[$ - 1] target; |
| 113 |
pragma(msg, typeof(target).stringof); |
| 114 |
auto tb = begin4(target);//, te = end(target); |
| 115 |
} |
| 116 |
|
| 117 |
void test4() |
| 118 |
{ |
| 119 |
int[] a, b, c; |
| 120 |
copy4(a, b, c); |
| 121 |
// comment the following line to prevent compiler from crashing |
| 122 |
copy4!("a > 1")(a, b, c); |
| 123 |
} |
| 124 |
|
| 125 |
/**********************************/ |
| 126 |
|
| 127 |
template foo5(T,S) |
| 128 |
{ |
| 129 |
void foo5(T t, S s) { |
| 130 |
const tstr = typeid(T).toString(); |
| 131 |
const sstr = typeid(S).toString(); |
| 132 |
printf("typeof(T)=%.*s typeof(S)=%.*s\n", |
| 133 |
cast(int)tstr.length, tstr.ptr, cast(int)sstr.length, sstr.ptr); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
template bar5(T,S) |
| 138 |
{ |
| 139 |
void bar5(S s) { |
| 140 |
const tstr = typeid(T).toString(); |
| 141 |
const sstr = typeid(S).toString(); |
| 142 |
printf("typeof(T)=%.*s typeof(S)=%.*s\n", |
| 143 |
cast(int)tstr.length, tstr.ptr, cast(int)sstr.length, sstr.ptr); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
void test5() |
| 149 |
{ |
| 150 |
foo5(1.0,33); |
| 151 |
bar5!(double,int)(33); |
| 152 |
bar5!(float)(33); |
| 153 |
} |
| 154 |
|
| 155 |
/**********************************/ |
| 156 |
|
| 157 |
int foo6(T...)(auto ref T x) |
| 158 |
{ int result; |
| 159 |
|
| 160 |
foreach (i, v; x) |
| 161 |
{ |
| 162 |
if (v == 10) |
| 163 |
assert(__traits(isRef, x[i])); |
| 164 |
else |
| 165 |
assert(!__traits(isRef, x[i])); |
| 166 |
result += v; |
| 167 |
} |
| 168 |
return result; |
| 169 |
} |
| 170 |
|
| 171 |
void test6() |
| 172 |
{ int y = 10; |
| 173 |
int r; |
| 174 |
r = foo6(8); |
| 175 |
assert(r == 8); |
| 176 |
r = foo6(y); |
| 177 |
assert(r == 10); |
| 178 |
r = foo6(3, 4, y); |
| 179 |
assert(r == 17); |
| 180 |
r = foo6(4, 5, y); |
| 181 |
assert(r == 19); |
| 182 |
r = foo6(y, 6, y); |
| 183 |
assert(r == 26); |
| 184 |
} |
| 185 |
|
| 186 |
/**********************************/ |
| 187 |
|
| 188 |
auto ref min(T, U)(auto ref T lhs, auto ref U rhs) |
| 189 |
{ |
| 190 |
return lhs > rhs ? rhs : lhs; |
| 191 |
} |
| 192 |
|
| 193 |
void test7() |
| 194 |
{ int x = 7, y = 8; |
| 195 |
int i; |
| 196 |
|
| 197 |
i = min(4, 3); |
| 198 |
assert(i == 3); |
| 199 |
i = min(x, y); |
| 200 |
assert(i == 7); |
| 201 |
min(x, y) = 10; |
| 202 |
assert(x == 10); |
| 203 |
static assert(!__traits(compiles, min(3, y) = 10)); |
| 204 |
static assert(!__traits(compiles, min(y, 3) = 10)); |
| 205 |
} |
| 206 |
|
| 207 |
/**********************************/ |
| 208 |
// https://issues.dlang.org/show_bug.cgi?id=5946 |
| 209 |
|
| 210 |
template TTest8() |
| 211 |
{ |
| 212 |
int call(){ return this.g(); } |
| 213 |
} |
| 214 |
class CTest8 |
| 215 |
{ |
| 216 |
int f() { mixin TTest8!(); return call(); } |
| 217 |
int g() { return 10; } |
| 218 |
} |
| 219 |
void test8() |
| 220 |
{ |
| 221 |
assert((new CTest8()).f() == 10); |
| 222 |
} |
| 223 |
|
| 224 |
/**********************************/ |
| 225 |
// https://issues.dlang.org/show_bug.cgi?id=693 |
| 226 |
|
| 227 |
template TTest9(alias sym) |
| 228 |
{ |
| 229 |
int call(){ return sym.g(); } |
| 230 |
} |
| 231 |
class CTest9 |
| 232 |
{ |
| 233 |
int f1() { mixin TTest9!(this); return call(); } |
| 234 |
int f2() { mixin TTest9!this; return call(); } |
| 235 |
int g() { return 10; } |
| 236 |
} |
| 237 |
void test9() |
| 238 |
{ |
| 239 |
assert((new CTest9()).f1() == 10); |
| 240 |
assert((new CTest9()).f2() == 10); |
| 241 |
} |
| 242 |
|
| 243 |
/**********************************/ |
| 244 |
// https://issues.dlang.org/show_bug.cgi?id=1780 |
| 245 |
|
| 246 |
template Tuple1780(Ts ...) { alias Ts Tuple1780; } |
| 247 |
|
| 248 |
template Decode1780( T ) { alias Tuple1780!() Types; } |
| 249 |
template Decode1780( T : TT!(Us), alias TT, Us... ) { alias Us Types; } |
| 250 |
|
| 251 |
void test1780() |
| 252 |
{ |
| 253 |
struct S1780(T1, T2) {} |
| 254 |
|
| 255 |
// should extract tuple (bool,short) but matches the first specialisation |
| 256 |
alias Decode1780!( S1780!(bool,short) ).Types SQ1780; // --> SQ2 is empty tuple! |
| 257 |
static assert(is(SQ1780 == Tuple1780!(bool, short))); |
| 258 |
} |
| 259 |
|
| 260 |
/**********************************/ |
| 261 |
// https://issues.dlang.org/show_bug.cgi?id=1659 |
| 262 |
|
| 263 |
class Foo1659 { } |
| 264 |
class Bar1659 : Foo1659 { } |
| 265 |
|
| 266 |
void f1659(T : Foo1659)() { } |
| 267 |
void f1659(alias T)() { static assert(false); } |
| 268 |
|
| 269 |
void test1659() |
| 270 |
{ |
| 271 |
f1659!Bar1659(); |
| 272 |
} |
| 273 |
|
| 274 |
/**********************************/ |
| 275 |
// https://issues.dlang.org/show_bug.cgi?id=2025 |
| 276 |
|
| 277 |
struct S2025 {} |
| 278 |
void f2025() {} |
| 279 |
|
| 280 |
template Foo2025(int i) { enum Foo2025 = 1; } |
| 281 |
template Foo2025(TL...) { enum Foo2025 = 2; } |
| 282 |
static assert(Foo2025!1 == 1); |
| 283 |
static assert(Foo2025!int == 2); |
| 284 |
static assert(Foo2025!S2025 == 2); |
| 285 |
static assert(Foo2025!f2025 == 2); |
| 286 |
|
| 287 |
template Bar2025(T) { enum Bar2025 = 1; } |
| 288 |
template Bar2025(A...) { enum Bar2025 = 2; } |
| 289 |
static assert(Bar2025!1 == 2); |
| 290 |
static assert(Bar2025!int == 1); // 2 -> 1 |
| 291 |
static assert(Bar2025!S2025 == 1); // 2 -> 1 |
| 292 |
static assert(Bar2025!f2025 == 2); |
| 293 |
|
| 294 |
template Baz2025(T) { enum Baz2025 = 1; } |
| 295 |
template Baz2025(alias A) { enum Baz2025 = 2; } |
| 296 |
static assert(Baz2025!1 == 2); |
| 297 |
static assert(Baz2025!int == 1); |
| 298 |
static assert(Baz2025!S2025 == 1); // 2 -> 1 |
| 299 |
static assert(Baz2025!f2025 == 2); |
| 300 |
|
| 301 |
/**********************************/ |
| 302 |
// https://issues.dlang.org/show_bug.cgi?id=3608 |
| 303 |
|
| 304 |
template foo3608(T, U){} |
| 305 |
|
| 306 |
template BaseTemplate3608(alias TTT : U!V, alias U, V...) |
| 307 |
{ |
| 308 |
alias U BaseTemplate3608; |
| 309 |
} |
| 310 |
template TemplateParams3608(alias T : U!V, alias U, V...) |
| 311 |
{ |
| 312 |
alias V TemplateParams3608; |
| 313 |
} |
| 314 |
|
| 315 |
template TyueTuple3608(T...) { alias T TyueTuple3608; } |
| 316 |
|
| 317 |
void test3608() |
| 318 |
{ |
| 319 |
alias foo3608!(int, long) Foo3608; |
| 320 |
|
| 321 |
static assert(__traits(isSame, BaseTemplate3608!Foo3608, foo3608)); |
| 322 |
static assert(is(TemplateParams3608!Foo3608 == TyueTuple3608!(int, long))); |
| 323 |
} |
| 324 |
|
| 325 |
/**********************************/ |
| 326 |
// https://issues.dlang.org/show_bug.cgi?id=5015 |
| 327 |
|
| 328 |
import breaker; |
| 329 |
|
| 330 |
static if (is(ElemType!(int))){} |
| 331 |
|
| 332 |
template ElemType(T) { |
| 333 |
alias _ElemType!(T).type ElemType; |
| 334 |
} |
| 335 |
|
| 336 |
template _ElemType(T) { |
| 337 |
alias r type; |
| 338 |
} |
| 339 |
|
| 340 |
/**********************************/ |
| 341 |
// https://issues.dlang.org/show_bug.cgi?id=5185 |
| 342 |
|
| 343 |
class C5185(V) |
| 344 |
{ |
| 345 |
void f() |
| 346 |
{ |
| 347 |
C5185!(C5185!(int)) c; |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
void test5185() |
| 352 |
{ |
| 353 |
C5185!(C5185!(int)) c; |
| 354 |
} |
| 355 |
|
| 356 |
/**********************************/ |
| 357 |
// https://issues.dlang.org/show_bug.cgi?id=5893 |
| 358 |
|
| 359 |
class C5893 |
| 360 |
{ |
| 361 |
int concatAssign(C5893 other) { return 1; } |
| 362 |
int concatAssign(int other) { return 2; } // to demonstrate overloading |
| 363 |
|
| 364 |
template opOpAssign(string op) if (op == "~") |
| 365 |
{ alias concatAssign opOpAssign; } |
| 366 |
|
| 367 |
int opOpAssign(string op)(int other) if (op == "+") { return 3; } |
| 368 |
} |
| 369 |
|
| 370 |
void test5893() |
| 371 |
{ |
| 372 |
auto c = new C5893; |
| 373 |
assert(c.opOpAssign!"~"(c) == 1); // works |
| 374 |
assert(c.opOpAssign!"~"(1) == 2); // works |
| 375 |
assert((c ~= 1) == 2); |
| 376 |
assert((c += 1) == 3); // overload |
| 377 |
} |
| 378 |
|
| 379 |
/**********************************/ |
| 380 |
// https://issues.dlang.org/show_bug.cgi?id=5988 |
| 381 |
|
| 382 |
template Templ5988(alias T) |
| 383 |
{ |
| 384 |
alias T!int Templ5988; |
| 385 |
} |
| 386 |
|
| 387 |
class C5988a(T) { Templ5988!C5988a foo; } |
| 388 |
//Templ5988!C5988a foo5988a; // Commented version |
| 389 |
void test5988a() { C5988a!int a; } // Was error, now works |
| 390 |
|
| 391 |
class C5988b(T) { Templ5988!C5988b foo; } |
| 392 |
Templ5988!C5988b foo5988b; // Uncomment version |
| 393 |
void test5988b() { C5988b!int a; } // Works |
| 394 |
|
| 395 |
/**********************************/ |
| 396 |
// https://issues.dlang.org/show_bug.cgi?id=6404 |
| 397 |
|
| 398 |
// receive only rvalue |
| 399 |
void rvalue(T)(auto ref T x) if (!__traits(isRef, x)) {} |
| 400 |
void rvalueVargs(T...)(auto ref T x) if (!__traits(isRef, x[0])) {} |
| 401 |
|
| 402 |
// receive only lvalue |
| 403 |
void lvalue(T)(auto ref T x) if ( __traits(isRef, x)) {} |
| 404 |
void lvalueVargs(T...)(auto ref T x) if ( __traits(isRef, x[0])) {} |
| 405 |
|
| 406 |
void test6404() |
| 407 |
{ |
| 408 |
int n; |
| 409 |
|
| 410 |
static assert(!__traits(compiles, rvalue(n))); |
| 411 |
static assert( __traits(compiles, rvalue(0))); |
| 412 |
|
| 413 |
static assert( __traits(compiles, lvalue(n))); |
| 414 |
static assert(!__traits(compiles, lvalue(0))); |
| 415 |
|
| 416 |
static assert(!__traits(compiles, rvalueVargs(n))); |
| 417 |
static assert( __traits(compiles, rvalueVargs(0))); |
| 418 |
|
| 419 |
static assert( __traits(compiles, lvalueVargs(n))); |
| 420 |
static assert(!__traits(compiles, lvalueVargs(0))); |
| 421 |
} |
| 422 |
|
| 423 |
/**********************************/ |
| 424 |
// https://issues.dlang.org/show_bug.cgi?id=2246 |
| 425 |
|
| 426 |
class A2246(T,d){ |
| 427 |
T p; |
| 428 |
} |
| 429 |
|
| 430 |
class B2246(int rk){ |
| 431 |
int[rk] p; |
| 432 |
} |
| 433 |
|
| 434 |
class C2246(T,int rk){ |
| 435 |
T[rk] p; |
| 436 |
} |
| 437 |
|
| 438 |
template f2246(T:A2246!(U,d),U,d){ |
| 439 |
void f2246(){ } |
| 440 |
} |
| 441 |
|
| 442 |
template f2246(T:B2246!(rank),int rank){ |
| 443 |
void f2246(){ } |
| 444 |
} |
| 445 |
|
| 446 |
template f2246(T:C2246!(U,rank),U,int rank){ |
| 447 |
void f2246(){ } |
| 448 |
} |
| 449 |
|
| 450 |
void test2246(){ |
| 451 |
A2246!(int,long) a; |
| 452 |
B2246!(2) b; |
| 453 |
C2246!(int,2) c; |
| 454 |
f2246!(A2246!(int,long))(); |
| 455 |
f2246!(B2246!(2))(); |
| 456 |
f2246!(C2246!(int,2))(); |
| 457 |
} |
| 458 |
|
| 459 |
/**********************************/ |
| 460 |
// https://issues.dlang.org/show_bug.cgi?id=2296 |
| 461 |
|
| 462 |
void foo2296(size_t D)(int[D] i...){} |
| 463 |
void test2296() |
| 464 |
{ |
| 465 |
foo2296(1, 2, 3); |
| 466 |
} |
| 467 |
|
| 468 |
/**********************************/ |
| 469 |
// https://issues.dlang.org/show_bug.cgi?id=1684 |
| 470 |
|
| 471 |
template Test1684( uint memberOffset ){} |
| 472 |
|
| 473 |
class MyClass1684 { |
| 474 |
int flags2; |
| 475 |
mixin Test1684!(cast(uint)flags2.offsetof) t1; // compiles ok |
| 476 |
mixin Test1684!(cast(int)flags2.offsetof) t2; // compiles ok |
| 477 |
mixin Test1684!(flags2.offsetof) t3; // Error: no property 'offsetof' for type 'int' |
| 478 |
} |
| 479 |
|
| 480 |
/**********************************/ |
| 481 |
|
| 482 |
void bug4984a(int n)() if (n > 0 && is(typeof(bug4984a!(n-1) ()))) { |
| 483 |
} |
| 484 |
|
| 485 |
void bug4984a(int n : 0)() { |
| 486 |
} |
| 487 |
|
| 488 |
void bug4984b(U...)(U args) if ( is(typeof( bug4984b(args[1..$]) )) ) { |
| 489 |
} |
| 490 |
|
| 491 |
void bug4984b(U)(U u) { |
| 492 |
} |
| 493 |
|
| 494 |
void bug4984() { |
| 495 |
// Note: compiling this overflows the stack if dmd is build with DEBUG |
| 496 |
//bug4984a!400(); |
| 497 |
bug4984a!200(); |
| 498 |
bug4984b(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19); |
| 499 |
} |
| 500 |
|
| 501 |
/***************************************/ |
| 502 |
// https://issues.dlang.org/show_bug.cgi?id=2579 |
| 503 |
|
| 504 |
void foo2579(T)(T delegate(in Object) dlg) |
| 505 |
{ |
| 506 |
} |
| 507 |
|
| 508 |
void test2579() |
| 509 |
{ |
| 510 |
foo2579( (in Object o) { return 15; } ); |
| 511 |
} |
| 512 |
|
| 513 |
/**********************************/ |
| 514 |
// https://issues.dlang.org/show_bug.cgi?id=2803 |
| 515 |
|
| 516 |
auto foo2803(T)(T t = 0) { return t; } |
| 517 |
|
| 518 |
struct S2803 {} |
| 519 |
S2803 s2803; |
| 520 |
ref S2803 getS2803() { return s2803; } |
| 521 |
auto fun2803(T, U)(T t, ref U u = getS2803) |
| 522 |
{ |
| 523 |
static assert(is(U == S2803)); |
| 524 |
return &u; |
| 525 |
} |
| 526 |
|
| 527 |
// from the past version of std.conv |
| 528 |
template to2803(T) { T to2803(S)(S src) { return T.init; } } |
| 529 |
auto toImpl2803a(T, S)(S s, in T left, in T sep = ", ", in T right = "]") {} |
| 530 |
auto toImpl2803b(T, S)(S s, in T left = to2803!T(S.stringof~"("), in T right = ")") {} |
| 531 |
auto toImpl2803c(T, S)(S s, in T left = S.stringof~"(" , in T right = ")") {} // combination with enh 13944 |
| 532 |
|
| 533 |
// from std.range.package in 2.067a. |
| 534 |
auto enumerate2803(En = size_t, R)(R r, En start = 0) |
| 535 |
{ |
| 536 |
// The type of 'start' should be size_t, it's the defaultArg of En, |
| 537 |
// rather than the deduced type from its defualtArg '0'. |
| 538 |
static assert(is(typeof(start) == size_t)); |
| 539 |
return start; |
| 540 |
} |
| 541 |
|
| 542 |
// from std.numeric. |
| 543 |
alias ElementType2803(R) = typeof(R.init[0].init); |
| 544 |
void normalize2803(R)(R range, ElementType2803!R sum = 1) |
| 545 |
{ |
| 546 |
// The type of 'sum' should be determined to ElementType!(double[]) == double |
| 547 |
// before the type deduction from its defaultArg '1'. |
| 548 |
static assert(is(typeof(sum) == double)); |
| 549 |
} |
| 550 |
|
| 551 |
auto foo14468(T)(T[]...) { return 1; } |
| 552 |
auto foo14468(bool flag, T)(T[]...) { return 2; } |
| 553 |
|
| 554 |
void test2803() |
| 555 |
{ |
| 556 |
assert(foo2803() == 0); |
| 557 |
assert(foo2803(1) == 1); |
| 558 |
|
| 559 |
S2803 s; |
| 560 |
assert(fun2803(1) is &s2803); |
| 561 |
assert(fun2803(1, s) is &s); |
| 562 |
|
| 563 |
// regression cases |
| 564 |
|
| 565 |
toImpl2803a!string(1, "["); |
| 566 |
|
| 567 |
toImpl2803b! string(1); |
| 568 |
toImpl2803b!wstring(1); |
| 569 |
toImpl2803b!dstring(1); |
| 570 |
|
| 571 |
toImpl2803c! string(1); |
| 572 |
toImpl2803c!wstring(1); // requires enhancement 13944 |
| 573 |
toImpl2803c!dstring(1); // requires enhancement 13944 |
| 574 |
|
| 575 |
enumerate2803([1]); |
| 576 |
|
| 577 |
double[] a = []; |
| 578 |
normalize2803(a); |
| 579 |
|
| 580 |
assert(foo14468!int() == 1); |
| 581 |
} |
| 582 |
|
| 583 |
/**********************************/ |
| 584 |
// https://issues.dlang.org/show_bug.cgi?id=6613 |
| 585 |
|
| 586 |
alias Tuple6613(T...) = T; |
| 587 |
|
| 588 |
void f6613(T...)(int x = 0, T xs = Tuple6613!()) |
| 589 |
{ |
| 590 |
assert(x == 0); |
| 591 |
static assert(T.length == 0); |
| 592 |
} |
| 593 |
|
| 594 |
void test6613() |
| 595 |
{ |
| 596 |
f6613(); |
| 597 |
} |
| 598 |
|
| 599 |
/**********************************/ |
| 600 |
// https://issues.dlang.org/show_bug.cgi?id=4953 |
| 601 |
|
| 602 |
void bug4953(T = void)(short x) {} |
| 603 |
static assert(is(typeof(bug4953(3)))); |
| 604 |
|
| 605 |
/**********************************/ |
| 606 |
// https://issues.dlang.org/show_bug.cgi?id=5886 |
| 607 |
// https://issues.dlang.org/show_bug.cgi?id=5393 |
| 608 |
|
| 609 |
mixin template Foo5886(T) |
| 610 |
{ |
| 611 |
void foo(U : T, this X)() const { static assert(is(X == const K5886)); } |
| 612 |
} |
| 613 |
|
| 614 |
struct K5886 |
| 615 |
{ |
| 616 |
void get1(this T)() const |
| 617 |
{ |
| 618 |
pragma(msg, T); |
| 619 |
} |
| 620 |
void get2(int N=4, this T)() const |
| 621 |
{ |
| 622 |
pragma(msg, N, " ; ", T); |
| 623 |
} |
| 624 |
|
| 625 |
mixin Foo5886!double; |
| 626 |
mixin Foo5886!string; |
| 627 |
|
| 628 |
void test() const |
| 629 |
{ |
| 630 |
get1; // OK |
| 631 |
get2; // OK |
| 632 |
get2!8; // NG |
| 633 |
|
| 634 |
foo!(int); |
| 635 |
foo!(typeof(null)); |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
void test5886() |
| 640 |
{ |
| 641 |
K5886 km; |
| 642 |
const(K5886) kc; |
| 643 |
immutable(K5886) ki; |
| 644 |
|
| 645 |
km.get1; // OK |
| 646 |
kc.get1; // OK |
| 647 |
ki.get1; // OK |
| 648 |
km.get2; // OK |
| 649 |
kc.get2; // OK |
| 650 |
ki.get2; // OK |
| 651 |
km.get2!(1, K5886); // Ugly |
| 652 |
kc.get2!(2, const(K5886)); // Ugly |
| 653 |
ki.get2!(3, immutable(K5886)); // Ugly |
| 654 |
km.get2!8; // Error |
| 655 |
kc.get2!9; // Error |
| 656 |
ki.get2!10; // Error |
| 657 |
} |
| 658 |
|
| 659 |
// -------- |
| 660 |
|
| 661 |
void test5393() |
| 662 |
{ |
| 663 |
class A |
| 664 |
{ |
| 665 |
void opDispatch (string name, this T) () { } |
| 666 |
} |
| 667 |
|
| 668 |
class B : A {} |
| 669 |
|
| 670 |
auto b = new B; |
| 671 |
b.foobar(); |
| 672 |
} |
| 673 |
|
| 674 |
/**********************************/ |
| 675 |
// https://issues.dlang.org/show_bug.cgi?id=5896 |
| 676 |
|
| 677 |
struct X5896 |
| 678 |
{ |
| 679 |
T opCast(T)(){ return 1; } |
| 680 |
const T opCast(T)(){ return 2; } |
| 681 |
immutable T opCast(T)(){ return 3; } |
| 682 |
shared T opCast(T)(){ return 4; } |
| 683 |
const shared T opCast(T)(){ return 5; } |
| 684 |
} |
| 685 |
void test5896() |
| 686 |
{ |
| 687 |
auto xm = X5896 (); |
| 688 |
auto xc = const(X5896) (); |
| 689 |
auto xi = immutable(X5896) (); |
| 690 |
auto xs = shared(X5896) (); |
| 691 |
auto xcs= const(shared(X5896))(); |
| 692 |
assert(cast(int)xm == 1); |
| 693 |
assert(cast(int)xc == 2); |
| 694 |
assert(cast(int)xi == 3); |
| 695 |
assert(cast(int)xs == 4); |
| 696 |
assert(cast(int)xcs== 5); |
| 697 |
} |
| 698 |
|
| 699 |
/**********************************/ |
| 700 |
// https://issues.dlang.org/show_bug.cgi?id=6312 |
| 701 |
|
| 702 |
void h6312() {} |
| 703 |
|
| 704 |
class Bla6312 |
| 705 |
{ |
| 706 |
mixin wrap6312!h6312; |
| 707 |
} |
| 708 |
|
| 709 |
mixin template wrap6312(alias f) |
| 710 |
{ |
| 711 |
void blub(alias g = f)() |
| 712 |
{ |
| 713 |
g(); |
| 714 |
} |
| 715 |
} |
| 716 |
|
| 717 |
void test6312() |
| 718 |
{ |
| 719 |
Bla6312 b = new Bla6312(); |
| 720 |
b.blub(); |
| 721 |
} |
| 722 |
|
| 723 |
/**********************************/ |
| 724 |
// https://issues.dlang.org/show_bug.cgi?id=6825 |
| 725 |
|
| 726 |
void test6825() |
| 727 |
{ |
| 728 |
struct File |
| 729 |
{ |
| 730 |
void write(S...)(S args) {} |
| 731 |
} |
| 732 |
|
| 733 |
void dump(void delegate(string) d) {} |
| 734 |
|
| 735 |
auto o = File(); |
| 736 |
dump(&o.write!string); |
| 737 |
} |
| 738 |
|
| 739 |
/**********************************/ |
| 740 |
// https://issues.dlang.org/show_bug.cgi?id=6789 |
| 741 |
|
| 742 |
template isStaticArray6789(T) |
| 743 |
{ |
| 744 |
static if (is(T U : U[N], size_t N)) // doesn't match |
| 745 |
{ |
| 746 |
pragma(msg, "> U = ", U, ", N:", typeof(N), " = ", N); |
| 747 |
enum isStaticArray6789 = true; |
| 748 |
} |
| 749 |
else |
| 750 |
enum isStaticArray6789 = false; |
| 751 |
} |
| 752 |
|
| 753 |
void test6789() |
| 754 |
{ |
| 755 |
alias int[3] T; |
| 756 |
static assert(isStaticArray6789!T); |
| 757 |
} |
| 758 |
|
| 759 |
/**********************************/ |
| 760 |
// https://issues.dlang.org/show_bug.cgi?id=2778 |
| 761 |
|
| 762 |
struct ArrayWrapper2778(T) |
| 763 |
{ |
| 764 |
T[] data; |
| 765 |
alias data this; |
| 766 |
} |
| 767 |
|
| 768 |
void doStuffFunc2778(int[] data) {} |
| 769 |
|
| 770 |
void doStuffTempl2778(T)(T[] data) {} |
| 771 |
|
| 772 |
int doStuffTemplOver2778(T)(void* data) { return 1; } |
| 773 |
int doStuffTemplOver2778(T)(ArrayWrapper2778!T w) { return 2; } |
| 774 |
|
| 775 |
void test2778() |
| 776 |
{ |
| 777 |
ArrayWrapper2778!(int) foo; |
| 778 |
|
| 779 |
doStuffFunc2778(foo); // Works. |
| 780 |
|
| 781 |
doStuffTempl2778!(int)(foo); // Works. |
| 782 |
|
| 783 |
doStuffTempl2778(foo); // Error |
| 784 |
|
| 785 |
assert(doStuffTemplOver2778(foo) == 2); |
| 786 |
} |
| 787 |
|
| 788 |
// ---- |
| 789 |
|
| 790 |
void test2778aa() |
| 791 |
{ |
| 792 |
void foo(K, V)(V[K] aa){ pragma(msg, "K=", K, ", V=", V); } |
| 793 |
|
| 794 |
int[string] aa1; |
| 795 |
foo(aa1); // OK |
| 796 |
|
| 797 |
struct SubTypeOf(T) |
| 798 |
{ |
| 799 |
T val; |
| 800 |
alias val this; |
| 801 |
} |
| 802 |
SubTypeOf!(string[char]) aa2; |
| 803 |
foo(aa2); // NG |
| 804 |
} |
| 805 |
|
| 806 |
// ---- |
| 807 |
|
| 808 |
void test2778get() |
| 809 |
{ |
| 810 |
void foo(ubyte[]){} |
| 811 |
|
| 812 |
static struct S |
| 813 |
{ |
| 814 |
ubyte[] val = [1,2,3]; |
| 815 |
@property ref ubyte[] get() return { return val; } |
| 816 |
alias get this; |
| 817 |
} |
| 818 |
S s; |
| 819 |
foo(s); |
| 820 |
} |
| 821 |
|
| 822 |
/**********************************/ |
| 823 |
// https://issues.dlang.org/show_bug.cgi?id=6208 |
| 824 |
|
| 825 |
int getRefNonref(T)(ref T s){ return 1; } |
| 826 |
int getRefNonref(T)( T s){ return 2; } |
| 827 |
|
| 828 |
int getAutoRef(T)(auto ref T s){ return __traits(isRef, s) ? 1 : 2; } |
| 829 |
|
| 830 |
void getOut(T)(out T s){ {} } |
| 831 |
|
| 832 |
void getLazy1(T=int)(lazy void s){ s(), s(); } |
| 833 |
void getLazy2(T)(lazy T s){ s(), s(); } |
| 834 |
|
| 835 |
void test6208a() |
| 836 |
{ |
| 837 |
int lvalue; |
| 838 |
int rvalue(){ int t; return t; } |
| 839 |
|
| 840 |
assert(getRefNonref(lvalue ) == 1); |
| 841 |
assert(getRefNonref(rvalue()) == 2); |
| 842 |
|
| 843 |
assert(getAutoRef(lvalue ) == 1); |
| 844 |
assert(getAutoRef(rvalue()) == 2); |
| 845 |
|
| 846 |
static assert( __traits(compiles, getOut(lvalue ))); |
| 847 |
static assert(!__traits(compiles, getOut(rvalue()))); |
| 848 |
|
| 849 |
int n1; getLazy1(++n1); assert(n1 == 2); |
| 850 |
int n2; getLazy2(++n2); assert(n2 == 2); |
| 851 |
|
| 852 |
struct X |
| 853 |
{ |
| 854 |
int f(T)(auto ref T t){ return 1; } |
| 855 |
int f(T)(auto ref T t, ...){ return -1; } |
| 856 |
} |
| 857 |
auto xm = X (); |
| 858 |
auto xc = const(X)(); |
| 859 |
int n; |
| 860 |
assert(xm.f!int(n) == 1); // resolved 'auto ref' |
| 861 |
assert(xm.f!int(0) == 1); // ditto |
| 862 |
} |
| 863 |
|
| 864 |
void test6208b() |
| 865 |
{ |
| 866 |
void foo(T)(const T value) if (!is(T == int)) {} |
| 867 |
|
| 868 |
int mn; |
| 869 |
const int cn; |
| 870 |
static assert(!__traits(compiles, foo(mn))); // OK -> OK |
| 871 |
static assert(!__traits(compiles, foo(cn))); // NG -> OK |
| 872 |
} |
| 873 |
|
| 874 |
void test6208c() |
| 875 |
{ |
| 876 |
struct S |
| 877 |
{ |
| 878 |
// Original test case. |
| 879 |
int foo(V)(in V v) { return 1; } |
| 880 |
int foo(Args...)(auto ref const Args args) { return 2; } |
| 881 |
|
| 882 |
// Reduced test cases |
| 883 |
|
| 884 |
int hoo(V)(const V v) { return 1; } // typeof(10) : const V -> MATCHconst |
| 885 |
int hoo(Args...)(const Args args) { return 2; } // typeof(10) : const Args[0] -> MATCHconst |
| 886 |
// If deduction matching level is same, tuple parameter is less specialized than others. |
| 887 |
|
| 888 |
int bar(V)(V v) { return 1; } // typeof(10) : V -> MATCHexact |
| 889 |
int bar(Args...)(const Args args) { return 2; } // typeof(10) : const Args[0] -> MATCHconst |
| 890 |
|
| 891 |
int baz(V)(const V v) { return 1; } // typeof(10) : const V -> MATCHconst |
| 892 |
int baz(Args...)(Args args) { return 2; } // typeof(10) : Args[0] -> MATCHexact |
| 893 |
|
| 894 |
inout(int) war(V)(inout V v) { return 1; } |
| 895 |
inout(int) war(Args...)(inout Args args){ return 2; } |
| 896 |
|
| 897 |
inout(int) waz(Args...)(inout Args args){ return 0; } // wild deduction test |
| 898 |
} |
| 899 |
|
| 900 |
S s; |
| 901 |
|
| 902 |
int nm = 10; |
| 903 |
assert(s.foo(nm) == 1); |
| 904 |
assert(s.hoo(nm) == 1); |
| 905 |
assert(s.bar(nm) == 1); |
| 906 |
assert(s.baz(nm) == 2); |
| 907 |
assert(s.war(nm) == 1); |
| 908 |
static assert(is(typeof(s.waz(nm)) == int)); |
| 909 |
|
| 910 |
const int nc = 10; |
| 911 |
assert(s.foo(nc) == 1); |
| 912 |
assert(s.hoo(nc) == 1); |
| 913 |
assert(s.bar(nc) == 1); |
| 914 |
assert(s.baz(nc) == 1); |
| 915 |
assert(s.war(nc) == 1); |
| 916 |
static assert(is(typeof(s.waz(nc)) == const(int))); |
| 917 |
|
| 918 |
immutable int ni = 10; |
| 919 |
assert(s.foo(ni) == 1); |
| 920 |
assert(s.hoo(ni) == 1); |
| 921 |
assert(s.bar(ni) == 1); |
| 922 |
assert(s.baz(ni) == 2); |
| 923 |
assert(s.war(ni) == 1); |
| 924 |
static assert(is(typeof(s.waz(ni)) == immutable(int))); |
| 925 |
|
| 926 |
static assert(is(typeof(s.waz(nm, nm)) == int)); |
| 927 |
static assert(is(typeof(s.waz(nm, nc)) == const(int))); |
| 928 |
static assert(is(typeof(s.waz(nm, ni)) == const(int))); |
| 929 |
static assert(is(typeof(s.waz(nc, nm)) == const(int))); |
| 930 |
static assert(is(typeof(s.waz(nc, nc)) == const(int))); |
| 931 |
static assert(is(typeof(s.waz(nc, ni)) == const(int))); |
| 932 |
static assert(is(typeof(s.waz(ni, nm)) == const(int))); |
| 933 |
static assert(is(typeof(s.waz(ni, nc)) == const(int))); |
| 934 |
static assert(is(typeof(s.waz(ni, ni)) == immutable(int))); |
| 935 |
} |
| 936 |
|
| 937 |
/**********************************/ |
| 938 |
// https://issues.dlang.org/show_bug.cgi?id=6805 |
| 939 |
|
| 940 |
struct T6805 |
| 941 |
{ |
| 942 |
template opDispatch(string name) |
| 943 |
{ |
| 944 |
alias int Type; |
| 945 |
} |
| 946 |
} |
| 947 |
static assert(is(T6805.xxx.Type == int)); |
| 948 |
|
| 949 |
/**********************************/ |
| 950 |
// https://issues.dlang.org/show_bug.cgi?id=6738 |
| 951 |
|
| 952 |
struct Foo6738 |
| 953 |
{ |
| 954 |
int _val = 10; |
| 955 |
|
| 956 |
@property int val()() { return _val; } |
| 957 |
int get() { return val; } // fail |
| 958 |
} |
| 959 |
|
| 960 |
void test6738() |
| 961 |
{ |
| 962 |
Foo6738 foo; |
| 963 |
auto x = foo.val; // ok |
| 964 |
assert(x == 10); |
| 965 |
assert(foo.get() == 10); |
| 966 |
} |
| 967 |
|
| 968 |
/**********************************/ |
| 969 |
// https://issues.dlang.org/show_bug.cgi?id=7498 |
| 970 |
|
| 971 |
template IndexMixin(){ |
| 972 |
void insert(T)(T value){ } |
| 973 |
} |
| 974 |
|
| 975 |
class MultiIndexContainer{ |
| 976 |
mixin IndexMixin!() index0; |
| 977 |
class Index0{ |
| 978 |
void baburk(){ |
| 979 |
this.outer.index0.insert(1); |
| 980 |
} |
| 981 |
} |
| 982 |
} |
| 983 |
|
| 984 |
/**********************************/ |
| 985 |
// https://issues.dlang.org/show_bug.cgi?id=6780 |
| 986 |
|
| 987 |
@property int foo6780()(){ return 10; } |
| 988 |
|
| 989 |
int g6780; |
| 990 |
@property void bar6780()(int n){ g6780 = n; } |
| 991 |
|
| 992 |
void test6780() |
| 993 |
{ |
| 994 |
auto n = foo6780; |
| 995 |
assert(n == 10); |
| 996 |
|
| 997 |
bar6780 = 10; |
| 998 |
assert(g6780 == 10); |
| 999 |
} |
| 1000 |
|
| 1001 |
/**********************************/ |
| 1002 |
// https://issues.dlang.org/show_bug.cgi?id=6810 |
| 1003 |
|
| 1004 |
int f6810(int n)(int) { return 1;} |
| 1005 |
int f6810(U...)(U) { assert(0); } |
| 1006 |
int f6810(U...)(U a) { assert(0); } |
| 1007 |
int f6810(U...)(U) if (true) { assert(0); } |
| 1008 |
int f6810(U...)(U a) if (true) { assert(0); } |
| 1009 |
|
| 1010 |
void test6810() |
| 1011 |
{ |
| 1012 |
assert(f6810!0(0) == 1); |
| 1013 |
} |
| 1014 |
|
| 1015 |
/**********************************/ |
| 1016 |
// https://issues.dlang.org/show_bug.cgi?id=6891 |
| 1017 |
|
| 1018 |
struct S6891(int N, T) |
| 1019 |
{ |
| 1020 |
void f(U)(S6891!(N, U) u) { } |
| 1021 |
} |
| 1022 |
|
| 1023 |
void test6891() |
| 1024 |
{ |
| 1025 |
alias S6891!(1, void) A; |
| 1026 |
A().f(A()); |
| 1027 |
} |
| 1028 |
|
| 1029 |
/**********************************/ |
| 1030 |
// https://issues.dlang.org/show_bug.cgi?id=6994 |
| 1031 |
|
| 1032 |
struct Foo6994 |
| 1033 |
{ |
| 1034 |
T get(T)(){ return T.init; } |
| 1035 |
|
| 1036 |
T func1(T)() |
| 1037 |
if (__traits(compiles, get!T())) |
| 1038 |
{ return get!T; } |
| 1039 |
|
| 1040 |
T func2(T)() |
| 1041 |
if (__traits(compiles, this.get!T())) // add explicit 'this' |
| 1042 |
{ return get!T; } |
| 1043 |
} |
| 1044 |
void test6994() |
| 1045 |
{ |
| 1046 |
Foo6994 foo; |
| 1047 |
foo.get!int(); // OK |
| 1048 |
foo.func1!int(); // OK |
| 1049 |
foo.func2!int(); // NG |
| 1050 |
} |
| 1051 |
|
| 1052 |
/**********************************/ |
| 1053 |
// https://issues.dlang.org/show_bug.cgi?id=6764 |
| 1054 |
|
| 1055 |
enum N6764 = 1; //use const for D1 |
| 1056 |
|
| 1057 |
alias size_t[N6764] T6764; //workaround |
| 1058 |
void f6764()(T6764 arr...) { } |
| 1059 |
|
| 1060 |
void g6764()(size_t[1] arr...) { } |
| 1061 |
|
| 1062 |
void h6764()(size_t[N6764] arr...) { } |
| 1063 |
|
| 1064 |
void test6764() |
| 1065 |
{ |
| 1066 |
f6764(0); //good |
| 1067 |
g6764(0); //good |
| 1068 |
h6764!()(0); //good |
| 1069 |
h6764(0); //Error: template main.f() does not match any function template declaration |
| 1070 |
} |
| 1071 |
|
| 1072 |
/**********************************/ |
| 1073 |
// https://issues.dlang.org/show_bug.cgi?id=3467 |
| 1074 |
// https://issues.dlang.org/show_bug.cgi?id=6806 |
| 1075 |
|
| 1076 |
struct Foo3467( uint n ) |
| 1077 |
{ |
| 1078 |
Foo3467!( n ) bar( ) { |
| 1079 |
typeof( return ) result; |
| 1080 |
return result; |
| 1081 |
} |
| 1082 |
} |
| 1083 |
struct Vec3467(size_t N) |
| 1084 |
{ |
| 1085 |
void opBinary(string op:"~", size_t M)(Vec3467!M) {} |
| 1086 |
} |
| 1087 |
void test3467() |
| 1088 |
{ |
| 1089 |
Foo3467!( 4 ) baz; |
| 1090 |
baz = baz.bar;// FAIL |
| 1091 |
|
| 1092 |
Vec3467!2 a1; |
| 1093 |
Vec3467!3 a2; |
| 1094 |
a1 ~ a2; // line 7, Error |
| 1095 |
} |
| 1096 |
|
| 1097 |
struct TS6806(uint n) { pragma(msg, typeof(n)); } |
| 1098 |
static assert(is(TS6806!(1u) == TS6806!(1))); |
| 1099 |
|
| 1100 |
/**********************************/ |
| 1101 |
// https://issues.dlang.org/show_bug.cgi?id=4413 |
| 1102 |
|
| 1103 |
struct Foo4413 |
| 1104 |
{ |
| 1105 |
alias typeof(this) typeof_this; |
| 1106 |
void bar1(typeof_this other) {} |
| 1107 |
void bar2()(typeof_this other) {} |
| 1108 |
void bar3(typeof(this) other) {} |
| 1109 |
void bar4()(typeof(this) other) {} |
| 1110 |
} |
| 1111 |
|
| 1112 |
void test4413() |
| 1113 |
{ |
| 1114 |
Foo4413 f; |
| 1115 |
f.bar1(f); // OK |
| 1116 |
f.bar2(f); // OK |
| 1117 |
f.bar3(f); // OK |
| 1118 |
f.bar4(f); // ERR |
| 1119 |
} |
| 1120 |
|
| 1121 |
/**********************************/ |
| 1122 |
// https://issues.dlang.org/show_bug.cgi?id=4675 |
| 1123 |
|
| 1124 |
template isNumeric(T) |
| 1125 |
{ |
| 1126 |
enum bool test1 = is(T : long); // should be hidden |
| 1127 |
enum bool test2 = is(T : real); // should be hidden |
| 1128 |
enum bool isNumeric = test1 || test2; |
| 1129 |
} |
| 1130 |
void test4675() |
| 1131 |
{ |
| 1132 |
static assert( isNumeric!int); |
| 1133 |
static assert(!isNumeric!string); |
| 1134 |
static assert(!__traits(compiles, isNumeric!int.test1)); // should be an error |
| 1135 |
static assert(!__traits(compiles, isNumeric!int.test2)); // should be an error |
| 1136 |
static assert(!__traits(compiles, isNumeric!int.isNumeric)); |
| 1137 |
} |
| 1138 |
|
| 1139 |
/**********************************/ |
| 1140 |
// https://issues.dlang.org/show_bug.cgi?id=5525 |
| 1141 |
|
| 1142 |
template foo5525(T) |
| 1143 |
{ |
| 1144 |
T foo5525(T t) { return t; } |
| 1145 |
T foo5525(T t, T u) { return t + u; } |
| 1146 |
} |
| 1147 |
|
| 1148 |
void test5525() |
| 1149 |
{ |
| 1150 |
alias foo5525!int f; |
| 1151 |
assert(f(1) == 1); |
| 1152 |
assert(f(1, 2) == 3); |
| 1153 |
} |
| 1154 |
|
| 1155 |
/**********************************/ |
| 1156 |
// https://issues.dlang.org/show_bug.cgi?id=5801 |
| 1157 |
|
| 1158 |
int a5801; |
| 1159 |
void bar5801(T = double)(typeof(a5801) i) {} |
| 1160 |
void baz5801(T)(typeof(a5801) i, T t) {} |
| 1161 |
void test5801() |
| 1162 |
{ |
| 1163 |
bar5801(2); // Does not compile. |
| 1164 |
baz5801(3, "baz"); // Does not compile. |
| 1165 |
} |
| 1166 |
|
| 1167 |
/**********************************/ |
| 1168 |
// https://issues.dlang.org/show_bug.cgi?id=5832 |
| 1169 |
|
| 1170 |
struct Bar5832(alias v) {} |
| 1171 |
|
| 1172 |
template isBar5832a(T) |
| 1173 |
{ |
| 1174 |
static if (is(T _ : Bar5832!(v), alias v)) |
| 1175 |
enum isBar5832a = true; |
| 1176 |
else |
| 1177 |
enum isBar5832a = false; |
| 1178 |
} |
| 1179 |
template isBar5832b(T) |
| 1180 |
{ |
| 1181 |
static if (is(T _ : Bar5832!(v), alias int v)) |
| 1182 |
enum isBar5832b = true; |
| 1183 |
else |
| 1184 |
enum isBar5832b = false; |
| 1185 |
} |
| 1186 |
template isBar5832c(T) |
| 1187 |
{ |
| 1188 |
static if (is(T _ : Bar5832!(v), alias string v)) |
| 1189 |
enum isBar5832c = true; |
| 1190 |
else |
| 1191 |
enum isBar5832c = false; |
| 1192 |
} |
| 1193 |
static assert( isBar5832a!(Bar5832!1234)); |
| 1194 |
static assert( isBar5832b!(Bar5832!1234)); |
| 1195 |
static assert(!isBar5832c!(Bar5832!1234)); |
| 1196 |
|
| 1197 |
/**********************************/ |
| 1198 |
// https://issues.dlang.org/show_bug.cgi?id=2550 |
| 1199 |
|
| 1200 |
template pow10_2550(long n) |
| 1201 |
{ |
| 1202 |
const long pow10_2550 = 0; |
| 1203 |
static if (n < 0) |
| 1204 |
const long pow10_2550 = 0; |
| 1205 |
else |
| 1206 |
const long pow10_2550 = 10 * pow10_2550!(n - 1); |
| 1207 |
} |
| 1208 |
template pow10_2550(long n:0) |
| 1209 |
{ |
| 1210 |
const long pow10_2550 = 1; |
| 1211 |
} |
| 1212 |
static assert(pow10_2550!(0) == 1); |
| 1213 |
|
| 1214 |
/**********************************/ |
| 1215 |
// [2.057] Remove top const in IFTI, 9198 |
| 1216 |
|
| 1217 |
void foo10a(T )(T) { static assert(is(T == const(int)[])); } |
| 1218 |
void foo10b(T...)(T) { static assert(is(T[0] == const(int)[])); } |
| 1219 |
|
| 1220 |
// ref parameter doesn't remove top const |
| 1221 |
void boo10a(T )(ref T) { static assert(is(T == const(int[]))); } |
| 1222 |
void boo10b(T...)(ref T) { static assert(is(T[0] == const(int[]))); } |
| 1223 |
|
| 1224 |
// auto ref with lvalue doesn't |
| 1225 |
void goo10a(T )(auto ref T) { static assert(is(T == const(int[]))); } |
| 1226 |
void goo10b(T...)(auto ref T) { static assert(is(T[0] == const(int[]))); } |
| 1227 |
|
| 1228 |
// auto ref with rvalue does |
| 1229 |
void hoo10a(T )(auto ref T) { static assert(is(T == const(int)[])); } |
| 1230 |
void hoo10b(T...)(auto ref T) { static assert(is(T[0] == const(int)[])); } |
| 1231 |
|
| 1232 |
void bar10a(T )(T) { static assert(is(T == const(int)*)); } |
| 1233 |
void bar10b(T...)(T) { static assert(is(T[0] == const(int)*)); } |
| 1234 |
|
| 1235 |
void test10() |
| 1236 |
{ |
| 1237 |
const a = [1,2,3]; |
| 1238 |
static assert(is(typeof(a) == const(int[]))); |
| 1239 |
foo10a(a); |
| 1240 |
foo10b(a); |
| 1241 |
boo10a(a); |
| 1242 |
boo10b(a); |
| 1243 |
goo10a(a); |
| 1244 |
goo10b(a); |
| 1245 |
hoo10a(cast(const)[1,2,3]); |
| 1246 |
hoo10b(cast(const)[1,2,3]); |
| 1247 |
|
| 1248 |
int n; |
| 1249 |
const p = &n; |
| 1250 |
static assert(is(typeof(p) == const(int*))); |
| 1251 |
bar10a(p); |
| 1252 |
bar10b(p); |
| 1253 |
} |
| 1254 |
|
| 1255 |
/**********************************/ |
| 1256 |
// https://issues.dlang.org/show_bug.cgi?id=3092 |
| 1257 |
|
| 1258 |
template Foo3092(A...) |
| 1259 |
{ |
| 1260 |
alias A[0] Foo3092; |
| 1261 |
} |
| 1262 |
static assert(is(Foo3092!(int, "foo") == int)); |
| 1263 |
|
| 1264 |
/**********************************/ |
| 1265 |
// https://issues.dlang.org/show_bug.cgi?id=7037 |
| 1266 |
|
| 1267 |
struct Foo7037 {} |
| 1268 |
struct Bar7037 { Foo7037 f; alias f this; } |
| 1269 |
void works7037( T )( T value ) if ( is( T : Foo7037 ) ) {} |
| 1270 |
void doesnotwork7037( T : Foo7037 )( T value ) {} |
| 1271 |
|
| 1272 |
void test7037() |
| 1273 |
{ |
| 1274 |
Bar7037 b; |
| 1275 |
works7037( b ); |
| 1276 |
doesnotwork7037( b ); |
| 1277 |
} |
| 1278 |
|
| 1279 |
/**********************************/ |
| 1280 |
// https://issues.dlang.org/show_bug.cgi?id=7110 |
| 1281 |
|
| 1282 |
struct S7110 |
| 1283 |
{ |
| 1284 |
int opSlice(int, int) const { return 0; } |
| 1285 |
int opSlice() const { return 0; } |
| 1286 |
int opIndex(int, int) const { return 0; } |
| 1287 |
int opIndex(int) const { return 0; } |
| 1288 |
} |
| 1289 |
|
| 1290 |
enum e7110 = S7110(); |
| 1291 |
|
| 1292 |
template T7110(alias a) { } // or T7110(a...) |
| 1293 |
|
| 1294 |
alias T7110!( S7110 ) T71100; // passes |
| 1295 |
alias T7110!((S7110)) T71101; // passes |
| 1296 |
|
| 1297 |
alias T7110!( S7110()[0..0] ) A0; // passes |
| 1298 |
alias T7110!( (e7110[0..0]) ) A1; // passes |
| 1299 |
alias T7110!( e7110[0..0] ) A2; // passes |
| 1300 |
|
| 1301 |
alias T7110!( S7110()[0, 0] ) B0; // passes |
| 1302 |
alias T7110!( (e7110[0, 0]) ) B1; // passes |
| 1303 |
alias T7110!( e7110[0, 0] ) B2; // passes |
| 1304 |
|
| 1305 |
alias T7110!( S7110()[] ) C0; // passes |
| 1306 |
alias T7110!( (e7110[]) ) C1; // passes |
| 1307 |
alias T7110!( e7110[] ) C2; // fails: e7110 is used as a type |
| 1308 |
|
| 1309 |
alias T7110!( S7110()[0] ) D0; // passes |
| 1310 |
alias T7110!( (e7110[0]) ) D1; // passes |
| 1311 |
alias T7110!( e7110[0] ) D2; // fails: e7110 must be an array or pointer type, not S7110 |
| 1312 |
|
| 1313 |
/**********************************/ |
| 1314 |
// https://issues.dlang.org/show_bug.cgi?id=7124 |
| 1315 |
|
| 1316 |
template StaticArrayOf(T : E[dim], E, size_t dim) |
| 1317 |
{ |
| 1318 |
pragma(msg, "T = ", T, ", E = ", E, ", dim = ", dim); |
| 1319 |
alias E[dim] StaticArrayOf; |
| 1320 |
} |
| 1321 |
|
| 1322 |
template DynamicArrayOf(T : E[], E) |
| 1323 |
{ |
| 1324 |
pragma(msg, "T = ", T, ", E = ", E); |
| 1325 |
alias E[] DynamicArrayOf; |
| 1326 |
} |
| 1327 |
|
| 1328 |
template AssocArrayOf(T : V[K], K, V) |
| 1329 |
{ |
| 1330 |
pragma(msg, "T = ", T, ", K = ", K, ", V = ", V); |
| 1331 |
alias V[K] AssocArrayOf; |
| 1332 |
} |
| 1333 |
void test7124() |
| 1334 |
{ |
| 1335 |
struct SA { int[5] sa; alias sa this; } |
| 1336 |
static assert(is(StaticArrayOf!SA == int[5])); |
| 1337 |
|
| 1338 |
struct DA { int[] da; alias da this; } |
| 1339 |
static assert(is(DynamicArrayOf!DA == int[])); |
| 1340 |
|
| 1341 |
struct AA { int[string] aa; alias aa this; } |
| 1342 |
static assert(is(AssocArrayOf!AA == int[string])); |
| 1343 |
} |
| 1344 |
|
| 1345 |
/**********************************/ |
| 1346 |
// https://issues.dlang.org/show_bug.cgi?id=7359 |
| 1347 |
|
| 1348 |
bool foo7359(T)(T[] a ...) |
| 1349 |
{ |
| 1350 |
return true; |
| 1351 |
} |
| 1352 |
|
| 1353 |
void test7359() |
| 1354 |
{ |
| 1355 |
assert(foo7359(1,1,1,1,1,1)); // OK |
| 1356 |
assert(foo7359("abc","abc","abc","abc")); // NG |
| 1357 |
} |
| 1358 |
|
| 1359 |
/**********************************/ |
| 1360 |
// https://issues.dlang.org/show_bug.cgi?id=7363 |
| 1361 |
|
| 1362 |
template t7363() |
| 1363 |
{ |
| 1364 |
enum e = 0; |
| 1365 |
static if (true) |
| 1366 |
enum t7363 = 0; |
| 1367 |
} |
| 1368 |
static assert(!__traits(compiles, t7363!().t7363 == 0)); // Assertion fails |
| 1369 |
static assert(t7363!() == 0); // Error: void has no value |
| 1370 |
|
| 1371 |
template u7363() |
| 1372 |
{ |
| 1373 |
static if (true) |
| 1374 |
{ |
| 1375 |
enum e = 0; |
| 1376 |
enum u73631 = 0; |
| 1377 |
} |
| 1378 |
alias u73631 u7363; |
| 1379 |
} |
| 1380 |
static assert(!__traits(compiles, u7363!().u7363 == 0)); // Assertion fails |
| 1381 |
static assert(u7363!() == 0); // Error: void has no value |
| 1382 |
|
| 1383 |
/**********************************/ |
| 1384 |
|
| 1385 |
struct S4371(T ...) { } |
| 1386 |
|
| 1387 |
alias S4371!("hi!") t; |
| 1388 |
|
| 1389 |
static if (is(t U == S4371!(U))) { } |
| 1390 |
|
| 1391 |
/**********************************/ |
| 1392 |
// https://issues.dlang.org/show_bug.cgi?id=7416 |
| 1393 |
|
| 1394 |
void t7416(alias a)() if(is(typeof(a()))) |
| 1395 |
{} |
| 1396 |
|
| 1397 |
void test7416() { |
| 1398 |
void f() {} |
| 1399 |
alias t7416!f x; |
| 1400 |
} |
| 1401 |
|
| 1402 |
/**********************************/ |
| 1403 |
// https://issues.dlang.org/show_bug.cgi?id=7563 |
| 1404 |
|
| 1405 |
class Test7563 |
| 1406 |
{ |
| 1407 |
void test(T, bool a = true)(T t) |
| 1408 |
{ |
| 1409 |
|
| 1410 |
} |
| 1411 |
} |
| 1412 |
|
| 1413 |
void test7563() |
| 1414 |
{ |
| 1415 |
auto test = new Test7563; |
| 1416 |
pragma(msg, typeof(test.test!(int, true)).stringof); |
| 1417 |
pragma(msg, typeof(test.test!(int)).stringof); // Error: expression (test.test!(int)) has no type |
| 1418 |
} |
| 1419 |
|
| 1420 |
/**********************************/ |
| 1421 |
// https://issues.dlang.org/show_bug.cgi?id=7572 |
| 1422 |
|
| 1423 |
class F7572 |
| 1424 |
{ |
| 1425 |
Tr fn7572(Tr, T...)(T t) { return 1; } |
| 1426 |
} |
| 1427 |
Tr Fn7572(Tr, T...)(T t) { return 2; } |
| 1428 |
|
| 1429 |
void test7572() |
| 1430 |
{ |
| 1431 |
F7572 f = new F7572(); |
| 1432 |
int delegate() dg = &f.fn7572!int; |
| 1433 |
assert(dg() == 1); |
| 1434 |
|
| 1435 |
int function() fn = &Fn7572!int; |
| 1436 |
assert(fn() == 2); |
| 1437 |
} |
| 1438 |
|
| 1439 |
/**********************************/ |
| 1440 |
// https://issues.dlang.org/show_bug.cgi?id=7580 |
| 1441 |
|
| 1442 |
struct S7580(T) |
| 1443 |
{ |
| 1444 |
void opAssign()(T value) {} |
| 1445 |
} |
| 1446 |
struct X7580(T) |
| 1447 |
{ |
| 1448 |
private T val; |
| 1449 |
@property ref inout(T) get()() inout { return val; } // template |
| 1450 |
alias get this; |
| 1451 |
} |
| 1452 |
struct Y7580(T) |
| 1453 |
{ |
| 1454 |
private T val; |
| 1455 |
@property ref auto get()() inout { return val; } // template + auto return |
| 1456 |
alias get this; |
| 1457 |
} |
| 1458 |
|
| 1459 |
void test7580() |
| 1460 |
{ |
| 1461 |
S7580!(int) s; |
| 1462 |
X7580!int x; |
| 1463 |
Y7580!int y; |
| 1464 |
s = x; |
| 1465 |
s = y; |
| 1466 |
|
| 1467 |
shared(X7580!int) sx; |
| 1468 |
static assert(!__traits(compiles, s = sx)); |
| 1469 |
} |
| 1470 |
|
| 1471 |
/**********************************/ |
| 1472 |
// https://issues.dlang.org/show_bug.cgi?id=7585 |
| 1473 |
|
| 1474 |
extern(C) alias void function() Callback; |
| 1475 |
|
| 1476 |
template W7585a(alias dg) |
| 1477 |
{ |
| 1478 |
//pragma(msg, typeof(dg)); |
| 1479 |
extern(C) void W7585a() { dg(); } |
| 1480 |
} |
| 1481 |
|
| 1482 |
void test7585() |
| 1483 |
{ |
| 1484 |
static void f7585a(){} |
| 1485 |
Callback cb1 = &W7585a!(f7585a); // OK |
| 1486 |
static assert(!__traits(compiles, |
| 1487 |
{ |
| 1488 |
void f7585b(){} |
| 1489 |
Callback cb2 = &W7585a!(f7585b); // NG |
| 1490 |
})); |
| 1491 |
|
| 1492 |
Callback cb3 = &W7585a!((){}); // NG -> OK |
| 1493 |
Callback cb4 = &W7585a!(function(){}); // OK |
| 1494 |
static assert(!__traits(compiles, |
| 1495 |
{ |
| 1496 |
Callback cb5 = &W7585a!(delegate(){}); // NG |
| 1497 |
})); |
| 1498 |
|
| 1499 |
static int global; // global data |
| 1500 |
Callback cb6 = &W7585a!((){return global;}); // NG -> OK |
| 1501 |
static assert(!__traits(compiles, |
| 1502 |
{ |
| 1503 |
int n; |
| 1504 |
Callback cb7 = &W7585a!((){return n;}); // NG |
| 1505 |
})); |
| 1506 |
} |
| 1507 |
|
| 1508 |
/**********************************/ |
| 1509 |
// https://issues.dlang.org/show_bug.cgi?id=7643 |
| 1510 |
|
| 1511 |
template T7643(A...){ alias A T7643; } |
| 1512 |
|
| 1513 |
alias T7643!(long, "x", string, "y") Specs7643; |
| 1514 |
|
| 1515 |
alias T7643!( Specs7643[] ) U7643; // Error: tuple A is used as a type |
| 1516 |
|
| 1517 |
/**********************************/ |
| 1518 |
// https://issues.dlang.org/show_bug.cgi?id=7671 |
| 1519 |
|
| 1520 |
inout(int)[3] id7671n1 ( inout(int)[3] ); |
| 1521 |
inout( U )[n] id7671x1(U, size_t n)( inout( U )[n] ); |
| 1522 |
|
| 1523 |
shared(inout int)[3] id7671n2 ( shared(inout int)[3] ); |
| 1524 |
shared(inout U )[n] id7671x2(U, size_t n)( shared(inout U )[n] ); |
| 1525 |
|
| 1526 |
void test7671() |
| 1527 |
{ |
| 1528 |
static assert(is( typeof( id7671n1( (immutable(int)[3]).init ) ) == immutable(int[3]) )); |
| 1529 |
static assert(is( typeof( id7671x1( (immutable(int)[3]).init ) ) == immutable(int[3]) )); |
| 1530 |
|
| 1531 |
static assert(is( typeof( id7671n2( (immutable(int)[3]).init ) ) == immutable(int[3]) )); |
| 1532 |
static assert(is( typeof( id7671x2( (immutable(int)[3]).init ) ) == immutable(int[3]) )); |
| 1533 |
} |
| 1534 |
|
| 1535 |
/************************************/ |
| 1536 |
// https://issues.dlang.org/show_bug.cgi?id=7672 |
| 1537 |
|
| 1538 |
T foo7672(T)(T a){ return a; } |
| 1539 |
|
| 1540 |
void test7672(inout(int[]) a = null, inout(int*) p = null) |
| 1541 |
{ |
| 1542 |
static assert(is( typeof( a ) == inout(int[]) )); |
| 1543 |
static assert(is( typeof(foo7672(a)) == inout(int)[] )); |
| 1544 |
|
| 1545 |
static assert(is( typeof( p ) == inout(int*) )); |
| 1546 |
static assert(is( typeof(foo7672(p)) == inout(int)* )); |
| 1547 |
} |
| 1548 |
|
| 1549 |
/**********************************/ |
| 1550 |
// https://issues.dlang.org/show_bug.cgi?id=7684 |
| 1551 |
|
| 1552 |
U[] id7684(U)( U[] ); |
| 1553 |
shared(U[]) id7684(U)( shared(U[]) ); |
| 1554 |
|
| 1555 |
void test7684() |
| 1556 |
{ |
| 1557 |
shared(int)[] x; |
| 1558 |
static assert(is( typeof(id7684(x)) == shared(int)[] )); |
| 1559 |
} |
| 1560 |
|
| 1561 |
/**********************************/ |
| 1562 |
// https://issues.dlang.org/show_bug.cgi?id=7694 |
| 1563 |
|
| 1564 |
void match7694(alias m)() |
| 1565 |
{ |
| 1566 |
m.foo(); //removing this line suppresses ice in both cases |
| 1567 |
} |
| 1568 |
|
| 1569 |
struct T7694 |
| 1570 |
{ |
| 1571 |
void foo(){} |
| 1572 |
void bootstrap() |
| 1573 |
{ |
| 1574 |
//next line causes ice |
| 1575 |
match7694!(this)(); |
| 1576 |
//while this works: |
| 1577 |
alias this p; |
| 1578 |
match7694!(p)(); |
| 1579 |
} |
| 1580 |
} |
| 1581 |
|
| 1582 |
/**********************************/ |
| 1583 |
// https://issues.dlang.org/show_bug.cgi?id=7755 |
| 1584 |
|
| 1585 |
template to7755(T) |
| 1586 |
{ |
| 1587 |
T to7755(A...)(A args) |
| 1588 |
{ |
| 1589 |
return toImpl7755!T(args); |
| 1590 |
} |
| 1591 |
} |
| 1592 |
|
| 1593 |
T toImpl7755(T, S)(S value) |
| 1594 |
{ |
| 1595 |
return T.init; |
| 1596 |
} |
| 1597 |
|
| 1598 |
template Foo7755(T){} |
| 1599 |
|
| 1600 |
struct Bar7755 |
| 1601 |
{ |
| 1602 |
void qux() |
| 1603 |
{ |
| 1604 |
if (is(typeof(to7755!string(Foo7755!int)))){} |
| 1605 |
} |
| 1606 |
} |
| 1607 |
|
| 1608 |
/**********************************/ |
| 1609 |
|
| 1610 |
U[] id11a(U)( U[] ); |
| 1611 |
inout(U)[] id11a(U)( inout(U)[] ); |
| 1612 |
inout(U[]) id11a(U)( inout(U[]) ); |
| 1613 |
inout(shared(U[])) id11a(U)( inout(shared(U[])) ); |
| 1614 |
|
| 1615 |
void test11a(inout int _ = 0) |
| 1616 |
{ |
| 1617 |
shared(const(int))[] x; |
| 1618 |
static assert(is( typeof(id11a(x)) == shared(const(int))[] )); |
| 1619 |
|
| 1620 |
shared(int)[] y; |
| 1621 |
static assert(is( typeof(id11a(y)) == shared(int)[] )); |
| 1622 |
|
| 1623 |
inout(U)[n] idz(U, size_t n)( inout(U)[n] ); |
| 1624 |
|
| 1625 |
inout(shared(bool[1])) z; |
| 1626 |
static assert(is( typeof(idz(z)) == inout(shared(bool[1])) )); |
| 1627 |
} |
| 1628 |
|
| 1629 |
inout(U[]) id11b(U)( inout(U[]) ); |
| 1630 |
|
| 1631 |
void test11b() |
| 1632 |
{ |
| 1633 |
alias const(shared(int)[]) T; |
| 1634 |
static assert(is(typeof(id11b(T.init)) == const(shared(int)[]))); |
| 1635 |
} |
| 1636 |
|
| 1637 |
/**********************************/ |
| 1638 |
// https://issues.dlang.org/show_bug.cgi?id=7769 |
| 1639 |
|
| 1640 |
void f7769(K)(inout(K) value){} |
| 1641 |
void test7769() |
| 1642 |
{ |
| 1643 |
f7769("abc"); |
| 1644 |
} |
| 1645 |
|
| 1646 |
/**********************************/ |
| 1647 |
// https://issues.dlang.org/show_bug.cgi?id=7812 |
| 1648 |
|
| 1649 |
template A7812(T...) {} |
| 1650 |
|
| 1651 |
template B7812(alias C) if (C) {} |
| 1652 |
|
| 1653 |
template D7812() |
| 1654 |
{ |
| 1655 |
alias B7812!(A7812!(NonExistent!())) D7812; |
| 1656 |
} |
| 1657 |
|
| 1658 |
static assert(!__traits(compiles, D7812!())); |
| 1659 |
|
| 1660 |
/**********************************/ |
| 1661 |
// https://issues.dlang.org/show_bug.cgi?id=7873 |
| 1662 |
|
| 1663 |
inout(T)* foo(T)(inout(T)* t) |
| 1664 |
{ |
| 1665 |
static assert(is(T == int*)); |
| 1666 |
return t; |
| 1667 |
} |
| 1668 |
|
| 1669 |
inout(T)* bar(T)(inout(T)* t) |
| 1670 |
{ |
| 1671 |
return foo(t); |
| 1672 |
} |
| 1673 |
|
| 1674 |
void test7873() |
| 1675 |
{ |
| 1676 |
int *i; |
| 1677 |
bar(&i); |
| 1678 |
} |
| 1679 |
|
| 1680 |
/**********************************/ |
| 1681 |
// https://issues.dlang.org/show_bug.cgi?id=7933 |
| 1682 |
|
| 1683 |
struct Boo7933(size_t dim){int a;} |
| 1684 |
struct Baa7933(size_t dim) |
| 1685 |
{ |
| 1686 |
Boo7933!dim a; |
| 1687 |
//Boo7933!1 a; //(1) This version causes no errors |
| 1688 |
} |
| 1689 |
|
| 1690 |
auto foo7933()(Boo7933!1 b){return b;} |
| 1691 |
//auto fuu7933(Boo7933!1 b){return b;} //(2) This line neutralizes the error |
| 1692 |
|
| 1693 |
void test7933() |
| 1694 |
{ |
| 1695 |
Baa7933!1 a; //(3) This line causes the error message |
| 1696 |
auto b = foo7933(Boo7933!1(1)); |
| 1697 |
} |
| 1698 |
|
| 1699 |
/**********************************/ |
| 1700 |
// https://issues.dlang.org/show_bug.cgi?id=8094 |
| 1701 |
|
| 1702 |
struct Tuple8094(T...) {} |
| 1703 |
|
| 1704 |
template getParameters8094(T, alias P) |
| 1705 |
{ |
| 1706 |
static if (is(T t == P!U, U...)) |
| 1707 |
alias U getParameters8094; |
| 1708 |
else |
| 1709 |
static assert(false); |
| 1710 |
} |
| 1711 |
|
| 1712 |
void test8094() |
| 1713 |
{ |
| 1714 |
alias getParameters8094!(Tuple8094!(int, string), Tuple8094) args; |
| 1715 |
} |
| 1716 |
|
| 1717 |
/**********************************/ |
| 1718 |
|
| 1719 |
struct Tuple12(T...) |
| 1720 |
{ |
| 1721 |
void foo(alias P)() |
| 1722 |
{ |
| 1723 |
alias Tuple12 X; |
| 1724 |
static if (is(typeof(this) t == X!U, U...)) |
| 1725 |
alias U getParameters; |
| 1726 |
else |
| 1727 |
static assert(false); |
| 1728 |
} |
| 1729 |
} |
| 1730 |
|
| 1731 |
void test12() |
| 1732 |
{ |
| 1733 |
Tuple12!(int, string) t; |
| 1734 |
t.foo!Tuple12(); |
| 1735 |
} |
| 1736 |
|
| 1737 |
/**********************************/ |
| 1738 |
// https://issues.dlang.org/show_bug.cgi?id=14290 |
| 1739 |
|
| 1740 |
struct Foo14290(int i) {} |
| 1741 |
alias Foo14290a = Foo14290!1; |
| 1742 |
static assert(!is(Foo14290!2 == Foo14290a!T, T...)); |
| 1743 |
|
| 1744 |
/**********************************/ |
| 1745 |
// https://issues.dlang.org/show_bug.cgi?id=8125 |
| 1746 |
|
| 1747 |
void foo8125(){} |
| 1748 |
|
| 1749 |
struct X8125(alias a) {} |
| 1750 |
|
| 1751 |
template Y8125a(T : A!f, alias A, alias f) {} //OK |
| 1752 |
template Y8125b(T : A!foo8125, alias A) {} //NG |
| 1753 |
|
| 1754 |
void test8125() |
| 1755 |
{ |
| 1756 |
alias Y8125a!(X8125!foo8125) y1; |
| 1757 |
alias Y8125b!(X8125!foo8125) y2; |
| 1758 |
} |
| 1759 |
|
| 1760 |
/**********************************/ |
| 1761 |
|
| 1762 |
struct A13() {} |
| 1763 |
struct B13(TT...) {} |
| 1764 |
struct C13(T1) {} |
| 1765 |
struct D13(T1, TT...) {} |
| 1766 |
struct E13(T1, T2) {} |
| 1767 |
struct F13(T1, T2, TT...) {} |
| 1768 |
|
| 1769 |
template Test13(alias X) |
| 1770 |
{ |
| 1771 |
static if (is(X x : P!U, alias P, U...)) |
| 1772 |
enum Test13 = true; |
| 1773 |
else |
| 1774 |
enum Test13 = false; |
| 1775 |
} |
| 1776 |
|
| 1777 |
void test13() |
| 1778 |
{ |
| 1779 |
static assert(Test13!( A13!() )); |
| 1780 |
static assert(Test13!( B13!(int) )); |
| 1781 |
static assert(Test13!( B13!(int, double) )); |
| 1782 |
static assert(Test13!( B13!(int, double, string) )); |
| 1783 |
static assert(Test13!( C13!(int) )); |
| 1784 |
static assert(Test13!( D13!(int) )); |
| 1785 |
static assert(Test13!( D13!(int, double) )); |
| 1786 |
static assert(Test13!( D13!(int, double, string) )); |
| 1787 |
static assert(Test13!( E13!(int, double) )); |
| 1788 |
static assert(Test13!( F13!(int, double) )); |
| 1789 |
static assert(Test13!( F13!(int, double, string) )); |
| 1790 |
static assert(Test13!( F13!(int, double, string, bool) )); |
| 1791 |
} |
| 1792 |
|
| 1793 |
/**********************************/ |
| 1794 |
|
| 1795 |
struct A14(T, U, int n = 1) |
| 1796 |
{ |
| 1797 |
} |
| 1798 |
|
| 1799 |
template Test14(alias X) |
| 1800 |
{ |
| 1801 |
static if (is(X x : P!U, alias P, U...)) |
| 1802 |
alias U Test14; |
| 1803 |
else |
| 1804 |
static assert(0); |
| 1805 |
} |
| 1806 |
|
| 1807 |
void test14() |
| 1808 |
{ |
| 1809 |
alias A14!(int, double) Type; |
| 1810 |
alias Test14!Type Params; |
| 1811 |
static assert(Params.length == 3); |
| 1812 |
static assert(is(Params[0] == int)); |
| 1813 |
static assert(is(Params[1] == double)); |
| 1814 |
static assert( Params[2] == 1); |
| 1815 |
} |
| 1816 |
|
| 1817 |
/**********************************/ |
| 1818 |
// test for evaluateConstraint assertion |
| 1819 |
|
| 1820 |
bool canSearchInCodeUnits15(C)(dchar c) |
| 1821 |
if (is(C == char)) |
| 1822 |
{ |
| 1823 |
return true; |
| 1824 |
} |
| 1825 |
|
| 1826 |
void test15() |
| 1827 |
{ |
| 1828 |
int needle = 0; |
| 1829 |
auto b = canSearchInCodeUnits15!char(needle); |
| 1830 |
} |
| 1831 |
|
| 1832 |
/**********************************/ |
| 1833 |
// https://issues.dlang.org/show_bug.cgi?id=8129 |
| 1834 |
|
| 1835 |
class X8129 {} |
| 1836 |
class A8129 {} |
| 1837 |
class B8129 : A8129 {} |
| 1838 |
|
| 1839 |
int foo8129(T : A8129)(X8129 x) { return 1; } |
| 1840 |
int foo8129(T : A8129)(X8129 x, void function (T) block) { return 2; } |
| 1841 |
|
| 1842 |
int bar8129(T, R)(R range, T value) { return 1; } |
| 1843 |
|
| 1844 |
int baz8129(T, R)(R range, T value) { return 1; } |
| 1845 |
int baz8129(T, R)(R range, Undefined value) { return 2; } |
| 1846 |
|
| 1847 |
void test8129() |
| 1848 |
{ |
| 1849 |
auto x = new X8129; |
| 1850 |
assert(x.foo8129!B8129() == 1); |
| 1851 |
assert(x.foo8129!B8129((a){}) == 2); |
| 1852 |
assert(foo8129!B8129(x) == 1); |
| 1853 |
assert(foo8129!B8129(x, (a){}) == 2); |
| 1854 |
assert(foo8129!B8129(x) == 1); |
| 1855 |
assert(foo8129!B8129(x, (B8129 b){}) == 2); |
| 1856 |
|
| 1857 |
ubyte[] buffer = [0, 1, 2]; |
| 1858 |
assert(bar8129!ushort(buffer, 915) == 1); |
| 1859 |
|
| 1860 |
// While deduction, parameter type 'Undefined' shows semantic error. |
| 1861 |
static assert(!__traits(compiles, { |
| 1862 |
baz8129!ushort(buffer, 915); |
| 1863 |
})); |
| 1864 |
} |
| 1865 |
|
| 1866 |
/**********************************/ |
| 1867 |
// https://issues.dlang.org/show_bug.cgi?id=8238 |
| 1868 |
|
| 1869 |
void test8238() |
| 1870 |
{ |
| 1871 |
static struct S { template t(){ int t; } } |
| 1872 |
|
| 1873 |
S s1, s2; |
| 1874 |
assert(cast(void*)&s1 != cast(void*)&s2 ); |
| 1875 |
assert(cast(void*)&s1 != cast(void*)&s1.t!()); |
| 1876 |
assert(cast(void*)&s2 != cast(void*)&s2.t!()); |
| 1877 |
assert(cast(void*)&s1.t!() == cast(void*)&s2.t!()); |
| 1878 |
s1.t!() = 256; |
| 1879 |
assert(s2.t!() == 256); |
| 1880 |
} |
| 1881 |
|
| 1882 |
/**********************************/ |
| 1883 |
// https://issues.dlang.org/show_bug.cgi?id=8669 |
| 1884 |
|
| 1885 |
struct X8669 |
| 1886 |
{ |
| 1887 |
void mfoo(this T)() |
| 1888 |
{ |
| 1889 |
static assert(is(typeof(this) == T)); |
| 1890 |
} |
| 1891 |
void cfoo(this T)() const |
| 1892 |
{ |
| 1893 |
static assert(is(typeof(this) == const(T))); |
| 1894 |
} |
| 1895 |
void sfoo(this T)() shared |
| 1896 |
{ |
| 1897 |
static assert(is(typeof(this) == shared(T))); |
| 1898 |
} |
| 1899 |
void scfoo(this T)() shared const |
| 1900 |
{ |
| 1901 |
static assert(is(typeof(this) == shared(const(T)))); |
| 1902 |
} |
| 1903 |
void ifoo(this T)() immutable |
| 1904 |
{ |
| 1905 |
static assert(is(typeof(this) == immutable(T))); |
| 1906 |
} |
| 1907 |
} |
| 1908 |
|
| 1909 |
void test8669() |
| 1910 |
{ |
| 1911 |
X8669 mx; |
| 1912 |
const X8669 cx; |
| 1913 |
immutable X8669 ix; |
| 1914 |
shared X8669 sx; |
| 1915 |
shared const X8669 scx; |
| 1916 |
|
| 1917 |
mx.mfoo(); |
| 1918 |
cx.mfoo(); |
| 1919 |
ix.mfoo(); |
| 1920 |
sx.mfoo(); |
| 1921 |
scx.mfoo(); |
| 1922 |
|
| 1923 |
mx.cfoo(); |
| 1924 |
cx.cfoo(); |
| 1925 |
ix.cfoo(); |
| 1926 |
sx.cfoo(); |
| 1927 |
scx.cfoo(); |
| 1928 |
|
| 1929 |
static assert(!is(typeof( mx.sfoo() ))); |
| 1930 |
static assert(!is(typeof( cx.sfoo() ))); |
| 1931 |
ix.sfoo(); |
| 1932 |
sx.sfoo(); |
| 1933 |
scx.sfoo(); |
| 1934 |
|
| 1935 |
static assert(!is(typeof( mx.scfoo() ))); |
| 1936 |
static assert(!is(typeof( cx.scfoo() ))); |
| 1937 |
ix.scfoo(); |
| 1938 |
sx.scfoo(); |
| 1939 |
scx.scfoo(); |
| 1940 |
|
| 1941 |
static assert(!is(typeof( mx.ifoo() ))); |
| 1942 |
static assert(!is(typeof( cx.ifoo() ))); |
| 1943 |
ix.ifoo(); |
| 1944 |
static assert(!is(typeof( sx.ifoo() ))); |
| 1945 |
static assert(!is(typeof( scx.ifoo() ))); |
| 1946 |
} |
| 1947 |
|
| 1948 |
/**********************************/ |
| 1949 |
// https://issues.dlang.org/show_bug.cgi?id=8833 |
| 1950 |
|
| 1951 |
template TypeTuple8833(T...) { alias TypeTuple = T; } |
| 1952 |
|
| 1953 |
void func8833(alias arg)() { } |
| 1954 |
|
| 1955 |
void test8833() |
| 1956 |
{ |
| 1957 |
int x, y; |
| 1958 |
|
| 1959 |
alias TypeTuple8833!( |
| 1960 |
func8833!(x), |
| 1961 |
func8833!(y), |
| 1962 |
) Map; |
| 1963 |
} |
| 1964 |
|
| 1965 |
/**********************************/ |
| 1966 |
// https://issues.dlang.org/show_bug.cgi?id=8976 |
| 1967 |
|
| 1968 |
void f8976(ref int) { } |
| 1969 |
|
| 1970 |
void g8976()() |
| 1971 |
{ |
| 1972 |
f8976(0); // line 5 |
| 1973 |
} |
| 1974 |
|
| 1975 |
|
| 1976 |
void h8976()() |
| 1977 |
{ |
| 1978 |
g8976!()(); |
| 1979 |
} |
| 1980 |
|
| 1981 |
static assert( __traits(compiles, h8976!()() ) ); // causes error |
| 1982 |
static assert(is(typeof( h8976!()() ))); |
| 1983 |
|
| 1984 |
void test8976() |
| 1985 |
{ |
| 1986 |
static assert( __traits(compiles, h8976!()() ) ); |
| 1987 |
static assert(is(typeof( h8976!()() ))); |
| 1988 |
} |
| 1989 |
|
| 1990 |
/****************************************/ |
| 1991 |
// https://issues.dlang.org/show_bug.cgi?id=8940 |
| 1992 |
|
| 1993 |
const int n8940; // or `immutable` |
| 1994 |
shared static this() { n8940 = 3; } |
| 1995 |
|
| 1996 |
void f8940(T)(ref int val) |
| 1997 |
{ |
| 1998 |
assert(val == 3); |
| 1999 |
++val; |
| 2000 |
} |
| 2001 |
|
| 2002 |
static assert(!__traits(compiles, f8940!void(n8940))); // fails |
| 2003 |
void test8940() |
| 2004 |
{ |
| 2005 |
assert(n8940 == 3); |
| 2006 |
static assert(!__traits(compiles, f8940!void(n8940))); |
| 2007 |
//assert(n8940 == 3); // may pass as compiler caches comparison result |
| 2008 |
//assert(n8940 != 4); // may pass but likely will fail |
| 2009 |
} |
| 2010 |
|
| 2011 |
/**********************************/ |
| 2012 |
// https://issues.dlang.org/show_bug.cgi?id=6969 |
| 2013 |
// https://issues.dlang.org/show_bug.cgi?id=8990 |
| 2014 |
|
| 2015 |
class A6969() { alias C6969!() C1; } |
| 2016 |
class B6969 { alias A6969!() A1; } |
| 2017 |
class C6969() : B6969 {} |
| 2018 |
|
| 2019 |
struct A8990(T) { T t; } |
| 2020 |
struct B8990(T) { A8990!T* a; } |
| 2021 |
struct C8990 { B8990!C8990* b; } |
| 2022 |
|
| 2023 |
/**********************************/ |
| 2024 |
// https://issues.dlang.org/show_bug.cgi?id=9018 |
| 2025 |
|
| 2026 |
template Inst9018(alias Template, T) |
| 2027 |
{ |
| 2028 |
alias Template!T Inst; |
| 2029 |
} |
| 2030 |
|
| 2031 |
template Template9018(T) |
| 2032 |
{ |
| 2033 |
enum Template9018 = T; |
| 2034 |
} |
| 2035 |
|
| 2036 |
static assert(!__traits(compiles, Inst9018!(Template9018, int))); // Assert passes |
| 2037 |
static assert(!__traits(compiles, Inst9018!(Template9018, int))); // Assert fails |
| 2038 |
|
| 2039 |
/**********************************/ |
| 2040 |
// https://issues.dlang.org/show_bug.cgi?id=9022 |
| 2041 |
|
| 2042 |
class C9022 |
| 2043 |
{ |
| 2044 |
struct X {} |
| 2045 |
|
| 2046 |
alias B = X; |
| 2047 |
} |
| 2048 |
class D9022 |
| 2049 |
{ |
| 2050 |
struct X {} |
| 2051 |
} |
| 2052 |
|
| 2053 |
void test9022() |
| 2054 |
{ |
| 2055 |
auto c = new C9022(); |
| 2056 |
auto d = new D9022(); |
| 2057 |
auto cx = C9022.X(); |
| 2058 |
auto dx = D9022.X(); |
| 2059 |
|
| 2060 |
void foo1(T)(T, T.X) { static assert(is(T == C9022)); } |
| 2061 |
void foo2(T)(T.X, T) { static assert(is(T == C9022)); } |
| 2062 |
foo1(c, cx); |
| 2063 |
foo2(cx, c); |
| 2064 |
|
| 2065 |
void hoo1(T)(T, T.B) { static assert(is(T == C9022)); } |
| 2066 |
void hoo2(T)(T.B, T) { static assert(is(T == C9022)); } |
| 2067 |
hoo1(c, cx); |
| 2068 |
hoo1(c, cx); |
| 2069 |
|
| 2070 |
void bar1(alias A)(A.C9022, A.D9022) { static assert(A.stringof == "module breaker"); } |
| 2071 |
void bar2(alias A)(A.D9022, A.C9022) { static assert(A.stringof == "module breaker"); } |
| 2072 |
bar1(c, d); |
| 2073 |
bar2(d, c); |
| 2074 |
|
| 2075 |
void var1(alias A)(A.C9022, A.D9022.X) { static assert(A.stringof == "module breaker"); } |
| 2076 |
void var2(alias A)(A.D9022.X, A.C9022) { static assert(A.stringof == "module breaker"); } |
| 2077 |
var1(c, dx); |
| 2078 |
var2(dx, c); |
| 2079 |
|
| 2080 |
void baz(T)(T.X t, T.X u) { } |
| 2081 |
static assert(!__traits(compiles, baz(cx, dx))); |
| 2082 |
} |
| 2083 |
|
| 2084 |
/**********************************/ |
| 2085 |
// https://issues.dlang.org/show_bug.cgi?id=9026 |
| 2086 |
|
| 2087 |
mixin template node9026() |
| 2088 |
{ |
| 2089 |
static if (is(this == struct)) |
| 2090 |
alias typeof(this)* E; |
| 2091 |
else |
| 2092 |
alias typeof(this) E; |
| 2093 |
E prev, next; |
| 2094 |
} |
| 2095 |
|
| 2096 |
struct list9026(alias N) |
| 2097 |
{ |
| 2098 |
N.E head; |
| 2099 |
N.E tail; |
| 2100 |
} |
| 2101 |
|
| 2102 |
class A9026 |
| 2103 |
{ |
| 2104 |
mixin node9026 L1; |
| 2105 |
mixin node9026 L2; |
| 2106 |
} |
| 2107 |
|
| 2108 |
list9026!(A9026.L1) g9026_l1; |
| 2109 |
list9026!(A9026.L2) g9026_l2; |
| 2110 |
|
| 2111 |
void test9026() |
| 2112 |
{ |
| 2113 |
list9026!(A9026.L1) l9026_l1; |
| 2114 |
list9026!(A9026.L2) l9026_l2; |
| 2115 |
} |
| 2116 |
|
| 2117 |
/**********************************/ |
| 2118 |
// https://issues.dlang.org/show_bug.cgi?id=9038 |
| 2119 |
|
| 2120 |
mixin template Foo9038() |
| 2121 |
{ |
| 2122 |
string data = "default"; |
| 2123 |
} |
| 2124 |
|
| 2125 |
class Bar9038 |
| 2126 |
{ |
| 2127 |
string data; |
| 2128 |
mixin Foo9038 f; |
| 2129 |
} |
| 2130 |
|
| 2131 |
void check_data9038(alias M, T)(T obj) |
| 2132 |
{ |
| 2133 |
//writeln(M.stringof); |
| 2134 |
assert(obj.data == "Bar"); |
| 2135 |
assert(obj.f.data == "F"); |
| 2136 |
} |
| 2137 |
|
| 2138 |
void test9038() |
| 2139 |
{ |
| 2140 |
auto bar = new Bar9038; |
| 2141 |
bar.data = "Bar"; |
| 2142 |
bar.f.data = "F"; |
| 2143 |
|
| 2144 |
assert(bar.data == "Bar"); |
| 2145 |
assert(bar.f.data == "F"); |
| 2146 |
|
| 2147 |
check_data9038!(Bar9038)(bar); |
| 2148 |
check_data9038!(Bar9038.f)(bar); |
| 2149 |
check_data9038!(bar.f)(bar); |
| 2150 |
} |
| 2151 |
|
| 2152 |
/**********************************/ |
| 2153 |
// https://issues.dlang.org/show_bug.cgi?id=9050 |
| 2154 |
|
| 2155 |
struct A9050(T) {} |
| 2156 |
|
| 2157 |
struct B9050(T) |
| 2158 |
{ |
| 2159 |
void f() { foo9050(A9050!int()); } |
| 2160 |
} |
| 2161 |
|
| 2162 |
auto foo9050()(A9050!int base) pure |
| 2163 |
{ |
| 2164 |
return B9050!int(); |
| 2165 |
} |
| 2166 |
|
| 2167 |
auto s9050 = foo9050(A9050!int()); |
| 2168 |
|
| 2169 |
/**********************************/ |
| 2170 |
// https://issues.dlang.org/show_bug.cgi?id=10936 (dup of 9050) |
| 2171 |
|
| 2172 |
struct Vec10936(string s) |
| 2173 |
{ |
| 2174 |
auto foo(string v)() |
| 2175 |
{ |
| 2176 |
return Vec10936!(v)(); |
| 2177 |
} |
| 2178 |
|
| 2179 |
static void bar() |
| 2180 |
{ |
| 2181 |
Vec10936!"" v; |
| 2182 |
auto p = v.foo!"sup"; |
| 2183 |
} |
| 2184 |
} |
| 2185 |
|
| 2186 |
Vec10936!"" v; |
| 2187 |
|
| 2188 |
/**********************************/ |
| 2189 |
// https://issues.dlang.org/show_bug.cgi?id=9076 |
| 2190 |
|
| 2191 |
template forward9076(args...) |
| 2192 |
{ |
| 2193 |
@property forward9076()(){ return args[0]; } |
| 2194 |
} |
| 2195 |
|
| 2196 |
void test9076() |
| 2197 |
{ |
| 2198 |
int a = 1; |
| 2199 |
int b = 1; |
| 2200 |
assert(a == forward9076!b); |
| 2201 |
} |
| 2202 |
|
| 2203 |
/**********************************/ |
| 2204 |
// https://issues.dlang.org/show_bug.cgi?id=9083 |
| 2205 |
|
| 2206 |
template isFunction9083(X...) if (X.length == 1) |
| 2207 |
{ |
| 2208 |
enum isFunction9083 = true; |
| 2209 |
} |
| 2210 |
|
| 2211 |
struct S9083 |
| 2212 |
{ |
| 2213 |
static string func(alias Class)() |
| 2214 |
{ |
| 2215 |
foreach (m; __traits(allMembers, Class)) |
| 2216 |
{ |
| 2217 |
pragma(msg, m); // prints "func" |
| 2218 |
enum x1 = isFunction9083!(mixin(m)); //NG |
| 2219 |
enum x2 = isFunction9083!(func); //OK |
| 2220 |
} |
| 2221 |
return ""; |
| 2222 |
} |
| 2223 |
} |
| 2224 |
enum nothing9083 = S9083.func!S9083(); |
| 2225 |
|
| 2226 |
class C9083 |
| 2227 |
{ |
| 2228 |
int x; // some class members |
| 2229 |
|
| 2230 |
void func() |
| 2231 |
{ |
| 2232 |
void templateFunc(T)(const T obj) |
| 2233 |
{ |
| 2234 |
enum x1 = isFunction9083!(mixin("x")); // NG |
| 2235 |
enum x2 = isFunction9083!(x); // NG |
| 2236 |
} |
| 2237 |
templateFunc(this); |
| 2238 |
} |
| 2239 |
} |
| 2240 |
|
| 2241 |
/**********************************/ |
| 2242 |
// https://issues.dlang.org/show_bug.cgi?id=9100 |
| 2243 |
|
| 2244 |
template Id(alias A) { alias Id = A; } |
| 2245 |
template ErrId(alias A) { static assert(0); } |
| 2246 |
template TypeTuple9100(TL...) { alias TypeTuple9100 = TL; } |
| 2247 |
|
| 2248 |
class C9100 |
| 2249 |
{ |
| 2250 |
int value; |
| 2251 |
|
| 2252 |
int fun() { return value; } |
| 2253 |
int tfun(T)() { return value; } |
| 2254 |
TypeTuple9100!(int, long) field; |
| 2255 |
|
| 2256 |
void test() |
| 2257 |
{ |
| 2258 |
this.value = 1; |
| 2259 |
auto c = new C9100(); |
| 2260 |
c.value = 2; |
| 2261 |
|
| 2262 |
alias t1a = Id!(c.fun); // OK |
| 2263 |
alias t1b = Id!(this.fun); // Prints weird error, bad |
| 2264 |
// -> internally given TOKdotvar |
| 2265 |
assert(t1a() == this.value); |
| 2266 |
assert(t1b() == this.value); |
| 2267 |
|
| 2268 |
alias t2a = Id!(c.tfun); // OK |
| 2269 |
static assert(!__traits(compiles, ErrId!(this.tfun))); |
| 2270 |
alias t2b = Id!(this.tfun); // No error occurs, why? |
| 2271 |
// -> internally given TOKdottd |
| 2272 |
assert(t2a!int() == this.value); |
| 2273 |
assert(t2b!int() == this.value); |
| 2274 |
|
| 2275 |
alias t3a = Id!(foo9100); // OK |
| 2276 |
alias t3b = Id!(mixin("foo9100")); // Prints weird error, bad |
| 2277 |
// -> internally given TOKtemplate |
| 2278 |
assert(t3a() == 10); |
| 2279 |
assert(t3b() == 10); |
| 2280 |
|
| 2281 |
assert(field[0] == 0); |
| 2282 |
alias t4a = TypeTuple9100!(field); // NG |
| 2283 |
alias t4b = TypeTuple9100!(GetField9100!()); // NG |
| 2284 |
t4a[0] = 1; assert(field[0] == 1); |
| 2285 |
t4b[0] = 2; assert(field[0] == 2); |
| 2286 |
} |
| 2287 |
} |
| 2288 |
|
| 2289 |
int foo9100()() { return 10; } |
| 2290 |
template GetField9100() { alias GetField9100 = C9100.field[0]; } |
| 2291 |
|
| 2292 |
void test9100() |
| 2293 |
{ |
| 2294 |
(new C9100()).test(); |
| 2295 |
} |
| 2296 |
|
| 2297 |
/**********************************/ |
| 2298 |
// https://issues.dlang.org/show_bug.cgi?id=9101 |
| 2299 |
|
| 2300 |
class Node9101 |
| 2301 |
{ |
| 2302 |
template ForwardCtorNoId() |
| 2303 |
{ |
| 2304 |
this() {} // default constructor |
| 2305 |
void foo() { 0 = 1; } // wrong code |
| 2306 |
} |
| 2307 |
} |
| 2308 |
enum x9101 = __traits(compiles, Node9101.ForwardCtorNoId!()); |
| 2309 |
|
| 2310 |
/**********************************/ |
| 2311 |
// https://issues.dlang.org/show_bug.cgi?id=9124 |
| 2312 |
|
| 2313 |
struct Foo9124a(N...) |
| 2314 |
{ |
| 2315 |
enum SIZE = N[0]; |
| 2316 |
private int _val; |
| 2317 |
|
| 2318 |
public void opAssign (T) (T other) |
| 2319 |
if (is(T unused == Foo9124a!(_N), _N...)) |
| 2320 |
{ |
| 2321 |
_val = other._val; // compile error |
| 2322 |
this._val = other._val; // explicit this make it work |
| 2323 |
} |
| 2324 |
|
| 2325 |
public auto opUnary (string op) () if (op == "~") { |
| 2326 |
Foo9124a!(SIZE) result = this; |
| 2327 |
return result; |
| 2328 |
} |
| 2329 |
} |
| 2330 |
void test9124a() |
| 2331 |
{ |
| 2332 |
Foo9124a!(28) a; |
| 2333 |
Foo9124a!(28) b = ~a; |
| 2334 |
} |
| 2335 |
|
| 2336 |
// -------- |
| 2337 |
|
| 2338 |
template Foo9124b(T, U, string OP) |
| 2339 |
{ |
| 2340 |
enum N = T.SIZE; |
| 2341 |
alias Foo9124b = Foo9124b!(false, true, N); |
| 2342 |
} |
| 2343 |
struct Foo9124b(bool S, bool L, N...) |
| 2344 |
{ |
| 2345 |
enum SIZE = 5; |
| 2346 |
long[1] _a = 0; |
| 2347 |
void someFunction() const { |
| 2348 |
auto data1 = _a; // Does not compile |
| 2349 |
auto data2 = this._a; // <--- Compiles |
| 2350 |
} |
| 2351 |
auto opBinary(string op, T)(T) { |
| 2352 |
Foo9124b!(typeof(this), T, op) test; |
| 2353 |
} |
| 2354 |
} |
| 2355 |
void test9124b() |
| 2356 |
{ |
| 2357 |
auto p = Foo9124b!(false, false, 5)(); |
| 2358 |
auto q = Foo9124b!(false, false, 5)(); |
| 2359 |
p|q; |
| 2360 |
p&q; |
| 2361 |
} |
| 2362 |
|
| 2363 |
/**********************************/ |
| 2364 |
// https://issues.dlang.org/show_bug.cgi?id=9143 |
| 2365 |
|
| 2366 |
struct Foo9143a(bool S, bool L) |
| 2367 |
{ |
| 2368 |
auto noCall() { |
| 2369 |
Foo9143a!(S, false) x1; // compiles if this line commented |
| 2370 |
static if(S) Foo9143a!(true, false) x2; |
| 2371 |
else Foo9143a!(false, false) x2; |
| 2372 |
} |
| 2373 |
this(T)(T other) // constructor |
| 2374 |
if (is(T unused == Foo9143a!(P, Q), bool P, bool Q)) { } |
| 2375 |
} |
| 2376 |
|
| 2377 |
struct Foo9143b(bool L, size_t N) |
| 2378 |
{ |
| 2379 |
void baaz0() { |
| 2380 |
bar!(Foo9143b!(false, N))(); // line 7 |
| 2381 |
// -> move to before the baaz semantic |
| 2382 |
} |
| 2383 |
void baaz() { |
| 2384 |
bar!(Foo9143b!(false, 2LU))(); // line 3 |
| 2385 |
bar!(Foo9143b!(true, 2LU))(); // line 4 |
| 2386 |
bar!(Foo9143b!(L, N))(); // line 5 |
| 2387 |
bar!(Foo9143b!(true, N))(); // line 6 |
| 2388 |
bar!(Foo9143b!(false, N))(); // line 7 |
| 2389 |
} |
| 2390 |
void bar(T)() |
| 2391 |
if (is(T unused == Foo9143b!(_L, _N), bool _L, size_t _N)) |
| 2392 |
{} |
| 2393 |
} |
| 2394 |
|
| 2395 |
void test9143() |
| 2396 |
{ |
| 2397 |
Foo9143a!(false, true) k = Foo9143a!(false, false)(); |
| 2398 |
|
| 2399 |
auto p = Foo9143b!(true, 2LU)(); |
| 2400 |
} |
| 2401 |
|
| 2402 |
/**********************************/ |
| 2403 |
// https://issues.dlang.org/show_bug.cgi?id=9266 |
| 2404 |
|
| 2405 |
template Foo9266(T...) |
| 2406 |
{ |
| 2407 |
T Foo9266; |
| 2408 |
} |
| 2409 |
struct Bar9266() |
| 2410 |
{ |
| 2411 |
alias Foo9266!int f; |
| 2412 |
} |
| 2413 |
void test9266() |
| 2414 |
{ |
| 2415 |
Bar9266!() a, b; |
| 2416 |
} |
| 2417 |
|
| 2418 |
/**********************************/ |
| 2419 |
// https://issues.dlang.org/show_bug.cgi?id=9361 |
| 2420 |
|
| 2421 |
struct Unit9361(A) |
| 2422 |
{ |
| 2423 |
void butPleaseDontUseMe()() |
| 2424 |
if (is(unitType9361!((this)))) // ! |
| 2425 |
{} |
| 2426 |
|
| 2427 |
} |
| 2428 |
template isUnit9361(alias T) if ( is(T)) {} |
| 2429 |
template isUnit9361(alias T) if (!is(T)) {} |
| 2430 |
|
| 2431 |
template unitType9361(alias T) if (isUnit9361!T) {} |
| 2432 |
|
| 2433 |
void test9361() |
| 2434 |
{ |
| 2435 |
Unit9361!int u; |
| 2436 |
static assert(!__traits(compiles, u.butPleaseDontUseMe())); // crashes |
| 2437 |
} |
| 2438 |
|
| 2439 |
/**********************************/ |
| 2440 |
// https://issues.dlang.org/show_bug.cgi?id=9536 |
| 2441 |
|
| 2442 |
struct S9536 |
| 2443 |
{ |
| 2444 |
static A foo(A)(A a) |
| 2445 |
{ |
| 2446 |
return a * 2; |
| 2447 |
} |
| 2448 |
int bar() const |
| 2449 |
{ |
| 2450 |
return foo(42); |
| 2451 |
} |
| 2452 |
} |
| 2453 |
|
| 2454 |
void test9536() |
| 2455 |
{ |
| 2456 |
S9536 s; |
| 2457 |
assert(s.bar() == 84); |
| 2458 |
} |
| 2459 |
|
| 2460 |
/**********************************/ |
| 2461 |
// https://issues.dlang.org/show_bug.cgi?id=9578 |
| 2462 |
|
| 2463 |
template t9578(alias f) { void tf()() { f(); } } |
| 2464 |
|
| 2465 |
void g9578a(alias f)() { f(); } // Error -> OK |
| 2466 |
void g9578b(alias ti)() { ti.tf(); } // Error -> OK |
| 2467 |
|
| 2468 |
void test9578() |
| 2469 |
{ |
| 2470 |
int i = 0; |
| 2471 |
int m() { return i; } |
| 2472 |
|
| 2473 |
g9578a!(t9578!m.tf)(); |
| 2474 |
g9578b!(t9578!m)(); |
| 2475 |
} |
| 2476 |
|
| 2477 |
/**********************************/ |
| 2478 |
// https://issues.dlang.org/show_bug.cgi?id=9596 |
| 2479 |
|
| 2480 |
int foo9596a(K, V)(inout( V [K])) { return 1; } |
| 2481 |
int foo9596a(K, V)(inout(shared(V) [K])) { return 2; } |
| 2482 |
|
| 2483 |
int foo9596b(K, V)(inout( V [K])) { return 1; } |
| 2484 |
int foo9596b(K, V)(inout( const(V) [K])) { return 3; } |
| 2485 |
|
| 2486 |
int foo9596c(K, V)(inout(shared(V) [K])) { return 2; } |
| 2487 |
int foo9596c(K, V)(inout( const(V) [K])) { return 3; } |
| 2488 |
|
| 2489 |
int foo9596d(K, V)(inout( V [K])) { return 1; } |
| 2490 |
int foo9596d(K, V)(inout(shared(V) [K])) { return 2; } |
| 2491 |
int foo9596d(K, V)(inout( const(V) [K])) { return 3; } |
| 2492 |
|
| 2493 |
int foo9596e(K, V)(inout(shared(V) [K])) { return 2; } |
| 2494 |
int foo9596e(K, V)(inout( V [K])) { return 1; } |
| 2495 |
int foo9596e(K, V)(inout( const(V) [K])) { return 3; } |
| 2496 |
|
| 2497 |
void test9596() |
| 2498 |
{ |
| 2499 |
shared(int)[int] aa; |
| 2500 |
static assert(!__traits(compiles, foo9596a(aa))); |
| 2501 |
|
| 2502 |
assert(foo9596b(aa) == 1); |
| 2503 |
assert(foo9596c(aa) == 2); |
| 2504 |
|
| 2505 |
static assert(!__traits(compiles, foo9596d(aa))); |
| 2506 |
static assert(!__traits(compiles, foo9596e(aa))); |
| 2507 |
} |
| 2508 |
|
| 2509 |
/******************************************/ |
| 2510 |
// https://issues.dlang.org/show_bug.cgi?id=9806 |
| 2511 |
|
| 2512 |
struct S9806a(alias x) |
| 2513 |
{ |
| 2514 |
alias S9806a!0 N; |
| 2515 |
} |
| 2516 |
enum expr9806a = 0 * 0; |
| 2517 |
alias S9806a!expr9806a T9806a; |
| 2518 |
|
| 2519 |
// -------- |
| 2520 |
|
| 2521 |
struct S9806b(alias x) |
| 2522 |
{ |
| 2523 |
template Next() |
| 2524 |
{ |
| 2525 |
enum expr = x + 1; |
| 2526 |
alias S9806b!expr Next; |
| 2527 |
} |
| 2528 |
} |
| 2529 |
alias S9806b!1 One9806b; |
| 2530 |
alias S9806b!0.Next!() OneAgain9806b; |
| 2531 |
|
| 2532 |
// -------- |
| 2533 |
|
| 2534 |
struct S9806c(x...) |
| 2535 |
{ |
| 2536 |
template Next() |
| 2537 |
{ |
| 2538 |
enum expr = x[0] + 1; |
| 2539 |
alias S9806c!expr Next; |
| 2540 |
} |
| 2541 |
} |
| 2542 |
alias S9806c!1 One9806c; |
| 2543 |
alias S9806c!0.Next!() OneAgain9806c; |
| 2544 |
|
| 2545 |
/******************************************/ |
| 2546 |
// https://issues.dlang.org/show_bug.cgi?id=9837 |
| 2547 |
|
| 2548 |
void test9837() |
| 2549 |
{ |
| 2550 |
enum DA : int[] { a = [1,2,3] } |
| 2551 |
DA da; |
| 2552 |
int[] bda = da; |
| 2553 |
static assert(is(DA : int[])); |
| 2554 |
void fda1(int[] a) {} |
| 2555 |
void fda2(T)(T[] a) {} |
| 2556 |
fda1(da); |
| 2557 |
fda2(da); |
| 2558 |
|
| 2559 |
enum SA : int[3] { a = [1,2,3] } |
| 2560 |
SA sa; |
| 2561 |
int[3] bsa = sa; |
| 2562 |
static assert(is(SA : int[3])); |
| 2563 |
void fsa1(int[3] a) {} |
| 2564 |
void fsa2(T)(T[3] a) {} |
| 2565 |
void fsa3(size_t d)(int[d] a) {} |
| 2566 |
void fsa4(T, size_t d)(T[d] a) {} |
| 2567 |
fsa1(sa); |
| 2568 |
fsa2(sa); |
| 2569 |
fsa3(sa); |
| 2570 |
fsa4(sa); |
| 2571 |
|
| 2572 |
enum AA : int[int] { a = null } |
| 2573 |
AA aa; |
| 2574 |
int[int] baa = aa; |
| 2575 |
static assert(is(AA : int[int])); |
| 2576 |
void faa1(int[int] a) {} |
| 2577 |
void faa2(V)(V[int] a) {} |
| 2578 |
void faa3(K)(int[K] a) {} |
| 2579 |
void faa4(K, V)(V[K] a) {} |
| 2580 |
faa1(aa); |
| 2581 |
faa2(aa); |
| 2582 |
faa3(aa); |
| 2583 |
faa4(aa); |
| 2584 |
} |
| 2585 |
|
| 2586 |
/******************************************/ |
| 2587 |
// https://issues.dlang.org/show_bug.cgi?id=9874 |
| 2588 |
|
| 2589 |
bool foo9874() { return true; } |
| 2590 |
void bar9874(T)(T) if (foo9874()) {} // OK |
| 2591 |
void baz9874(T)(T) if (foo9874) {} // error |
| 2592 |
|
| 2593 |
void test9874() |
| 2594 |
{ |
| 2595 |
foo9874; // OK |
| 2596 |
bar9874(0); |
| 2597 |
baz9874(0); |
| 2598 |
} |
| 2599 |
|
| 2600 |
/******************************************/ |
| 2601 |
|
| 2602 |
void test9885() |
| 2603 |
{ |
| 2604 |
void foo(int[1][]) {} |
| 2605 |
void boo()(int[1][]){} |
| 2606 |
struct X(T...) { static void xoo(T){} } |
| 2607 |
struct Y(T...) { static void yoo()(T){} } |
| 2608 |
struct Z(T...) { static void zoo(U...)(T, U){} } |
| 2609 |
|
| 2610 |
struct V(T...) { static void voo()(T, ...){} } |
| 2611 |
struct W(T...) { static void woo()(T...){} } |
| 2612 |
|
| 2613 |
struct R(T...) { static void roo(U...)(int, U, T){} } |
| 2614 |
|
| 2615 |
// OK |
| 2616 |
foo([[10]]); |
| 2617 |
boo([[10]]); |
| 2618 |
|
| 2619 |
// OK |
| 2620 |
X!(int[1][]).xoo([[10]]); |
| 2621 |
|
| 2622 |
// NG! |
| 2623 |
Y!().yoo(); |
| 2624 |
Y!(int).yoo(1); |
| 2625 |
Y!(int, int[]).yoo(1, [10]); |
| 2626 |
static assert(!__traits(compiles, Y!().yoo(1))); |
| 2627 |
static assert(!__traits(compiles, Y!(int).yoo("a"))); |
| 2628 |
static assert(!__traits(compiles, Y!().yoo!(int)())); |
| 2629 |
|
| 2630 |
// NG! |
| 2631 |
Z!().zoo(); |
| 2632 |
Z!().zoo([1], [1:1]); |
| 2633 |
Z!(int, string).zoo(1, "a"); |
| 2634 |
Z!(int, string).zoo(1, "a", [1], [1:1]); |
| 2635 |
Z!().zoo!()(); |
| 2636 |
static assert(!__traits(compiles, Z!().zoo!()(1))); // (none) <- 1 |
| 2637 |
static assert(!__traits(compiles, Z!(int).zoo!()())); // int <- (none) |
| 2638 |
static assert(!__traits(compiles, Z!(int).zoo!()(""))); // int <- "" |
| 2639 |
static assert(!__traits(compiles, Z!().zoo!(int)())); // int <- (none) |
| 2640 |
static assert(!__traits(compiles, Z!().zoo!(int)(""))); // int <- "" |
| 2641 |
|
| 2642 |
V!().voo(1,2,3); |
| 2643 |
V!(int).voo(1,2,3); |
| 2644 |
V!(int, long).voo(1,2,3); |
| 2645 |
static assert(!__traits(compiles, V!(int).voo())); // int <- (none) |
| 2646 |
static assert(!__traits(compiles, V!(int, long).voo(1))); // long <- (none) |
| 2647 |
static assert(!__traits(compiles, V!(int, string).voo(1,2,3))); // string <- 2 |
| 2648 |
|
| 2649 |
W!().woo(); |
| 2650 |
//W!().woo(1, 2, 3); // Access Violation |
| 2651 |
{ // this behavior is consistent with: |
| 2652 |
//alias TL = TypeTuple!(); |
| 2653 |
//void foo(TL...) {} |
| 2654 |
//foo(1, 2, 3); // Access Violation |
| 2655 |
//pragma(msg, typeof(foo)); // void(...) -> D-style variadic function? |
| 2656 |
} |
| 2657 |
W!(int,int[]).woo(1,2,3); |
| 2658 |
W!(int,int[2]).woo(1,2,3); |
| 2659 |
static assert(!__traits(compiles, W!(int,int,int).woo(1,2,3))); // int... <- 2 |
| 2660 |
static assert(!__traits(compiles, W!(int,int).woo(1,2))); // int... <- 2 |
| 2661 |
static assert(!__traits(compiles, W!(int,int[2]).woo(1,2))); // int[2]... <- 2 |
| 2662 |
|
| 2663 |
R!().roo(1, "", []); |
| 2664 |
R!(int).roo(1, "", [], 1); |
| 2665 |
R!(int, string).roo(1, "", [], 1, ""); |
| 2666 |
R!(int, string).roo(1, 2, ""); |
| 2667 |
static assert(!__traits(compiles, R!(int).roo(1, "", []))); // int <- [] |
| 2668 |
static assert(!__traits(compiles, R!(int, int).roo(1, "", []))); // int <- [] |
| 2669 |
static assert(!__traits(compiles, R!(int, string).roo(1, 2, 3))); // string <- 3 |
| 2670 |
|
| 2671 |
// test case |
| 2672 |
struct Tuple(T...) { this()(T values) {} } |
| 2673 |
alias T = Tuple!(int[1][]); |
| 2674 |
auto t = T([[10]]); |
| 2675 |
} |
| 2676 |
|
| 2677 |
/******************************************/ |
| 2678 |
// https://issues.dlang.org/show_bug.cgi?id=9971 |
| 2679 |
|
| 2680 |
void goo9971()() |
| 2681 |
{ |
| 2682 |
auto g = &goo9971; |
| 2683 |
} |
| 2684 |
|
| 2685 |
struct S9971 |
| 2686 |
{ |
| 2687 |
void goo()() |
| 2688 |
{ |
| 2689 |
auto g = &goo; |
| 2690 |
static assert(is(typeof(g) == delegate)); |
| 2691 |
} |
| 2692 |
} |
| 2693 |
|
| 2694 |
void test9971() |
| 2695 |
{ |
| 2696 |
goo9971!()(); |
| 2697 |
|
| 2698 |
S9971.init.goo!()(); |
| 2699 |
} |
| 2700 |
|
| 2701 |
/******************************************/ |
| 2702 |
// https://issues.dlang.org/show_bug.cgi?id=9977 |
| 2703 |
|
| 2704 |
void test9977() |
| 2705 |
{ |
| 2706 |
struct S1(T) { T value; } |
| 2707 |
auto func1(T)(T value) { return value; } |
| 2708 |
static assert(is(S1!int == struct)); |
| 2709 |
assert(func1(10) == 10); |
| 2710 |
|
| 2711 |
template S2(T) { struct S2 { T value; } } |
| 2712 |
template func2(T) { auto func2(T value) { return value; } } |
| 2713 |
static assert(is(S2!int == struct)); |
| 2714 |
assert(func2(10) == 10); |
| 2715 |
|
| 2716 |
template X(T) { alias X = T[3]; } |
| 2717 |
static assert(is(X!int == int[3])); |
| 2718 |
|
| 2719 |
int a; |
| 2720 |
template Y(T) { alias Y = T[typeof(a)]; } |
| 2721 |
static assert(is(Y!double == double[int])); |
| 2722 |
|
| 2723 |
int v = 10; |
| 2724 |
template Z() { alias Z = v; } |
| 2725 |
assert(v == 10); |
| 2726 |
Z!() = 20; |
| 2727 |
assert(v == 20); |
| 2728 |
} |
| 2729 |
|
| 2730 |
/******************************************/ |
| 2731 |
|
| 2732 |
enum T8848a(int[] a) = a; |
| 2733 |
enum T8848b(int[int] b) = b; |
| 2734 |
enum T8848c(void* c) = c; |
| 2735 |
|
| 2736 |
static assert(T8848a!([1,2,3]) == [1,2,3]); |
| 2737 |
static assert(T8848b!([1:2,3:4]) == [1:2,3:4]); |
| 2738 |
static assert(T8848c!(null) == null); |
| 2739 |
|
| 2740 |
/******************************************/ |
| 2741 |
// https://issues.dlang.org/show_bug.cgi?id=9990 |
| 2742 |
|
| 2743 |
auto initS9990() { return "hi"; } |
| 2744 |
|
| 2745 |
class C9990(alias init) {} |
| 2746 |
|
| 2747 |
alias SC9990 = C9990!(initS9990); |
| 2748 |
|
| 2749 |
/******************************************/ |
| 2750 |
// https://issues.dlang.org/show_bug.cgi?id=10067 |
| 2751 |
|
| 2752 |
struct assumeSize10067(alias F) {} |
| 2753 |
|
| 2754 |
template useItemAt10067(size_t idx, T) |
| 2755 |
{ |
| 2756 |
void impl(){ } |
| 2757 |
|
| 2758 |
alias useItemAt10067 = assumeSize10067!(impl); |
| 2759 |
} |
| 2760 |
|
| 2761 |
useItemAt10067!(0, char) mapS10067; |
| 2762 |
|
| 2763 |
/******************************************/ |
| 2764 |
// https://issues.dlang.org/show_bug.cgi?id=4072 |
| 2765 |
|
| 2766 |
void bug4072(T)(T x) |
| 2767 |
if (is(typeof(bug4072(x)))) |
| 2768 |
{} |
| 2769 |
|
| 2770 |
static assert(!is(typeof(bug4072(7)))); |
| 2771 |
|
| 2772 |
/******************************************/ |
| 2773 |
// https://issues.dlang.org/show_bug.cgi?id=10074 |
| 2774 |
|
| 2775 |
template foo10074(F) |
| 2776 |
{ |
| 2777 |
enum foo10074 = false; |
| 2778 |
} |
| 2779 |
bool foo10074(F)(F f) |
| 2780 |
if (foo10074!F) |
| 2781 |
{ |
| 2782 |
return false; |
| 2783 |
} |
| 2784 |
|
| 2785 |
static assert(!is(typeof(foo10074(1)))); |
| 2786 |
|
| 2787 |
/******************************************/ |
| 2788 |
// https://issues.dlang.org/show_bug.cgi?id=10083 |
| 2789 |
|
| 2790 |
// [a-c] IFTI can find syntactic eponymous member |
| 2791 |
template foo10083a(T) |
| 2792 |
{ |
| 2793 |
int foo10083a(double) { return 1; } |
| 2794 |
int foo10083a(T) { return 2; } |
| 2795 |
} |
| 2796 |
template foo10083b(T) |
| 2797 |
{ |
| 2798 |
int foo10083b(T) { return 1; } |
| 2799 |
int foo10083b(T, T) { return 2; } |
| 2800 |
} |
| 2801 |
template foo10083c1(T) |
| 2802 |
{ |
| 2803 |
int foo10083c1(T) { return 1; } |
| 2804 |
static if (true) { int x; } |
| 2805 |
} |
| 2806 |
template foo10083c2(T) |
| 2807 |
{ |
| 2808 |
int foo10083c2(T) { return 1; } |
| 2809 |
static if (true) { int x; } else { int y; } |
| 2810 |
} |
| 2811 |
|
| 2812 |
// [d-f] IFTI cannot find syntactic eponymous member |
| 2813 |
template foo10083d1(T) |
| 2814 |
{ |
| 2815 |
static if (true) |
| 2816 |
{ |
| 2817 |
int foo10083d1(T) { return 1; } |
| 2818 |
} |
| 2819 |
else |
| 2820 |
{ |
| 2821 |
} |
| 2822 |
} |
| 2823 |
template foo10083d2(T) |
| 2824 |
{ |
| 2825 |
static if (true) |
| 2826 |
{ |
| 2827 |
} |
| 2828 |
else |
| 2829 |
{ |
| 2830 |
int foo10083d2(T) { return 1; } |
| 2831 |
} |
| 2832 |
} |
| 2833 |
template foo10083e(T) |
| 2834 |
{ |
| 2835 |
static if (true) |
| 2836 |
{ |
| 2837 |
int foo10083e(double arg) { return 1; } |
| 2838 |
} |
| 2839 |
int foo10083e(T arg) { return 2; } |
| 2840 |
} |
| 2841 |
template foo10083f(T) |
| 2842 |
{ |
| 2843 |
static if (true) |
| 2844 |
{ |
| 2845 |
int foo10083f(T) { return 1; } |
| 2846 |
} |
| 2847 |
else |
| 2848 |
{ |
| 2849 |
int foo10083f(T) { return 2; } |
| 2850 |
} |
| 2851 |
} |
| 2852 |
|
| 2853 |
void test10083() |
| 2854 |
{ |
| 2855 |
assert(foo10083a(1) == 2); |
| 2856 |
assert(foo10083a!int(1) == 2); |
| 2857 |
assert(foo10083a!int(1.0) == 1); |
| 2858 |
static assert(!__traits(compiles, foo10083a!double(1))); |
| 2859 |
static assert(!__traits(compiles, foo10083a!double(1.0))); |
| 2860 |
static assert(!__traits(compiles, foo10083a!real(1))); |
| 2861 |
assert(foo10083a!real(1.0) == 1); |
| 2862 |
assert(foo10083a!real(1.0L) == 2); |
| 2863 |
|
| 2864 |
assert(foo10083b(2) == 1); |
| 2865 |
assert(foo10083b(3, 4) == 2); |
| 2866 |
static assert(!__traits(compiles, foo10083b(2, ""))); |
| 2867 |
|
| 2868 |
assert(foo10083c1(1) == 1); |
| 2869 |
assert(foo10083c2(1) == 1); |
| 2870 |
|
| 2871 |
static assert(!__traits(compiles, foo10083d1(2))); |
| 2872 |
static assert(!__traits(compiles, foo10083d2(2))); |
| 2873 |
static assert(!__traits(compiles, foo10083e(3))); |
| 2874 |
static assert(!__traits(compiles, foo10083f(3))); |
| 2875 |
} |
| 2876 |
|
| 2877 |
/******************************************/ |
| 2878 |
// https://issues.dlang.org/show_bug.cgi?id=10134 |
| 2879 |
|
| 2880 |
template ReturnType10134(alias func) |
| 2881 |
{ |
| 2882 |
static if (is(typeof(func) R == return)) |
| 2883 |
alias R ReturnType10134; |
| 2884 |
else |
| 2885 |
static assert(0); |
| 2886 |
} |
| 2887 |
|
| 2888 |
struct Result10134(T) {} |
| 2889 |
|
| 2890 |
template getResultType10134(alias func) |
| 2891 |
{ |
| 2892 |
static if(is(ReturnType10134!(func.exec) _ == Result10134!(T), T)) |
| 2893 |
{ |
| 2894 |
alias getResultType10134 = T; |
| 2895 |
} |
| 2896 |
} |
| 2897 |
|
| 2898 |
template f10134(alias func) |
| 2899 |
{ |
| 2900 |
Result10134!(getResultType10134!(func)) exec(int i) |
| 2901 |
{ |
| 2902 |
return typeof(return)(); |
| 2903 |
} |
| 2904 |
} |
| 2905 |
|
| 2906 |
template a10134() |
| 2907 |
{ |
| 2908 |
Result10134!(double) exec(int i) |
| 2909 |
{ |
| 2910 |
return b10134!().exec(i); |
| 2911 |
} |
| 2912 |
} |
| 2913 |
|
| 2914 |
template b10134() |
| 2915 |
{ |
| 2916 |
Result10134!(double) exec(int i) |
| 2917 |
{ |
| 2918 |
return f10134!(a10134!()).exec(i); |
| 2919 |
} |
| 2920 |
} |
| 2921 |
|
| 2922 |
pragma(msg, getResultType10134!(a10134!())); |
| 2923 |
|
| 2924 |
/******************************************/ |
| 2925 |
// https://issues.dlang.org/show_bug.cgi?id=10313 |
| 2926 |
|
| 2927 |
void test10313() |
| 2928 |
{ |
| 2929 |
struct Nullable(T) |
| 2930 |
{ |
| 2931 |
this()(inout T value) inout {} |
| 2932 |
} |
| 2933 |
|
| 2934 |
struct S { S[] array; } |
| 2935 |
S s; |
| 2936 |
auto ns = Nullable!S(s); |
| 2937 |
|
| 2938 |
class C { C[] array; } |
| 2939 |
C c; |
| 2940 |
auto nc = Nullable!C(c); |
| 2941 |
} |
| 2942 |
|
| 2943 |
/******************************************/ |
| 2944 |
// https://issues.dlang.org/show_bug.cgi?id=10498 |
| 2945 |
|
| 2946 |
template triggerIssue10498a() |
| 2947 |
{ |
| 2948 |
enum triggerIssue10498a = __traits(compiles, { T10498a; }); |
| 2949 |
} |
| 2950 |
|
| 2951 |
template PackedGenericTuple10498a(Args...) |
| 2952 |
{ |
| 2953 |
alias Args Tuple; |
| 2954 |
enum e = triggerIssue10498a!(); |
| 2955 |
} |
| 2956 |
|
| 2957 |
struct S10498a { } |
| 2958 |
|
| 2959 |
template T10498a() |
| 2960 |
{ |
| 2961 |
alias PackedGenericTuple10498a!S10498a T10498a; |
| 2962 |
} |
| 2963 |
|
| 2964 |
void test10498a() |
| 2965 |
{ |
| 2966 |
alias T10498a!() t; |
| 2967 |
static assert(is(t.Tuple[0])); // Fails -> OK |
| 2968 |
} |
| 2969 |
|
| 2970 |
// -------- |
| 2971 |
|
| 2972 |
template triggerIssue10498b(A...) |
| 2973 |
{ |
| 2974 |
enum triggerIssue10498b = __traits(compiles, { auto a = A[0]; }); |
| 2975 |
} |
| 2976 |
|
| 2977 |
template PackedGenericTuple10498b(Args...) |
| 2978 |
{ |
| 2979 |
alias Args Tuple; |
| 2980 |
enum e = triggerIssue10498b!Args; |
| 2981 |
} |
| 2982 |
|
| 2983 |
template T10498b() |
| 2984 |
{ |
| 2985 |
struct S {} // The fact `S` is in `T` causes the problem |
| 2986 |
alias PackedGenericTuple10498b!S T10498b; |
| 2987 |
} |
| 2988 |
|
| 2989 |
void test10498b() |
| 2990 |
{ |
| 2991 |
alias T10498b!() t; |
| 2992 |
static assert(is(t.Tuple[0])); |
| 2993 |
} |
| 2994 |
|
| 2995 |
/******************************************/ |
| 2996 |
// https://issues.dlang.org/show_bug.cgi?id=10537 |
| 2997 |
|
| 2998 |
struct Iota10537 |
| 2999 |
{ |
| 3000 |
int s,e,i; |
| 3001 |
mixin Yield10537!q{ ; }; |
| 3002 |
} |
| 3003 |
|
| 3004 |
auto skipStrings10537(T)(T source) |
| 3005 |
{ |
| 3006 |
return ""; |
| 3007 |
} |
| 3008 |
|
| 3009 |
mixin template Yield10537(dstring code) |
| 3010 |
{ |
| 3011 |
alias X = typeof({ enum x = rewriteCode10537(code); }()); |
| 3012 |
} |
| 3013 |
|
| 3014 |
dstring rewriteCode10537(dstring code) |
| 3015 |
{ |
| 3016 |
skipStrings10537(code); // IFTI causes forward reference |
| 3017 |
return ""; |
| 3018 |
} |
| 3019 |
|
| 3020 |
/******************************************/ |
| 3021 |
// https://issues.dlang.org/show_bug.cgi?id=10558 |
| 3022 |
|
| 3023 |
template Template10558() {} |
| 3024 |
|
| 3025 |
struct Struct10558(alias T){} |
| 3026 |
|
| 3027 |
alias bar10558 = foo10558!(Template10558!()); |
| 3028 |
|
| 3029 |
template foo10558(alias T) |
| 3030 |
{ |
| 3031 |
alias foobar = Struct10558!T; |
| 3032 |
|
| 3033 |
void fun() |
| 3034 |
{ |
| 3035 |
alias a = foo10558!T; |
| 3036 |
} |
| 3037 |
} |
| 3038 |
|
| 3039 |
/******************************************/ |
| 3040 |
// https://issues.dlang.org/show_bug.cgi?id=10592 |
| 3041 |
|
| 3042 |
void test10592() |
| 3043 |
{ |
| 3044 |
struct A(E) |
| 3045 |
{ |
| 3046 |
int put()(const(E)[] data) |
| 3047 |
{ |
| 3048 |
return 1; |
| 3049 |
} |
| 3050 |
|
| 3051 |
int put()(const(dchar)[] data) if (!is(E == dchar)) |
| 3052 |
{ |
| 3053 |
return 2; |
| 3054 |
} |
| 3055 |
|
| 3056 |
int put(C)(const(C)[] data) if (!is(C == dchar) && !is(E == C)) |
| 3057 |
{ |
| 3058 |
return 3; |
| 3059 |
} |
| 3060 |
} |
| 3061 |
|
| 3062 |
A!char x; |
| 3063 |
assert(x.put("abcde"c) == 1); // OK: hit 1 |
| 3064 |
assert(x.put("abcde"w) == 3); // NG: this should hit 3 |
| 3065 |
assert(x.put("abcde"d) == 2); // OK: hit 2 |
| 3066 |
} |
| 3067 |
|
| 3068 |
/******************************************/ |
| 3069 |
// https://issues.dlang.org/show_bug.cgi?id=11242 |
| 3070 |
|
| 3071 |
inout(T[]) fromString11242(T)(inout(char[]) s, T[] dst) |
| 3072 |
{ |
| 3073 |
return s; |
| 3074 |
} |
| 3075 |
|
| 3076 |
void test11242() |
| 3077 |
{ |
| 3078 |
char[] a; |
| 3079 |
fromString11242(a, a); |
| 3080 |
} |
| 3081 |
|
| 3082 |
/******************************************/ |
| 3083 |
// https://issues.dlang.org/show_bug.cgi?id=10811 |
| 3084 |
|
| 3085 |
void foo10811a(R1, R2)(R1, R2) {} |
| 3086 |
template foo10811a(alias pred) { void foo10811a(R1, R2)(R1, R2) {} } |
| 3087 |
|
| 3088 |
template foo10811b(alias pred) { void foo10811b(R1, R2)(R1, R2) {} } |
| 3089 |
void foo10811b(R1, R2)(R1, R2) {} |
| 3090 |
|
| 3091 |
void test10811() |
| 3092 |
{ |
| 3093 |
foo10811a(1, 2); |
| 3094 |
foo10811a!(a => a)(1, 2); |
| 3095 |
|
| 3096 |
foo10811b(1, 2); |
| 3097 |
foo10811b!(a => a)(1, 2); |
| 3098 |
} |
| 3099 |
|
| 3100 |
/******************************************/ |
| 3101 |
// https://issues.dlang.org/show_bug.cgi?id=10969 |
| 3102 |
|
| 3103 |
template A10969(T, U...) { alias A10969 = T; } |
| 3104 |
void foo10969(T, U...)(A10969!(T, U) a) {} |
| 3105 |
|
| 3106 |
template B10969(T, U) { alias B10969 = T; } |
| 3107 |
void bar10969(T, U...)(B10969!(T, U[0]) a) {} |
| 3108 |
|
| 3109 |
void test10969() |
| 3110 |
{ |
| 3111 |
foo10969!(int, float)(3); |
| 3112 |
bar10969!(int, float)(3); |
| 3113 |
} |
| 3114 |
|
| 3115 |
/******************************************/ |
| 3116 |
// https://issues.dlang.org/show_bug.cgi?id=11271 |
| 3117 |
|
| 3118 |
struct SmartPtr11271(T) |
| 3119 |
{ |
| 3120 |
~this() {} |
| 3121 |
void opAssign(U)(auto ref U rh) {} |
| 3122 |
} |
| 3123 |
|
| 3124 |
void test11271() |
| 3125 |
{ |
| 3126 |
SmartPtr11271!Object a; |
| 3127 |
a = SmartPtr11271!Object(); |
| 3128 |
} |
| 3129 |
|
| 3130 |
/******************************************/ |
| 3131 |
// https://issues.dlang.org/show_bug.cgi?id=11533 |
| 3132 |
|
| 3133 |
version (none) |
| 3134 |
{ |
| 3135 |
struct S11533 |
| 3136 |
{ |
| 3137 |
void put(alias fun)() { fun!int(); } |
| 3138 |
} |
| 3139 |
void test11533a() |
| 3140 |
{ |
| 3141 |
static void foo(T)() {} |
| 3142 |
S11533 s; |
| 3143 |
s.put!foo(); |
| 3144 |
} |
| 3145 |
|
| 3146 |
void test11533b() |
| 3147 |
{ |
| 3148 |
static void bar(alias fun)() { fun(); } |
| 3149 |
void nested() {} |
| 3150 |
bar!nested(); |
| 3151 |
} |
| 3152 |
|
| 3153 |
void test11533c() |
| 3154 |
{ |
| 3155 |
static struct Foo(alias fun) |
| 3156 |
{ |
| 3157 |
auto call() { return fun(); } |
| 3158 |
} |
| 3159 |
int var = 1; |
| 3160 |
auto getVar() { return var; } |
| 3161 |
Foo!getVar foo; |
| 3162 |
assert(foo.call() == var); |
| 3163 |
var += 1; |
| 3164 |
assert(foo.call() == var); |
| 3165 |
} |
| 3166 |
|
| 3167 |
void test11533() |
| 3168 |
{ |
| 3169 |
test11533a(); |
| 3170 |
test11533b(); |
| 3171 |
test11533c(); |
| 3172 |
} |
| 3173 |
} |
| 3174 |
else |
| 3175 |
{ |
| 3176 |
void test11533() |
| 3177 |
{ |
| 3178 |
} |
| 3179 |
} |
| 3180 |
|
| 3181 |
/******************************************/ |
| 3182 |
// https://issues.dlang.org/show_bug.cgi?id=11553 |
| 3183 |
|
| 3184 |
struct Pack11553(T ...) |
| 3185 |
{ |
| 3186 |
alias Unpack = T; |
| 3187 |
enum length = T.length; |
| 3188 |
} |
| 3189 |
|
| 3190 |
template isPack11553(TList ...) |
| 3191 |
{ |
| 3192 |
static if (TList.length == 1 && is(Pack11553!(TList[0].Unpack) == TList[0])) |
| 3193 |
{ |
| 3194 |
enum isPack11553 = true; |
| 3195 |
} |
| 3196 |
else |
| 3197 |
{ |
| 3198 |
enum isPack11553 = false; |
| 3199 |
} |
| 3200 |
} |
| 3201 |
|
| 3202 |
template PartialApply11553(alias T, uint argLoc, Arg ...) |
| 3203 |
if (Arg.length == 1) |
| 3204 |
{ |
| 3205 |
template PartialApply11553(L ...) |
| 3206 |
{ |
| 3207 |
alias PartialApply11553 = T!(L[0 .. argLoc], Arg, L[argLoc .. $]); |
| 3208 |
} |
| 3209 |
} |
| 3210 |
|
| 3211 |
template _hasLength11553(size_t len, T) |
| 3212 |
{ |
| 3213 |
static if (T.length == len) |
| 3214 |
{ |
| 3215 |
enum _hasLength11553 = true; |
| 3216 |
} |
| 3217 |
else |
| 3218 |
{ |
| 3219 |
enum _hasLength11553 = false; |
| 3220 |
} |
| 3221 |
} |
| 3222 |
|
| 3223 |
alias _hasLength11553(size_t len) = PartialApply11553!(._hasLength11553, 0, len); |
| 3224 |
|
| 3225 |
|
| 3226 |
alias hl11553 = _hasLength11553!1; |
| 3227 |
|
| 3228 |
// this segfaults |
| 3229 |
static if (!isPack11553!hl11553) { pragma(msg, "All good 1"); } |
| 3230 |
|
| 3231 |
// these are fine |
| 3232 |
static if ( hl11553!(Pack11553!(5))) { pragma(msg, "All good 2"); } |
| 3233 |
|
| 3234 |
static if (!hl11553!(Pack11553!( ))) { pragma(msg, "All good 3"); } |
| 3235 |
|
| 3236 |
/******************************************/ |
| 3237 |
// https://issues.dlang.org/show_bug.cgi?id=11818 |
| 3238 |
|
| 3239 |
enum E11818 { e0, e1 } |
| 3240 |
|
| 3241 |
struct SortedRange11818 |
| 3242 |
{ |
| 3243 |
void fun(E11818 e = true ? E11818.e0 : E11818.e1)() |
| 3244 |
{ |
| 3245 |
} |
| 3246 |
} |
| 3247 |
|
| 3248 |
void test11818() |
| 3249 |
{ |
| 3250 |
SortedRange11818 s; |
| 3251 |
s.fun(); |
| 3252 |
} |
| 3253 |
|
| 3254 |
/******************************************/ |
| 3255 |
// https://issues.dlang.org/show_bug.cgi?id=11843 |
| 3256 |
|
| 3257 |
void test11843() |
| 3258 |
{ |
| 3259 |
struct Foo |
| 3260 |
{ |
| 3261 |
int[string] x; |
| 3262 |
} |
| 3263 |
|
| 3264 |
struct Bar(alias foo) {} |
| 3265 |
|
| 3266 |
enum bar1 = Bar!(Foo(["a": 1]))(); |
| 3267 |
enum bar2 = Bar!(Foo(["a": 1]))(); |
| 3268 |
static assert(is(typeof(bar1) == typeof(bar2))); |
| 3269 |
|
| 3270 |
enum foo1 = Foo(["a": 1]); |
| 3271 |
enum foo2 = Foo(["b": -1]); |
| 3272 |
static assert(!__traits(isSame, foo1, foo2)); |
| 3273 |
enum bar3 = Bar!foo1(); |
| 3274 |
enum bar4 = Bar!foo2(); |
| 3275 |
static assert(!is(typeof(bar3) == typeof(bar4))); |
| 3276 |
} |
| 3277 |
|
| 3278 |
/******************************************/ |
| 3279 |
// https://issues.dlang.org/show_bug.cgi?id=11872 |
| 3280 |
|
| 3281 |
class Foo11872 |
| 3282 |
{ |
| 3283 |
auto test(int v)() {} |
| 3284 |
auto test(int v)(string) {} |
| 3285 |
|
| 3286 |
template Bar(T) |
| 3287 |
{ |
| 3288 |
void test(T) {} |
| 3289 |
} |
| 3290 |
} |
| 3291 |
|
| 3292 |
void test11872() |
| 3293 |
{ |
| 3294 |
auto foo = new Foo11872(); |
| 3295 |
|
| 3296 |
with (foo) |
| 3297 |
{ |
| 3298 |
// ScopeExp(ti) -> DotTemplateInstanceExp(wthis, ti) |
| 3299 |
foo.test!2(); // works |
| 3300 |
test!2(); // works <- fails |
| 3301 |
test!2; // works <- fails |
| 3302 |
|
| 3303 |
// ScopeExp(ti) -> DotTemplateInstanceExp(wthis, ti) -> DotExp(wthis, ScopeExp) |
| 3304 |
foo.Bar!int.test(1); // works |
| 3305 |
Bar!int.test(1); // works <- fails |
| 3306 |
} |
| 3307 |
} |
| 3308 |
|
| 3309 |
/******************************************/ |
| 3310 |
// https://issues.dlang.org/show_bug.cgi?id=12042 |
| 3311 |
|
| 3312 |
struct S12042 |
| 3313 |
{ |
| 3314 |
int[] t; |
| 3315 |
|
| 3316 |
void m()() |
| 3317 |
{ |
| 3318 |
t = null; // CTFE error -> OK |
| 3319 |
} |
| 3320 |
} |
| 3321 |
|
| 3322 |
int test12042() |
| 3323 |
{ |
| 3324 |
S12042 s; |
| 3325 |
|
| 3326 |
with (s) |
| 3327 |
m!()(); |
| 3328 |
|
| 3329 |
return 1; |
| 3330 |
} |
| 3331 |
|
| 3332 |
static assert(test12042()); |
| 3333 |
|
| 3334 |
/******************************************/ |
| 3335 |
// https://issues.dlang.org/show_bug.cgi?id=12077 |
| 3336 |
|
| 3337 |
struct S12077(A) {} |
| 3338 |
|
| 3339 |
alias T12077(alias T : Base!Args, alias Base, Args...) = Base; |
| 3340 |
static assert(__traits(isSame, T12077!(S12077!int), S12077)); |
| 3341 |
|
| 3342 |
alias U12077(alias T : Base!Args, alias Base, Args...) = Base; |
| 3343 |
alias U12077( T : Base!Args, alias Base, Args...) = Base; |
| 3344 |
static assert(__traits(isSame, U12077!(S12077!int), S12077)); |
| 3345 |
|
| 3346 |
/******************************************/ |
| 3347 |
// https://issues.dlang.org/show_bug.cgi?id=12262 |
| 3348 |
|
| 3349 |
template Inst12262(T) { int x; } |
| 3350 |
|
| 3351 |
enum fqnSym12262(alias a) = 1; |
| 3352 |
enum fqnSym12262(alias a : B!A, alias B, A...) = 2; |
| 3353 |
|
| 3354 |
static assert(fqnSym12262!(Inst12262!(Object)) == 2); |
| 3355 |
static assert(fqnSym12262!(Inst12262!(Object).x) == 1); |
| 3356 |
|
| 3357 |
/******************************************/ |
| 3358 |
// https://issues.dlang.org/show_bug.cgi?id=12264 |
| 3359 |
|
| 3360 |
struct S12264(A) {} |
| 3361 |
|
| 3362 |
template AX12264(alias A1) { enum AX12264 = 1; } |
| 3363 |
template AX12264(alias A2 : B!A, alias B, A...) { enum AX12264 = 2; } |
| 3364 |
template AY12264(alias A1) { enum AY12264 = 1; } |
| 3365 |
template AY12264(alias A2 : B!int, alias B) { enum AY12264 = 2; } |
| 3366 |
template AZ12264(alias A1) { enum AZ12264 = 1; } |
| 3367 |
template AZ12264(alias A2 : S12264!T, T) { enum AZ12264 = 2; } |
| 3368 |
static assert(AX12264!(S12264!int) == 2); |
| 3369 |
static assert(AY12264!(S12264!int) == 2); |
| 3370 |
static assert(AZ12264!(S12264!int) == 2); |
| 3371 |
|
| 3372 |
template TX12264(T1) { enum TX12264 = 1; } |
| 3373 |
template TX12264(T2 : B!A, alias B, A...) { enum TX12264 = 2; } |
| 3374 |
template TY12264(T1) { enum TY12264 = 1; } |
| 3375 |
template TY12264(T2 : B!int, alias B) { enum TY12264 = 2; } |
| 3376 |
template TZ12264(T1) { enum TZ12264 = 1; } |
| 3377 |
template TZ12264(T2 : S12264!T, T) { enum TZ12264 = 2; } |
| 3378 |
static assert(TX12264!(S12264!int) == 2); |
| 3379 |
static assert(TY12264!(S12264!int) == 2); |
| 3380 |
static assert(TZ12264!(S12264!int) == 2); |
| 3381 |
|
| 3382 |
/******************************************/ |
| 3383 |
// https://issues.dlang.org/show_bug.cgi?id=12122 |
| 3384 |
|
| 3385 |
enum N12122 = 1; |
| 3386 |
|
| 3387 |
void foo12122(T)(T[N12122]) if(is(T == int)) {} |
| 3388 |
|
| 3389 |
void test12122() |
| 3390 |
{ |
| 3391 |
int[N12122] data; |
| 3392 |
foo12122(data); |
| 3393 |
} |
| 3394 |
|
| 3395 |
/******************************************/ |
| 3396 |
// https://issues.dlang.org/show_bug.cgi?id=12186 |
| 3397 |
|
| 3398 |
template map_front12186(fun...) |
| 3399 |
{ |
| 3400 |
auto map_front12186(Range)(Range r) |
| 3401 |
{ |
| 3402 |
return fun[0](r[0]); |
| 3403 |
} |
| 3404 |
} |
| 3405 |
|
| 3406 |
void test12186() |
| 3407 |
{ |
| 3408 |
immutable int[][] mat; |
| 3409 |
|
| 3410 |
mat.map_front12186!((in r) => 0); // OK |
| 3411 |
mat.map_front12186!((const r) => 0); // OK |
| 3412 |
mat.map_front12186!((immutable int[] r) => 0); // OK |
| 3413 |
mat.map_front12186!((immutable r) => 0); // OK <- Error |
| 3414 |
} |
| 3415 |
|
| 3416 |
/******************************************/ |
| 3417 |
// https://issues.dlang.org/show_bug.cgi?id=12207 |
| 3418 |
|
| 3419 |
void test12207() |
| 3420 |
{ |
| 3421 |
static struct S |
| 3422 |
{ |
| 3423 |
static void f(T)(T) {} |
| 3424 |
} |
| 3425 |
|
| 3426 |
immutable S s; |
| 3427 |
|
| 3428 |
s.f(1); |
| 3429 |
} |
| 3430 |
|
| 3431 |
/******************************************/ |
| 3432 |
// https://issues.dlang.org/show_bug.cgi?id=12263 |
| 3433 |
|
| 3434 |
template A12263(alias a) { int x; } |
| 3435 |
template B12263(alias a) { int x; } |
| 3436 |
|
| 3437 |
template fqnSym12263(alias T : B12263!A, alias B12263, A...) |
| 3438 |
{ |
| 3439 |
enum fqnSym12263 = true; |
| 3440 |
} |
| 3441 |
|
| 3442 |
static assert(fqnSym12263!(A12263!(Object))); |
| 3443 |
static assert(fqnSym12263!(B12263!(Object))); |
| 3444 |
|
| 3445 |
/******************************************/ |
| 3446 |
// https://issues.dlang.org/show_bug.cgi?id=12290 |
| 3447 |
|
| 3448 |
void test12290() |
| 3449 |
{ |
| 3450 |
short[] arrS; |
| 3451 |
float[] arrF; |
| 3452 |
double[] arrD; |
| 3453 |
real[] arrR; |
| 3454 |
string cstr; |
| 3455 |
wstring wstr; |
| 3456 |
dstring dstr; |
| 3457 |
short[short] aa; |
| 3458 |
|
| 3459 |
auto func1a(E)(E[], E) { return E.init; } |
| 3460 |
auto func1b(E)(E, E[]) { return E.init; } |
| 3461 |
|
| 3462 |
static assert(is(typeof(func1a(arrS, 1)) == short)); |
| 3463 |
static assert(is(typeof(func1b(1, arrS)) == short)); |
| 3464 |
static assert(is(typeof(func1a(arrF, 1.0)) == float)); |
| 3465 |
static assert(is(typeof(func1b(1.0, arrF)) == float)); |
| 3466 |
static assert(is(typeof(func1a(arrD, 1.0L)) == double)); |
| 3467 |
static assert(is(typeof(func1b(1.0L, arrD)) == double)); |
| 3468 |
static assert(is(typeof(func1a(arrR, 1)) == real)); |
| 3469 |
static assert(is(typeof(func1b(1, arrR)) == real)); |
| 3470 |
static assert(is(typeof(func1a("str" , 'a')) == immutable char)); |
| 3471 |
static assert(is(typeof(func1b('a', "str" )) == immutable char)); |
| 3472 |
static assert(is(typeof(func1a("str"c, 'a')) == immutable char)); |
| 3473 |
static assert(is(typeof(func1b('a', "str"c)) == immutable char)); |
| 3474 |
static assert(is(typeof(func1a("str"w, 'a')) == immutable wchar)); |
| 3475 |
static assert(is(typeof(func1b('a', "str"w)) == immutable wchar)); |
| 3476 |
static assert(is(typeof(func1a("str"d, 'a')) == immutable dchar)); |
| 3477 |
static assert(is(typeof(func1b('a', "str"d)) == immutable dchar)); |
| 3478 |
static assert(is(typeof(func1a([1,2,3], 1L)) == long)); |
| 3479 |
static assert(is(typeof(func1b(1L, [1,2,3])) == long)); |
| 3480 |
static assert(is(typeof(func1a([1,2,3], 1.5)) == double)); |
| 3481 |
static assert(is(typeof(func1b(1.5, [1,2,3])) == double)); |
| 3482 |
static assert(is(typeof(func1a(["a","b"], "s"c)) == string)); |
| 3483 |
static assert(is(typeof(func1b("s"c, ["a","b"])) == string)); |
| 3484 |
static assert(is(typeof(func1a(["a","b"], "s"w)) == wstring)); |
| 3485 |
static assert(is(typeof(func1b("s"w, ["a","b"])) == wstring)); |
| 3486 |
static assert(is(typeof(func1a(["a","b"], "s"d)) == dstring)); |
| 3487 |
static assert(is(typeof(func1b("s"d, ["a","b"])) == dstring)); |
| 3488 |
|
| 3489 |
auto func2a(K, V)(V[K], K, V) { return V[K].init; } |
| 3490 |
auto func2b(K, V)(V, K, V[K]) { return V[K].init; } |
| 3491 |
|
| 3492 |
static assert(is(typeof(func2a(aa, 1, 1)) == short[short])); |
| 3493 |
static assert(is(typeof(func2b(1, 1, aa)) == short[short])); |
| 3494 |
static assert(is(typeof(func2a([1:10,2:20,3:30], 1L, 10L)) == long[long])); |
| 3495 |
static assert(is(typeof(func2b(1L, 10L, [1:20,2:20,3:30])) == long[long])); |
| 3496 |
|
| 3497 |
auto func3a(T)(T, T) { return T.init; } |
| 3498 |
auto func3b(T)(T, T) { return T.init; } |
| 3499 |
|
| 3500 |
static assert(is(typeof(func3a(arrS, null)) == short[])); |
| 3501 |
static assert(is(typeof(func3b(null, arrS)) == short[])); |
| 3502 |
static assert(is(typeof(func3a(arrR, null)) == real[])); |
| 3503 |
static assert(is(typeof(func3b(null, arrR)) == real[])); |
| 3504 |
static assert(is(typeof(func3a(cstr, "str")) == string)); |
| 3505 |
static assert(is(typeof(func3b("str", cstr)) == string)); |
| 3506 |
static assert(is(typeof(func3a(wstr, "str")) == wstring)); |
| 3507 |
static assert(is(typeof(func3b("str", wstr)) == wstring)); |
| 3508 |
static assert(is(typeof(func3a(dstr, "str")) == dstring)); |
| 3509 |
static assert(is(typeof(func3b("str", dstr)) == dstring)); |
| 3510 |
static assert(is(typeof(func3a("str1" , "str2"c)) == string)); |
| 3511 |
static assert(is(typeof(func3b("str1"c, "str2" )) == string)); |
| 3512 |
static assert(is(typeof(func3a("str1" , "str2"w)) == wstring)); |
| 3513 |
static assert(is(typeof(func3b("str1"w, "str2" )) == wstring)); |
| 3514 |
static assert(is(typeof(func3a("str1" , "str2"d)) == dstring)); |
| 3515 |
static assert(is(typeof(func3b("str1"d, "str2" )) == dstring)); |
| 3516 |
|
| 3517 |
inout(V) get(K, V)(inout(V[K]) aa, K key, lazy V defaultValue) { return V.init; } |
| 3518 |
|
| 3519 |
short[short] hash12220; |
| 3520 |
short res12220 = get(hash12220, 1, 1); |
| 3521 |
|
| 3522 |
short[short] hash12221; |
| 3523 |
enum Key12221 : short { a } |
| 3524 |
get(hash12221, Key12221.a, Key12221.a); |
| 3525 |
|
| 3526 |
int[][string] mapping13026; |
| 3527 |
int[] v = get(mapping13026, "test", []); |
| 3528 |
} |
| 3529 |
|
| 3530 |
/******************************************/ |
| 3531 |
// https://issues.dlang.org/show_bug.cgi?id=12292 |
| 3532 |
|
| 3533 |
void test12292() |
| 3534 |
{ |
| 3535 |
void fun(T : string)(T data) {} |
| 3536 |
|
| 3537 |
ubyte[3] sa; |
| 3538 |
static assert(!__traits(compiles, fun(sa))); |
| 3539 |
static assert(!__traits(compiles, { alias f = fun!(ubyte[3]); })); |
| 3540 |
} |
| 3541 |
|
| 3542 |
/******************************************/ |
| 3543 |
// https://issues.dlang.org/show_bug.cgi?id=12376 |
| 3544 |
|
| 3545 |
static auto encode12376(size_t sz)(dchar ch) if (sz > 1) |
| 3546 |
{ |
| 3547 |
undefined; |
| 3548 |
} |
| 3549 |
|
| 3550 |
void test12376() |
| 3551 |
{ |
| 3552 |
enum x = __traits(compiles, encode12376!2(x)); |
| 3553 |
} |
| 3554 |
|
| 3555 |
/******************************************/ |
| 3556 |
// https://issues.dlang.org/show_bug.cgi?id=12447 |
| 3557 |
|
| 3558 |
enum test12447(string str) = str; // [1] |
| 3559 |
string test12447(T...)(T args) if (T.length) { return args[0]; } // [2] |
| 3560 |
|
| 3561 |
// With [1]: The template parameter str cannot be be deduced -> no match |
| 3562 |
// With [2]: T is deduced to a type tuple (string), then match to the function call. |
| 3563 |
static assert(test12447("foo") == "foo"); |
| 3564 |
|
| 3565 |
// With [1]: template parameter str is deduced to "bar", then match. |
| 3566 |
// With [2]: T is deduced to an expression tuple ("bar"), but it will make invalid the function signature (T args). |
| 3567 |
// The failure should be masked silently and prefer the 1st version. |
| 3568 |
static assert(test12447!("bar") == "bar"); |
| 3569 |
|
| 3570 |
/******************************************/ |
| 3571 |
// https://issues.dlang.org/show_bug.cgi?id=12651 |
| 3572 |
|
| 3573 |
alias TemplateArgsOf12651(alias T : Base!Args, alias Base, Args...) = Args; |
| 3574 |
|
| 3575 |
struct S12651(T) { } |
| 3576 |
|
| 3577 |
static assert(!__traits(compiles, TemplateArgsOf12651!(S12651!int, S, float))); |
| 3578 |
|
| 3579 |
/******************************************/ |
| 3580 |
// https://issues.dlang.org/show_bug.cgi?id=12719 |
| 3581 |
|
| 3582 |
struct A12719 |
| 3583 |
{ |
| 3584 |
B12719!int b(); |
| 3585 |
} |
| 3586 |
|
| 3587 |
struct B12719(T) |
| 3588 |
{ |
| 3589 |
A12719 a; |
| 3590 |
void m() |
| 3591 |
{ |
| 3592 |
auto v = B12719!T.init; |
| 3593 |
} |
| 3594 |
} |
| 3595 |
|
| 3596 |
// -------- |
| 3597 |
|
| 3598 |
enum canDoIt12719(R) = is(typeof(W12719!R)); |
| 3599 |
|
| 3600 |
struct W12719(R) |
| 3601 |
{ |
| 3602 |
R r; |
| 3603 |
static if (canDoIt12719!R) {} |
| 3604 |
} |
| 3605 |
|
| 3606 |
W12719!int a12719; |
| 3607 |
|
| 3608 |
/******************************************/ |
| 3609 |
// https://issues.dlang.org/show_bug.cgi?id=12746 |
| 3610 |
|
| 3611 |
template foo12746() |
| 3612 |
{ |
| 3613 |
void bar() |
| 3614 |
{ |
| 3615 |
static assert(!__traits(compiles, bar(1))); |
| 3616 |
} |
| 3617 |
alias foo12746 = bar; |
| 3618 |
} |
| 3619 |
|
| 3620 |
void foo12746(int) |
| 3621 |
{ |
| 3622 |
assert(0); |
| 3623 |
} |
| 3624 |
|
| 3625 |
void test12746() |
| 3626 |
{ |
| 3627 |
foo12746(); // instantiate |
| 3628 |
} |
| 3629 |
|
| 3630 |
/******************************************/ |
| 3631 |
// https://issues.dlang.org/show_bug.cgi?id=12748 |
| 3632 |
|
| 3633 |
void foo12748(S, C : typeof(S.init[0]))(S s, C c) |
| 3634 |
{ |
| 3635 |
} |
| 3636 |
|
| 3637 |
void test12748() |
| 3638 |
{ |
| 3639 |
foo12748("abc", 'd'); |
| 3640 |
} |
| 3641 |
|
| 3642 |
/******************************************/ |
| 3643 |
// https://issues.dlang.org/show_bug.cgi?id=9708 |
| 3644 |
|
| 3645 |
struct S9708 |
| 3646 |
{ |
| 3647 |
void f()(inout(Object)) inout {} |
| 3648 |
} |
| 3649 |
|
| 3650 |
void test9708() |
| 3651 |
{ |
| 3652 |
S9708 s; |
| 3653 |
s.f(new Object); |
| 3654 |
} |
| 3655 |
|
| 3656 |
/******************************************/ |
| 3657 |
// https://issues.dlang.org/show_bug.cgi?id=12880 |
| 3658 |
|
| 3659 |
void f12880(T)(in T value) { static assert(is(T == string)); } |
| 3660 |
void test12880() { f12880(string.init); } |
| 3661 |
|
| 3662 |
/******************************************/ |
| 3663 |
// https://issues.dlang.org/show_bug.cgi?id=13087 |
| 3664 |
|
| 3665 |
struct Vec13087 |
| 3666 |
{ |
| 3667 |
int x; |
| 3668 |
void m() { auto n = component13087!(this, 'x'); } |
| 3669 |
void c() const { auto n = component13087!(this, 'x'); } |
| 3670 |
void w() inout { auto n = component13087!(this, 'x'); } |
| 3671 |
void wc() inout const { auto n = component13087!(this, 'x'); } |
| 3672 |
void s() shared { auto n = component13087!(this, 'x'); } |
| 3673 |
void sc() shared const { auto n = component13087!(this, 'x'); } |
| 3674 |
void sw() shared inout { auto n = component13087!(this, 'x'); } |
| 3675 |
void swc() shared inout const { auto n = component13087!(this, 'x'); } |
| 3676 |
void i() immutable { auto n = component13087!(this, 'x'); } |
| 3677 |
} |
| 3678 |
|
| 3679 |
template component13087(alias vec, char c) |
| 3680 |
{ |
| 3681 |
alias component13087 = vec.x; |
| 3682 |
} |
| 3683 |
|
| 3684 |
/******************************************/ |
| 3685 |
// https://issues.dlang.org/show_bug.cgi?id=13127 |
| 3686 |
|
| 3687 |
/+void test13127(inout int = 0) |
| 3688 |
{ |
| 3689 |
int [] ma1; |
| 3690 |
const(int)[] ca1; |
| 3691 |
const(int[]) ca2; |
| 3692 |
inout( int)[] wma1; |
| 3693 |
inout( int[]) wma2; |
| 3694 |
inout(const int)[] wca1; |
| 3695 |
inout(const int[]) wca2; |
| 3696 |
immutable(int)[] ia1; |
| 3697 |
immutable(int[]) ia2; |
| 3698 |
shared( int)[] sma1; |
| 3699 |
shared( int[]) sma2; |
| 3700 |
shared( const int)[] sca1; |
| 3701 |
shared( const int[]) sca2; |
| 3702 |
shared(inout int)[] swma1; |
| 3703 |
shared(inout int[]) swma2; |
| 3704 |
shared(inout const int)[] swca1; |
| 3705 |
shared(inout const int[]) swca2; |
| 3706 |
|
| 3707 |
/* In all cases, U should be deduced to top-unqualified type. |
| 3708 |
*/ |
| 3709 |
|
| 3710 |
/* Parameter is (shared) mutable |
| 3711 |
*/ |
| 3712 |
U f_m(U)( U) { return null; } |
| 3713 |
U fsm(U)(shared U) { return null; } |
| 3714 |
// 9 * 2 - 1 |
| 3715 |
static assert(is(typeof(f_m( ma1)) == int [])); |
| 3716 |
static assert(is(typeof(f_m( ca1)) == const(int)[])); |
| 3717 |
static assert(is(typeof(f_m( ca2)) == const(int)[])); |
| 3718 |
static assert(is(typeof(f_m( wma1)) == inout( int)[])); |
| 3719 |
static assert(is(typeof(f_m( wma2)) == inout( int)[])); |
| 3720 |
static assert(is(typeof(f_m( wca1)) == inout(const int)[])); |
| 3721 |
static assert(is(typeof(f_m( wca2)) == inout(const int)[])); |
| 3722 |
static assert(is(typeof(f_m( ia1)) == immutable(int)[])); |
| 3723 |
static assert(is(typeof(f_m( ia2)) == immutable(int)[])); |
| 3724 |
static assert(is(typeof(f_m( sma1)) == shared( int)[])); |
| 3725 |
static assert(is(typeof(f_m( sma2)) == shared( int)[])); // <- shared(int[]) |
| 3726 |
static assert(is(typeof(f_m( sca1)) == shared( const int)[])); |
| 3727 |
static assert(is(typeof(f_m( sca2)) == shared( const int)[])); // <- shared(const(int)[]) |
| 3728 |
static assert(is(typeof(f_m(swma1)) == shared(inout int)[])); |
| 3729 |
static assert(is(typeof(f_m(swma2)) == shared(inout int)[])); // <- shared(inout(int[])) |
| 3730 |
static assert(is(typeof(f_m(swca1)) == shared(inout const int)[])); |
| 3731 |
static assert(is(typeof(f_m(swca2)) == shared(inout const int)[])); // <- shared(inout(const(int))[]) |
| 3732 |
// 9 * 2 - 1 |
| 3733 |
static assert(is(typeof(fsm( ma1))) == false); |
| 3734 |
static assert(is(typeof(fsm( ca1))) == false); |
| 3735 |
static assert(is(typeof(fsm( ca2))) == false); |
| 3736 |
static assert(is(typeof(fsm( wma1))) == false); |
| 3737 |
static assert(is(typeof(fsm( wma2))) == false); |
| 3738 |
static assert(is(typeof(fsm( wca1))) == false); |
| 3739 |
static assert(is(typeof(fsm( wca2))) == false); |
| 3740 |
static assert(is(typeof(fsm( ia1))) == false); |
| 3741 |
static assert(is(typeof(fsm( ia2))) == false); |
| 3742 |
static assert(is(typeof(fsm( sma1)) == shared( int)[])); // <- NG |
| 3743 |
static assert(is(typeof(fsm( sma2)) == shared( int)[])); |
| 3744 |
static assert(is(typeof(fsm( sca1)) == shared( const int)[])); // <- NG |
| 3745 |
static assert(is(typeof(fsm( sca2)) == shared( const int)[])); |
| 3746 |
static assert(is(typeof(fsm(swma1)) == shared(inout int)[])); // <- NG |
| 3747 |
static assert(is(typeof(fsm(swma2)) == shared(inout int)[])); |
| 3748 |
static assert(is(typeof(fsm(swca1)) == shared(inout const int)[])); // <- NG |
| 3749 |
static assert(is(typeof(fsm(swca2)) == shared(inout const int)[])); |
| 3750 |
|
| 3751 |
/* Parameter is (shared) const |
| 3752 |
*/ |
| 3753 |
U f_c(U)( const U) { return null; } |
| 3754 |
U fsc(U)(shared const U) { return null; } |
| 3755 |
// 9 * 2 - 1 |
| 3756 |
static assert(is(typeof(f_c( ma1)) == int [])); |
| 3757 |
static assert(is(typeof(f_c( ca1)) == const(int)[])); |
| 3758 |
static assert(is(typeof(f_c( ca2)) == const(int)[])); |
| 3759 |
static assert(is(typeof(f_c( wma1)) == inout( int)[])); |
| 3760 |
static assert(is(typeof(f_c( wma2)) == inout( int)[])); |
| 3761 |
static assert(is(typeof(f_c( wca1)) == inout(const int)[])); |
| 3762 |
static assert(is(typeof(f_c( wca2)) == inout(const int)[])); |
| 3763 |
static assert(is(typeof(f_c( ia1)) == immutable(int)[])); |
| 3764 |
static assert(is(typeof(f_c( ia2)) == immutable(int)[])); |
| 3765 |
static assert(is(typeof(f_c( sma1)) == shared( int)[])); |
| 3766 |
static assert(is(typeof(f_c( sma2)) == shared( int)[])); // <- shared(int[]) |
| 3767 |
static assert(is(typeof(f_c( sca1)) == shared( const int)[])); |
| 3768 |
static assert(is(typeof(f_c( sca2)) == shared( const int)[])); // <- shared(const(int)[]) |
| 3769 |
static assert(is(typeof(f_c(swma1)) == shared(inout int)[])); |
| 3770 |
static assert(is(typeof(f_c(swma2)) == shared(inout int)[])); // shared(inout(int)[]) |
| 3771 |
static assert(is(typeof(f_c(swca1)) == shared(inout const int)[])); |
| 3772 |
static assert(is(typeof(f_c(swca2)) == shared(inout const int)[])); // shared(inout(const(int))[]) |
| 3773 |
// 9 * 2 - 1 |
| 3774 |
static assert(is(typeof(fsc( ma1))) == false); |
| 3775 |
static assert(is(typeof(fsc( ca1))) == false); |
| 3776 |
static assert(is(typeof(fsc( ca2))) == false); |
| 3777 |
static assert(is(typeof(fsc( wma1))) == false); |
| 3778 |
static assert(is(typeof(fsc( wma2))) == false); |
| 3779 |
static assert(is(typeof(fsc( wca1))) == false); |
| 3780 |
static assert(is(typeof(fsc( wca2))) == false); |
| 3781 |
static assert(is(typeof(fsc( ia1)) == immutable(int)[])); // <- NG |
| 3782 |
static assert(is(typeof(fsc( ia2)) == immutable(int)[])); // <- NG |
| 3783 |
static assert(is(typeof(fsc( sma1)) == shared( int)[])); // <- NG |
| 3784 |
static assert(is(typeof(fsc( sma2)) == shared( int)[])); |
| 3785 |
static assert(is(typeof(fsc( sca1)) == shared( const int)[])); // <- NG |
| 3786 |
static assert(is(typeof(fsc( sca2)) == shared( const int)[])); |
| 3787 |
static assert(is(typeof(fsc(swma1)) == shared(inout int)[])); // <- NG |
| 3788 |
static assert(is(typeof(fsc(swma2)) == shared(inout int)[])); |
| 3789 |
static assert(is(typeof(fsc(swca1)) == shared(inout const int)[])); // <- NG |
| 3790 |
static assert(is(typeof(fsc(swca2)) == shared(inout const int)[])); |
| 3791 |
|
| 3792 |
/* Parameter is immutable |
| 3793 |
*/ |
| 3794 |
U fi(U)(immutable U) { return null; } |
| 3795 |
// 9 * 2 - 1 |
| 3796 |
static assert(is(typeof(fi( ma1))) == false); |
| 3797 |
static assert(is(typeof(fi( ca1))) == false); |
| 3798 |
static assert(is(typeof(fi( ca2))) == false); |
| 3799 |
static assert(is(typeof(fi( wma1))) == false); |
| 3800 |
static assert(is(typeof(fi( wma2))) == false); |
| 3801 |
static assert(is(typeof(fi( wca1))) == false); |
| 3802 |
static assert(is(typeof(fi( wca2))) == false); |
| 3803 |
static assert(is(typeof(fi( ia1)) == immutable(int)[])); // <- NG |
| 3804 |
static assert(is(typeof(fi( ia2)) == immutable(int)[])); // <- NG |
| 3805 |
static assert(is(typeof(fi( sma1))) == false); |
| 3806 |
static assert(is(typeof(fi( sma2))) == false); |
| 3807 |
static assert(is(typeof(fi( sca1))) == false); |
| 3808 |
static assert(is(typeof(fi( sca2))) == false); |
| 3809 |
static assert(is(typeof(fi(swma1))) == false); |
| 3810 |
static assert(is(typeof(fi(swma2))) == false); |
| 3811 |
static assert(is(typeof(fi(swca1))) == false); |
| 3812 |
static assert(is(typeof(fi(swca2))) == false); |
| 3813 |
|
| 3814 |
/* Parameter is (shared) inout |
| 3815 |
*/ |
| 3816 |
U f_w(U)( inout U) { return null; } |
| 3817 |
U fsw(U)(shared inout U) { return null; } |
| 3818 |
// 9 * 2 - 1 |
| 3819 |
static assert(is(typeof(f_w( ma1)) == int [])); |
| 3820 |
static assert(is(typeof(f_w( ca1)) == int [])); // <- const(int)[] |
| 3821 |
static assert(is(typeof(f_w( ca2)) == int [])); // <- const(int)[] |
| 3822 |
static assert(is(typeof(f_w( wma1)) == int [])); // <- inout(int)[] |
| 3823 |
static assert(is(typeof(f_w( wma2)) == int [])); // <- inout(int)[] |
| 3824 |
static assert(is(typeof(f_w( wca1)) == const(int)[])); // <- inout(const(int))[] |
| 3825 |
static assert(is(typeof(f_w( wca2)) == const(int)[])); // <- inout(const(int))[] |
| 3826 |
static assert(is(typeof(f_w( ia1)) == int [])); // <- immutable(int)[] |
| 3827 |
static assert(is(typeof(f_w( ia2)) == int [])); // <- immutable(int)[] |
| 3828 |
static assert(is(typeof(f_w( sma1)) == shared( int)[])); |
| 3829 |
static assert(is(typeof(f_w( sma2)) == shared( int)[])); // <- shared(int[]) |
| 3830 |
static assert(is(typeof(f_w( sca1)) == shared( int)[])); // <- shared(const(int))[] |
| 3831 |
static assert(is(typeof(f_w( sca2)) == shared( int)[])); // <- shared(const(int)[]) |
| 3832 |
static assert(is(typeof(f_w(swma1)) == shared( int)[])); // <- shared(inout(int))[] |
| 3833 |
static assert(is(typeof(f_w(swma2)) == shared( int)[])); // <- shared(inout(int)[]) |
| 3834 |
static assert(is(typeof(f_w(swca1)) == shared(const int)[])); // <- shared(inout(const(int)))[] |
| 3835 |
static assert(is(typeof(f_w(swca2)) == shared(const int)[])); // <- shared(inout(const(int))[]) |
| 3836 |
// 9 * 2 - 1 |
| 3837 |
static assert(is(typeof(fsw( ma1))) == false); |
| 3838 |
static assert(is(typeof(fsw( ca1))) == false); |
| 3839 |
static assert(is(typeof(fsw( ca2))) == false); |
| 3840 |
static assert(is(typeof(fsw( wma1))) == false); |
| 3841 |
static assert(is(typeof(fsw( wma2))) == false); |
| 3842 |
static assert(is(typeof(fsw( wca1))) == false); |
| 3843 |
static assert(is(typeof(fsw( wca2))) == false); |
| 3844 |
static assert(is(typeof(fsw( ia1)) == int [])); // <- NG |
| 3845 |
static assert(is(typeof(fsw( ia2)) == int [])); // <- NG |
| 3846 |
static assert(is(typeof(fsw( sma1)) == int [])); // <- NG |
| 3847 |
static assert(is(typeof(fsw( sma2)) == int [])); |
| 3848 |
static assert(is(typeof(fsw( sca1)) == int [])); // <- NG |
| 3849 |
static assert(is(typeof(fsw( sca2)) == int [])); // const(int)[] |
| 3850 |
static assert(is(typeof(fsw(swma1)) == int [])); // <- NG |
| 3851 |
static assert(is(typeof(fsw(swma2)) == int [])); // inout(int)[] |
| 3852 |
static assert(is(typeof(fsw(swca1)) == const(int)[])); // <- NG |
| 3853 |
static assert(is(typeof(fsw(swca2)) == const(int)[])); // <- inout(const(int))[] |
| 3854 |
|
| 3855 |
/* Parameter is (shared) inout const |
| 3856 |
*/ |
| 3857 |
U f_wc(U)( inout const U) { return null; } |
| 3858 |
U fswc(U)(shared inout const U) { return null; } |
| 3859 |
// 9 * 2 - 1 |
| 3860 |
static assert(is(typeof(f_wc( ma1)) == int [])); |
| 3861 |
static assert(is(typeof(f_wc( ca1)) == int [])); // <- const(int)[] |
| 3862 |
static assert(is(typeof(f_wc( ca2)) == int [])); // <- const(int)[] |
| 3863 |
static assert(is(typeof(f_wc( wma1)) == int [])); // <- inout(int)[] |
| 3864 |
static assert(is(typeof(f_wc( wma2)) == int [])); // <- inout(int)[] |
| 3865 |
static assert(is(typeof(f_wc( wca1)) == int [])); // <- inout(const(int))[] |
| 3866 |
static assert(is(typeof(f_wc( wca2)) == int [])); // <- inout(const(int))[] |
| 3867 |
static assert(is(typeof(f_wc( ia1)) == int [])); // <- immutable(int)[] |
| 3868 |
static assert(is(typeof(f_wc( ia2)) == int [])); // <- immutable(int)[] |
| 3869 |
static assert(is(typeof(f_wc( sma1)) == shared(int)[])); |
| 3870 |
static assert(is(typeof(f_wc( sma2)) == shared(int)[])); // <- shared(int[]) |
| 3871 |
static assert(is(typeof(f_wc( sca1)) == shared(int)[])); // <- shared(const(int))[] |
| 3872 |
static assert(is(typeof(f_wc( sca2)) == shared(int)[])); // <- shared(const(int)[]) |
| 3873 |
static assert(is(typeof(f_wc(swma1)) == shared(int)[])); // <- shared(inout(int))[] |
| 3874 |
static assert(is(typeof(f_wc(swma2)) == shared(int)[])); // <- shared(inout(int)[]) |
| 3875 |
static assert(is(typeof(f_wc(swca1)) == shared(int)[])); // <- shared(inout(const(int)))[] |
| 3876 |
static assert(is(typeof(f_wc(swca2)) == shared(int)[])); // <- shared(inout(const(int))[]) |
| 3877 |
// 9 * 2 - 1 |
| 3878 |
static assert(is(typeof(fswc( ma1))) == false); |
| 3879 |
static assert(is(typeof(fswc( ca1))) == false); |
| 3880 |
static assert(is(typeof(fswc( ca2))) == false); |
| 3881 |
static assert(is(typeof(fswc( wma1))) == false); |
| 3882 |
static assert(is(typeof(fswc( wma2))) == false); |
| 3883 |
static assert(is(typeof(fswc( wca1))) == false); |
| 3884 |
static assert(is(typeof(fswc( wca2))) == false); |
| 3885 |
static assert(is(typeof(fswc( ia1)) == int [])); // <- NG |
| 3886 |
static assert(is(typeof(fswc( ia2)) == int [])); // <- NG |
| 3887 |
static assert(is(typeof(fswc( sma1)) == int [])); // <- NG |
| 3888 |
static assert(is(typeof(fswc( sma2)) == int [])); |
| 3889 |
static assert(is(typeof(fswc( sca1)) == int [])); // <- NG |
| 3890 |
static assert(is(typeof(fswc( sca2)) == int [])); // <- const(int)[] |
| 3891 |
static assert(is(typeof(fswc(swma1)) == int [])); // <- NG |
| 3892 |
static assert(is(typeof(fswc(swma2)) == int [])); // <- inout(int)[] |
| 3893 |
static assert(is(typeof(fswc(swca1)) == int [])); // <- NG |
| 3894 |
static assert(is(typeof(fswc(swca2)) == int [])); // <- inout(const(int))[] |
| 3895 |
}+/ |
| 3896 |
|
| 3897 |
void test13127a() |
| 3898 |
{ |
| 3899 |
void foo(T)(in T[] src, T[] dst) { static assert(is(T == int[])); } |
| 3900 |
|
| 3901 |
int[][] a; |
| 3902 |
foo(a, a); |
| 3903 |
} |
| 3904 |
|
| 3905 |
/******************************************/ |
| 3906 |
// https://issues.dlang.org/show_bug.cgi?id=13159 |
| 3907 |
|
| 3908 |
template maxSize13159(T...) |
| 3909 |
{ |
| 3910 |
static if (T.length == 1) |
| 3911 |
{ |
| 3912 |
enum size_t maxSize13159 = T[0].sizeof; |
| 3913 |
} |
| 3914 |
else |
| 3915 |
{ |
| 3916 |
enum size_t maxSize13159 = |
| 3917 |
T[0].sizeof >= maxSize13159!(T[1 .. $]) |
| 3918 |
? T[0].sizeof |
| 3919 |
: maxSize13159!(T[1 .. $]); |
| 3920 |
} |
| 3921 |
} |
| 3922 |
|
| 3923 |
struct Node13159 |
| 3924 |
{ |
| 3925 |
struct Pair |
| 3926 |
{ |
| 3927 |
Node13159 value; |
| 3928 |
} |
| 3929 |
|
| 3930 |
//alias Algebraic!(Node[], int) Value; |
| 3931 |
enum n = maxSize13159!(Node13159[], int); |
| 3932 |
} |
| 3933 |
|
| 3934 |
/******************************************/ |
| 3935 |
// https://issues.dlang.org/show_bug.cgi?id=13180 |
| 3936 |
|
| 3937 |
void test13180() |
| 3938 |
{ |
| 3939 |
inout(V) get1a(K, V)(inout(V[K]) aa, lazy inout(V) defaultValue) |
| 3940 |
{ |
| 3941 |
static assert(is(V == string)); |
| 3942 |
static assert(is(K == string)); |
| 3943 |
return defaultValue; |
| 3944 |
} |
| 3945 |
inout(V) get1b(K, V)(lazy inout(V) defaultValue, inout(V[K]) aa) |
| 3946 |
{ |
| 3947 |
static assert(is(V == string)); |
| 3948 |
static assert(is(K == string)); |
| 3949 |
return defaultValue; |
| 3950 |
} |
| 3951 |
|
| 3952 |
inout(V) get2a(K, V)(inout(V)[K] aa, lazy inout(V) defaultValue) |
| 3953 |
{ |
| 3954 |
static assert(is(V == string)); |
| 3955 |
static assert(is(K == string)); |
| 3956 |
return defaultValue; |
| 3957 |
} |
| 3958 |
inout(V) get2b(K, V)(lazy inout(V) defaultValue, inout(V)[K] aa) |
| 3959 |
{ |
| 3960 |
static assert(is(V == string)); |
| 3961 |
static assert(is(K == string)); |
| 3962 |
return defaultValue; |
| 3963 |
} |
| 3964 |
string def; |
| 3965 |
string[string] aa; |
| 3966 |
string s1a = get1a(aa, def); |
| 3967 |
string s1b = get1b(def, aa); |
| 3968 |
string s2a = get2a(aa, def); |
| 3969 |
string s2b = get2b(def, aa); |
| 3970 |
} |
| 3971 |
|
| 3972 |
/******************************************/ |
| 3973 |
// https://issues.dlang.org/show_bug.cgi?id=13204 |
| 3974 |
|
| 3975 |
struct A13204(uint v) |
| 3976 |
{ |
| 3977 |
alias whatever = A13204y; |
| 3978 |
static assert(is(whatever == A13204)); |
| 3979 |
} |
| 3980 |
alias A13204x = A13204!1; |
| 3981 |
alias A13204y = A13204x; |
| 3982 |
|
| 3983 |
struct B13204(uint v) |
| 3984 |
{ |
| 3985 |
alias whatever = B13204z; |
| 3986 |
static assert(is(whatever == B13204)); |
| 3987 |
} |
| 3988 |
alias B13204x = B13204!1; |
| 3989 |
alias B13204y = B13204x; |
| 3990 |
alias B13204z = B13204y; |
| 3991 |
|
| 3992 |
void test13204() |
| 3993 |
{ |
| 3994 |
static assert(is(A13204x == A13204!1)); |
| 3995 |
static assert(is(A13204x == A13204!1.whatever)); |
| 3996 |
static assert(is(A13204x == A13204y)); |
| 3997 |
|
| 3998 |
static assert(is(B13204x == B13204!1)); |
| 3999 |
static assert(is(B13204x == B13204!1.whatever)); |
| 4000 |
static assert(is(B13204x == B13204y)); |
| 4001 |
static assert(is(B13204x == B13204z)); |
| 4002 |
} |
| 4003 |
|
| 4004 |
/******************************************/ |
| 4005 |
// https://issues.dlang.org/show_bug.cgi?id=8462 (dup of 13204) |
| 4006 |
|
| 4007 |
alias FP8462 = void function(C8462.Type arg); |
| 4008 |
|
| 4009 |
class C8462 |
| 4010 |
{ |
| 4011 |
enum Type { Foo } |
| 4012 |
alias funcPtrPtr = FP8462*; |
| 4013 |
} |
| 4014 |
|
| 4015 |
/******************************************/ |
| 4016 |
// https://issues.dlang.org/show_bug.cgi?id=13218 |
| 4017 |
|
| 4018 |
template isCallable13218(T...) |
| 4019 |
if (T.length == 1) |
| 4020 |
{ |
| 4021 |
static assert(0); |
| 4022 |
} |
| 4023 |
|
| 4024 |
template ParameterTypeTuple13218(func...) |
| 4025 |
if (func.length == 1 && isCallable13218!func) |
| 4026 |
{ |
| 4027 |
static assert(0); |
| 4028 |
} |
| 4029 |
|
| 4030 |
struct R13218 |
| 4031 |
{ |
| 4032 |
private static string mangleFuncPtr(ArgTypes...)() |
| 4033 |
{ |
| 4034 |
string result = "fnp_"; |
| 4035 |
foreach (T; ArgTypes) |
| 4036 |
result ~= T.mangleof; |
| 4037 |
return result; |
| 4038 |
} |
| 4039 |
void function(int) fnp_i; |
| 4040 |
double delegate(double) fnp_d; |
| 4041 |
|
| 4042 |
void opAssign(FnT)(FnT func) |
| 4043 |
{ |
| 4044 |
mixin(mangleFuncPtr!( ParameterTypeTuple13218!FnT) ~ " = func;"); // parsed as TypeInstance |
| 4045 |
//mixin(mangleFuncPtr!(.ParameterTypeTuple13218!FnT) ~ " = func;"); // parsed as DotTemplateInstanceExp -> works |
| 4046 |
} |
| 4047 |
} |
| 4048 |
|
| 4049 |
/******************************************/ |
| 4050 |
// https://issues.dlang.org/show_bug.cgi?id=13219 |
| 4051 |
|
| 4052 |
struct Map13219(V) {} |
| 4053 |
|
| 4054 |
void test13219a(alias F, VA, VB)(Map13219!VA a, Map13219!VB b) |
| 4055 |
if (is(VA : typeof(F(VA.init, VB.init)))) |
| 4056 |
{} |
| 4057 |
|
| 4058 |
void test13219b(alias F)() |
| 4059 |
{ |
| 4060 |
test13219a!((a, b) => b)(Map13219!int.init, Map13219!int.init); |
| 4061 |
} |
| 4062 |
|
| 4063 |
void test13219() |
| 4064 |
{ |
| 4065 |
int x; |
| 4066 |
test13219b!x(); |
| 4067 |
} |
| 4068 |
|
| 4069 |
/******************************************/ |
| 4070 |
// https://issues.dlang.org/show_bug.cgi?id=13223 |
| 4071 |
|
| 4072 |
void test13223() |
| 4073 |
{ |
| 4074 |
T[] f1(T)(T[] a1, T[] a2) |
| 4075 |
{ |
| 4076 |
static assert(is(T == int)); |
| 4077 |
return a1 ~ a2; |
| 4078 |
} |
| 4079 |
T[] f2(T)(T[] a1, T[] a2) |
| 4080 |
{ |
| 4081 |
static assert(is(T == int)); |
| 4082 |
return a1 ~ a2; |
| 4083 |
} |
| 4084 |
int[] a = [1, 2]; |
| 4085 |
static assert(is(typeof(f1(a, [])) == int[])); |
| 4086 |
static assert(is(typeof(f2([], a)) == int[])); |
| 4087 |
static assert(is(typeof(f1(a, null)) == int[])); |
| 4088 |
static assert(is(typeof(f2(null, a)) == int[])); |
| 4089 |
|
| 4090 |
T[] f3(T)(T[] a) { return a; } |
| 4091 |
static assert(is(typeof(f3([])) == void[])); |
| 4092 |
static assert(is(typeof(f3(null)) == void[])); |
| 4093 |
|
| 4094 |
T f4(T)(T a) { return a; } |
| 4095 |
static assert(is(typeof(f4([])) == void[])); |
| 4096 |
static assert(is(typeof(f4(null)) == typeof(null))); |
| 4097 |
|
| 4098 |
T[][] f5(T)(T[][] a) { return a; } |
| 4099 |
static assert(is(typeof(f5([])) == void[][])); |
| 4100 |
static assert(is(typeof(f5(null)) == void[][])); |
| 4101 |
|
| 4102 |
void translate(C = immutable char)(const(C)[] toRemove) |
| 4103 |
{ |
| 4104 |
static assert(is(C == char)); |
| 4105 |
} |
| 4106 |
translate(null); |
| 4107 |
} |
| 4108 |
|
| 4109 |
void test13223a() |
| 4110 |
{ |
| 4111 |
T f(T)(T, T) { return T.init; } |
| 4112 |
|
| 4113 |
immutable i = 0; |
| 4114 |
const c = 0; |
| 4115 |
auto m = 0; |
| 4116 |
shared s = 0; |
| 4117 |
|
| 4118 |
static assert(is(typeof(f(i, i)) == immutable int)); |
| 4119 |
static assert(is(typeof(f(i, c)) == const int)); |
| 4120 |
static assert(is(typeof(f(c, i)) == const int)); |
| 4121 |
static assert(is(typeof(f(i, m)) == int)); |
| 4122 |
static assert(is(typeof(f(m, i)) == int)); |
| 4123 |
static assert(is(typeof(f(c, m)) == int)); |
| 4124 |
static assert(is(typeof(f(m, c)) == int)); |
| 4125 |
static assert(is(typeof(f(m, m)) == int)); |
| 4126 |
static assert(is(typeof(f(i, s)) == shared int)); |
| 4127 |
static assert(is(typeof(f(s, i)) == shared int)); |
| 4128 |
static assert(is(typeof(f(c, s)) == shared int)); |
| 4129 |
static assert(is(typeof(f(s, c)) == shared int)); |
| 4130 |
static assert(is(typeof(f(s, s)) == shared int)); |
| 4131 |
static assert(is(typeof(f(s, m)) == int)); |
| 4132 |
static assert(is(typeof(f(m, s)) == int)); |
| 4133 |
} |
| 4134 |
|
| 4135 |
/******************************************/ |
| 4136 |
// https://issues.dlang.org/show_bug.cgi?id=13235 |
| 4137 |
|
| 4138 |
struct Tuple13235(T...) |
| 4139 |
{ |
| 4140 |
T expand; |
| 4141 |
alias expand field; |
| 4142 |
|
| 4143 |
this(T values) |
| 4144 |
{ |
| 4145 |
field = values; |
| 4146 |
} |
| 4147 |
} |
| 4148 |
struct Foo13235 |
| 4149 |
{ |
| 4150 |
Tuple13235!(int, Foo13235)* foo; |
| 4151 |
} |
| 4152 |
|
| 4153 |
template Inst13235(T...) |
| 4154 |
{ |
| 4155 |
struct Tuple |
| 4156 |
{ |
| 4157 |
T expand; |
| 4158 |
alias expand field; |
| 4159 |
|
| 4160 |
this(T values) |
| 4161 |
{ |
| 4162 |
field = values; |
| 4163 |
} |
| 4164 |
} |
| 4165 |
alias Inst13235 = Tuple*; |
| 4166 |
} |
| 4167 |
struct Bar13235 |
| 4168 |
{ |
| 4169 |
Inst13235!(int, Bar13235) bar; |
| 4170 |
} |
| 4171 |
|
| 4172 |
void test13235() |
| 4173 |
{ |
| 4174 |
alias Tup1 = Tuple13235!(int, Foo13235); |
| 4175 |
assert(Tup1(1, Foo13235()).expand[0] == 1); |
| 4176 |
|
| 4177 |
alias Tup2 = typeof(*Inst13235!(int, Bar13235).init); |
| 4178 |
assert(Tup2(1, Bar13235()).expand[0] == 1); |
| 4179 |
} |
| 4180 |
|
| 4181 |
/******************************************/ |
| 4182 |
// https://issues.dlang.org/show_bug.cgi?id=13252 |
| 4183 |
|
| 4184 |
alias TypeTuple13252(T...) = T; |
| 4185 |
|
| 4186 |
static assert(is(typeof(TypeTuple13252!(cast(int )1)[0]) == int )); |
| 4187 |
static assert(is(typeof(TypeTuple13252!(cast(long)1)[0]) == long)); |
| 4188 |
|
| 4189 |
static assert(is(typeof(TypeTuple13252!(cast(float )3.14)[0]) == float )); |
| 4190 |
static assert(is(typeof(TypeTuple13252!(cast(double)3.14)[0]) == double)); |
| 4191 |
|
| 4192 |
static assert(is(typeof(TypeTuple13252!(cast(string )null)[0]) == string )); |
| 4193 |
static assert(is(typeof(TypeTuple13252!(cast(string[])null)[0]) == string[])); // OK <- NG |
| 4194 |
|
| 4195 |
static assert(is(typeof(TypeTuple13252!(cast(wstring)"abc")[0]) == wstring)); |
| 4196 |
static assert(is(typeof(TypeTuple13252!(cast(dstring)"abc")[0]) == dstring)); |
| 4197 |
|
| 4198 |
static assert(is(typeof(TypeTuple13252!(cast(int[] )[])[0]) == int[] )); |
| 4199 |
static assert(is(typeof(TypeTuple13252!(cast(long[])[])[0]) == long[])); // OK <- NG |
| 4200 |
|
| 4201 |
struct S13252 { } |
| 4202 |
static assert(is(typeof(TypeTuple13252!(const S13252())[0]) == const(S13252))); |
| 4203 |
static assert(is(typeof(TypeTuple13252!(immutable S13252())[0]) == immutable(S13252))); // OK <- NG |
| 4204 |
|
| 4205 |
/******************************************/ |
| 4206 |
// https://issues.dlang.org/show_bug.cgi?id=13294 |
| 4207 |
|
| 4208 |
void test13294() |
| 4209 |
{ |
| 4210 |
void f(T)(const ref T src, ref T dst) |
| 4211 |
{ |
| 4212 |
pragma(msg, "T = ", T); |
| 4213 |
static assert(!is(T == const)); |
| 4214 |
} |
| 4215 |
{ |
| 4216 |
const byte src; |
| 4217 |
byte dst; |
| 4218 |
f(src, dst); |
| 4219 |
} |
| 4220 |
{ |
| 4221 |
const char src; |
| 4222 |
char dst; |
| 4223 |
f(src, dst); |
| 4224 |
} |
| 4225 |
|
| 4226 |
// https://issues.dlang.org/show_bug.cgi?id=13351 |
| 4227 |
T add(T)(in T x, in T y) |
| 4228 |
{ |
| 4229 |
T z; |
| 4230 |
z = x + y; |
| 4231 |
return z; |
| 4232 |
} |
| 4233 |
const double a = 1.0; |
| 4234 |
const double b = 2.0; |
| 4235 |
double c; |
| 4236 |
c = add(a,b); |
| 4237 |
} |
| 4238 |
|
| 4239 |
/******************************************/ |
| 4240 |
// https://issues.dlang.org/show_bug.cgi?id=13299 |
| 4241 |
|
| 4242 |
struct Foo13299 |
| 4243 |
{ |
| 4244 |
Foo13299 opDispatch(string name)(int a, int[] b...) |
| 4245 |
if (name == "bar") |
| 4246 |
{ |
| 4247 |
return Foo13299(); |
| 4248 |
} |
| 4249 |
|
| 4250 |
Foo13299 opDispatch(string name)() |
| 4251 |
if (name != "bar") |
| 4252 |
{ |
| 4253 |
return Foo13299(); |
| 4254 |
} |
| 4255 |
} |
| 4256 |
|
| 4257 |
void test13299() |
| 4258 |
{ |
| 4259 |
Foo13299() |
| 4260 |
.bar(0) |
| 4261 |
.bar(1) |
| 4262 |
.bar(2); |
| 4263 |
|
| 4264 |
Foo13299() |
| 4265 |
.opDispatch!"bar"(0) |
| 4266 |
.opDispatch!"bar"(1) |
| 4267 |
.opDispatch!"bar"(2); |
| 4268 |
} |
| 4269 |
|
| 4270 |
/******************************************/ |
| 4271 |
// https://issues.dlang.org/show_bug.cgi?id=13333 |
| 4272 |
|
| 4273 |
template AliasThisTypeOf13333(T) |
| 4274 |
{ |
| 4275 |
static assert(0, T.stringof); // T.stringof is important |
| 4276 |
} |
| 4277 |
|
| 4278 |
template StaticArrayTypeOf13333(T) |
| 4279 |
{ |
| 4280 |
static if (is(AliasThisTypeOf13333!T AT)) |
| 4281 |
alias X = StaticArrayTypeOf13333!AT; |
| 4282 |
else |
| 4283 |
alias X = T; |
| 4284 |
|
| 4285 |
static if (is(X : E[n], E, size_t n)) |
| 4286 |
alias StaticArrayTypeOf13333 = X; |
| 4287 |
else |
| 4288 |
static assert(0, T.stringof~" is not a static array type"); |
| 4289 |
} |
| 4290 |
|
| 4291 |
enum bool isStaticArray13333(T) = is(StaticArrayTypeOf13333!T); |
| 4292 |
|
| 4293 |
struct VaraiantN13333(T) |
| 4294 |
{ |
| 4295 |
static if (isStaticArray13333!T) |
| 4296 |
~this() { static assert(0); } |
| 4297 |
} |
| 4298 |
|
| 4299 |
struct DummyScope13333 |
| 4300 |
{ |
| 4301 |
alias A = VaraiantN13333!C; |
| 4302 |
|
| 4303 |
static class C |
| 4304 |
{ |
| 4305 |
A entity; |
| 4306 |
} |
| 4307 |
} |
| 4308 |
|
| 4309 |
void test13333() |
| 4310 |
{ |
| 4311 |
struct DummyScope |
| 4312 |
{ |
| 4313 |
alias A = VaraiantN13333!C; |
| 4314 |
|
| 4315 |
static class C |
| 4316 |
{ |
| 4317 |
A entity; |
| 4318 |
} |
| 4319 |
} |
| 4320 |
} |
| 4321 |
|
| 4322 |
/******************************************/ |
| 4323 |
// https://issues.dlang.org/show_bug.cgi?id=13374 |
| 4324 |
|
| 4325 |
int f13374(alias a)() { return 1; } |
| 4326 |
int f13374(string s)() { return 2; } |
| 4327 |
|
| 4328 |
void x13374(int i) {} |
| 4329 |
|
| 4330 |
void test13374() |
| 4331 |
{ |
| 4332 |
assert(f13374!x13374() == 1); |
| 4333 |
} |
| 4334 |
|
| 4335 |
/******************************************/ |
| 4336 |
// https://issues.dlang.org/show_bug.cgi?id=14109 |
| 4337 |
|
| 4338 |
string f14109() { return "a"; } |
| 4339 |
string g14109()() { return "a"; } |
| 4340 |
|
| 4341 |
struct S14109(string s) { static assert(s == "a"); } |
| 4342 |
|
| 4343 |
alias X14109 = S14109!(f14109); |
| 4344 |
alias Y14109 = S14109!(g14109!()); |
| 4345 |
static assert(is(X14109 == Y14109)); |
| 4346 |
|
| 4347 |
/******************************************/ |
| 4348 |
// https://issues.dlang.org/show_bug.cgi?id=13378 |
| 4349 |
|
| 4350 |
struct Vec13378(size_t n, T, string as) |
| 4351 |
{ |
| 4352 |
T[n] data; |
| 4353 |
} |
| 4354 |
|
| 4355 |
void doSome13378(size_t n, T, string as)(Vec13378!(n,T,as) v) {} |
| 4356 |
|
| 4357 |
void test13378() |
| 4358 |
{ |
| 4359 |
auto v = Vec13378!(3, float, "xyz")([1,2,3]); |
| 4360 |
doSome13378(v); |
| 4361 |
} |
| 4362 |
|
| 4363 |
/******************************************/ |
| 4364 |
// https://issues.dlang.org/show_bug.cgi?id=13379 |
| 4365 |
|
| 4366 |
void test13379() |
| 4367 |
{ |
| 4368 |
match13379(""); |
| 4369 |
} |
| 4370 |
|
| 4371 |
auto match13379(RegEx )(RegEx re) |
| 4372 |
if (is(RegEx == Regex13379!char)) // #1 Regex!char (speculative && tinst == NULL) |
| 4373 |
{} |
| 4374 |
auto match13379(String)(String re) |
| 4375 |
{} |
| 4376 |
|
| 4377 |
struct Regex13379(Char) |
| 4378 |
{ |
| 4379 |
ShiftOr13379!Char kickstart; // #2 ShiftOr!char (speculative && tinst == Regex!char) |
| 4380 |
} |
| 4381 |
struct ShiftOr13379(Char) |
| 4382 |
{ |
| 4383 |
this(ref Regex13379!Char re) // #3 Regex!Char (speculative && tinst == ShiftOr!char) |
| 4384 |
{ |
| 4385 |
uint n_length; |
| 4386 |
uint idx; |
| 4387 |
n_length = min13379(idx, n_length); |
| 4388 |
} |
| 4389 |
} |
| 4390 |
|
| 4391 |
template MinType13379(T...) |
| 4392 |
{ |
| 4393 |
alias MinType13379 = T[0]; |
| 4394 |
} |
| 4395 |
MinType13379!T min13379(T...)(T args) // #4 MinType!uint (speculative && thist == ShiftOr!char) |
| 4396 |
{ |
| 4397 |
alias a = args[0]; |
| 4398 |
alias b = args[$-1]; |
| 4399 |
return cast(typeof(return)) (a < b ? a : b); |
| 4400 |
} |
| 4401 |
|
| 4402 |
/******************************************/ |
| 4403 |
// https://issues.dlang.org/show_bug.cgi?id=13417 |
| 4404 |
|
| 4405 |
struct V13417(size_t N, E, alias string AS) |
| 4406 |
{ |
| 4407 |
} |
| 4408 |
|
| 4409 |
auto f13417(E)(in V13417!(4, E, "ijka")) |
| 4410 |
{ |
| 4411 |
return V13417!(3, E, "xyz")(); |
| 4412 |
} |
| 4413 |
|
| 4414 |
void test13417() |
| 4415 |
{ |
| 4416 |
f13417(V13417!(4, float, "ijka")()); |
| 4417 |
} |
| 4418 |
|
| 4419 |
/******************************************/ |
| 4420 |
// https://issues.dlang.org/show_bug.cgi?id=13484 |
| 4421 |
|
| 4422 |
int foo13484()(void delegate() hi) { return 1; } |
| 4423 |
int foo13484(T)(void delegate(T) hi) { return 2; } |
| 4424 |
|
| 4425 |
void test13484() |
| 4426 |
{ |
| 4427 |
assert(foo13484({}) == 1); // works |
| 4428 |
assert(foo13484((float v){}) == 2); // works <- throws error |
| 4429 |
} |
| 4430 |
|
| 4431 |
/******************************************/ |
| 4432 |
// https://issues.dlang.org/show_bug.cgi?id=13675 |
| 4433 |
|
| 4434 |
enum E13675; |
| 4435 |
|
| 4436 |
bool foo13675(T : E13675)() |
| 4437 |
{ |
| 4438 |
return false; |
| 4439 |
} |
| 4440 |
|
| 4441 |
void test13675() |
| 4442 |
{ |
| 4443 |
if (foo13675!E13675) |
| 4444 |
{} |
| 4445 |
} |
| 4446 |
|
| 4447 |
/******************************************/ |
| 4448 |
// https://issues.dlang.org/show_bug.cgi?id=13694 |
| 4449 |
|
| 4450 |
auto foo13694(T)(string A, T[] G ...) { return 1; } |
| 4451 |
auto foo13694(T)(string A, long E, T[] G ...) { return 2; } |
| 4452 |
|
| 4453 |
void test13694() |
| 4454 |
{ |
| 4455 |
struct S {} |
| 4456 |
|
| 4457 |
S v; |
| 4458 |
assert(foo13694("A", v) == 1); // <- OK |
| 4459 |
assert(foo13694("A", 0, v) == 2); // <- used to be OK but now fails |
| 4460 |
assert(foo13694!S("A", 0, v) == 2); // <- workaround solution |
| 4461 |
} |
| 4462 |
|
| 4463 |
/******************************************/ |
| 4464 |
// https://issues.dlang.org/show_bug.cgi?id=13760 |
| 4465 |
|
| 4466 |
void test13760() |
| 4467 |
{ |
| 4468 |
void func(K, V)(inout(V[K]) aa, inout(V) val) {} |
| 4469 |
|
| 4470 |
class C {} |
| 4471 |
C[int] aa; |
| 4472 |
func(aa, new C); |
| 4473 |
} |
| 4474 |
|
| 4475 |
/******************************************/ |
| 4476 |
// https://issues.dlang.org/show_bug.cgi?id=13714 |
| 4477 |
|
| 4478 |
struct JSONValue13714 |
| 4479 |
{ |
| 4480 |
this(T)(T arg) |
| 4481 |
{ |
| 4482 |
} |
| 4483 |
this(T : JSONValue13714)(inout T arg) inout |
| 4484 |
{ |
| 4485 |
//store = arg.store; |
| 4486 |
} |
| 4487 |
|
| 4488 |
void opAssign(T)(T arg) |
| 4489 |
{ |
| 4490 |
} |
| 4491 |
} |
| 4492 |
|
| 4493 |
void test13714() |
| 4494 |
{ |
| 4495 |
enum DummyStringEnum |
| 4496 |
{ |
| 4497 |
foo = "bar" |
| 4498 |
} |
| 4499 |
|
| 4500 |
JSONValue13714[string] aa; |
| 4501 |
aa["A"] = DummyStringEnum.foo; |
| 4502 |
} |
| 4503 |
|
| 4504 |
/******************************************/ |
| 4505 |
// https://issues.dlang.org/show_bug.cgi?id=13807 |
| 4506 |
|
| 4507 |
T f13807(T)(inout(T)[] arr) |
| 4508 |
{ |
| 4509 |
return T.init; |
| 4510 |
} |
| 4511 |
|
| 4512 |
void test13807() |
| 4513 |
{ |
| 4514 |
static assert(is(typeof(f13807([1, 2, 3])) == int)); // OK |
| 4515 |
static assert(is(typeof(f13807(["a", "b"])) == string)); // OK <- Error |
| 4516 |
static assert(is(typeof(f13807!string(["a", "b"])) == string)); // OK |
| 4517 |
} |
| 4518 |
|
| 4519 |
/******************************************/ |
| 4520 |
// https://issues.dlang.org/show_bug.cgi?id=14174 |
| 4521 |
import imports.testmangle; |
| 4522 |
|
| 4523 |
struct Config14174(a, b) {} |
| 4524 |
|
| 4525 |
struct N14174 {} |
| 4526 |
|
| 4527 |
alias defConfig14174 = Config14174!(N14174, N14174); |
| 4528 |
|
| 4529 |
@safe @nogc pure nothrow |
| 4530 |
void accepter14174a(Config : Config14174!(T) = defConfig14174, T...)() |
| 4531 |
{ |
| 4532 |
static assert(equalDemangle(accepter14174a.mangleof, |
| 4533 |
"_D7breaker131__T14"~ |
| 4534 |
"accepter14174a"~ |
| 4535 |
"HTS7breaker51__T11Config14174TS7breaker6N14174TS7breaker6N14174Z11Config14174TS7breaker6N14174TS7breaker6N14174Z14"~ |
| 4536 |
"accepter14174a"~ |
| 4537 |
"FNaNbNiNfZv")); |
| 4538 |
} |
| 4539 |
|
| 4540 |
@safe @nogc pure nothrow |
| 4541 |
void accepter14174b(Config : Config14174!(T) = defConfig14174, T...)() |
| 4542 |
{ |
| 4543 |
static assert(equalDemangle(accepter14174b.mangleof, |
| 4544 |
"_D7breaker131__T14"~ |
| 4545 |
"accepter14174b"~ |
| 4546 |
"HTS7breaker51__T11Config14174TS7breaker6N14174TS7breaker6N14174Z11Config14174TS7breaker6N14174TS7breaker6N14174Z14"~ |
| 4547 |
"accepter14174b"~ |
| 4548 |
"FNaNbNiNfZv")); |
| 4549 |
} |
| 4550 |
|
| 4551 |
void test14174() |
| 4552 |
{ |
| 4553 |
accepter14174a!()(); |
| 4554 |
|
| 4555 |
accepter14174b!()(); |
| 4556 |
} |
| 4557 |
|
| 4558 |
/******************************************/ |
| 4559 |
// https://issues.dlang.org/show_bug.cgi?id=14836 |
| 4560 |
|
| 4561 |
template a14836x(alias B, C...) |
| 4562 |
{ |
| 4563 |
int a14836x(D...)() if (D.length == 0) { return 1; } |
| 4564 |
int a14836x(D...)(D d) if (D.length > 0) { return 2; } |
| 4565 |
} |
| 4566 |
template a14836y(alias B, C...) |
| 4567 |
{ |
| 4568 |
int a14836y(T, D...)(T t) if (D.length == 0) { return 1; } |
| 4569 |
int a14836y(T, D...)(T t, D d) if (D.length > 0) { return 2; } |
| 4570 |
} |
| 4571 |
|
| 4572 |
void test14836() |
| 4573 |
{ |
| 4574 |
int v; |
| 4575 |
assert(a14836x!(v)() == 1); |
| 4576 |
assert(a14836x!(v)(1) == 2); |
| 4577 |
assert(a14836y!(v)(1) == 1); |
| 4578 |
assert(a14836y!(v)(1, 2) == 2); |
| 4579 |
} |
| 4580 |
|
| 4581 |
/******************************************/ |
| 4582 |
// https://issues.dlang.org/show_bug.cgi?id=14357 |
| 4583 |
|
| 4584 |
template Qux14357(T : U*, U : V*, V) |
| 4585 |
{ |
| 4586 |
pragma(msg, T); // no match <- float** |
| 4587 |
pragma(msg, U); // no match <- float* |
| 4588 |
pragma(msg, V); // no match <- int |
| 4589 |
enum Qux14357 = T.sizeof + V.sizeof; |
| 4590 |
} |
| 4591 |
static assert(!__traits(compiles, Qux14357!(float**, int*))); |
| 4592 |
|
| 4593 |
/******************************************/ |
| 4594 |
// https://issues.dlang.org/show_bug.cgi?id=14481 |
| 4595 |
|
| 4596 |
template someT14481(alias e) |
| 4597 |
{ |
| 4598 |
alias someT14481 = e; |
| 4599 |
} |
| 4600 |
|
| 4601 |
mixin template Mix14481(alias e) |
| 4602 |
{ |
| 4603 |
alias SomeAlias = someT14481!e; |
| 4604 |
} |
| 4605 |
|
| 4606 |
struct Hoge14481 |
| 4607 |
{ |
| 4608 |
mixin Mix14481!e; |
| 4609 |
enum e = 10; |
| 4610 |
} |
| 4611 |
|
| 4612 |
/******************************************/ |
| 4613 |
// https://issues.dlang.org/show_bug.cgi?id=14520 |
| 4614 |
|
| 4615 |
template M14520(alias a) { enum M14520 = 1; } |
| 4616 |
template M14520(string s) { enum M14520 = 2; } |
| 4617 |
|
| 4618 |
int f14520a(); |
| 4619 |
string f14520b() { assert(0); } |
| 4620 |
string f14520c() { return "a"; } |
| 4621 |
|
| 4622 |
static assert(M14520!f14520a == 1); |
| 4623 |
static assert(M14520!f14520b == 1); |
| 4624 |
static assert(M14520!f14520c == 1); |
| 4625 |
|
| 4626 |
/******************************************/ |
| 4627 |
// https://issues.dlang.org/show_bug.cgi?id=14568 |
| 4628 |
|
| 4629 |
struct Interval14568() |
| 4630 |
{ |
| 4631 |
auto left = INVALID; |
| 4632 |
|
| 4633 |
auto opAssign()(Interval14568) { left; } |
| 4634 |
} |
| 4635 |
|
| 4636 |
auto interval14568(T)(T point) |
| 4637 |
{ |
| 4638 |
Interval14568!(); |
| 4639 |
} |
| 4640 |
|
| 4641 |
alias Instantiate14568(alias symbol, Args...) = symbol!Args; |
| 4642 |
|
| 4643 |
template Match14568(patterns...) |
| 4644 |
{ |
| 4645 |
static if (__traits(compiles, Instantiate14568!(patterns[0]))) |
| 4646 |
{ |
| 4647 |
alias Match14568 = patterns[0]; |
| 4648 |
} |
| 4649 |
else static if (patterns.length == 1) |
| 4650 |
{} |
| 4651 |
} |
| 4652 |
|
| 4653 |
template SubOps14568(Args...) |
| 4654 |
{ |
| 4655 |
auto opIndex() |
| 4656 |
{ |
| 4657 |
template IntervalType(T...) |
| 4658 |
{ |
| 4659 |
alias Point() = typeof(T.interval14568); |
| 4660 |
|
| 4661 |
alias IntervalType = Match14568!(Point); |
| 4662 |
} |
| 4663 |
alias Subspace = IntervalType!(Args); |
| 4664 |
} |
| 4665 |
} |
| 4666 |
|
| 4667 |
struct Nat14568 { mixin SubOps14568!(null); } |
| 4668 |
|
| 4669 |
/******************************************/ |
| 4670 |
// https://issues.dlang.org/show_bug.cgi?id=14603 |
| 4671 |
// https://issues.dlang.org/show_bug.cgi?id=14604 |
| 4672 |
|
| 4673 |
struct S14603 |
| 4674 |
{ |
| 4675 |
template opDispatch(string name) |
| 4676 |
{ |
| 4677 |
void opDispatch()() {} |
| 4678 |
} |
| 4679 |
} |
| 4680 |
alias a14603 = S14603.opDispatch!"go"; // OK |
| 4681 |
alias b14603 = S14603.go; // OK <- NG |
| 4682 |
|
| 4683 |
struct S14604 |
| 4684 |
{ |
| 4685 |
template opDispatch(string name) |
| 4686 |
{ |
| 4687 |
void opDispatch()() {} |
| 4688 |
} |
| 4689 |
} |
| 4690 |
alias Id14604(alias thing) = thing; |
| 4691 |
alias c14604 = Id14604!(S14604.opDispatch!"go"); // ok |
| 4692 |
// https://issues.dlang.org/show_bug.cgi?id=14604 |
| 4693 |
alias d14604 = Id14604!(S14604.go); // 'Error: template instance opDispatch!"go" cannot resolve forward reference' |
| 4694 |
|
| 4695 |
/******************************************/ |
| 4696 |
// https://issues.dlang.org/show_bug.cgi?id=14735 |
| 4697 |
|
| 4698 |
enum CS14735 { yes, no } |
| 4699 |
|
| 4700 |
int indexOf14735a(Range )(Range s, in dchar c) { return 1; } |
| 4701 |
int indexOf14735a(T, size_t n)(ref T[n] s, in dchar c) { return 2; } |
| 4702 |
|
| 4703 |
int indexOf14735b(Range )(Range s, in dchar c, in CS14735 cs = CS14735.yes) { return 1; } |
| 4704 |
int indexOf14735b(T, size_t n)(ref T[n] s, in dchar c, in CS14735 cs = CS14735.yes) { return 2; } |
| 4705 |
|
| 4706 |
void test14735() |
| 4707 |
{ |
| 4708 |
char[64] buf; |
| 4709 |
|
| 4710 |
// Supported from 2.063: (https://dlang.org/changelog/2.063.html#implicitarraycast) |
| 4711 |
assert(indexOf14735a(buf[0..32], '\0') == 2); |
| 4712 |
assert(indexOf14735b(buf[0..32], '\0') == 2); |
| 4713 |
|
| 4714 |
// Have to work as same as above. |
| 4715 |
assert(indexOf14735a(buf[], '\0') == 2); |
| 4716 |
assert(indexOf14735b(buf[], '\0') == 2); |
| 4717 |
} |
| 4718 |
|
| 4719 |
/******************************************/ |
| 4720 |
// https://issues.dlang.org/show_bug.cgi?id=14743 |
| 4721 |
|
| 4722 |
class A14743 |
| 4723 |
{ |
| 4724 |
auto func1 = (A14743 a) { a.func2!int(); }; |
| 4725 |
auto func2(T)() {} |
| 4726 |
} |
| 4727 |
|
| 4728 |
/******************************************/ |
| 4729 |
// https://issues.dlang.org/show_bug.cgi?id=14802 |
| 4730 |
|
| 4731 |
void test14802() |
| 4732 |
{ |
| 4733 |
auto func(T)(T x, T y) { return x; } |
| 4734 |
|
| 4735 |
struct S1 { double x; alias x this; } |
| 4736 |
struct S2 { double x; alias x this; } |
| 4737 |
S1 s1; |
| 4738 |
S2 s2; |
| 4739 |
|
| 4740 |
enum E1 : double { a = 1.0 } |
| 4741 |
enum E2 : double { a = 1.0 } |
| 4742 |
|
| 4743 |
static assert(is(typeof( func(1 , 1 ) ) == int)); |
| 4744 |
static assert(is(typeof( func(1u, 1u) ) == uint)); |
| 4745 |
static assert(is(typeof( func(1u, 1 ) ) == uint)); |
| 4746 |
static assert(is(typeof( func(1 , 1u) ) == uint)); |
| 4747 |
|
| 4748 |
static assert(is(typeof( func(1.0f, 1.0f) ) == float)); |
| 4749 |
static assert(is(typeof( func(1.0 , 1.0 ) ) == double)); |
| 4750 |
static assert(is(typeof( func(1.0 , 1.0f) ) == double)); |
| 4751 |
static assert(is(typeof( func(1.0f, 1.0 ) ) == double)); |
| 4752 |
|
| 4753 |
static assert(is(typeof( func(s1, s1) ) == S1)); |
| 4754 |
static assert(is(typeof( func(s2, s2) ) == S2)); |
| 4755 |
static assert(is(typeof( func(s1, s2) ) == double)); |
| 4756 |
static assert(is(typeof( func(s2, s1) ) == double)); |
| 4757 |
|
| 4758 |
static assert(is(typeof( func(E1.a, E1.a) ) == E1)); |
| 4759 |
static assert(is(typeof( func(E2.a, E2.a) ) == E2)); |
| 4760 |
static assert(is(typeof( func(E1.a, 1.0) ) == double)); |
| 4761 |
static assert(is(typeof( func(E2.a, 1.0) ) == double)); |
| 4762 |
static assert(is(typeof( func(1.0, E1.a) ) == double)); |
| 4763 |
static assert(is(typeof( func(1.0, E2.a) ) == double)); |
| 4764 |
static assert(is(typeof( func(E1.a, E2.a) ) == double)); |
| 4765 |
static assert(is(typeof( func(E2.a, E1.a) ) == double)); |
| 4766 |
} |
| 4767 |
|
| 4768 |
/******************************************/ |
| 4769 |
// https://issues.dlang.org/show_bug.cgi?id=14886 |
| 4770 |
|
| 4771 |
void test14886() |
| 4772 |
{ |
| 4773 |
alias R = int[100_000]; |
| 4774 |
|
| 4775 |
auto front(T)(T[] a) {} |
| 4776 |
front(R.init); |
| 4777 |
|
| 4778 |
auto bar1(T)(T, T[] a) { return T.init; } |
| 4779 |
auto bar2(T)(T[] a, T) { return T.init; } |
| 4780 |
|
| 4781 |
static assert(is(typeof(bar1(1L, R.init)) == long)); |
| 4782 |
static assert(is(typeof(bar2(R.init, 1L)) == long)); |
| 4783 |
// <-- T should be deduced to int because R.init is rvalue...? |
| 4784 |
|
| 4785 |
ubyte x; |
| 4786 |
static assert(is(typeof(bar1(x, R.init)) == int)); |
| 4787 |
static assert(is(typeof(bar2(R.init, x)) == int)); |
| 4788 |
} |
| 4789 |
|
| 4790 |
/******************************************/ |
| 4791 |
// https://issues.dlang.org/show_bug.cgi?id=15156 |
| 4792 |
|
| 4793 |
// https://issues.dlang.org/show_bug.cgi?id=15156 |
| 4794 |
auto f15116a(T)(string s, string arg2) { return 1; } |
| 4795 |
auto f15116b(T)(int i, string arg2) { return 2; } |
| 4796 |
|
| 4797 |
template bish15116(T) |
| 4798 |
{ |
| 4799 |
alias bish15116 = f15116a!T; |
| 4800 |
alias bish15116 = f15116b!T; |
| 4801 |
} |
| 4802 |
|
| 4803 |
void test15116() |
| 4804 |
{ |
| 4805 |
alias func = bish15116!string; |
| 4806 |
assert(func("", "") == 1); |
| 4807 |
assert(func(12, "") == 2); |
| 4808 |
} |
| 4809 |
|
| 4810 |
/******************************************/ |
| 4811 |
// https://issues.dlang.org/show_bug.cgi?id=15152 |
| 4812 |
|
| 4813 |
void test15152() |
| 4814 |
{ |
| 4815 |
void func(string M)() { } |
| 4816 |
|
| 4817 |
struct S |
| 4818 |
{ |
| 4819 |
enum name = "a"; |
| 4820 |
} |
| 4821 |
|
| 4822 |
enum s = S.init; |
| 4823 |
func!(s.name); |
| 4824 |
} |
| 4825 |
|
| 4826 |
/******************************************/ |
| 4827 |
// https://issues.dlang.org/show_bug.cgi?id=15352 |
| 4828 |
|
| 4829 |
struct S15352(T, T delegate(uint idx) supplier) |
| 4830 |
{ |
| 4831 |
} |
| 4832 |
|
| 4833 |
auto make15352a(T, T delegate(uint idx) supplier)() |
| 4834 |
{ |
| 4835 |
enum local = supplier; // OK |
| 4836 |
S15352!(T, local) ret; |
| 4837 |
return ret; |
| 4838 |
} |
| 4839 |
|
| 4840 |
auto make15352b(T, T delegate(uint idx) supplier)() |
| 4841 |
{ |
| 4842 |
S15352!(T, supplier) ret; // OK <- Error |
| 4843 |
return ret; |
| 4844 |
} |
| 4845 |
|
| 4846 |
void test15352() |
| 4847 |
{ |
| 4848 |
enum dg = delegate(uint idx) => idx; |
| 4849 |
auto s1 = S15352!(uint, dg)(); |
| 4850 |
auto s2 = make15352a!(uint, dg)(); |
| 4851 |
auto s3 = make15352b!(uint, dg)(); |
| 4852 |
assert(is(typeof(s1) == typeof(s2))); |
| 4853 |
assert(is(typeof(s1) == typeof(s3))); |
| 4854 |
} |
| 4855 |
|
| 4856 |
/******************************************/ |
| 4857 |
// https://issues.dlang.org/show_bug.cgi?id=15623 |
| 4858 |
|
| 4859 |
struct WithFoo15623a { void foo() {} } |
| 4860 |
struct WithFoo15623b { void foo() {} } |
| 4861 |
struct WithFoo15623c { void foo() {} } |
| 4862 |
struct WithFoo15623d { void foo() {} } |
| 4863 |
|
| 4864 |
struct WithoutFoo15623a {} |
| 4865 |
struct WithoutFoo15623b {} |
| 4866 |
struct WithoutFoo15623c {} |
| 4867 |
struct WithoutFoo15623d {} |
| 4868 |
|
| 4869 |
struct CallsFoo15623(T) |
| 4870 |
{ |
| 4871 |
T t; |
| 4872 |
void bar() { t.foo(); } // error occurs during TemplateInstance.semantic3 |
| 4873 |
} |
| 4874 |
|
| 4875 |
// Instantiations outside of function bodies |
| 4876 |
static assert( is(CallsFoo15623!WithFoo15623a)); |
| 4877 |
static assert(!is(CallsFoo15623!WithoutFoo15623a)); // OK <- NG |
| 4878 |
static assert( __traits(compiles, CallsFoo15623!WithFoo15623b)); |
| 4879 |
static assert(!__traits(compiles, CallsFoo15623!WithoutFoo15623b)); // OK <- NG |
| 4880 |
|
| 4881 |
// Instantiations inside function bodies (OK) |
| 4882 |
static assert( is(typeof({ alias Baz = CallsFoo15623!WithFoo15623c; return Baz.init; }()))); |
| 4883 |
static assert(!is(typeof({ alias Baz = CallsFoo15623!WithoutFoo15623c; return Baz.init; }()))); |
| 4884 |
static assert( __traits(compiles, { alias Baz = CallsFoo15623!WithFoo15623d; return Baz.init; }())); |
| 4885 |
static assert(!__traits(compiles, { alias Baz = CallsFoo15623!WithoutFoo15623d; return Baz.init; }())); |
| 4886 |
|
| 4887 |
/******************************************/ |
| 4888 |
// https://issues.dlang.org/show_bug.cgi?id=15781 |
| 4889 |
|
| 4890 |
void test15781() |
| 4891 |
{ |
| 4892 |
static struct S |
| 4893 |
{ |
| 4894 |
int value; |
| 4895 |
} |
| 4896 |
|
| 4897 |
T foo(T)(T a, T b) |
| 4898 |
{ |
| 4899 |
return T(); |
| 4900 |
} |
| 4901 |
|
| 4902 |
const S cs; |
| 4903 |
S ms; |
| 4904 |
static assert(is(typeof(foo(ms, ms)) == S)); |
| 4905 |
static assert(is(typeof(foo(ms, cs)) == const S)); |
| 4906 |
static assert(is(typeof(foo(cs, ms)) == const S)); |
| 4907 |
static assert(is(typeof(foo(cs, cs)) == const S)); |
| 4908 |
} |
| 4909 |
|
| 4910 |
/******************************************/ |
| 4911 |
// https://issues.dlang.org/show_bug.cgi?id=16042 |
| 4912 |
|
| 4913 |
struct Foo16042 {} |
| 4914 |
|
| 4915 |
auto map16042(alias func, T)(T t) |
| 4916 |
{ |
| 4917 |
return func(t); |
| 4918 |
} |
| 4919 |
|
| 4920 |
auto toChars16042(R)(R r) if (is(R == int[])) |
| 4921 |
{ |
| 4922 |
Foo16042 f; |
| 4923 |
assert(toChars16042(f) == 1); // OK |
| 4924 |
assert(map16042!(toChars16042)(f) == 1); // OK <- NG |
| 4925 |
assert(map16042!((toChars16042))(f) == 1); // OK |
| 4926 |
} |
| 4927 |
|
| 4928 |
auto toChars16042(Foo16042 f) |
| 4929 |
{ |
| 4930 |
return 1; |
| 4931 |
} |
| 4932 |
|
| 4933 |
void test16042() |
| 4934 |
{ |
| 4935 |
[1].toChars16042(); |
| 4936 |
} |
| 4937 |
|
| 4938 |
// --- |
| 4939 |
|
| 4940 |
auto fn16042(R)(R r) if (is(R == int[])) {} |
| 4941 |
auto fn16042(Foo16042 f) { return 1; } |
| 4942 |
|
| 4943 |
struct Namespace16042 |
| 4944 |
{ |
| 4945 |
alias fn = fn16042!(int[]); |
| 4946 |
} |
| 4947 |
|
| 4948 |
void test16042b() |
| 4949 |
{ |
| 4950 |
Foo16042 f; |
| 4951 |
|
| 4952 |
with (Namespace16042) |
| 4953 |
{ |
| 4954 |
static assert(!__traits(compiles, fn(f))); // NG |
| 4955 |
static assert(!__traits(compiles, map16042!(fn)(f))); // should be NG -> actually NG |
| 4956 |
static assert(!__traits(compiles, map16042!((fn))(f))); // NG |
| 4957 |
} |
| 4958 |
} |
| 4959 |
|
| 4960 |
/******************************************/ |
| 4961 |
// https://issues.dlang.org/show_bug.cgi?id=15243 |
| 4962 |
|
| 4963 |
struct S15243(Types...) |
| 4964 |
{ |
| 4965 |
void apply1(U)(U delegate(Types[0]) f0) {} |
| 4966 |
|
| 4967 |
void apply2(U)(U delegate(Types) f0) {} |
| 4968 |
|
| 4969 |
void apply3(U)(U delegate(Types[1..$]) f0) {} |
| 4970 |
} |
| 4971 |
|
| 4972 |
void test15243() |
| 4973 |
{ |
| 4974 |
int f1(int) { return 0; } |
| 4975 |
int f2(int, long) { return 0; } |
| 4976 |
int f3(long, string) { return 0; } |
| 4977 |
|
| 4978 |
S15243!(int) s1; |
| 4979 |
s1.apply1(&f1); |
| 4980 |
s1.apply2(&f1); |
| 4981 |
|
| 4982 |
S15243!(int, long) s2; |
| 4983 |
s2.apply2(&f2); |
| 4984 |
|
| 4985 |
S15243!(int, long, string) s3; |
| 4986 |
s3.apply3(&f3); |
| 4987 |
} |
| 4988 |
|
| 4989 |
/******************************************/ |
| 4990 |
// https://issues.dlang.org/show_bug.cgi?id=15653 |
| 4991 |
|
| 4992 |
alias TypeTuple15653(T...) = T; |
| 4993 |
|
| 4994 |
void test15653() |
| 4995 |
{ |
| 4996 |
void foo(U, T)(const T x) { static assert(is(T == U)); } |
| 4997 |
void bar(U, T)(immutable T x) { static assert(is(T == U)); } |
| 4998 |
|
| 4999 |
struct X { int a; long[2] b; } |
| 5000 |
struct Y { int* a; long[] b; } |
| 5001 |
|
| 5002 |
foreach (U; TypeTuple15653!( byte, short, int, long, |
| 5003 |
ubyte, ushort, uint, ulong, |
| 5004 |
float, double, real, |
| 5005 |
void delegate(), |
| 5006 |
int[2], X, X[2])) |
| 5007 |
{ |
| 5008 |
foo!U(U.init); // OK |
| 5009 |
bar!U(U.init); // Was error, now OK |
| 5010 |
|
| 5011 |
U u; |
| 5012 |
foo!U(u); // OK |
| 5013 |
bar!U(u); // Was error, now OK |
| 5014 |
} |
| 5015 |
|
| 5016 |
foreach (U; TypeTuple15653!(void*, int**, long[], double*[2])) |
| 5017 |
{ |
| 5018 |
foo!U(U.init); // OK |
| 5019 |
bar!U(U.init); // Was error, now OK |
| 5020 |
|
| 5021 |
U u; |
| 5022 |
foo!U(u); |
| 5023 |
static assert(!__traits(compiles, bar!U(u)), U.stringof); |
| 5024 |
} |
| 5025 |
|
| 5026 |
foreach (U; TypeTuple15653!(Object, Y, Y[2], int[int])) |
| 5027 |
{ |
| 5028 |
foo!U(U.init); // OK |
| 5029 |
static assert(!__traits(compiles, bar!U(U.init)), U.stringof); |
| 5030 |
|
| 5031 |
U u; |
| 5032 |
foo!U(u); // OK |
| 5033 |
static assert(!__traits(compiles, bar!U(u)), U.stringof); |
| 5034 |
} |
| 5035 |
} |
| 5036 |
|
| 5037 |
/******************************************/ |
| 5038 |
|
| 5039 |
template foo23733(T, alias T a) {} |
| 5040 |
|
| 5041 |
int n23733; |
| 5042 |
alias _ = foo23733!(int, n23733); |
| 5043 |
|
| 5044 |
/******************************************/ |
| 5045 |
|
| 5046 |
int main() |
| 5047 |
{ |
| 5048 |
test1(); |
| 5049 |
test2(); |
| 5050 |
test3(); |
| 5051 |
test4(); |
| 5052 |
test5(); |
| 5053 |
test6(); |
| 5054 |
test7(); |
| 5055 |
test8(); |
| 5056 |
test9(); |
| 5057 |
test1780(); |
| 5058 |
test3608(); |
| 5059 |
test5893(); |
| 5060 |
test6404(); |
| 5061 |
test2246(); |
| 5062 |
test2296(); |
| 5063 |
bug4984(); |
| 5064 |
test2579(); |
| 5065 |
test2803(); |
| 5066 |
test6613(); |
| 5067 |
test5886(); |
| 5068 |
test5393(); |
| 5069 |
test5896(); |
| 5070 |
test6825(); |
| 5071 |
test6789(); |
| 5072 |
test2778(); |
| 5073 |
test2778aa(); |
| 5074 |
test2778get(); |
| 5075 |
test6208a(); |
| 5076 |
test6208b(); |
| 5077 |
test6208c(); |
| 5078 |
test6738(); |
| 5079 |
test6780(); |
| 5080 |
test6810(); |
| 5081 |
test6891(); |
| 5082 |
test6994(); |
| 5083 |
test6764(); |
| 5084 |
test3467(); |
| 5085 |
test4413(); |
| 5086 |
test5525(); |
| 5087 |
test5801(); |
| 5088 |
test10(); |
| 5089 |
test7037(); |
| 5090 |
test7124(); |
| 5091 |
test7359(); |
| 5092 |
test7416(); |
| 5093 |
test7563(); |
| 5094 |
test7572(); |
| 5095 |
test7580(); |
| 5096 |
test7585(); |
| 5097 |
test7671(); |
| 5098 |
test7672(); |
| 5099 |
test7684(); |
| 5100 |
test11a(); |
| 5101 |
test11b(); |
| 5102 |
test7769(); |
| 5103 |
test7873(); |
| 5104 |
test7933(); |
| 5105 |
test8094(); |
| 5106 |
test12(); |
| 5107 |
test8125(); |
| 5108 |
test13(); |
| 5109 |
test14(); |
| 5110 |
test8129(); |
| 5111 |
test8238(); |
| 5112 |
test8669(); |
| 5113 |
test8833(); |
| 5114 |
test8976(); |
| 5115 |
test8940(); |
| 5116 |
test9022(); |
| 5117 |
test9026(); |
| 5118 |
test9038(); |
| 5119 |
test9076(); |
| 5120 |
test9100(); |
| 5121 |
test9124a(); |
| 5122 |
test9124b(); |
| 5123 |
test9143(); |
| 5124 |
test9266(); |
| 5125 |
test9536(); |
| 5126 |
test9578(); |
| 5127 |
test9596(); |
| 5128 |
test9837(); |
| 5129 |
test9874(); |
| 5130 |
test9885(); |
| 5131 |
test9971(); |
| 5132 |
test9977(); |
| 5133 |
test10083(); |
| 5134 |
test10592(); |
| 5135 |
test11242(); |
| 5136 |
test10811(); |
| 5137 |
test10969(); |
| 5138 |
test11271(); |
| 5139 |
test11533(); |
| 5140 |
test11818(); |
| 5141 |
test11843(); |
| 5142 |
test11872(); |
| 5143 |
test12122(); |
| 5144 |
test12207(); |
| 5145 |
test12376(); |
| 5146 |
test13235(); |
| 5147 |
test13294(); |
| 5148 |
test13299(); |
| 5149 |
test13374(); |
| 5150 |
test13378(); |
| 5151 |
test13379(); |
| 5152 |
test13484(); |
| 5153 |
test13694(); |
| 5154 |
test14836(); |
| 5155 |
test14735(); |
| 5156 |
test14802(); |
| 5157 |
test15116(); |
| 5158 |
test16042(); |
| 5159 |
test16042b(); |
| 5160 |
test15243(); |
| 5161 |
test15653(); |
| 5162 |
|
| 5163 |
printf("Success\n"); |
| 5164 |
return 0; |
| 5165 |
} |