ldc-0.17.5-src/0000755000175000017500000000000013200164644013341 5ustar matthiasmatthiasldc-0.17.5-src/tests/0000755000175000017500000000000013156012230014474 5ustar matthiasmatthiasldc-0.17.5-src/tests/ir/0000755000175000017500000000000013200164641015112 5ustar matthiasmatthiasldc-0.17.5-src/tests/ir/attr_target_x86.d0000644000175000017500000000372513200164641020313 0ustar matthiasmatthias// Tests @target attribute for x86 // REQUIRES: atleast_llvm307 // REQUIRES: target_X86 // RUN: %ldc -O -c -mcpu=i386 -mtriple=i386-linux-gnu -output-ll -of=%t.ll %s && FileCheck %s --check-prefix LLVM < %t.ll // RUN: %ldc -O -c -mcpu=i386 -mtriple=i386-linux-gnu -output-s -of=%t.s %s && FileCheck %s --check-prefix ASM < %t.s import ldc.attributes; // LLVM-LABEL: define{{.*}} void @{{.*}}foo // ASM-LABEL: _D15attr_target_x863fooFPfPffZv: void foo(float *A, float* B, float K) { for (int i = 0; i < 128; ++i) A[i] *= B[i] + K; // ASM-NOT: addps } // LLVM-LABEL: define{{.*}} void @{{.*}}foo_sse // LLVM-SAME: #[[SSE:[0-9]+]] // ASM-LABEL: _D15attr_target_x867foo_sseFPfPffZv: @(target("sse")) void foo_sse(float *A, float* B, float K) { for (int i = 0; i < 128; ++i) A[i] *= B[i] + K; // ASM: addps } // Make sure that no-sse overrides sse (attribute sorting). Also tests multiple @target attribs. // LLVM-LABEL: define{{.*}} void @{{.*}}foo_nosse // LLVM-SAME: #[[NOSSE:[0-9]+]] // ASM-LABEL: _D15attr_target_x869foo_nosseFPfPffZv: @(target("no-sse\n , \tsse ")) void foo_nosse(float *A, float* B, float K) { for (int i = 0; i < 128; ++i) A[i] *= B[i] + K; // ASM-NOT: addps } // LLVM-LABEL: define{{.*}} void @{{.*}}bar_nosse // LLVM-SAME: #[[NOSSE]] // ASM-LABEL: _D15attr_target_x869bar_nosseFPfPffZv: @(target("sse")) @(target(" no-sse")) void bar_nosse(float *A, float* B, float K) { for (int i = 0; i < 128; ++i) A[i] *= B[i] + K; // ASM-NOT: addps } // LLVM-LABEL: define{{.*}} void @{{.*}}haswell // LLVM-SAME: #[[HSW:[0-9]+]] // ASM-LABEL: _D15attr_target_x867haswellFPfPffZv: @(target("arch=haswell ")) void haswell(float *A, float* B, float K) { for (int i = 0; i < 128; ++i) A[i] *= B[i] + K; // ASM: vaddps } // LLVM-DAG: attributes #[[SSE]] = {{.*}} "target-features"="+sse" // LLVM-DAG: attributes #[[NOSSE]] = {{.*}} "target-features"="+sse,-sse" // LLVM-DAG: attributes #[[HSW]] = {{.*}} "target-cpu"="haswell" ldc-0.17.5-src/tests/ir/lit.site.cfg.in0000644000175000017500000000470713200164641017743 0ustar matthiasmatthiasimport lit.formats import os import sys import platform ## Auto-initialized variables by cmake: config.ldc2_bin = "@LDC2_BIN@" config.ldc2_bin_dir = "@LDC2_BIN_DIR@" config.test_source_root = "@TESTS_IR_DIR@" config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" config.llvm_version = @LDC_LLVM_VER@ config.llvm_targetsstr = "@LLVM_TARGETS_TO_BUILD@" config.name = 'LLVM IR codegen' # testFormat: The test format to use to interpret tests. config.test_format = lit.formats.ShTest(execute_external=False) # suffixes: A list of file extensions to treat as test files. This is overriden # by individual lit.local.cfg files in the test subdirectories. config.suffixes = ['.d', ] # excludes: A list of directories to exclude from the testsuite. The 'inputs' # subdirectories contain auxiliary inputs for various tests in their parent # directories. config.excludes = ['inputs'] # Define available features so that we can disable tests depending on LLVM version config.available_features.add("llvm%d" % config.llvm_version) for version in range(305, config.llvm_version+1): config.available_features.add("atleast_llvm%d" % version) # Define OS as available feature (Windows, Darwin, Linux) config.available_features.add(platform.system()) # Define available features based on what LLVM can target # Examples: 'target_X86', 'target_ARM', 'target_PowerPC', 'target_AArch64' for t in config.llvm_targetsstr.split(';'): config.available_features.add('target_' + t) config.target_triple = '(unused)' # test_exec_root: The root path where tests should be run. config.test_exec_root = os.path.dirname(__file__) # add LDC bin dir to the path path = os.path.pathsep.join( (config.ldc2_bin_dir, config.environment['PATH']) ) config.environment['PATH'] = path # add LLVM tools bin dir to the path path = os.path.pathsep.join( (config.llvm_tools_dir, config.environment['PATH']) ) config.environment['PATH'] = path # add test root dir to the path (FileCheck might sit there) path = os.path.pathsep.join( (config.test_source_root, config.environment['PATH']) ) config.environment['PATH'] = path # Add substitutions config.substitutions.append( ('%ldc', config.ldc2_bin) ) # Add platform-dependent file extension substitutions if (platform.system() == 'Windows'): config.substitutions.append( ('%obj', '.obj') ) config.substitutions.append( ('%exe', '.exe') ) else: config.substitutions.append( ('%obj', '.o') ) config.substitutions.append( ('%exe', '') ) ldc-0.17.5-src/tests/ir/runlit.py0000755000175000017500000000072313200164641017006 0ustar matthiasmatthias#!/usr/bin/env python # wrapper to run lit from commandline if __name__=='__main__': try: import lit except ImportError: import sys sys.exit('Package lit cannot be imported.\n' \ 'Lit can be installed using: \'python -m pip install lit\'\n' \ '(Python versions older than 2.7.9 or 3.4 do not have pip installed, see:\n' \ 'https://pip.pypa.io/en/latest/installing/)') lit.main() ldc-0.17.5-src/tests/ir/CMakeLists.txt0000644000175000017500000000063713200164641017660 0ustar matthiasmatthiasset( LDC2_BIN ${PROJECT_BINARY_DIR}/bin/${LDC_EXE} ) set( LLVM_TOOLS_DIR ${LLVM_ROOT_DIR}/bin ) set( LDC2_BIN_DIR ${PROJECT_BINARY_DIR}/bin ) set( TESTS_IR_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) configure_file(lit.site.cfg.in lit.site.cfg ) configure_file(runlit.py runlit.py COPYONLY) add_test(NAME llvm-ir-testsuite COMMAND python runlit.py -v . ) ldc-0.17.5-src/tests/ir/atomicrmw.d0000644000175000017500000000146013200164641017262 0ustar matthiasmatthias// RUN: %ldc -c -de -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import core.atomic; void main() { shared ubyte x = 3; ubyte r; r = atomicOp!"+="(x, uint(257)); assert(x == r); // CHECK: = atomicrmw add i8* r = atomicOp!"+="(x, int(-263)); assert(x == r); // CHECK: = atomicrmw add i8* r = atomicOp!"-="(x, ushort(257)); assert(x == r); // CHECK: = atomicrmw sub i8* r = atomicOp!"-="(x, short(-263)); assert(x == r); // CHECK: = atomicrmw sub i8* r = atomicOp!"&="(x, ubyte(255)); assert(x == r); // CHECK: = atomicrmw and i8* r = atomicOp!"|="(x, short(3)); assert(x == r); // CHECK: = atomicrmw or i8* r = atomicOp!"^="(x, int(3)); assert(x == r); // CHECK: = atomicrmw xor i8* r = atomicOp!"+="(x, 1.0f); assert(x == r); // CHECK: = cmpxchg i8* } ldc-0.17.5-src/tests/ir/attr_weak.d0000644000175000017500000000061213200164641017237 0ustar matthiasmatthias// Test linking+running a program with @weak functions // RUN: %ldc -O3 %S/inputs/attr_weak_input.d -c -of=%t%obj // RUN: %ldc -O3 %t%obj -run %s import ldc.attributes; extern(C) int return_two() { return 2; } // Should be overridden by attr_weak_input.d extern(C) @weak int return_seven() { return 1; } void main() { assert( return_two() == 2 ); assert( return_seven() == 7 ); } ldc-0.17.5-src/tests/ir/attributes.d0000644000175000017500000000171313200164641017447 0ustar matthiasmatthias// Tests LDC-specific attributes // RUN: %ldc -O -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll import ldc.attributes; //---- @(section) ----------------------------------------------------- // CHECK-DAG: @{{.*}}mySectionedGlobali ={{.*}} section ".mySection" @(section(".mySection")) int mySectionedGlobal; // CHECK-DAG: define void @{{.*}}sectionedfoo{{.*}} section "funcSection" @(section("funcSection")) void sectionedfoo() {} //--------------------------------------------------------------------- //--------------------------------------------------------------------- //---- @(weak) -------------------------------------------------------- // CHECK-DAG: @{{.*}}myWeakGlobali = weak @(ldc.attributes.weak) int myWeakGlobal; // CHECK-DAG: define{{.*}} weak {{.*}}void @{{.*}}weakFunc @weak void weakFunc() {} //--------------------------------------------------------------------- // CHECK-LABEL: define i32 @_Dmain void main() { sectionedfoo(); } ldc-0.17.5-src/tests/ir/inputs/0000755000175000017500000000000013200164641016434 5ustar matthiasmatthiasldc-0.17.5-src/tests/ir/inputs/attr_weak_input.d0000644000175000017500000000016713200164641022005 0ustar matthiasmatthiasimport ldc.attributes; extern(C) @weak int return_two() { return 1; } extern(C) int return_seven() { return 7; } ldc-0.17.5-src/tests/ir/asm_output.d0000644000175000017500000000047313200164641017463 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s --check-prefix LLVM < %t.ll // RUN: %ldc -c -output-s -of=%t.s %s && FileCheck %s --check-prefix ASM < %t.s int main() { return 42; // Try to keep these very simple checks independent of architecture: // LLVM: ret i32 42 // ASM: {{(\$|#|.long )}}42 } ldc-0.17.5-src/tests/ir/align.d0000644000175000017500000000432713200164641016357 0ustar matthiasmatthias// RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll align(32) struct Outer { int a; } struct Inner { align(32) int a; } static Outer globalOuter; // CHECK: constant %align.Outer_init zeroinitializer{{(, comdat)?}}, align 32 static Inner globalInner; // CHECK: constant %align.Inner_init zeroinitializer{{(, comdat)?}}, align 32 Outer passAndReturnOuterByVal(Outer arg) { return arg; } // CHECK: define void @_D5align23passAndReturnOuterByValFS5align5OuterZS5align5Outer /* no sret align attributes for MSVC targets at the moment */ // C HECK-SAME: %align.Outer* noalias sret align 32 %.sret_arg /* how the arg is passed by value is ABI-specific, but the pointer must be aligned */ // CHECK-SAME: align 32 % Inner passAndReturnInnerByVal(Inner arg) { return arg; } // CHECK: define void @_D5align23passAndReturnInnerByValFS5align5InnerZS5align5Inner // C HECK-SAME: %align.Inner* noalias sret align 32 %.sret_arg // CHECK-SAME: align 32 % void main() { Outer outer; // CHECK: %outer = alloca %align.Outer, align 32 Inner inner; // CHECK: %inner = alloca %align.Inner, align 32 align(16) byte byte16; // CHECK: %byte16 = alloca i8, align 16 align(64) Outer outer64; // CHECK: %outer64 = alloca %align.Outer, align 64 align(128) Inner inner128; // CHECK: %inner128 = alloca %align.Inner, align 128 alias Byte8 = align(8) byte; Byte8 byte8; // Can aliases contain align(x) ? // C HECK: %byte8 = alloca i8, align 8 // C HECK: %byte8 = alloca i8, align 1 align(16) Outer outeroverride; // Yet undecided if align() should override type alignment: // C HECK: %outeroverride = alloca %align.Outer, align 16 // C HECK: %outeroverride = alloca %align.Outer, align 32 // CHECK: %.rettmp = alloca %align.Outer, align 32 // CHECK: %.rettmp1 = alloca %align.Inner, align 32 outer = passAndReturnOuterByVal(outer); // CHECK: call void @_D5align23passAndReturnOuterByValFS5align5OuterZS5align5Outer // C HECK-SAME: %align.Outer* noalias sret align 32 %.rettmp // CHECK-SAME: align 32 % inner = passAndReturnInnerByVal(inner); // CHECK: call void @_D5align23passAndReturnInnerByValFS5align5InnerZS5align5Inner // C HECK-SAME: %align.Inner* noalias sret align 32 %.rettmp1 // CHECK-SAME: align 32 % } ldc-0.17.5-src/tests/d2/0000755000175000017500000000000013200164643015007 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/src/0000755000175000017500000000000013200164641015574 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/src/osmodel.mak0000644000175000017500000000210113200164641017722 0ustar matthiasmatthias# This Makefile snippet detects the OS and the architecture MODEL # Keep this file in sync between druntime, phobos, and dmd repositories! ifeq (,$(OS)) uname_S:=$(shell uname -s) ifeq (Darwin,$(uname_S)) OS:=osx endif ifeq (Linux,$(uname_S)) OS:=linux endif ifeq (FreeBSD,$(uname_S)) OS:=freebsd endif ifeq (OpenBSD,$(uname_S)) OS:=openbsd endif ifeq (Solaris,$(uname_S)) OS:=solaris endif ifeq (SunOS,$(uname_S)) OS:=solaris endif ifeq (,$(OS)) $(error Unrecognized or unsupported OS for uname: $(uname_S)) endif endif # When running make from XCode it may set environment var OS=MACOS. # Adjust it here: ifeq (MACOS,$(OS)) OS:=osx endif ifeq (,$(MODEL)) ifeq ($(OS), solaris) uname_M:=$(shell isainfo -n) else uname_M:=$(shell uname -m) endif ifneq (,$(findstring $(uname_M),x86_64 amd64)) MODEL:=64 endif ifneq (,$(findstring $(uname_M),i386 i586 i686)) MODEL:=32 endif ifeq (,$(MODEL)) $(error Cannot figure 32/64 model from uname -m: $(uname_M)) endif endif MODEL_FLAG:=-m$(MODEL) ldc-0.17.5-src/tests/d2/dmd-testsuite/0000755000175000017500000000000013200164643017602 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/0000755000175000017500000000000013200164642021710 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test12567b.d0000644000175000017500000000016713200164641023606 0ustar matthiasmatthias// REQUIRED_ARGS: // PERMUTE_ARGS: /* TEST_OUTPUT: --- --- */ deprecated("message") module test12567b; void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test62.d0000644000175000017500000000011113200164641023174 0ustar matthiasmatthias// PERMUTE_ARGS: import imports.test62a; struct S { } void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice13071.d0000644000175000017500000000021113200164641023202 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: T foo(T)() { __gshared int[] bar = []; return T.init; } void main() { foo!char(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protattr.d0000644000175000017500000000020713200164641023732 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: import protection.basic.tests; import protection.subpkg.tests; import protection.subpkg2.tests; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testheader2.d0000644000175000017500000000031613200164641024266 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/header2.d // REQUIRED_ARGS: -o- -H -Hf${RESULTS_DIR}/compilable/header2.di // PERMUTE_ARGS: // POST_SCRIPT: compilable/extra-files/header-postscript.sh header2 void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10073.d0000644000175000017500000000046613200164641023434 0ustar matthiasmatthiasstruct Arr(T) { T[] dArr; alias dArr this; bool opEquals(Arr!T d) { foreach (idx, it; d) { if (this[idx] != it) { return false; } } return true; } } class Bar { Arr!Foo fooQ; } class Foo {} // NG ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice11054.d0000644000175000017500000000016413200164641023210 0ustar matthiasmatthiasimport imports.ice11054a; static assert(!__traits(compiles, tuple())); E[] appender(A : E, E)() { return E; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/compile1.d0000644000175000017500000004704013200164641023572 0ustar matthiasmatthias// PERMUTE_ARGS: /************************************************** 1748 class template with stringof **************************************************/ struct S1748(T) {} static assert(S1748!int.stringof == "S1748!int"); class C1748(T) {} static assert(C1748!int.stringof == "C1748!int"); /************************************************** 2438 **************************************************/ alias void delegate() Dg2438; alias typeof(Dg2438.ptr) CP2438a; alias typeof(Dg2438.funcptr) FP2438a; static assert(is(CP2438a == void*)); static assert(is(FP2438a == void function())); alias typeof(Dg2438.init.ptr) CP2438b; alias typeof(Dg2438.init.funcptr) FP2438b; static assert(is(CP2438b == void*)); static assert(is(FP2438b == void function())); /************************************************** 4225 **************************************************/ struct Foo4225 { enum x = Foo4225(); static Foo4225 opCall() { return Foo4225.init; } } /************************************************** 5996 ICE(expression.c) **************************************************/ template T5996(T) { auto bug5996() { if (anyOldGarbage) {} return 2; } } static assert(!is(typeof(T5996!(int).bug5996()))); /************************************************** 8532 segfault(mtype.c) - type inference + pure **************************************************/ auto segfault8532(Y, R ...)(R r, Y val) pure { return segfault8532(r, val); } static assert(!is(typeof( segfault8532(1,2,3)))); /************************************************** 8982 ICE(ctfeexpr.c) __parameters with error in default value **************************************************/ template ice8982(T) { void bug8982(ref const int v = 7){} static if (is(typeof(bug8982) P == __parameters)) { pragma(msg, ((P[0..1] g) => g[0])()); } } static assert(!is(ice8982!(int))); /************************************************** 8801 ICE assigning to __ctfe **************************************************/ static assert(!is(typeof( { bool __ctfe= true; }))); static assert(!is(typeof( { __ctfe |= true; }))); /************************************************** 5932 ICE(s2ir.c) 6675 ICE(glue.c) **************************************************/ void bug3932(T)() { static assert( 0 ); func5932( 7 ); } void func5932(T)( T val ) { void onStandardMsg() { foreach( t; T ) { } } } static assert(!is(typeof( { bug3932!(int)(); }() ))); /************************************************** 6650 ICE(glue.c) or wrong-code **************************************************/ auto bug6650(X)(X y) { X q; q = "abc"; return y; } static assert(!is(typeof(bug6650!(int)(6)))); static assert(!is(typeof(bug6650!(int)(18)))); /************************************************** 6661 Templates instantiated only through is(typeof()) shouldn't cause errors **************************************************/ template bug6661(Q) { int qutz(Q y) { Q q = "abc"; return 67; } static assert(qutz(13).sizeof!=299); const Q blaz = 6; } static assert(!is(typeof(bug6661!(int).blaz))); template bug6661x(Q) { int qutz(Q y) { Q q = "abc"; return 67; } } // should pass, but doesn't in current //static assert(!is(typeof(bug6661x!(int)))); /************************************************** 6599 ICE(constfold.c) or segfault **************************************************/ string bug6599extraTest(string x) { return x ~ "abc"; } template Bug6599(X) { class Orbit { Repository repository = Repository(); } struct Repository { string fileProtocol = "file://"; string blah = bug6599extraTest("abc"); string source = fileProtocol ~ "/usr/local/orbit/repository"; } } static assert(!is(typeof(Bug6599!int))); /************************************************** 8422 TypeTuple of tuples can't be read at compile time **************************************************/ template TypeTuple8422(TList...) { alias TList TypeTuple8422; } struct S8422 { int x; } void test8422() { enum a = S8422(1); enum b = S8422(2); enum c = [1,2,3]; foreach(t; TypeTuple8422!(b, a)) { enum u = t; } foreach(t; TypeTuple8422!(c)) { enum v = t; } } /************************************************** 6096 ICE(el.c) with -O **************************************************/ cdouble c6096; int bug6096() { if (c6096) return 0; return 1; } /************************************************** 7681 Segfault **************************************************/ static assert( !is(typeof( (){ undefined ~= delegate(){}; return 7; }()))); /************************************************** 8639 Buffer overflow **************************************************/ void t8639(alias a)() {} void bug8639() { t8639!({auto r = -real.max;})(); } /************************************************** 7751 Segfault **************************************************/ static assert( !is(typeof( (){ bar[]r; r ~= []; return 7; }()))); /************************************************** 7639 Segfault **************************************************/ static assert( !is(typeof( (){ enum foo = [ str : "functions", ]; }))); /************************************************** 11991 **************************************************/ void main() { int Throwable; int object; try { } catch { } } /************************************************** 11939 **************************************************/ void test11939() { scope(failure) { import object : Object; } throw new Exception(""); } /************************************************** 5796 **************************************************/ template A(B) { pragma(msg, "missing ;") enum X = 0; } static assert(!is(typeof(A!(int)))); /************************************************** 6720 **************************************************/ void bug6720() { } static assert(!is(typeof( cast(bool)bug6720() ))); /************************************************** 1099 **************************************************/ template Mix1099(int a) { alias typeof(this) ThisType; static assert (ThisType.init.tupleof.length == 2); } struct Foo1099 { mixin Mix1099!(0); int foo; mixin Mix1099!(1); int bar; mixin Mix1099!(2); } /************************************************** 8788 - super() and return **************************************************/ class B8788 { this ( ) { } } class C8788(int test) : B8788 { this ( int y ) { // TESTS WHICH SHOULD PASS static if (test == 1) { if (y == 3) { super(); return; } super(); return; } else static if (test == 2) { if (y == 3) { super(); return; } super(); } else static if (test == 3) { if (y > 3) { if (y == 7) { super(); return; } super(); return; } super(); } else static if (test == 4) { if (y > 3) { if (y == 7) { super(); return; } else if (y> 5) super(); else super(); return; } super(); } // TESTS WHICH SHOULD FAIL else static if (test == 5) { if (y == 3) { super(); return; } return; // no super } else static if (test == 6) { if (y > 3) { if (y == 7) { super(); return; } super(); } super(); // two calls } else static if (test == 7) { if (y == 3) { return; // no super } super(); } else static if (test == 8) { if (y > 3) { if (y == 7) { return; // no super } super(); return; } super(); } else static if (test == 9) { if (y > 3) { if (y == 7) { super(); return; } else if (y> 5) super(); else return; // no super return; } super(); } } } static assert( is(typeof( { new C8788!(1)(0); } ))); static assert( is(typeof( { new C8788!(2)(0); } ))); static assert( is(typeof( { new C8788!(3)(0); } ))); static assert( is(typeof( { new C8788!(4)(0); } ))); static assert(!is(typeof( { new C8788!(5)(0); } ))); static assert(!is(typeof( { new C8788!(6)(0); } ))); static assert(!is(typeof( { new C8788!(7)(0); } ))); static assert(!is(typeof( { new C8788!(8)(0); } ))); static assert(!is(typeof( { new C8788!(9)(0); } ))); /************************************************** 4967, 7058 **************************************************/ enum Bug7058 bug7058 = { 1.5f, 2}; static assert(bug7058.z == 99); struct Bug7058 { float x = 0; float y = 0; float z = 99; } /***************************************************/ void test12094() { auto n = null; int *a; int[int] b; int[] c; auto u = true ? null : a; auto v = true ? null : b; auto w = true ? null : c; auto x = true ? n : a; auto y = true ? n : b; auto z = true ? n : c; a = n; b = n; c = n; } /***************************************************/ template test8163(T...) { struct Point { T fields; } enum N = 2; // N>=2 triggers the bug extern Point[N] bar(); void foo() { Point[N] _ = bar(); } } alias test8163!(long) _l; alias test8163!(double) _d; alias test8163!(float, float) _ff; alias test8163!(int, int) _ii; alias test8163!(int, float) _if; alias test8163!(ushort, ushort, ushort, ushort) _SSSS; alias test8163!(ubyte, ubyte, ubyte, ubyte, ubyte, ubyte, ubyte, ubyte) _BBBBBBBB; alias test8163!(ubyte, ubyte, ushort, float) _BBSf; /***************************************************/ // 4757 auto foo4757(T)(T) { static struct Bar(T) { void spam() { foo4757(1); } } return Bar!T(); } void test4757() { foo4757(1); } /***************************************************/ // 9348 void test9348() { @property Object F(int E)() { return null; } assert(F!0 !is null); assert(F!0 !in [new Object():1]); } /***************************************************/ // 9690 @disable { void dep9690() {} void test9690() { dep9690(); // OK void inner() { dep9690(); // OK <- NG } } } /+ LDC_FIXME: See discussion at D-Programming-Language/dmd#2175. /***************************************************/ // 9987 static if (is(object.ModuleInfo == struct)) { struct ModuleInfo {} static assert(!is(object.ModuleInfo == ModuleInfo)); static assert(object.ModuleInfo.sizeof != ModuleInfo.sizeof); } static if (is(object.ModuleInfo == class)) { class ModuleInfo {} static assert(!is(object.ModuleInfo == ModuleInfo)); static assert(__traits(classInstanceSize, object.ModuleInfo) != __traits(classInstanceSize, ModuleInfo)); } +/ /***************************************************/ // 10158 class Outer10158 { static struct Inner { int f; } void test() { static assert( Inner.f .offsetof == 0); // OK <- NG static assert((Inner.f).offsetof == 0); // OK } } void test10158() { static assert(Outer10158.Inner.f.offsetof == 0); // OK } /***************************************************/ // 10326 class C10326 { int val; invariant { assert(val == 0); } invariant() { assert(val == 0); } } /***************************************************/ // 11042 static if ((true || error) == true ) {} else { static assert(0); } static if ((false && error) == false) {} else { static assert(0); } static assert ((true || error) == true ); static assert ((false && error) == false); int f11042a1()() if ((true || error) == true ) { return 0; } enum x11042a1 = f11042a1(); int f11042b1()() if ((false && error) == false) { return 0; } enum x11042b1 = f11042b1(); static if (is(typeof(true || error)) == false) {} else { static assert(0); } static if (is(typeof(false && error)) == false) {} else { static assert(0); } static assert (is(typeof(true || error)) == false); static assert (is(typeof(false && error)) == false); int f11042a2()() if (is(typeof(true || error)) == false) { return 0; } enum x11042a2 = f11042a2(); int f11042b2()() if (is(typeof(false && error)) == false) { return 0; } enum x11042b2 = f11042b2(); static if (__traits(compiles, true || error) == false) {} else { static assert(0); } static if (__traits(compiles, false && error) == false) {} else { static assert(0); } static assert (__traits(compiles, true || error) == false); static assert (__traits(compiles, false && error) == false); int f11042a3()() if (__traits(compiles, true || error) == false) { return 0; } enum x11042a3 = f11042a3(); int f11042b3()() if (__traits(compiles, false && error) == false) { return 0; } enum x11042b3 = f11042b3(); /***************************************************/ // 11554 enum E11554; static assert(is(E11554 == enum)); struct Bro11554(N...) {} static assert(!is(E11554 unused : Bro11554!M, M...)); /***************************************************/ // 12302 template isCallable12302(T...) if (T.length == 1) { static if (is(typeof(& T[0].opCall) == delegate)) enum bool isCallable12302 = true; else static if (is(typeof(& T[0].opCall) V : V*) && is(V == function)) enum bool isCallable12302 = true; else enum bool isCallable12302 = true; } class A12302 { struct X {} X x; auto opDispatch(string s, TArgs...)(TArgs args) { mixin("return x."~s~"(args);"); } } A12302 func12302() { return null; } enum b12302 = isCallable12302!func12302; /***************************************************/ // 12476 template A12476(T) { } struct S12476(T) { alias B = A12476!T; } class C12476(T) { alias B = A12476!T; } struct Bar12476(alias Foo) { Foo!int baz; alias baz this; } alias Identity12476(alias A) = A; alias sb12476 = Identity12476!(Bar12476!S12476.B); alias cb12476 = Identity12476!(Bar12476!C12476.B); static assert(__traits(isSame, sb12476, A12476!int)); static assert(__traits(isSame, cb12476, A12476!int)); /***************************************************/ // 12506 import imports.a12506; private bool[9] r12506a = f12506!(i => true)(); // OK private immutable bool[9] r12506b = f12506!(i => true)(); // OK <- error /***************************************************/ // 12555 class A12555(T) { Undef12555 error; } static assert(!__traits(compiles, { class C : A12555!C { } })); /***************************************************/ // 11622 class A11622(T) { B11622!T foo() { return new B11622!T; } } class B11622(T) : T { } static assert(!__traits(compiles, { class C : A11622!C { } })); /***************************************************/ // 12688 void writeln12688(A...)(A) {} struct S12688 { int foo() @property { return 1; } } void test12688() { S12688 s; s.foo.writeln12688; // ok (s.foo).writeln12688; // ok <- ng } /***************************************************/ // 12703 struct S12703 { this(int) {} } final class C12703 { S12703 s = S12703(1); } /***************************************************/ // 12799 struct A12799 { int a; enum C = A12799.sizeof; enum D = C; // OK <- Error } /***************************************************/ // 13236 pragma(msg, is(typeof({ struct S { S x; } }))); /***************************************************/ // 13280 struct S13280 { alias U = ubyte; alias T1 = ubyte[this.sizeof]; // ok alias T2 = const U[this.sizeof]; // ok alias T3 = const ubyte[this.sizeof]; // ok <- error } /***************************************************/ // 13481 mixin template Mix13481(void function() callback) { static this() { callback(); } } void sort13481() { int[] arr; arr.sort; } mixin Mix13481!(&sort13481); mixin Mix13481!({ int[] arr; arr.sort; }); /***************************************************/ // 13564 class E13564(T) { int pos; } class C13564(T) { struct S { ~this() { C13564!int c; c.element.pos = 0; } } E13564!T element; } void test13564() { auto c = new C13564!int(); } /***************************************************/ // 14166 struct Proxy14166(T) { T* ptr; ref deref() { return *ptr; } alias deref this; } struct Test14166 { auto opIndex() { return this; } auto opIndex(int) { return 1; } } template Elem14166a(R) { alias Elem14166a = typeof(R.init[][0]); } template Elem14166b(R) { alias Elem14166b = typeof(R.init[0]); } void test14166() { alias T = Proxy14166!Test14166; static assert(is(Elem14166a!T == int)); // rejects-valid case static assert(is(Elem14166b!T == int)); // regression case } // other related cases struct S14166 { int x; double y; int[] a; S14166 opUnary(string op : "++")() { return this; } } S14166 s14166; struct X14166 { this(int) { } X14166 opAssign(int) { return this; } } X14166[int] aa14166; X14166[int] makeAA14166() { return aa14166; } struct Tup14166(T...) { T field; alias field this; } Tup14166!(int, int) tup14166; Tup14166!(int, int) makeTup14166() { return tup14166; } pragma(msg, typeof((s14166.x += 1) = 2)); // ok <- error pragma(msg, typeof(s14166.a.length += 2)); // ok <- error pragma(msg, typeof(s14166++)); // ok <- error pragma(msg, typeof(s14166.x ^^ 2)); // ok <- error pragma(msg, typeof(s14166.y ^^= 2.5)); // ok <- error pragma(msg, typeof(makeAA14166()[0] = 1)); // ok <- error pragma(msg, typeof(tup14166.field = makeTup14166())); // ok <- error /***************************************************/ // 14388 @property immutable(T)[] idup14388(T)(T[] a) { alias U = immutable(T); U[] res; foreach (ref e; a) res ~= e; return res; } struct Data14388(A14388 a) { auto foo() { return Data14388!a.init; // [B] } } struct A14388 { struct Item {} immutable(Item)[] items; this(int dummy) { items = [Item()].idup14388; } } void test14388() { auto test = Data14388!(A14388(42)).init.foo(); // [A] /* * A(42) is interpreter to a struct literal A([immutable(Item)()]). * The internal VarDeclaration with STCmanifest for the Data's template parameteter 'a' * calls syntaxCopy() on its ((ExpInitializer *)init)->exp in VarDeclaration::semantic(), * and 'immutable(Item)()'->syntaxCopy() had incorrectly removed the qualifier. * Then, the arguments of two Data template instances at [A] and [B] had become unmatch, * and the second instantiation had created the AST duplication. */ } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test11563.d0000644000175000017500000000023413200164641023432 0ustar matthiasmatthiasimport imports.test11563std_traits; interface J : I {} // comment out to let compilation succeed struct A { } pragma(msg, moduleName!A); interface I {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8038.d0000644000175000017500000000016413200164641023357 0ustar matthiasmatthiastemplate t(T){alias T t;} t!(#line 10 t!( int, ) ) i; t!( t!(#line 10 int, ) ) j; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/vgc3.d0000644000175000017500000000222713200164641022721 0ustar matthiasmatthias// REQUIRED_ARGS: -vgc -o- // PERMUTE_ARGS: /***************** AssignExp *******************/ /* TEST_OUTPUT: --- compilable/vgc3.d(16): vgc: setting 'length' may cause GC allocation compilable/vgc3.d(17): vgc: setting 'length' may cause GC allocation compilable/vgc3.d(18): vgc: setting 'length' may cause GC allocation --- */ void testArrayLength(int[] a) { a.length = 3; a.length += 1; a.length -= 1; } /***************** CallExp *******************/ void barCall(); /* TEST_OUTPUT: --- --- */ void testCall() { auto fp = &barCall; (*fp)(); barCall(); } /****************** Closure ***********************/ @nogc void takeDelegate2(scope int delegate() dg) {} @nogc void takeDelegate3( int delegate() dg) {} /* TEST_OUTPUT: --- compilable/vgc3.d(51): vgc: using closure causes GC allocation compilable/vgc3.d(63): vgc: using closure causes GC allocation --- */ auto testClosure1() { int x; int bar() { return x; } return &bar; } void testClosure2() { int x; int bar() { return x; } takeDelegate2(&bar); // no error } void testClosure3() { int x; int bar() { return x; } takeDelegate3(&bar); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test12567d.d0000644000175000017500000000016013200164641023601 0ustar matthiasmatthias// REQUIRED_ARGS: -d // PERMUTE_ARGS: /* TEST_OUTPUT: --- --- */ import imports.a12567; void main() { foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9278b.d0000644000175000017500000000033213200164641023525 0ustar matthiasmatthias// PREMUTE_ARGS: // Works fine here //struct datum { float num = 0.0; } datum emitOne() { datum t; return t; } const dataArr = [emitOne()]; // A very bad day struct datum { float num = 0.0; } void main(){} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test3673.d0000644000175000017500000000143713200164641023363 0ustar matthiasmatthiasclass Base {} class Foo(T) if (is(T == int)) : Base { } class Bar(T) : Base if (is(T == bool)) { } interface OutputRange(T...) if (T.length == 1) { void put(T[0] value); } interface OutputRange(T...) : OutputRange!(T[0]), OutputRange!(T[1 .. $]) if (T.length > 1) { } alias OutputRange!(int, float) OR; class COR : OR { void put(int) { } void put(float) { } } class A {}; class B(T) : A if (true) {} class C(T) if (false) : A {} alias Foo!int FooInt; alias Bar!bool BarBool; static assert(!__traits(compiles, Foo!bool)); static assert(!__traits(compiles, Bar!int)); void main() { auto fi = new FooInt; auto bb = new BarBool; auto cor = new COR; auto a = new A(); auto b = new B!int(); static assert(!__traits(compiles, new C!int())); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc2.d0000644000175000017500000000137713200164641023057 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 2 /** * Summary * * Description1 * * Description2 * * Description3 * * Macros: * WIKI = StdStream * meemie * See_Also: * Things to see also. * * And more things. */ /* */ module std.test; /// A base class for stream exceptions. class StreamException: Exception { /** Construct a StreamException with given error message msg. * Params: * msg = the $(RED red) $(BLUE blue) $(GREEN green) $(YELLOW yellow). * foo = next parameter which is a much longer * message spanning multiple * lines. */ this(string msg, int foo) { super(msg); } /********** stars ***************/ int stars; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test66.d0000644000175000017500000000024513200164641023210 0ustar matthiasmatthias// PERMUTE_ARGS: import imports.test66a; alias int TOK; enum { TOKmax }; struct Token { static char[] tochars[TOKmax]; } class Lexer { Token token; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection/0000755000175000017500000000000013156012230024071 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection/subpkg2/0000755000175000017500000000000013200164641025452 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection/subpkg2/tests.d0000644000175000017500000000020113200164641026752 0ustar matthiasmatthiasmodule protection.subpkg2.tests; import pkg = protection.subpkg.explicit; static assert (is(typeof(pkg.commonAncestorFoo()))); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection/basic/0000755000175000017500000000000013200164641025156 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection/basic/tests.d0000644000175000017500000000125213200164641026465 0ustar matthiasmatthiasmodule protection.basic.tests; import protection.basic.mod1; static assert ( is(typeof(publicFoo()))); static assert ( is(typeof(packageFoo()))); static assert (!is(typeof(privateFoo()))); static assert ( is(typeof(Test.init.publicFoo()))); static assert (!is(typeof(Test.init.protectedFoo()))); static assert ( is(typeof(Test.init.packageFoo()))); static assert (!is(typeof(Test.init.privateFoo()))); class Deriv : Test { void stub() { static assert ( is(typeof(this.publicFoo()))); static assert ( is(typeof(this.protectedFoo()))); static assert ( is(typeof(this.packageFoo()))); static assert (!is(typeof(this.privateFoo()))); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection/basic/mod1.d0000644000175000017500000000040213200164641026157 0ustar matthiasmatthiasmodule protection.basic.mod1; public void publicFoo() {} package void packageFoo() {} private void privateFoo() {} class Test { public void publicFoo(); protected void protectedFoo(); package void packageFoo(); private void privateFoo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection/subpkg/0000755000175000017500000000000013200164641025370 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection/subpkg/explicit.d0000644000175000017500000000020013200164641027346 0ustar matthiasmatthiasmodule protection.subpkg.explicit; package(protection) void commonAncestorFoo(); package(protection.subpkg) void samePkgFoo(); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection/subpkg/tests.d0000644000175000017500000000060213200164641026675 0ustar matthiasmatthiasmodule protection.subpkg.tests; import crosspkg = protection.basic.mod1; static assert ( is(typeof(crosspkg.publicFoo()))); static assert (!is(typeof(crosspkg.packageFoo()))); static assert (!is(typeof(crosspkg.privateFoo()))); import samepkg = protection.subpkg.explicit; static assert ( is(typeof(samepkg.commonAncestorFoo()))); static assert ( is(typeof(samepkg.samePkgFoo()))); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection/bug/0000755000175000017500000000000013200164641024652 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection/bug/bug14275.d0000644000175000017500000000033113200164641026174 0ustar matthiasmatthiasmodule protection.bug.bug14275; import protection.aggregate.mod14275; // https://issues.dlang.org/show_bug.cgi?id=14275 void main() { Foo f; f.foo(); static assert (!is(typeof(f.foo2()))); bar(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection/aggregate/0000755000175000017500000000000013200164641026023 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection/aggregate/mod14275.d0000644000175000017500000000024213200164641027350 0ustar matthiasmatthiasmodule protection.aggregate.mod14275; public struct Foo { package(protection) void foo() {} package void foo2() {} } package(protection) void bar() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9436.d0000644000175000017500000000014413200164641023360 0ustar matthiasmatthias// REQUIRED_ARGS: -c compilable/imports/test9436interp.d // this is a dummy module for test 9436. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_355.d0000644000175000017500000000025413200164641024555 0ustar matthiasmatthiasstruct S { uint x; } template MakeS(uint x) { const MakeS = S(x); } struct S2 { alias .MakeS MakeS; } void f() { S2 s2; auto n = s2.MakeS!(0); //////////// XXX }ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8543.d0000644000175000017500000000132613200164641023361 0ustar matthiasmatthias version (D_SIMD) { struct vfloat { public: __vector(float[4]) f32; this(float X) nothrow { f32.ptr[0] = X; f32.ptr[1] = X; f32.ptr[2] = X; f32.ptr[3] = X; } this(float X, float Y, float Z, float W) nothrow { f32.array[0] = X; f32.array[1] = Y; f32.array[2] = Z; f32.array[3] = W; } this(float[4] values) nothrow { f32.array = values; } } immutable GvfGlobal_ThreeA = vfloat(3.0f); immutable GvfGlobal_ThreeB = vfloat(3.0f, 3.0f, 3.0f, 3.0f); immutable GvfGlobal_ThreeC = vfloat([3.0f, 3.0f, 3.0f, 3.0f]); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice11596.d0000644000175000017500000000042213200164641023220 0ustar matthiasmatthias// PERMUTE_ARGS: -inline -release -g -O -version=X version(X) alias M = real; else alias M = int[2]; /* or other T[n] with n != 1 */ struct S { M m; } S f() { assert(false); } class C { S[1] ss; /* Here, size doesn't matter. */ this() { ss[] = f(); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice12956.d0000644000175000017500000000115513200164641023225 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: template isCallable(T...) { static if (is(typeof(& T[0].opCall) == delegate)) { enum bool isCallable = true; } else static if (is(typeof(& T[0].opCall) V : V*) && is(V == function)) { enum bool isCallable = true; } else enum bool isCallable = false; } @property auto injectChain(Injectors...)() { return &ChainTemplates!(Injectors); } template ChainTemplates(Templates...) { alias Head = Templates[0]; alias Tail = Templates[1..$]; alias Head!(Tail) ChainTemplates; } static assert(!isCallable!(injectChain)); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test50.d0000644000175000017500000000021513200164641023176 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test50a.d // PERMUTE_ARGS: import imports.test50a; class Bar : Foo { alias typeof(Foo.tupleof) Bleh; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test11980.d0000644000175000017500000000005513200164641023436 0ustar matthiasmatthiasvoid start() {} pragma(startaddress, start); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddocbackticks.d0000644000175000017500000000141713200164641024647 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh backticks /++ Closely related to std.datetime is `core.time`, and some of the time types used in std.datetime come from there - such as $(CXREF time, Duration), $(CXREF time, TickDuration), and $(CXREF time, FracSec). core.time is publically imported into std.datetime, it isn't necessary to import it separately. +/ module ddocbackticks; /// This should produce `inline code`. void test() {} /// But `this should NOT be inline' /// /// However, restarting on a new line should be `inline again`. void test2() {} /// This `int foo;` should show highlight on foo, but not int. void foo() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc10236.d0000644000175000017500000000232013200164641023356 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -w -o- /* TEST_OUTPUT: --- compilable/ddoc10236.d(33): Warning: Ddoc: parameter count mismatch compilable/ddoc10236.d(45): Warning: Ddoc: function declaration has no parameter 'y' compilable/ddoc10236.d(57): Warning: Ddoc: function declaration has no parameter 'y' compilable/ddoc10236.d(57): Warning: Ddoc: parameter count mismatch --- */ /*********************************** * foo_good does this. * Params: * x = is for this * and not for that * y = is for that */ void foo_good(int x, int y) { } /*********************************** * foo_count_mismatch does this. * Params: * x = is for this * and not for that */ void foo_count_mismatch(int x, int y) // Warning: Ddoc: parameter count mismatch { } /*********************************** * foo_no_param_y does this. * Params: * x = is for this * and not for that * y = is for that */ void foo_no_param_y(int x, int z) // Warning: Ddoc: function declaration has no parameter 'y' { } /*********************************** * foo_count_mismatch_no_param_y does this. * Params: * x = is for this * and not for that * y = is for that */ void foo_count_mismatch_no_param_y(int x) { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/diag10768.d0000644000175000017500000000117313200164641023370 0ustar matthiasmatthias// PERMUTE_ARGS: /* TEST_OUTPUT: --- compilable/diag10768.d(36): Deprecation: implicitly overriding base class method diag10768.Frop.frop with diag10768.Foo.frop deprecated; add 'override' attribute --- */ struct CirBuff(T) { import std.traits: isArray; CirBuff!T opAssign(R)(R) if (isArray!R) {} T[] toArray() { T[] ret; // = new T[this.length]; return ret; } alias toArray this; } class Bar(T=int) { CirBuff!T _bar; } class Once { Bar!Foo _foobar; } class Foo : Frop { // override public int frop() { return 1; } } class Frop { public int frop() { return 0; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test4090.d0000644000175000017500000002453713200164641023363 0ustar matthiasmatthiasvoid test4090a() { // for the mutable elements { int[] arr = [1,2,3]; // inference + qualifier foreach ( x; arr) static assert(is(typeof(x) == int)); foreach ( const x; arr) static assert(is(typeof(x) == const int)); foreach (immutable x; arr) static assert(is(typeof(x) == immutable int)); // inference + qualifier + ref foreach ( ref x; arr) static assert(is(typeof(x) == int)); foreach ( const ref x; arr) static assert(is(typeof(x) == const int)); static assert(!__traits(compiles, { foreach (immutable ref x; arr) {} })); // with exact type + qualifier foreach ( int x; arr) static assert(is(typeof(x) == int)); foreach ( const int x; arr) static assert(is(typeof(x) == const int)); foreach (immutable int x; arr) static assert(is(typeof(x) == immutable int)); // with exact type + qualifier + ref foreach ( ref int x; arr) static assert(is(typeof(x) == int)); foreach ( const ref int x; arr) static assert(is(typeof(x) == const int)); static assert(!__traits(compiles, { foreach (immutable ref int x; arr) {} })); // convertible type + qualifier foreach ( double x; arr) static assert(is(typeof(x) == double)); foreach ( const double x; arr) static assert(is(typeof(x) == const double)); foreach (immutable double x; arr) static assert(is(typeof(x) == immutable double)); // convertible type + qualifier + ref static assert(!__traits(compiles, { foreach ( ref double x; arr) {} })); static assert(!__traits(compiles, { foreach ( const ref double x; arr) {} })); static assert(!__traits(compiles, { foreach (immutable ref double x; arr) {} })); } // for the immutable elements { immutable(int)[] iarr = [1,2,3]; // inference + qualifier foreach ( x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach ( const x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach (immutable x; iarr) static assert(is(typeof(x) == immutable int)); // inference + qualifier + ref foreach ( ref x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach ( const ref x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach (immutable ref x; iarr) static assert(is(typeof(x) == immutable int)); // with exact type + qualifier foreach ( int x; iarr) static assert(is(typeof(x) == int)); foreach ( const int x; iarr) static assert(is(typeof(x) == const int)); foreach (immutable int x; iarr) static assert(is(typeof(x) == immutable int)); // with exact type + qualifier + ref static assert(!__traits(compiles, { foreach ( ref int x; iarr) {} })); foreach ( const ref int x; iarr) static assert(is(typeof(x) == const int)); foreach (immutable ref int x; iarr) static assert(is(typeof(x) == immutable int)); // convertible type + qualifier foreach ( double x; iarr) static assert(is(typeof(x) == double)); foreach ( const double x; iarr) static assert(is(typeof(x) == const double)); foreach (immutable double x; iarr) static assert(is(typeof(x) == immutable double)); // convertible type + qualifier + ref static assert(!__traits(compiles, { foreach (ref double x; iarr) {} })); static assert(!__traits(compiles, { foreach (const ref double x; iarr) {} })); static assert(!__traits(compiles, { foreach (immutable ref double x; iarr) {} })); } } void test4090b() { // for the key { int[] arr = [1,2,3]; // inference + qualifier foreach ( i, x; arr) static assert(is(typeof(i) == size_t)); foreach ( const i, x; arr) static assert(is(typeof(i) == const size_t)); foreach (immutable i, x; arr) static assert(is(typeof(i) == immutable size_t)); // inference + qualifier + ref foreach ( ref i, x; arr) static assert(is(typeof(i) == size_t)); foreach ( const ref i, x; arr) static assert(is(typeof(i) == const size_t)); static assert(!__traits(compiles, { foreach (immutable ref i, x; arr) {} })); // with exact type + qualifier foreach ( size_t i, x; arr) static assert(is(typeof(i) == size_t)); foreach ( const size_t i, x; arr) static assert(is(typeof(i) == const size_t)); foreach (immutable size_t i, x; arr) static assert(is(typeof(i) == immutable size_t)); // with exact type + qualifier + ref foreach ( ref size_t i, x; arr) static assert(is(typeof(i) == size_t)); foreach ( const ref size_t i, x; arr) static assert(is(typeof(i) == const size_t)); static assert(!__traits(compiles, { foreach (immutable ref size_t i, x; arr) {} })); } // for the mutable elements { int[] arr = [1,2,3]; // inference + qualifier foreach (i, x; arr) static assert(is(typeof(x) == int)); foreach (i, const x; arr) static assert(is(typeof(x) == const int)); foreach (i, immutable x; arr) static assert(is(typeof(x) == immutable int)); // inference + qualifier + ref foreach (i, ref x; arr) static assert(is(typeof(x) == int)); foreach (i, const ref x; arr) static assert(is(typeof(x) == const int)); static assert(!__traits(compiles, { foreach (i, immutable ref x; arr) {} })); // with exact type + qualifier foreach (i, int x; arr) static assert(is(typeof(x) == int)); foreach (i, const int x; arr) static assert(is(typeof(x) == const int)); foreach (i, immutable int x; arr) static assert(is(typeof(x) == immutable int)); // with exact type + qualifier + ref foreach (i, ref int x; arr) static assert(is(typeof(x) == int)); foreach (i, const ref int x; arr) static assert(is(typeof(x) == const int)); static assert(!__traits(compiles, { foreach (i, immutable ref int x; arr) {} })); // convertible type + qualifier foreach (i, double x; arr) static assert(is(typeof(x) == double)); foreach (i, const double x; arr) static assert(is(typeof(x) == const double)); foreach (i, immutable double x; arr) static assert(is(typeof(x) == immutable double)); // convertible type + qualifier + ref static assert(!__traits(compiles, { foreach (i, ref double x; arr) {} })); static assert(!__traits(compiles, { foreach (i, const ref double x; arr) {} })); static assert(!__traits(compiles, { foreach (i, immutable ref double x; arr) {} })); } // for the immutable elements { immutable(int)[] iarr = [1,2,3]; // inference + qualifier foreach (i, x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach (i, const x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach (i, immutable x; iarr) static assert(is(typeof(x) == immutable int)); // inference + qualifier + ref foreach (i, ref x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach (i, const ref x; iarr) static assert(is(typeof(x) == immutable int)); // same as variable declaration foreach (i, immutable ref x; iarr) static assert(is(typeof(x) == immutable int)); // with exact type + qualifier foreach (i, int x; iarr) static assert(is(typeof(x) == int)); foreach (i, const int x; iarr) static assert(is(typeof(x) == const int)); foreach (i, immutable int x; iarr) static assert(is(typeof(x) == immutable int)); // with exact type + qualifier + ref static assert(!__traits(compiles, { foreach (i, ref int x; iarr) {} })); foreach (i, const ref int x; iarr) static assert(is(typeof(x) == const int)); foreach (i, immutable ref int x; iarr) static assert(is(typeof(x) == immutable int)); // convertible type + qualifier foreach (i , double x; iarr) static assert(is(typeof(x) == double)); foreach (i, const double x; iarr) static assert(is(typeof(x) == const double)); foreach (i, immutable double x; iarr) static assert(is(typeof(x) == immutable double)); // convertible type + qualifier + ref static assert(!__traits(compiles, { foreach (i, ref double x; iarr) {} })); static assert(!__traits(compiles, { foreach (i, const ref double x; iarr) {} })); static assert(!__traits(compiles, { foreach (i, immutable ref double x; iarr) {} })); } } void test4090c() { foreach ( x; 1..11) static assert(is(typeof(x) == int)); foreach ( const x; 1..11) static assert(is(typeof(x) == const int)); foreach (immutable x; 1..11) static assert(is(typeof(x) == immutable int)); foreach ( int x; 1..11) static assert(is(typeof(x) == int)); foreach ( const int x; 1..11) static assert(is(typeof(x) == const int)); foreach (immutable int x; 1..11) static assert(is(typeof(x) == immutable int)); foreach ( ref x; 1..11) static assert(is(typeof(x) == int)); foreach ( const ref x; 1..11) static assert(is(typeof(x) == const int)); static assert(!__traits(compiles, { foreach (immutable ref x; 1..11) {} })); foreach ( double x; 1..11) static assert(is(typeof(x) == double)); foreach ( const double x; 1..11) static assert(is(typeof(x) == const double)); foreach (immutable double x; 1..11) static assert(is(typeof(x) == immutable double)); foreach ( ref double x; 1..11) static assert(is(typeof(x) == double)); foreach ( const ref double x; 1..11) static assert(is(typeof(x) == const double)); static assert(!__traits(compiles, { foreach (immutable ref double x; 1..11) {} })); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/nogc.d0000644000175000017500000000461113200164641023004 0ustar matthiasmatthias// REQUIRED_ARGS: -o- /***************** Covariance ******************/ class C1 { void foo() @nogc; void bar(); } class D1 : C1 { override void foo(); // no error override void bar() @nogc; // no error } /******************************************/ // __traits(compiles) static assert(__traits(compiles, new Object())); void foo_compiles() {} @nogc void test_compiles() { auto fp = &foo_compiles; static assert(!__traits(compiles, foo_compiles())); static assert(!__traits(compiles, fp())); static assert(!__traits(compiles, (*fp)())); static assert(!__traits(compiles, [1,2,3])); static assert(!__traits(compiles, [1:1, 2:2])); struct Struct {} static assert(!__traits(compiles, new int)); static assert(!__traits(compiles, new Struct())); static assert(!__traits(compiles, new Object())); int* p; static assert(!__traits(compiles, delete p)); int[int] aa; static assert(!__traits(compiles, aa[0])); int[] a; static assert(!__traits(compiles, a.length = 1)); static assert(!__traits(compiles, a.length += 1)); static assert(!__traits(compiles, a.length -= 1)); static assert(!__traits(compiles, a ~= 1)); static assert(!__traits(compiles, a ~ a)); } /******************************************/ // 12630 void test12630() @nogc { // All of these declarations should cause no errors. static const ex1 = new Exception("invalid"); //enum ex2 = new Exception("invalid"); static const arr1 = [[1,2], [3, 4]]; enum arr2 = [[1,2], [3, 4]]; //static const aa1 = [1:1, 2:2]; enum aa2 = [1:1, 2:2]; //static const v1 = aa1[1]; enum v2 = aa2[1]; Object o; static const del1 = (delete o).sizeof; enum del2 = (delete o).sizeof; int[] a; static const len1 = (a.length = 1).sizeof; enum len2 = (a.length = 1).sizeof; static const cata1 = (a ~= 1).sizeof; enum cata2 = (a ~= 1).sizeof; static const cat1 = (a ~ a).sizeof; enum cat2 = (a ~ a).sizeof; } /******************************************/ // 12642 static if (is(__vector(ulong[2]))) { import core.simd; ulong2 test12642() @nogc { return [0, 0]; } } /******************************************/ // 13550 auto foo13550() @nogc { static int[] bar() { return new int[2]; } return &bar; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test14962.d0000644000175000017500000000131013200164641023434 0ustar matthiasmatthiastemplate map(fun...) { auto map(R)(R r) { return MapResult!(fun, R)(r); } } struct MapResult(alias fun, R) { R _input; @property bool empty() { return _input.length == 0; } @property auto front() { return fun(_input[0]); } void popFront() { _input = _input[1..$]; } } struct Foo { int baz(int v) { static int id; return v + id++; } void bar() { auto arr1 = [1, 2, 3]; auto arr2 = [4, 5, 6]; arr1.map!( // lambda1 i => arr2.map!( // lambda2 j => baz(i + j) ) ); } } void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9526.d0000644000175000017500000000074013200164641023362 0ustar matthiasmatthiastemplate forward(args...) { @property fwd()() { return args[0]; } static assert(__traits(compiles, { auto ex = fwd; })); alias fwd forward; } void initializeClassInstance(C, Args...)(C chunk, auto ref Args args) { chunk.__ctor(forward!args); } void main() { static int si = 0; static class C { this(int) { ++si; } } void[__traits(classInstanceSize, C)] buff = void; auto c = cast(C) buff.ptr; initializeClassInstance(c, 0); assert(si); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice10431b.d0000644000175000017500000000013513200164641023346 0ustar matthiasmatthiasstruct X(alias Y) { } struct A { int[] data; } alias X!(A([])) X1; alias X!(A([])) X2; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/99bottles.d0000644000175000017500000000337413200164641023721 0ustar matthiasmatthias// written by Don Clugston: // http://www.digitalmars.com/d/archives/digitalmars/D/announce/4374.html // http://www.99-bottles-of-beer.net/language-d-1212.html // Displays the "99 bottles of beer" song at compile time, // using the template metaprograming facilities of D. // No executable is generated. No libraries are used. // Illustrates template default values, template string value parameters, // compile-time concatenation of constant strings, static if. module bottles99; template decimaldigit(int n) { const string decimaldigit = "0123456789"[n..n+1]; } template itoa(ulong n) { static if ( n < 10L ) const string itoa = decimaldigit!(n); else const string itoa = itoa!( n / 10L ) ~ decimaldigit!( n % 10L ); } template showHowMany(int n, string where, bool needcapital = false) { static if ( n > 1 ) const string showHowMany = itoa!(n) ~ " bottles of beer" ~ where ~ "\n"; else static if ( n == 1 ) const string showHowMany = "1 bottle of beer" ~ where ~ "\n"; else static if ( needcapital ) const string showHowMany = "No more bottles of beer" ~ where ~ "\n"; else const string showHowMany = "no more bottles of beer" ~ where ~ "\n"; } template beer(int maxbeers, int n = maxbeers) { static if ( n > 0 ) const string beer = showHowMany!(n, " on the wall,", true) ~ showHowMany!(n, ".") ~ "Take one down and pass it around, " ~ "\n" ~ showHowMany!( n - 1 , " on the wall.") ~ "\n" ~ beer!(maxbeers, n - 1); // recurse for subsequent verses. else const string beer = showHowMany!(n, " on the wall,", true) ~ showHowMany!(n, ".") ~ "Go to the store and buy some more, " ~ "\n" ~ showHowMany!( maxbeers, " on the wall."); } pragma(msg, beer!(99)); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test12009.d0000644000175000017500000000072313200164641023431 0ustar matthiasmatthiasstruct RefCounted(T) { struct RefCountedStore { private struct Impl { T _payload; } private Impl* _store; } RefCountedStore _refCounted; ~this() { import core.stdc.stdlib : free; } } struct GroupBy(R) { struct SharedInput { Group unused; } struct Group { private RefCounted!SharedInput _allGroups; } } void main() { GroupBy!(int[]) g1; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test6013.d0000644000175000017500000000060213200164641023343 0ustar matthiasmatthiasimport imports.test6013; static assert(__traits(compiles, public_alias_value)); static assert(!__traits(compiles, private_alias_value)); static assert(__traits(compiles, public_alias_func())); static assert(!__traits(compiles, private_alias_func())); static assert(__traits(compiles, () { public_alias_type val; })); static assert(!__traits(compiles, () { private_alias_type val; })); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9497a.d0000644000175000017500000000037413200164641023467 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/ddoc9497a.ddoc // PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9497a /** foo function. Args: $(XYZ arg1, arg2) */ void foo() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddocYear.d0000644000175000017500000000023413200164641023605 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocYear-postscript.sh /// $(YEAR) int year; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/derivedarray.d0000644000175000017500000000774113200164641024546 0ustar matthiasmatthias// PERMUTE_ARGS: class C {} class D : C {} void dynamicarrays() { C[] a; D[] b; const(C)[] c; const(D)[] d; immutable(C)[] e; immutable(D)[] f; static assert( __traits(compiles, a = a)); static assert(!__traits(compiles, a = b)); static assert(!__traits(compiles, a = c)); static assert(!__traits(compiles, a = d)); static assert(!__traits(compiles, a = e)); static assert(!__traits(compiles, a = f)); static assert(!__traits(compiles, b = a)); static assert( __traits(compiles, b = b)); static assert(!__traits(compiles, b = c)); static assert(!__traits(compiles, b = d)); static assert(!__traits(compiles, b = e)); static assert(!__traits(compiles, b = f)); static assert( __traits(compiles, c = a)); static assert( __traits(compiles, c = b)); static assert( __traits(compiles, c = c)); static assert( __traits(compiles, c = d)); static assert( __traits(compiles, c = e)); static assert( __traits(compiles, c = f)); static assert(!__traits(compiles, d = a)); static assert( __traits(compiles, d = b)); static assert(!__traits(compiles, d = c)); static assert( __traits(compiles, d = d)); static assert(!__traits(compiles, d = e)); static assert( __traits(compiles, d = f)); static assert(!__traits(compiles, e = a)); static assert(!__traits(compiles, e = b)); static assert(!__traits(compiles, e = c)); static assert(!__traits(compiles, e = d)); static assert( __traits(compiles, e = e)); static assert( __traits(compiles, e = f)); static assert(!__traits(compiles, f = a)); static assert(!__traits(compiles, f = b)); static assert(!__traits(compiles, f = c)); static assert(!__traits(compiles, f = d)); static assert(!__traits(compiles, f = e)); static assert( __traits(compiles, f = f)); } void statictodynamicarrays() { C[] a; D[] b; const(C)[] c; const(D)[] d; immutable(C)[] e; immutable(D)[] f; C[1] sa; D[1] sb; const(C)[1] sc = void; const(D)[1] sd = void; immutable(C)[1] se = void; immutable(D)[1] sf = void; static assert( __traits(compiles, a = sa)); static assert(!__traits(compiles, a = sb)); static assert(!__traits(compiles, a = sc)); static assert(!__traits(compiles, a = sd)); static assert(!__traits(compiles, a = se)); static assert(!__traits(compiles, a = sf)); static assert(!__traits(compiles, b = sa)); static assert( __traits(compiles, b = sb)); static assert(!__traits(compiles, b = sc)); static assert(!__traits(compiles, b = sd)); static assert(!__traits(compiles, b = se)); static assert(!__traits(compiles, b = sf)); static assert( __traits(compiles, c = sa)); static assert( __traits(compiles, c = sb)); static assert( __traits(compiles, c = sc)); static assert( __traits(compiles, c = sd)); static assert( __traits(compiles, c = se)); static assert( __traits(compiles, c = sf)); static assert(!__traits(compiles, d = sa)); static assert( __traits(compiles, d = sb)); static assert(!__traits(compiles, d = sc)); static assert( __traits(compiles, d = sd)); static assert(!__traits(compiles, d = se)); static assert( __traits(compiles, d = sf)); static assert(!__traits(compiles, e = sa)); static assert(!__traits(compiles, e = sb)); static assert(!__traits(compiles, e = sc)); static assert(!__traits(compiles, e = sd)); static assert( __traits(compiles, e = se)); static assert( __traits(compiles, e = sf)); static assert(!__traits(compiles, f = sa)); static assert(!__traits(compiles, f = sb)); static assert(!__traits(compiles, f = sc)); static assert(!__traits(compiles, f = sd)); static assert(!__traits(compiles, f = se)); static assert( __traits(compiles, f = sf)); } void staticarrays() { C[1] sa; D[1] sb; const(C)[1] sc = sa; const(D)[1] sd = sb; sa = sb; static assert(!__traits(compiles, sb = sa)); } void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice9663.d0000644000175000017500000000015613200164641023146 0ustar matthiasmatthias// REQUIRED_ARGS: -wi void main() { int[1] a; int[] b = [1]; a = 1; b[] = a; b = a; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8041.d0000644000175000017500000000030213200164641023343 0ustar matthiasmatthias// PERMUTE_ARGS: struct Foo { } void main() { static Foo sf; // ok __gshared Foo gf; // was: Error: non-constant expression gf = 0 __gshared int[1][1] arr; // dup: Issue 6089 } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test6999.d0000644000175000017500000000043513200164641023376 0ustar matthiasmatthias// 6999: inout in front of return type struct A { inout: inout(int) foo() { return 0; } } struct B { inout { inout(int) foo() { return 0; } } } struct C { inout inout(int) foo() { return 0; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9369.d0000644000175000017500000000002313200164641023361 0ustar matthiasmatthiasDdoc --- a=1; --- ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8513.d0000644000175000017500000000121113200164641023347 0ustar matthiasmatthiasinterface I_Foo { void i_outer(); } class C_Foo { void c_outer() { } } class Bar { interface I_Foo { void i_inner(); } class C_Foo { void c_inner() { } } class Impl1 : C_Foo, I_Foo { override void i_inner() { } override void c_inner() { } } class Impl2 : C_Foo, .I_Foo { override void i_outer() { } override void c_inner() { } } class Impl3 : .C_Foo, I_Foo { override void i_inner() { } override void c_outer() { } } class Impl4 : .C_Foo, .I_Foo { override void i_outer() { } override void c_outer() { } } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9680.sh0000755000175000017500000000140113200164641023550 0ustar matthiasmatthias#!/usr/bin/env bash name=`basename $0 .sh` dir=${RESULTS_DIR}/compilable if [ "${OS}" == "win32" -o "${OS}" == "Windows_NT" ]; then kinds=( main winmain dllmain ) else kinds=( main ) fi for kind in "${kinds[@]}" do file_name=${name}${kind} src_file=compilable/extra-files/${file_name}.d expect_file=compilable/extra-files/${file_name}.out output_file=${dir}/${file_name}.out rm -f ${output_file}{,.2} $DMD -m${MODEL} -v -o- ${src_file} > ${output_file} grep "^entry ${kind}" ${output_file} > ${output_file}.2 if [ `wc -c ${output_file}.2 | while read a b; do echo $a; done` -eq 0 ]; then echo "Error: not found expected entry point '${kind}' in ${src_file}" exit 1; fi rm ${output_file}{,.2} done echo Success >${dir}/`basename $0`.out ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc7656.d0000644000175000017500000000062413200164641023317 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 7656 module ddoc7656; /** -------- int x; // This is a $ comment (and here is some int y; // more information about that comment) -------- */ void main() { } /** (Regression check) Example: ---- assert(add(1, 1) == 2); ---- */ int add(int a, int b) { return a + b; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test6089.d0000644000175000017500000000007413200164641023363 0ustar matthiasmatthias// PERMUTE_ARGS: void main() { extern int[1][1] foo; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test1878a.d0000644000175000017500000000040313200164641023521 0ustar matthiasmatthiasvoid main() { ubyte from, to; foreach(i; from..to) { static assert(is(typeof(i) == ubyte)); } foreach(i; 'a'..'l') { static assert(is(typeof(i) == char)); } foreach(i; '×' .. 'ת') { static assert(is(typeof(i) == wchar)); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/deprecate12979a.d0000644000175000017500000000036513200164641024571 0ustar matthiasmatthias// REQUIRED_ARGS: -dw // PERMUTE_ARGS: /* TEST_OUTPUT: --- compilable/deprecate12979a.d(13): Deprecation: asm statement is assumed to throw - mark it with 'nothrow' if it does not --- */ void foo() nothrow { asm { ret; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice14075.d0000644000175000017500000000040613200164641023215 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: struct Foo { auto opAssign(this X)(ref typeof(this)); auto opAssign(this X, V)(ref V) if (!is(V == typeof(this))); } void test() { Foo src; const(Foo) target; static if (is(typeof(target = src))) {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc10366.d0000644000175000017500000000047513200164641023373 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 10366 /// struct S(T) { /// void method() {} public { /// struct Nested { /// void nestedMethod() {} } } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9672.d0000644000175000017500000000016013200164641023360 0ustar matthiasmatthiasmodule test9672; // node import imports.test9672a; // interpret mixin template ForwardCtor() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc6.d0000644000175000017500000000054713200164641023061 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 6 /** * */ struct MyStruct(T) { static if( true ) { void MyStruct() {} } } void main() { } /+ 23 C:\code\d\bugs>dmd -D -o- 148_1.d 148_1.d(6): Error: static if conditional cannot be at global scope +/ ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testcov1.d0000644000175000017500000000021713200164641023624 0ustar matthiasmatthias// EXTRA_SOURCES: imports/testcov1a.d imports/testcov1b.d // PERMUTE_ARGS: // REQUIRED_ARGS: -cov import core.stdc.string; import testcov1a; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc4899.d0000644000175000017500000000102113200164641023315 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -w -o- /* TEST_OUTPUT: --- compilable/ddoc4899.d(16): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses. compilable/ddoc4899.d(16): Warning: Ddoc: Stray ')'. This may cause incorrect Ddoc output. Use $(RPAREN) instead for unpaired right parentheses. --- */ /++ (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +/ module d; void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9434.d0000644000175000017500000000031113200164641023352 0ustar matthiasmatthiasimport test9435;//semantic; template Visitors() { mixin Semantic!(typeof(this)); } class Node { mixin Visitors; } class Expression : Node { } class BinaryExp(TokenType op) : Expression { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test4375.d0000644000175000017500000001642613200164641023367 0ustar matthiasmatthias// 4375: disallow dangling else void main() { if (true) { if (false) { assert(1); } else { assert(2); } } if (true) { if (false) assert(7); } else assert(8); if (true) { if (false) assert(9); else assert(10); } { if (true) assert(11); else assert(12); } { label1: if (true) assert(13); else assert(14); } if (true) foreach (i; 0 .. 5) { if (true) assert(17); else assert(18); } if (true) { foreach (i; 0 .. 5) if (true) assert(18.1); } else assert(18.2); if (true) assert(19); else assert(20); if (true) assert(21); else if (false) assert(22); else assert(23); version (A) { if (true) assert(26); } else assert(27); version (A) { if (true) assert(28); else assert(29); } version (A) assert(30); else version (B) assert(31); else assert(32); static if (true) { static if (true) assert(35); } else assert(36); static if (true) { static if (true) assert(37); else assert(38); } static if (true) assert(39); else static if (true) assert(40); else assert(41); switch (4) { case 0: if (true) assert(42); else assert(43); break; case 1: .. case 5: if (true) assert(44); else assert(45); break; default: if (true) assert(46); else assert(47); break; } // (o_O) switch (1) default: if (true) assert(113); else assert(114); // (o_O) final switch (1) case 1: if (true) assert(117); else assert(118); mixin(q{ if (true) assert(56); else assert(57); }); while (false) if (true) assert(66); else assert(67); if (true) while (false) assert(68); else assert(69); do if (true) assert(72); else assert(73); while (false); if (true) do if (true) assert(74); else assert(75); while (false); for ( if (true) // (o_O) assert(78); else assert(79); false; false ) if (true) assert(80); else assert(81); if (true) for (if (true) assert(84); else assert(85); false;) assert(86); if (true) if (true) if (true) if (true) if (true) assert(87); auto x = new C; if (true) while (false) for (;;) scope (exit) synchronized (x) assert(88); else assert(89); if (true) while (false) for (;;) { scope (exit) synchronized (x) if (true) assert(90); else assert(89); } if (true) while (false) for (;;) scope (exit) synchronized (x) if (true) assert(90); else assert(89); else assert(12); with (x) if (false) assert(92); else assert(93); try if (true) assert(94); else assert(95); catch (Exception e) if (true) assert(96); else assert(97); finally if (true) assert(98); else assert(99); if (true) try if (true) assert(100); else assert(101); finally assert(102); if (true) try assert(109); catch(Exception e) if (true) assert(110); else assert(112); finally assert(111); static struct F { static if (true) int x; else int y; static if (true) { static if (false) int z; } else int w; static if (true) int t; else static if (false) int u; else int v; } if (true) if (true) assert(113); else assert(114); else assert(115); static if (true) static if (true) assert(116); else assert(117); else assert(118); } unittest { if (true) assert(50); else assert(51); } class C { invariant() { if (true) assert(58); else assert(59); } int f() in { if (true) assert(60); else assert(61); } out(res) { if (true) assert(62); else assert(63); } body { if (true) assert(64); else assert(65); return 0; } } enum q = q{ if(true) if(true) assert(54.1); else assert(55.2); }; static if (true) struct F0 {} else static if (true) struct F1 {} else struct F2 {} static if (true) { static if (false) struct F3 {} } else struct F4 {} version(A) { version(B) struct F5 {} } else struct F6 {} version(A) { version(B) struct F5a {} else struct F5b {} } version (C) struct F5c {} else struct F5d {} struct F7 { static if (true) int x; else float x; private: static if (true) int y; else float y; } template F8() { static if (true) int x; else float x; } static if (true) align(1) static if (false) struct F9 {} static if (true) align(1) { extern(C) pure static if (false) void F10(){} else void F11(){} } void f() { int[] x; static if (5 > 0) version (Y) scope (failure) foreach (i, e; x) while (i > 20) with (e) if (e < 0) synchronized(e) assert(1); else assert(2); else x = null; else x = null; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10056.d0000644000175000017500000000242713200164641023434 0ustar matthiasmatthiasvoid main() { alias Zoo = Foo10056!(false, false, 1); } struct Foo10056(bool S, bool L, size_t N) { string bar() { Appender10056!(string) w; char[] buf; put10056(w, buf); return ""; } public bool opEquals(T)(T other) //const //If you add const, also fails to compile with 2.062. { alias Foo10056!(typeof(this), T, "CMP") P; return false; } } template Foo10056(T, U, string OP) { static if (T.ISEMPTY && U.ISEMPTY) enum bool S = false; else enum bool S = false; alias Foo10056 = Foo10056!(false, false, 0); } /**********************************************/ void put10056(R, E)(ref R r, E e) { static if (is(typeof(r.put(e)))) { r.put(e); } else { static assert(false, "Cannot put a "~E.stringof~" into a "~R.stringof); } } struct Appender10056(A : T[], T) { private template canPutItem(U) { enum bool canPutItem = is(U : T); } private template canPutRange(R) { enum bool canPutRange = is(typeof(Appender10056.init.put(R.init[0]))); } void put(U)(U item) if (canPutItem!U) { char[T.sizeof == 1 ? 4 : 2] encoded; put(encoded[]); } void put(R)(R items) if (canPutRange!R) { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc8739.d0000644000175000017500000000045113200164641023320 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 8739 module ddoc8739; /// void delegate(int a) dg; /// void delegate(int b) dg2; /// void delegate(int c)[] dg3; /// void delegate(int d)* dg4; void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8631.d0000644000175000017500000000043013200164641023352 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -de class B { int foo() immutable { return 2; } int foo() const { return 2; } } class D : B { override int foo() immutable { return 2; } int foo() const shared { return 2; } override int foo() const { return 2; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice1524.d0000644000175000017500000000106213200164641023127 0ustar matthiasmatthias// Issue 1524 - ICE(constfold.c) on using "is" with strings in CTFE /* 1524 PATCH Assertion failure: '0' on line 863 in file 'constfold.c' constfold.c @@ -845,9 +845,9 @@ Loc loc = e1->loc; int cmp; - if (e1->op == TOKnull && e2->op == TOKnull) + if (e1->op == TOKnull || e2->op == TOKnull) { - cmp = 1; + cmp = (e1->op == TOKnull && e2->op == TOKnull) ? 1 : 0; } else if (e1->op == TOKsymoff && e2->op == TOKsymoff) { */ bool isNull(string str) { return str is null; } const bool test = isNull("hello!"); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/depmsg.d0000644000175000017500000000104313200164641023331 0ustar matthiasmatthias// REQUIRED_ARGS: -d // PERMUTE_ARGS: -dw void main() { class Inner { deprecated("With message!") { struct A { } class B { } interface C { } union D { } enum E { e }; //typedef int F; alias int G; static int H; template I() { class I {} } } } with(Inner) { A a; B b; C c; D d; E e; //F f; G g; auto h = H; I!() i; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10375.d0000644000175000017500000000035613200164641023437 0ustar matthiasmatthias// REQUIRED_ARGS: -o- import imports.test10375a; void packIt(Pack)(Pack p){ } //3 void main() { alias p = packIt!(int); p(2); // OK <- NG packIt(2); // OK <- NG packIt!(int)(2); // OK <- NG } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/bug6963.d0000644000175000017500000000312213200164641023157 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: /* TEST_OUTPUT: --- output foo: 1e: pure nothrow @nogc @safe void(int x) output foo: 3e: pure nothrow @nogc @safe void(int x) --- */ alias void function(int) pure nothrow @safe @nogc FuncPtrType; void foo1a(X)(X x) {} void foo1b(X)(X x) {} void foo1c(X)(X x) {} void foo1d(X)(X x) {} void foo1e(X)(X x) {} // module level declaration with type inference auto fptr1 = &foo1a!int; static assert(is(typeof(fptr1) == FuncPtrType)); // array initializer auto fptrlist1 = [&foo1b!int]; static assert(is(typeof(fptrlist1) == FuncPtrType[])); // static assert static assert(is(typeof(&foo1c!int) == FuncPtrType)); // static if static if(is(typeof(&foo1d!int) PF)) static assert(is(PF == FuncPtrType)); else static assert(0); // pragma test pragma(msg, "output foo: 1e: ", typeof(foo1e!int).stringof); void foo2a(X)(X x) {} void foo2b(X)(X x) {} void foo2c(X)(X x) {} FuncPtrType fptr3 = &foo2a!int; // most similar to original issue FuncPtrType[] fptrlist3 = [&foo2b!int]; struct S{ FuncPtrType fp; } S s = { &foo2c!int }; void foo3a(X)(X x) {} void foo3b(X)(X x) {} void foo3c(X)(X x) {} void foo3d(X)(X x) {} void foo3e(X)(X x) {} void main() { auto fptr2 = &foo3a!int; static assert(is(typeof(fptr2) == FuncPtrType)); auto fptrlist2 = [&foo3b!int]; static assert(is(typeof(fptrlist2) == FuncPtrType[])); static assert(is(typeof(&foo1c!int) == FuncPtrType)); static if(is(typeof(&foo1d!int) PF)) static assert(is(PF == FuncPtrType)); else static assert(0); pragma(msg, "output foo: 3e: ", typeof(foo3e!int)); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test12979b.d0000644000175000017500000000121413200164641023607 0ustar matthiasmatthias// REQUIRED_ARGS: -w -de void foo() pure nothrow @nogc @safe { asm pure nothrow @nogc @trusted { ret; } } void bar()() { asm pure nothrow @nogc @trusted { ret; } } static assert(__traits(compiles, () pure nothrow @nogc @safe => bar())); void baz()() { asm { ret; } } // wait for deprecation of asm pure inference // static assert(!__traits(compiles, () pure => baz())); static assert(!__traits(compiles, () nothrow => baz())); // wait for deprecation of asm @nogc inference // static assert(!__traits(compiles, () @nogc => baz())); static assert(!__traits(compiles, () @safe => baz())); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/sw_transition_field.d0000644000175000017500000000113113200164641026116 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -c -transition=field /* TEST_OUTPUT: --- compilable/sw_transition_field.d(15): sw_transition_field.S1.ix is immutable field compilable/sw_transition_field.d(16): sw_transition_field.S1.cx is const field compilable/sw_transition_field.d(21): sw_transition_field.S2!(immutable(int)).S2.f is immutable field compilable/sw_transition_field.d(21): sw_transition_field.S2!(const(int)).S2.f is const field --- */ struct S1 { immutable int ix = 1; const int cx = 2; } struct S2(F) { F f = F.init; } alias S2!(immutable int) S2I; alias S2!( const int) S2C; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice11906.d0000644000175000017500000000034513200164641023217 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: nothrow /*extern(Windows) */export int GetModuleHandleA(const char* lpModuleName); void main() { /*extern(Windows) */int function(const char*) f; assert(f != &GetModuleHandleA); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice12002.d0000644000175000017500000000070713200164641023205 0ustar matthiasmatthias// REQUIRED_ARGS: -inline // PERMUTE_ARGS: void doFormat(void delegate(dchar) putc, TypeInfo[] arguments) { void formatArg(char fc) { const(char)* prefix = ""; void putstr(const char[] s) { //if (flags & FL0pad) { while (*prefix) putc(*prefix++); } foreach (dchar c; s) putc(c); } putstr(null); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test7754.d0000644000175000017500000000033113200164641023357 0ustar matthiasmatthias// REQUIRED_ARGS: -H -Hd${RESULTS_DIR}/compilable // POST_SCRIPT: compilable/extra-files/test7754-postscript.sh // PERMUTE_ARGS: -d -dw struct Foo(T) { shared static this() { } static this() { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8717.d0000644000175000017500000000340413200164641023363 0ustar matthiasmatthiasmodule test8717; struct SPR { private: enum e = 1; immutable int ii = 1; immutable static int sii = 1; static int sf() { return 1; } int f() const { return 1; } } static assert(SPR.e == 1); //static assert(SPR.ii == 1); static assert(SPR.sii == 1); static assert(SPR.sf() == 1); static assert(SPR.init.e == 1); static assert(SPR.init.ii == 1); static assert(SPR.init.sii == 1); static assert(SPR.sf() == 1); static assert(SPR.init.f() == 1); static if(SPR.e != 1) { static assert(0); } //static if(SPR.ii != 1) { static assert(0); } static if(SPR.sii != 1) { static assert(0); } static if(SPR.sf() != 1) { static assert(0); } static if(SPR.init.e != 1) { static assert(0); } static if(SPR.init.ii != 1) { static assert(0); } static if(SPR.init.sii != 1) { static assert(0); } static if(SPR.sf() != 1) { static assert(0); } static if(SPR.init.f() != 1) { static assert(0); } struct SPT { protected: enum e = 1; immutable int ii = 1; immutable static int sii = 1; static int sf() { return 1; } int f() const { return 1; } } static assert(SPT.e == 1); //static assert(SPT.ii == 1); static assert(SPT.sii == 1); static assert(SPT.sf() == 1); static assert(SPT.init.e == 1); static assert(SPT.init.ii == 1); static assert(SPT.init.sii == 1); static assert(SPT.sf() == 1); static assert(SPT.init.f() == 1); static if(SPT.e != 1) { static assert(0); } //static if(SPT.ii != 1) { static assert(0); } static if(SPT.sii != 1) { static assert(0); } static if(SPT.sf() != 1) { static assert(0); } static if(SPT.init.e != 1) { static assert(0); } static if(SPT.init.ii != 1) { static assert(0); } static if(SPT.init.sii != 1) { static assert(0); } static if(SPT.sf() != 1) { static assert(0); } static if(SPT.init.f() != 1) { static assert(0); } void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/const.d0000644000175000017500000000212213200164641023177 0ustar matthiasmatthias static assert(2.0 * 3.0 == 6 ); static assert(2.0 * 3.0i == 6i); static assert(2.0i * 3.0 == 6i); static assert(2.0i * 3.0i == -6 ); static assert(2.0 * (4.0 + 3.0i) == 8 + 6i); static assert(2.0i * (4.0 + 3.0i) == 8i - 6 ); static assert((4.0 + 3.0i) * 2.0 == 8 + 6i); static assert((4.0 + 3.0i) * 2.0i == 8i - 6 ); static assert((4.0 + 3.0i) * (5 + 7i) == -1 + 43i ); static assert((2.0).re == 2); static assert((2.0i).re == 0); static assert((3+2.0i).re == 3); static assert((4.0i).im == 4); static assert((2.0i).im == 2); static assert((3+2.0i).im == 2); static assert(6.0 / 2.0 == 3); static assert(6i / 2i == 3); static assert(6 / 2i == -3i); static assert(6i / 2 == 3i); static assert((6 + 4i) / 2 == 3 + 2i); static assert((6 + 4i) / 2i == -3i + 2); //static assert(2 / (6 + 4i) == -3i); //static assert(2i / (6 + 4i) == 3i); //static assert((1 + 2i) / (6 + 4i) == 3i); static assert(6.0 % 2.0 == 0); static assert(6.0 % 3.0 == 0); static assert(6.0 % 4.0 == 2); static assert(6.0i % 2.0i == 0); static assert(6.0i % 3.0i == 0); static assert(6.0i % 4.0i == 2i); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testDIP37a.d0000644000175000017500000000030313200164641023677 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -c -Icompilable/extra-files // EXTRA_SOURCES: extra-files/pkgDIP37/datetime/package.d // EXTRA_SOURCES: extra-files/pkgDIP37/datetime/common.d void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8296.d0000644000175000017500000000041113200164641023360 0ustar matthiasmatthiasstruct bar2 { int i; @disable this(); this(int i) { this.i = i; } } class InnerBar { bar2 b; this() { b = bar2(0); } } struct bar1 { InnerBar b; } class Foo { bar1 m_bar1; } void main(string[] args) { auto foo = new Foo(); }ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testDIP42.d0000644000175000017500000000503413200164641023540 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: // enum ident(tpl) = Initializer; enum isIntegral(T) = is(T == int) || is(T == long); static assert( isIntegral!int); static assert( isIntegral!long); static assert(!isIntegral!double); static assert(!isIntegral!(int[])); version(none) { enum allSatisfy(alias pred, TL...) = TL.length == 0 || (pred!(TL[0]) && allSatisfy!(pred, TL[1..$])), anySatisfy(alias pred, TL...) = TL.length != 0 && (pred!(TL[0]) || anySatisfy!(pred, TL[1..$])) || false; static assert( allSatisfy!(isIntegral, int, long)); static assert(!allSatisfy!(isIntegral, int, double)); static assert( anySatisfy!(isIntegral, int, double)); static assert(!anySatisfy!(isIntegral, int[], double)); } void test1() { // statement enum isIntegral2(T) = is(T == int) || is(T == long); static assert(isIntegral2!int); } /******************************************/ // alias ident(tpl) = Type; alias TypeTuple(TL...) = TL; static assert(is(TypeTuple!(int, long)[0] == int)); static assert(is(TypeTuple!(int, long)[1] == long)); alias Id(T) = T, Id(alias A) = A; static assert(is(Id!int == int)); static assert(__traits(isSame, Id!TypeTuple, TypeTuple)); void test2() { // statement alias TypeTuple2(TL...) = TL; static assert(is(TypeTuple2!(int, long)[0] == int)); static assert(is(TypeTuple2!(int, long)[1] == long)); alias IdT(T) = T, IdA(alias A) = A; static assert(is(IdT!int == int)); static assert(__traits(isSame, IdA!TypeTuple, TypeTuple)); } /******************************************/ // template auto declaration auto tynameLen(T) = T.stringof.length; void test3() { assert(tynameLen!int == 3); assert(tynameLen!long == 4); tynameLen!int = 4; tynameLen!long = 5; assert(tynameLen!int == 4); assert(tynameLen!long == 5); // statement auto tynameLen2(T) = T.stringof.length; assert(tynameLen2!int == 3); assert(tynameLen2!long == 4); tynameLen2!int = 4; tynameLen2!long = 5; assert(tynameLen2!int == 4); assert(tynameLen2!long == 5); } /******************************************/ // template variable declaration static T math_pi(T) = cast(T)3.1415; enum bool isFloatingPoint(T) = is(T == float) || is(T == double); static assert( isFloatingPoint!double); static assert(!isFloatingPoint!string); void main() { assert(math_pi!int == 3); assert(math_pi!double == 3.1415); enum bool isFloatingPoint2(T) = is(T == float) || is(T == double); static assert( isFloatingPoint2!double); static assert(!isFloatingPoint2!string); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10992b.d0000644000175000017500000000032613200164641023603 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -unittest version(none) {} else { unittest { } unittest { } unittest { } } void main() { static assert(__traits(getUnitTests, mixin(__MODULE__)).length == 3); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testimport12242.d0000644000175000017500000000141213200164641024657 0ustar matthiasmatthias// PERMUTE_ARGS: module testimport12242; import imports.imp12242a; // test // stripA == OverloadSet import imports.imp12242a1; // std.string // stripA == template import imports.imp12242b1; // std.string // stripB == template import imports.imp12242b; // test // stripB == OverloadSet void main() { static assert(stripA(" af ") == 1); static assert(" af ".stripA() == 1); // UFCS (1) static assert(" af ".stripA == 1); // UFCS (2) static assert(stripB(" af ") == 1); static assert(" af ".stripB() == 1); // UFCS (1) static assert(" af ".stripB == 1); // UFCS (2) static assert(foo!int == 1); static assert(foo!long == 2); static assert(foo!float == 3); static assert(foo!real == 4); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test11237.d0000644000175000017500000000016113200164641023427 0ustar matthiasmatthias// PERMUTE_ARGS: // POST_SCRIPT: compilable/extra-files/test11237.sh struct Buffer { ubyte[64 * 1024] buffer; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc3.d0000644000175000017500000000261713200164641023056 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/ddoc3.ddoc // PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 3 /** * Summary * * Description1 * * Description2 * * Description3 * * Macros: * WIKI = StdStream * meemie * ARG0 = $0 * ARG1 = $1 * ARG2 = $2 * ARG3 = $3 * PLUS = $+ * TROW = $(TR $(TCOL $1,$+)) * TCOL = $(TD $1) $(TCOL $+) * LPAREN = ( * See_Also: * Things to see also. * * And more things $(BR) * 'arg1, arg2, arg3' : $(ARG0 arg1, arg2, arg3). $(BR) * 'arg2, arg3' : $(PLUS arg1, arg2, arg3). $(BR) * 'arg1' : $(ARG1 arg1, arg2, arg3). $(BR) * 'arg2' : $(ARG2 arg1, arg2, arg3). $(BR) * 'arg3' : $(ARG3 arg1, arg2, arg3). $(BR) */ /** * Things to see also $(HELLO). * * $(TABLE * $(TROW 1, 2, 3) * $(TROW 4, 5, 6) * ) * * $(D_CODE $(B pragma)( $(I name) ); $(B pragma)( $(I name) , $(I option) [ $(I option) ] ); $(U $(LPAREN)) ) */ /* */ module std.test; /// A base class for stream exceptions. class StreamException: Exception { /** Construct a StreamException with given error message msg. * Params: * msg = the $(RED red) $(BLUE blue) $(GREEN green) $(YELLOW yellow). * foo = next parameter which is a much longer * message spanning multiple * lines. */ this(string msg, int foo) { super(msg); } /********** stars ***************/ int stars; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc4162.d0000644000175000017500000000036113200164641023302 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 4162 /// interface A { /// static void staticHello() { } /// final void hello() { } } void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test6395.d0000644000175000017500000000013013200164641023354 0ustar matthiasmatthias// REQUIRED_ARGS: -c compilable/b6395 -Icompilable/extra-files // 6395 import c6395; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test6056a.d0000644000175000017500000000013513200164641023514 0ustar matthiasmatthiasalias const(typeof('c')*) A; alias const(typeof(0)*) B; static assert(is(B == const(int*))); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc5.d0000644000175000017500000000061613200164641023055 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 5 /** Test module */ module test; /// class to test DDOC on members class TestMembers(TemplateArg) { public: /** a static method Params: idx = index */ static void PublicStaticMethod(int idx) { } } void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_454.d0000644000175000017500000000012013200164641024545 0ustar matthiasmatthiasimport std.file; void main() { auto a = dirEntries("","",SpanMode.depth); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc648.d0000644000175000017500000000251213200164641023227 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 648 module ddoc648; /// Mixin declaration mixin template Mixin1() { /// struct S struct S { } } /// class A class A { /// field x int x; /// no docs for mixin statement (only for expanded members) mixin Mixin1!(); } /// class AB class AB { /// field x int x; // no docs for mixin or its contents, must be a ddoc comment mixin Mixin1!(); } /// Mixin declaration2 mixin template Mixin2() { /// struct S2 struct S2 { } } /// Mixin declaration3 mixin template Mixin3() { /// another field int f; /// no docs for mixin statement (only for expanded members) mixin Mixin2!(); } /// class B1 class B1 { /// no docs for mixin statement (only for expanded members) mixin Mixin3!(); } /// Mixin declaration3 mixin template Mixin4() { /// another field int f; // no docs at all for non-ddoc comment mixin Mixin2!(); } /// class B2 class B2 { /// no docs for mixin statement (only for expanded members) mixin Mixin4!(); } /// no docs for mixin statement (only for expanded members) mixin Mixin3!(); /// struct TS(T) { mixin template MT() { } mixin MT; /// avoid calling semantic /// int field; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testfwdref.d0000644000175000017500000002032313200164641024231 0ustar matthiasmatthias// PERMUTE_ARGS: /***************************************************/ // 6766 class Foo6766 { this(int x) { } void test(Foo6766 foo = new Foo6766(1)) { } } struct Bar6766 { this(int x) { } void test(Bar6766 bar = Bar6766(1)) { } } /***************************************************/ // 8609 struct Tuple8609(T) { T arg; } // ---- struct Foo8609a { Bar8609a b; } struct Bar8609a { int x; Tuple8609!(Foo8609a) spam() { return Tuple8609!(Foo8609a)(); } } // ---- struct Foo8609b { Bar8609b b; } struct Bar8609b { int x; Tuple8609!(Foo8609b[1]) spam() { return Tuple8609!(Foo8609b[1])(); } } /***************************************************/ // 8698 interface IRoot8698a {} interface IClass8698a : IRoot8698a { } struct Struct8698a { } class Class8698a : IClass8698a { alias Struct8698a Value; } void test8698a(Class8698a.Value) { } //interface IRoot8698a {} // ---- //interface IRoot8698b {} interface IClass8698b : IRoot8698b { } struct Struct8698b { } class Class8698b : IClass8698b { alias Struct8698b Value; } void test8698b(Class8698b.Value) { } interface IRoot8698b {} /***************************************************/ // 9514 template TStructHelpers9514a() { void opEquals(Foo9514a) { auto n = FieldNames9514a!(); } } struct Foo9514a { mixin TStructHelpers9514a!(); } import imports.fwdref9514 : find9514; // selective import without aliasing template FieldNames9514a() { static if (find9514!`true`([1])) enum int FieldNames9514a = 1; } // ---- template TStructHelpers9514b() { void opEquals(Foo9514b) { auto n = FieldNames9514b!(); } } struct Foo9514b { mixin TStructHelpers9514b!(); } import imports.fwdref9514 : foo9514 = find9514; // selective import with aliasing template FieldNames9514b() { static if (foo9514!`true`([1])) enum int FieldNames9514b = 1; } /***************************************************/ // 10015 struct S10015(T) { alias X = int; } alias Y10015 = s10015.X; S10015!int s10015; /***************************************************/ // 10101 int front10101(int); mixin template reflectRange10101() { static if (is(typeof(this.front10101))) { int x; } } struct S10101(R) { R r_; typeof(r_.front10101) front10101() @property { return r_.front10101; } mixin reflectRange10101; } void test10101() { S10101!(int) s; } /***************************************************/ // 11019 class A11019 { A11019 View() { return null; } } class B11019 : A11019 { override D11019 View() { return null; } } class D11019 : B11019 {} /***************************************************/ // 11166 template Tup11166(T...) { alias Tup11166 = T; } struct S11166a { enum S11166a a = S11166a(0); enum S11166a b = S11166a(1); this(long value) { } long value; // only triggered when private and a template instance. private alias types = Tup11166!(a, b); } struct S11166b { enum S11166b a = S11166b(0); enum S11166b b = S11166b(1); // not at the last of members alias types = Tup11166!(a, b); this(long value) { } long value; } /***************************************************/ // 12152 class A12152 { alias Y = B12152.X; } class B12152 : A12152 { alias int X; } static assert(is(A12152.Y == int)); /***************************************************/ // 12201 template T12201() { alias imports.fwdref12201a.FILE* FP; } struct S12201a { mixin T12201; import imports.fwdref12201a; } union U12201 { mixin T12201; import imports.fwdref12201a; } class C12201 { mixin T12201; import imports.fwdref12201a; } interface I12201 { mixin T12201; import imports.fwdref12201a; } template TI12201() { mixin T12201; import imports.fwdref12201a; } mixin template TM12201() { mixin T12201; import imports.fwdref12201a; } struct S12201b { alias ti = TI12201!(); mixin TM12201; } /***************************************************/ // 12531 struct Node12531(T) { T _val; } void test12531() { static struct Foo { Node12531!Foo* node; } } /***************************************************/ // 12543 class C12543; static assert(C12543.sizeof == (void*).sizeof); static assert(C12543.alignof == (void*).sizeof); static assert(C12543.mangleof == "C10testfwdref6C12543"); /***************************************************/ // 14010 enum E14010; static assert(E14010.mangleof == "E10testfwdref6E14010"); struct S14010; static assert(S14010.mangleof == "S10testfwdref6S14010"); /***************************************************/ // 12983 alias I12983 = int; class B12983(T) { alias MyC = C12983!string; } class C12983(T) : B12983!float { void m() { f12983(0); } } alias MyB12983 = B12983!float; void f12983(); void f12983(I12983); /***************************************************/ // 12984 class B12984a { alias MyD = D12984a!int; } class C12984a : B12984a { } class D12984a(T) { alias MyE = E12984a!float; } class E12984a(T) : D12984a!int { void m() { auto c = new C12984a(); } } static assert(__traits(classInstanceSize, B12984a) == (void*).sizeof * 2); static assert(__traits(classInstanceSize, C12984a) == (void*).sizeof * 2); // ---- class B12984b { int b; alias MyD = D12984b!int; } class C12984b : B12984b { int c; } class D12984b(T) { int d; alias MyE = E12984b!float; } class E12984b(T) : D12984b!int { int e; void m() { auto c = new C12984b(); } } static assert(__traits(classInstanceSize, B12984b) == (void*).sizeof * 2 + int.sizeof); static assert(__traits(classInstanceSize, C12984b) == (void*).sizeof * 2 + int.sizeof * 2); /***************************************************/ // 14390 class B14390a { alias MyD = D14390a!int; } class C14390a : B14390a { void f(int) {} } class D14390a(T) { alias MyE = E14390a!float; } class E14390a(T) : D14390a!int { void m() { auto c = new C14390a(); } } class B14390b { alias MyD = D14390b!int; } class C14390b : B14390b { static struct S {} } class D14390b(T) { alias MyE = E14390b!float; } class E14390b(T) : D14390b!int { void m() { auto c = new C14390b(); } } /***************************************************/ // 13860 /* TEST_OUTPUT: --- pure nothrow @nogc @safe void() pure nothrow @nogc @safe void() --- */ struct Foo13860(Bar...) { Bar bars; auto baz(size_t d)() {} pragma(msg, typeof(baz!0)); } auto bar13860(S, R)(S s, R r) { pragma(msg, typeof(Foo13860!().baz!0)); } void test13860() { int[] x; int[] y; x.bar13860(y); } /***************************************************/ // 14083 class NBase14083 { int foo(NA14083 a) { return 1; } int foo(NB14083 a) { return 2; } } class NA14083 : NBase14083 { int v; this(int v) { this.v = v; } } class NB14083 : NBase14083 { override int foo(NA14083 a) { return a.v; } } class TBase14083(T) { int foo(TA14083!T a) { return 1; } int foo(TB14083!T a) { return 2; } } class TA14083(T) : TBase14083!T { T v; this(T v) { this.v = v; } } class TB14083(T) : TBase14083!T { override int foo(TA14083!T a) { return a.v; } } static assert( { NA14083 na = new NA14083(10); NB14083 nb = new NB14083(); assert(na.foo(na) == 1); assert(na.foo(nb) == 2); assert(nb.foo(na) == 10); TA14083!int ta = new TA14083!int(10); TB14083!int tb = new TB14083!int(); assert(ta.foo(ta) == 1); assert(ta.foo(tb) == 2); assert(tb.foo(ta) == 10); return true; }()); /***************************************************/ // 14549 string foo14549(T)() { static if (T.tupleof.length >= 0) return ""; } class Frop14549 { mixin(foo14549!(typeof(this))); static if (__traits(compiles, undefined)) { } else { int bar = 0; } static if (!__traits(isVirtualMethod, this.bar)) {} } // ---- // regression case template Mix14549() { mixin(code14549!(typeof(this))); } template code14549(T) { enum string code14549 = q{ static if (!__traits(isVirtualMethod, "boo")) {} }; } class Bar14549 { mixin Mix14549; int boo; } // ---- // 14609 - regression case interface Foo14609(T) { static if (is(T == int)) public int bar(); } class Frop14609 : Foo14609!int { public int bar() { return 0; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9155.d0000644000175000017500000000250113200164641023307 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9155 module ddoc9155; /++ + Note: + test document note + 2nd line + Example: + --- + import std.stdio; //& + writeln("Hello world!"); + if (test) { + writefln("D programming language"); + } + + algorithm; + + xxx; //comment + yyy; + /* test + * comment + */ + + // Create MIME Base64 with CRLF, per line 76. +File f = File("./text.txt", "r"); +uint line = 0; + // The ElementType of data is not aggregation type +foreach (encoded; Base64.encoder(data)) + --- +/ /** -------------------------------------------------------- wstring ws; transcode("hello world",ws); // transcode from UTF-8 to UTF-16 -------------------------------------------------------- */ /** * Example: * --- * import std.stdio; //& * writeln("Hello world!"); * if (test) { * writefln("D programming language"); * } * * algorithm; * * xxx; //comment * yyy; * /+ test * + comment * +/ * --- */ /** ---- #!/usr/bin/env rdmd // Computes average line length for standard input. import std.stdio; ---- */ /** --- writefln(q"EOS This is a multi-line heredoc string EOS" ); --- */ void foo(){} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_257.d0000644000175000017500000000017313200164641024556 0ustar matthiasmatthiasclass Baz { this(Bar[] a) {} } class Foo { Bar[] foo(){ return []; } } class Bar { Foo bar(){ return null; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testDIP37_10354.d0000644000175000017500000000033313200164641024275 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -o- -Icompilable/extra-files module testDIP37_10354; import pkgDIP37_10354.mfoo; void main() { import pkgDIP37_10354; foo!string(); // OK bar!string(); // OK <- ICE } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test13858.d0000644000175000017500000000032013200164641023437 0ustar matthiasmatthias// REQUIRED_ARGS: -w // 13858 void foo() { assert(0); } void main() { int x = 0; LSwitch: switch (x) { case 0: break LSwitch; default: return; } foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_256.d0000644000175000017500000000010513200164641024550 0ustar matthiasmatthiasbool foo(void delegate() a, void delegate() b) { return a < b; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test11137.d0000644000175000017500000000011213200164641023422 0ustar matthiasmatthias// REQUIRED_ARGS: -ofC:\test.exeC:\test.exe module test; void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test55.d0000644000175000017500000000040713200164641023206 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test55a.d // PERMUTE_ARGS: -dw // REQUIRED_ARGS: -d public import imports.test55a; class Queue { alias int ListHead; Arm a; } class MessageQueue : Queue { } class Queue2 { alias int ListHead; Arm2 a; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test1673.d0000644000175000017500000000251213200164641023354 0ustar matthiasmatthiasmodule test1673; template Foo(T...) { } template Bar(T...) { template Doo(T...) { } } template Tuple(T...) { alias Tuple = T; } void main() { static assert( __traits(isTemplate, Foo)); static assert(!__traits(isTemplate, Foo!int)); static assert(!__traits(isTemplate, main)); static assert( __traits(isTemplate, Bar)); static assert(!__traits(isTemplate, Bar!int)); static assert( __traits(isTemplate, Bar!(int).Doo)); static assert(!__traits(isTemplate, Bar!(int).Doo!int)); alias Tup = Tuple!(Foo, Foo!int, Bar, Bar!int, Bar!(int).Doo, Bar!(int).Doo!int); static assert( __traits(isTemplate, Tup[0])); static assert(!__traits(isTemplate, Tup[1])); static assert( __traits(isTemplate, Tup[2])); static assert(!__traits(isTemplate, Tup[3])); static assert( __traits(isTemplate, Tup[4])); static assert(!__traits(isTemplate, Tup[5])); } /// test overloads void foo_over() { } void foo_over(T : int)(T) { } void foo_over(T : float)(T) { } static assert(__traits(isTemplate, foo_over)); /// ditto void bar_over() { } void bar_over(int) { } static assert(!__traits(isTemplate, bar_over)); /// alias to overloads alias a_foo_over = foo_over; static assert(__traits(isTemplate, a_foo_over)); /// ditto alias a_bar_over = bar_over; static assert(!__traits(isTemplate, a_bar_over)); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc198.d0000644000175000017500000000071513200164641023232 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/ddoc198.ddoc // PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 198 module ddoc198; /// interface I1 { } /// class C1 { } /// class Foo : C1, I1 { } /// enum X { x = 1 } /// enum Y : X { y = X.x } /// struct S1 { } /// enum enS : S1 { a = S1() } // disabled until class enums are possible // enum enC : C1 { a = new C1() } void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9435.d0000644000175000017500000000033313200164641023357 0ustar matthiasmatthiasimport test9434;//expression; enum TokenType { Dot } template Tok(string type) { enum Tok = TokenType.Dot; } template Semantic(T) { invariant(){} } template Semantic(T) if (is(T == BinaryExp!(Tok!"."))) { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test7172.d0000644000175000017500000000150013200164641023350 0ustar matthiasmatthiasvoid main() { abstract class AbstractC{} static assert(!__traits(compiles, { new AbstractC(); })); final class FinalC{} static assert(!__traits(compiles, { class D : FinalC{} })); scope class ScopeC{} static assert(!__traits(compiles, { auto sc = new ScopeC(); })); static assert( __traits(compiles, { scope sc = new ScopeC(); })); synchronized class SyncC{ void f(){} } static assert(SyncC.f.mangleof[$-13..$] == "5SyncC1fMOFZv"); @safe class SCx{ void f(){} } @trusted class SCy{ void f(){} } @system class SCz{ void f(){} } static assert(SCx.f.mangleof[$-12..$] == "3SCx1fMFNfZv"); // Nf: FuncAttrSafe static assert(SCy.f.mangleof[$-12..$] == "3SCy1fMFNeZv"); // Ne: FuncAttrTrusted static assert(SCz.f.mangleof[$-10..$] == "3SCz1fMFZv"); // (none) } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test13194.d0000644000175000017500000000023613200164641023436 0ustar matthiasmatthiasmodule test13194; class C13194 { static Object o = void; } struct S13194 { static Object o = void; } union U13194 { static Object o = void; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc7715.d0000644000175000017500000000040413200164641023307 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 7715 module ddoc7656; /** $1 $2 --- string s = "$1$2 $ $4"; --- */ void foo(){} /// void test(string a = ")") {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testDIP37_10302.d0000644000175000017500000000033313200164641024266 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -c -Icompilable/extra-files // EXTRA_SOURCES: extra-files/pkgDIP37_10302/liba.d // EXTRA_SOURCES: extra-files/pkgDIP37_10302/libb.d module test; import pkgDIP37_10302; void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8922f.d0000644000175000017500000000056413200164641023533 0ustar matthiasmatthias// PERMUTE_ARGS: void test() { import renamed = imports.bug8922; enum x = __traits(parent, renamed).stringof; static assert(x == "package imports"); static assert(!__traits(compiles, __traits(parent, imports))); static assert(!__traits(compiles, __traits(parent, bug8922))); static assert(!__traits(compiles, __traits(parent, imports.bug8922))); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/a3682.d0000644000175000017500000000051513200164641022620 0ustar matthiasmatthias// EXTRA_SOURCES: imports/b3682.d // PERMUTE_ARGS: // 3682 struct Tuple(Types...) { Tuple!(Types[0..1]) slice()() { Tuple!(Types[0..1]) x; return x; } void fail() { Tuple!(float, double, int) a; auto s = a.slice(); static assert(is(typeof(s) == Tuple!(float))); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test6319.d0000644000175000017500000000016413200164641023357 0ustar matthiasmatthias// REQUIRED_ARGS: -debug int x; void main() pure { debug { { x = 0; } } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test11225a.d0000644000175000017500000000011413200164641023563 0ustar matthiasmatthias/* TEST_OUTPUT: --- WORKS --- */ import imports.test11225b; interface I {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testlibmain.d0000644000175000017500000000007013200164641024364 0ustar matthiasmatthias// REQUIRED_ARGS: -lib // PERMUTE_ARGS: void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9305.d0000644000175000017500000000444713200164641023317 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9305 module ddoc9305; /** foo() */ void foo(alias p = (a => a))() {} /* ret / prm / body */ /* _ / _ / expr */ template X(alias pred = x => x) {} /// /* _ / _ / stmt */ template X(alias pred = (x){ int y; return y; }) {} /// ditto /* _ / x / expr */ template X(alias pred = (int x) => x) {} /// ditto /* _ / x / stmt */ template X(alias pred = (int x){ int y; return y; }) {} /// ditto /* x / _ / expr */ /* x / _ / stmt */ /* x / x / expr */ /* x / x / stmt */ /* _ / _ / expr */ template X(alias pred = function (x) => x) {} /// /* _ / _ / stmt */ template X(alias pred = function (x){ return x + 1; }) {} /// ditto /* _ / x / expr */ template X(alias pred = function (int x) => x) {} /// ditto /* _ / x / stmt */ template X(alias pred = function (int x){ return x + 1; }) {} /// ditto /* x / _ / expr */ template X(alias pred = function int(x) => x) {} /// ditto /* x / _ / stmt */ template X(alias pred = function int(x){ return x + 1; }) {} /// ditto /* x / x / expr */ template X(alias pred = function int(int x) => x) {} /// ditto /* x / x / stmt */ template X(alias pred = function int(int x){ return x + 1; }) {} /// ditto /* _ / _ / expr */ template X(alias pred = delegate (x) => x) {} /// /* _ / _ / stmt */ template X(alias pred = delegate (x){ return x + 1; }) {} /// ditto /* _ / x / expr */ template X(alias pred = delegate (int x) => x) {} /// ditto /* _ / x / stmt */ template X(alias pred = delegate (int x){ return x + 1; }) {} /// ditto /* x / _ / expr */ template X(alias pred = delegate int(x) => x) {} /// ditto /* x / _ / stmt */ template X(alias pred = delegate int(x){ return x + 1; }) {} /// ditto /* x / x / expr */ template X(alias pred = delegate int(int x) => x) {} /// ditto /* x / x / stmt */ template X(alias pred = delegate int(int x){ return x + 1; }) {} /// ditto ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test1353.d0000644000175000017500000000032013200164641023342 0ustar matthiasmatthias class A {} interface B {} interface C {} interface D(X) {} void fun() { class T : typeof(new A), .B, const(C), D!int {} version(none) { class U : int, float, __vector(int[3]) {} } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test6534.d0000644000175000017500000000507313200164641023362 0ustar matthiasmatthiasvoid main() { class MC{ int x; } const class CC{ int x; } static assert(is(typeof( CC.x) == const)); immutable class IC{ int x; } static assert(is(typeof( IC.x) == immutable)); shared class SC{ int x; } static assert(is(typeof( SC.x) == shared)); shared const class SCC{ int x; } static assert(is(typeof(SCC.x) == shared) && is(typeof(SCC.x) == const)); struct MS{ int x; } const struct CS{ int x; } static assert(is(typeof( CS.x) == const)); immutable struct IS{ int x; } static assert(is(typeof( IS.x) == immutable)); shared struct SS{ int x; } static assert(is(typeof( SS.x) == shared)); shared const struct SCS{ int x; } static assert(is(typeof(SCS.x) == shared) && is(typeof(SCS.x) == const)); union MU{ int x; } const union CU{ int x; } static assert(is(typeof( CU.x) == const)); immutable union IU{ int x; } static assert(is(typeof( IU.x) == immutable)); shared union SU{ int x; } static assert(is(typeof( SU.x) == shared)); shared const union SCU{ int x; } static assert(is(typeof(SCU.x) == shared) && is(typeof(SCU.x) == const)); static class S_MC{ int x; } const static class S_CC{ int x; } static assert(is(typeof( S_CC.x) == const)); immutable static class S_IC{ int x; } static assert(is(typeof( S_IC.x) == immutable)); shared static class S_SC{ int x; } static assert(is(typeof( S_SC.x) == shared)); shared const static class S_SCC{ int x; } static assert(is(typeof(S_SCC.x) == shared) && is(typeof(S_SCC.x) == const)); static struct S_MS{ int x; } const static struct S_CS{ int x; } static assert(is(typeof( S_CS.x) == const)); immutable static struct S_IS{ int x; } static assert(is(typeof( S_IS.x) == immutable)); shared static struct S_SS{ int x; } static assert(is(typeof( S_SS.x) == shared)); shared const static struct S_SCS{ int x; } static assert(is(typeof(S_SCS.x) == shared) && is(typeof(S_SCS.x) == const)); static union S_MU{ int x; } const static union S_CU{ int x; } static assert(is(typeof( S_CU.x) == const)); immutable static union S_IU{ int x; } static assert(is(typeof( S_IU.x) == immutable)); shared static union S_SU{ int x; } static assert(is(typeof( S_SU.x) == shared)); shared const static union S_SCU{ int x; } static assert(is(typeof(S_SCU.x) == shared) && is(typeof(S_SCU.x) == const)); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/warn3882.d0000644000175000017500000000251113200164641023347 0ustar matthiasmatthias// PERMUTE_ARGS: -w -wi -debug /* TEST_OUTPUT: --- --- */ @safe pure nothrow void strictVoidReturn(T)(T x) {} @safe pure nothrow void nonstrictVoidReturn(T)(ref T x) {} void test3882() { int x = 3; strictVoidReturn(x); nonstrictVoidReturn(x); } /******************************************/ // 12619 extern (C) @system nothrow pure void* memcpy(void* s1, in void* s2, size_t n); // -> weakly pure void test12619() pure { ubyte[10] a, b; debug memcpy(a.ptr, b.ptr, 5); // memcpy call should have side effect } /******************************************/ // 12760 struct S12760(T) { T i; this(T j) inout {} } struct K12760 { S12760!int nullable; this(int) { nullable = 0; // weak purity } } /******************************************/ // 12909 int f12909(immutable(int[])[int] aa) pure nothrow { //aa[0] = []; // fix for issue 13701 return 0; } void test12909() { immutable(int[])[int] aa; f12909(aa); // from 12910 const(int[])[int] makeAA() { return null; } // to make r-value makeAA().rehash(); } /******************************************/ // 13899 const struct Foo13899 { int opApply(immutable int delegate(in ref int) pure nothrow dg) pure nothrow { return 1; } } void test13899() { foreach (x; Foo13899()) { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice13088.d0000644000175000017500000000030213200164641023213 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: struct X { void mfoo(this T)() {} } void test() { shared const X scx; scx.mfoo(); } struct Vec { int x; void sc() shared const {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test4364.d0000644000175000017500000000020713200164641023353 0ustar matthiasmatthiasstruct Object{} class Game {} void main() { static assert(is(Object == struct)); static assert(is(object.Object == class)); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc7555.d0000644000175000017500000000142613200164641023316 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 7555 module ddoc7555; /** Dummy doc. $(X0 DelimitedString TokenString) $(X1 DelimitedString TokenString) $(X2 x,HexString) $(X2 x, HexString) $(X3 x,x,HexString) $(X3 x,x, HexString) $(X4 x,x,x,HexString) $(X4 x,x,x, HexString) $(X5 x,x,x,x,HexString) $(X5 x,x,x,x, HexString) $(X6 x,x,x,x,x,HexString) $(X6 x,x,x,x,x, HexString) $(X7 x,x,x,x,x,x,HexString) $(X7 x,x,x,x,x,x, HexString) $(X8 x,x,x,x,x,x,x,HexString) $(X8 x,x,x,x,x,x,x, HexString) $(X9 x,x,x,x,x,x,x,x,HexString) $(X9 x,x,x,x,x,x,x,x, HexString) Macros: X0=$0 X1=$1 X2=$2 X3=$3 X4=$4 X5=$5 X6=$6 X7=$7 X8=$8 X9=$9 */ void dummy(); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10992.d0000644000175000017500000000026013200164641023436 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -unittest unittest { } unittest { } unittest { } void main() { static assert(__traits(getUnitTests, mixin(__MODULE__)).length == 3); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/json.d0000644000175000017500000000367313200164641023036 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -o- -X -Xf${RESULTS_DIR}/compilable/json.out // POST_SCRIPT: compilable/extra-files/json-postscript.sh module json; static this() {} static ~this() {} alias int myInt; myInt x; // bug 3404 struct Foo(T) { T t; } class Bar(int T) { int t = T; } interface Baz(T...) { T[0] t() const; } // bug 3466 template P(alias T) {} class Bar2 : Bar!1, Baz!(int, 2, null) { this() {} ~this() {} // bug 4178 static foo() {} protected abstract Foo!int baz(); override int t() const { return 0; } } class Bar3 : Bar2 { private int val; this(int i) { val = i; } protected override Foo!int baz() { return Foo!int(val); } } struct Foo2 { Bar2 bar2; union U { struct { short s; int i; } Object o; } } /++ + Documentation test +/ @trusted myInt bar(ref uint blah, Bar2 foo = new Bar3(7)) // bug 4477 { return -1; } @property int outer() nothrow in { assert(true); } out(result) { assert(result == 18); } body { int x = 8; int inner(void* v) nothrow { int y = 2; assert(true); return x + y; } int z = inner(null); return x + z; } /** Issue 9484 - selective and renamed imports */ import imports.jsonimport1 : target1, target2; import imports.jsonimport2 : alias1 = target1, alias2 = target2; import imports.jsonimport3 : alias3 = target1, alias4 = target2, target3; import imports.jsonimport4; struct S { /** Issue 9480 - Template name should be stripped of parameters */ this(T)(T t) { } } /** Issue 9755 - Protection not emitted properly for Templates. */ private struct S1_9755(T) { } package struct S2_9755(T) { } class C_9755 { protected static class CI_9755(T) { } } /** Issue 10011 - init property is wrong for object initializer. */ const Object c_10011 = new Object(); /// enum Numbers { unspecified1, one = 2, two = 3, FILE_NOT_FOUND = 101, unspecified3, unspecified4, four = 4, } template IncludeConstraint(T) if (T == string) {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc10325.d0000644000175000017500000000041713200164641023362 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 10325 module ddoc10325; /** */ template templ(T...) if (someConstraint!T) { } /** */ void foo(T)(T t) if (someConstraint!T) { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test7569.d0000644000175000017500000000013713200164641023367 0ustar matthiasmatthiastemplate Tuple(T...) { alias T Tuple; } void main() { Tuple!(int, int) tup1 = void; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc12706.d0000644000175000017500000000027413200164641023370 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 12706 /// void test()(string[] args) if (args[$]) { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10066.d0000644000175000017500000000224313200164641023431 0ustar matthiasmatthiasvoid main() { alias Zoo = Foo!(1); } struct Foo(size_t N) { string bar() { Appender!(string) w; char[] buf; put(w, buf); return ""; } public bool opEquals(T)(T other) const // Add const, different from bug 10056 { alias Foo!(typeof(this), T, "CMP") P; return false; } } template Foo(T, U, string OP) { static if (T.ISEMPTY && U.ISEMPTY) enum bool S = false; else enum bool S = false; alias Foo = Foo!(0); } /**********************************************/ void put(R, E)(ref R r, E e) { static if (is(typeof(r.put(e)))) { r.put(e); } else { static assert(false, "Cannot put a "~E.stringof~" into a "~R.stringof); } } struct Appender(A : T[], T) { private template canPutItem(U) { enum bool canPutItem = is(U : T); } private template canPutRange(R) { enum bool canPutRange = is(typeof(Appender.init.put(R.init[0]))); } void put(U)(U item) if (canPutItem!U) { char[T.sizeof == 1 ? 4 : 2] encoded; put(encoded[]); } void put(R)(R items) if (canPutRange!R) { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testpostblit.d0000644000175000017500000000021713200164641024614 0ustar matthiasmatthiasstruct Test1a { this(this) { } } struct Test1b { Test1a a; } struct Test1c { const Test1b b; @disable this(this); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test67.d0000644000175000017500000000012413200164641023205 0ustar matthiasmatthias// PERMUTE_ARGS: import imports.test67a; interface I { } interface SubI : I { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test7065.d0000644000175000017500000000230113200164641023351 0ustar matthiasmatthiasvoid main() { align(1) struct X1 { ubyte b; int n; } static assert(X1.sizeof == 8); static assert(X1.b.offsetof == 0); static assert(X1.n.offsetof == 4); //X1 x1; //assert(cast(void*)&x1.b == cast(void*)&x1 + 0); //assert(cast(void*)&x1.n == cast(void*)&x1 + 1); struct Y1 { ubyte b; int n; } static assert(Y1.sizeof == 8); static assert(Y1.b.offsetof == 0); static assert(Y1.n.offsetof == 4); //Y1 y1; //assert(cast(void*)&y1.b == cast(void*)&y1 + 0); //assert(cast(void*)&y1.n == cast(void*)&y1 + 4); int local; align(1) struct X2 { ubyte b; int n; int f(){ return local; } } static assert(X2.sizeof == 8 + (void*).sizeof); static assert(X2.b.offsetof == 0); static assert(X2.n.offsetof == 4); //X2 x2; //assert(cast(void*)&x2.b == cast(void*)&x2 + 0); //assert(cast(void*)&x2.n == cast(void*)&x2 + 1); struct Y2 { ubyte b; int n; int f(){ return local; } } static assert(Y2.sizeof == 8 + (void*).sizeof); static assert(Y2.b.offsetof == 0); static assert(Y2.n.offsetof == 4); //Y2 y2; //assert(cast(void*)&y2.b == cast(void*)&y2 + 0); //assert(cast(void*)&y2.n == cast(void*)&y2 + 4); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/sw_transition_tls.d0000644000175000017500000000034513200164641025643 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -c -transition=tls /* TEST_OUTPUT: --- compilable/sw_transition_tls.d(11): x is thread local compilable/sw_transition_tls.d(15): y is thread local --- */ int x; struct S { static int y; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9692.d0000644000175000017500000000027213200164641023366 0ustar matthiasmatthiasmodule test9692; import test9692a; import imports.test9692b; enum x = [__traits(allMembers, imports.test9692b)]; // ok enum y = [__traits(allMembers, test9692a)]; // ng: should work ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice10040.d0000644000175000017500000000034413200164641023202 0ustar matthiasmatthiasstruct MsgProc1 { mixin MsgMixin; } struct MsgProc2 { mixin MsgMixin; } struct MsgHeader {} template MsgMixin() { mixin(mixinMembers!(MsgHeader.init)); } string mixinMembers(T ...)() { struct Op {} return null; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test4003.d0000644000175000017500000000014113200164641023336 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test4003a.d // PERMUTE_ARGS: import imports.stdio4003; void main(){} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test7491.d0000644000175000017500000000252213200164641023361 0ustar matthiasmatthiasstruct Struct { import object; import imports.test7491a; import renamed=imports.test7491b; } struct AliasThis { Struct _struct; alias _struct this; } class Base { import object; import imports.test7491a; import renamed=imports.test7491b; } class Derived : Base { } interface Interface { import object; import imports.test7491a; import renamed=imports.test7491b; } class Impl : Interface { } static assert(__traits(compiles, Struct.object)); static assert(__traits(compiles, Struct.imports)); static assert(__traits(compiles, Struct.renamed)); static assert(__traits(compiles, AliasThis.object)); static assert(__traits(compiles, AliasThis.imports)); static assert(__traits(compiles, AliasThis.renamed)); static assert(__traits(compiles, Base.object)); static assert(__traits(compiles, Base.imports)); static assert(__traits(compiles, Base.renamed)); static assert(__traits(compiles, Derived.object)); static assert(__traits(compiles, Derived.imports)); static assert(__traits(compiles, Derived.renamed)); static assert(__traits(compiles, Interface.object)); static assert(__traits(compiles, Interface.imports)); static assert(__traits(compiles, Interface.renamed)); static assert(__traits(compiles, Impl.object)); static assert(__traits(compiles, Impl.imports)); static assert(__traits(compiles, Impl.renamed)); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test11471.d0000644000175000017500000000015713200164641023434 0ustar matthiasmatthias// REQUIRED_ARGS: -profile void main() nothrow { asm { nop; } } // Error: asm statements are assumed to throw ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc10870.d0000644000175000017500000000026513200164641023370 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 10870 /// interface I { /// void f(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/fail260.d0000644000175000017500000000121113200164641023212 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -d struct Static(uint width2, uint height2) { immutable width = width2; immutable height = height2; static Static opCall() { Static ret; return ret; } alias float E; template MultReturn(alias M1, alias M2) { alias Static!(M2.width, M1.height) MultReturn; } void opMultVectors(M2)(M2 b) { alias MultReturn!(Static, M2) ret_matrix; } } void test() { alias Static!(4, 1) matrix_stat; static matrix_stat m4 = matrix_stat(); alias Static!(1, 4) matrix_stat2; static m6 = matrix_stat2(); m6.opMultVectors(m4); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_791.d0000644000175000017500000000006313200164641024557 0ustar matthiasmatthiasint crash() { asm { naked; ret; }; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice11610.d0000644000175000017500000000400013200164641023177 0ustar matthiasmatthias struct Token { TokenType type; } enum TokenType : ushort { invalid } class Parser { bool peekIsOneOf(TokenType[] types...) { canFind(types, tokens[1].type); return true; } Token[] tokens; } /*************************************************/ // std.algorithm R find(alias pred = "a == b", R, E)(R haystack, E needle) { enum isIntegralNeedle = isSomeChar!E/* || isIntegral!E || isBoolean!E*/; return haystack; } bool canFind(alias pred = "a == b", R, E)(R haystack, E needle) if (is(typeof(find!pred(haystack, needle)))) // 1st instantiate of find template with error gagging { return find!pred(haystack, needle).length != 0; // 2nd instantiate of find template without gagging } /*************************************************/ // std.traits template CharTypeOf(T) { inout( char) idx( inout( char) ); inout(wchar) idx( inout(wchar) ); inout(dchar) idx( inout(dchar) ); shared(inout char) idx( shared(inout char) ); shared(inout wchar) idx( shared(inout wchar) ); shared(inout dchar) idx( shared(inout dchar) ); static if (is(T == enum)) { /* This line instantiates CharTypeOf!short and will make error. * But, when CharTypeOf!short is re-instantiated without gagging, * that's for correct error report, its 'members' does not re-created. * so, members' semantic will call FuncDeclaration::overloadInsert of * 'idx' functions, and will make circular linked list of * FuncDeclaration::overnext. Finally, iterating it will cause * infinite recursion and compiler segfault. */ alias .CharTypeOf!(OriginalType!T) CharTypeOf; } else static if (is(typeof(idx(T.init)) X)) { alias X CharTypeOf; } else static assert(0, T.stringof~" is not a character type"); } template isSomeChar(T) { enum isSomeChar = is(CharTypeOf!T); } template OriginalType(T) { alias OriginalType = ushort; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/b33.d0000644000175000017500000000021113200164641022435 0ustar matthiasmatthias// EXTRA_SOURCES: imports/b33a.d // PERMUTE_ARGS: module b33; private import imports.b33a; size_t fn() { return find( "123" ); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_aggregate.d0000644000175000017500000000023613200164641024625 0ustar matthiasmatthias union A { TypeInfo info; void[0] result; } struct B { TypeInfo info; void[0] result; } class C { TypeInfo info; void[0] result; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9497c.d0000644000175000017500000000037413200164641023471 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/ddoc9497c.ddoc // PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9497c /** foo function. Args: $(XYZ arg1, arg2) */ void foo() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9497d.d0000644000175000017500000000037413200164641023472 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/ddoc9497d.ddoc // PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9497d /** foo function. Args: $(XYZ arg1, arg2) */ void foo() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice10598.d0000644000175000017500000000011213200164641023215 0ustar matthiasmatthias// EXTRA_SOURCES: imports/ice10598a.d imports/ice10598b.d void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testheader12567b.d0000644000175000017500000000033413200164641024753 0ustar matthiasmatthias// REQUIRED_ARGS: -o- -H -Hf${RESULTS_DIR}/compilable/header12567b.di // PERMUTE_ARGS: // POST_SCRIPT: compilable/extra-files/header-postscript.sh header12567b deprecated("message") module header12567b; void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test7030.d0000644000175000017500000000133313200164641023345 0ustar matthiasmatthiasextern(C++) { struct S { void foo(int) const; void bar(int); static __gshared int boo; } } // DMD adds the extra underscore that is required for platform ABI compliance // to the mangleof string, see https://issues.dlang.org/show_bug.cgi?id=8207 and // LDC GitHub issue #114. version (DigitalMars) version (OSX) version = DMD_OSX; version (DMD_OSX) { static assert(S.foo.mangleof == "__ZNK1S3fooEi"); static assert(S.bar.mangleof == "__ZN1S3barEi"); static assert(S.boo.mangleof == "__ZN1S3booE"); } else version (Posix) { static assert(S.foo.mangleof == "_ZNK1S3fooEi"); static assert(S.bar.mangleof == "_ZN1S3barEi"); static assert(S.boo.mangleof == "_ZN1S3booE"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/iasm_labeloperand.d0000644000175000017500000000155713200164641025525 0ustar matthiasmatthias// LLVM mach-o backend: "32-bit absolute addressing is not supported in 64-bit mode" version (LDC) version(OSX) version = LDC_OSX; version (LDC_OSX) {} else version (D_InlineAsm_X86) version = TestInlineAsm; else version (D_InlineAsm_X86_64) version = TestInlineAsm; else pragma(msg, "Inline asm not supported, not testing."); version (TestInlineAsm) { void testInlineAsm() { asm { L1: nop; nop; nop; nop; mov EAX, dword ptr L1; // Check back references mov EAX, dword ptr L2; // Check forward references mov EAX, dword ptr DS:L1; // Not really useful in standard use, but who knows. mov EAX, dword ptr FS:L2; // Once again, not really useful, but it is valid. mov EAX, dword ptr CS:L1; // This is what the first test case should implicitly be. L2: nop; nop; nop; nop; } } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9.d0000644000175000017500000000065113200164641023060 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9 // 273 /// Template Documentation (OK) template Template(T) { } /// Function Documentation (Not included at all by DDoc) void Function(T)(T x) { } /// Class Documentation (OK) class Class(T) { } /// Struct Documentation struct Struct(T) { } /// Union Documentation union Union(T) { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice11925.d0000644000175000017500000000056213200164641023221 0ustar matthiasmatthiasvoid test11925a() { try { try { L1: {} } finally { } } finally { } goto L1; } void test11925b() { switch (1) { case 1: goto L1; break; default: break; } try { L1: { } } finally { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10752.d0000644000175000017500000000020613200164641023430 0ustar matthiasmatthiasimport imports.test10752; void main() { static assert(!__traits(compiles, priv)); static assert(!__traits(compiles, priv)); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc7795.d0000644000175000017500000000051413200164641023321 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 7795 module ddoc7795; struct TimeValue { this(int hour, int minute, int second = 0, int ms = 0) {} } /// struct DateTime { /// this(TimeValue t = TimeValue(0, 0)) {} } void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_982.d0000644000175000017500000000013013200164641024554 0ustar matthiasmatthiasimport std.datetime; void main() { auto r = cast(Duration[2])benchmark!({},{})(1); }ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_637.d0000644000175000017500000000007613200164641024562 0ustar matthiasmatthiasextern(C): struct Value { this(string) {} string s; }ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9727.d0000644000175000017500000000054413200164641023321 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9727 module ddoc9727; /** The function foo. */ void foo(int x); /** */ unittest { foo(1); } /** foo can be used like this: */ unittest { foo(2); } /** foo can also be used like this: */ unittest { foo(3); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8922b.d0000644000175000017500000000034513200164641023524 0ustar matthiasmatthias// PERMUTE_ARGS: void test() { import imports.bug8922; static assert(!__traits(compiles, __traits(parent, imports))); enum x = __traits(parent, imports.bug8922).stringof; static assert(x == "package imports"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc6491.d0000644000175000017500000000042513200164641023312 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 6491 module ddoc6491; import core.cpuid; enum int c6491 = 4; /// test void bug6491a(int a = ddoc6491.c6491, string b = core.cpuid.vendor); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8922a.d0000644000175000017500000000034113200164641023517 0ustar matthiasmatthias// PERMUTE_ARGS: import imports.bug8922; void test() { static assert(!__traits(compiles, __traits(parent, imports))); enum x = __traits(parent, imports.bug8922).stringof; static assert(x == "package imports"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddocunittest.d0000644000175000017500000001573613200164641024601 0ustar matthiasmatthias// PERMUTE_ARGS: -unittest // REQUIRED_ARGS: -D -w -o- -c -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh unittest module ddocunittest; /* Insert test-cases for documented unittests feature here. */ /// foo function - 1 example int foo(int a, int b) { return a + b; } /// unittest { assert(foo(1, 1) == 2); } /// bar function - 1 example bool bar() { return true; } /// unittest { // documented assert(bar()); } /// placeholder unittest { } /// doo function - no examples void doo() { } /// private unittest { // undocumented doo(); } unittest { // undocumented doo(); } /** add function - 3 examples Examples: ---- assert(add(1, 1) == 2); ---- */ int add(int a, int b) { return a + b; } /// unittest { // documented assert(add(3, 3) == 6); assert(add(4, 4) == 8); } unittest { // undocumented assert(add(2, 2) + add(2, 2) == 8); } /// unittest { // documented assert(add(5, 5) == 10); assert(add(6, 6) == 12); } /// class Foo immutable pure nothrow class Foo { int x; /// unittest { // another foo example Foo foo = new Foo; } } /// unittest { Foo foo = new Foo; } pure { const { immutable { /// some class - 1 example class SomeClass {} } } } /// unittest { SomeClass sc = new SomeClass; } /// Outer - 1 example class Outer { /// Inner static class Inner { } /// unittest { Inner inner = new Inner; } } /// unittest { Outer outer = new Outer; } /** foobar - no examples */ void foobar() { } unittest { foobar(); } /** func - 4 examples Examples: --- foo(1); --- Examples: --- foo(2); --- */ void foo(int x) { } /// unittest { foo(2); } /// unittest { foo(4); } // ------------------------------------ // insert import declaration between documented function and unittests /// void fooImport() {} import core.stdc.stdio; /// test unittest { fooImport(); } /// void fooStaticImport() {} static import core.stdc.stdlib; /// test unittest { fooStaticImport(); } /// void fooPublicImport() {} public import core.stdc.string; /// test unittest { fooPublicImport(); } /// void fooSelectiveImport() {} import core.stdc.ctype : isalpha; /// test unittest { fooSelectiveImport(); } /// void fooRenamedImport() {} import io = core.stdc.stdio; /// test unittest { fooRenamedImport(); } // ------------------------------------ // documented unittest after conditional declarations static if (true) void fooConditionalDecl1a() {} /** */ unittest { int x1a; } /// static if (true) { void fooConditionalDecl1b() {} /** */ } unittest { int x1b; } /// static if (false) void fooConditionalDecl2a() {} /** */ unittest { int x2a; } /// static if (false) { void fooConditionalDecl2b() {} /** */ } unittest { int x2b; } /// static if (true) { void fooConditionalDecl3a() {} /** */ } else { void barConditionalDecl3a() {} /** */ } unittest { int x3a; } /// static if (true) { void fooConditionalDecl3b() {} /** */ } else { void barConditionalDecl3b() {} /** */ } unittest { int x3b; } /// static if (false) void fooConditionalDecl4a() {} /** */ else void barConditionalDecl4a() {} /** */ unittest { int x4a; } /// static if (false) { void fooConditionalDecl4b() {} /** */ } else { void barConditionalDecl4b() {} /** */ } unittest { int x4b; } /// static if (true) {} else void barConditionalDecl5a() {} /** */ unittest { int x5a; } /// static if (true) {} else { void barConditionalDecl5b() {} /** */ } unittest { int x5b; } /// static if (false) {} else void barConditionalDecl6a() {} /** */ /// unittest { int x6a; } static if (false) {} else { void barConditionalDecl6b() {} /** */ } /// unittest { int x6b; } // ------------------------------------ // 9474 /// void foo9474() { } version(none) unittest { } /// Example unittest { foo9474(); } /// doc void bar9474() { } version(none) unittest { } /// Example unittest { bar9474(); } /// struct S9474 { } /// unittest { S9474 s; } /// auto autovar9474 = 1; /// unittest { int v = autovar9474; } /// auto autofun9474() { return 1; } /// unittest { int n = autofun9474(); } /// template Template9474() { /// Shouldn't link following unittest to here void foo() {} } /// unittest { alias Template9474!() T; } // ------------------------------------ // 9713 /// void fooNoDescription() {} /// unittest { fooNoDescription(); } /// unittest { if (true) {fooNoDescription(); } /* comment */ } // ------------------------------------ /// test for bugzilla 9757 void foo9757() {} /// ditto void bar9757() {} /// ditto void baz9757() {} /// unittest { foo9757(); bar9757(); } /// unittest { bar9757(); foo9757(); } /// with template functions auto redBlackTree(E)(E[] elems...) { return 1; } /// ditto auto redBlackTree(bool allowDuplicates, E)(E[] elems...) { return 2; } /// ditto auto redBlackTree(alias less, E)(E[] elems...) { return 3; } /// unittest { auto rbt1 = redBlackTree(0, 1, 5, 7); auto rbt2 = redBlackTree!string("hello", "world"); auto rbt3 = redBlackTree!true(0, 1, 5, 7, 5); auto rbt4 = redBlackTree!"a > b"(0, 1, 5, 7); } // ------------------------------------ // Issue 9758 /// test void foo(){} /// unittest { } // ------------------------------------ // Issue 10519 /// bool balancedParens10519(string, char, char) { return true; } /// unittest { auto s = "1 + (2 * (3 + 1 / 2)"; assert(!balancedParens10519(s, '(', ')')); } // ------------------------------------ // Issue 12097 /// declaration struct S12097 { /// method void foo() {} } /// ditto void f12097() {} /// ddoc code 1 unittest { int a = 1; } /// ditto struct T12097(T) {} /// ddoc code 2 unittest { int[] arr; } // ------------------------------------ // 14594 /******************* * testA */ void fun14594a()() {} /// unittest { fun14594a(); } /******************* * testB */ void fun14594b()() {} /// ditto void fun14594b(T)(T) {} /// unittest { fun14594b(); fun14594b(1); } /******************* * testC */ void fun14594c()() {} /// unittest { fun14594c(); fun14594c(1); } /// ditto void fun14594c(T)(T) {} /******************* * testD */ void fun14594d()() {} /// unittest { fun14594d(); } /// ditto void fun14594d(T)(T) {} /// unittest { fun14594d(1); } /******************* * testE */ template fun14594e() { /// concatenated doc-comment fun14594e void fun14594e() {} /// ignored-unittest fun14594e unittest { fun14594e(); } } /// doc-unittest fun14594e unittest { fun14594e(); } /******************* * testF */ template fun14594f() { /// concatenated doc-comment fun14594f void fun14594f() {} /// ignored-unittest fun14594f unittest { fun14594f(); } } /// ditto template fun14594f(T) { /// ignored doc-comment fun14594f void fun14594f(T) {} /// ignored-unittest fun14594f unittest { fun14594f(1); } } /// doc-unittest fun14594f unittest { fun14594f(); } // ------------------------------------ void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/bug11735.d0000644000175000017500000000121113200164641023225 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: /* TEST_OUTPUT: --- print string print wstring print dstring يطبع الترميز الموحد يطبع الترميز الموحد يطبع الترميز الموحد foo_str foo_wstr foo_dstr --- */ pragma(msg, "print string"); pragma(msg, "print wstring"w); pragma(msg, "print dstring"d); pragma(msg, "يطبع الترميز الموحد"); pragma(msg, "يطبع الترميز الموحد"w); pragma(msg, "يطبع الترميز الموحد"d); void main() { enum a = "foo_str"; enum b = "foo_wstr"w; enum c = "foo_dstr"d; pragma(msg, a); pragma(msg, b); pragma(msg, c); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test15056.d0000644000175000017500000000056213200164641023437 0ustar matthiasmatthiasnothrow: version (Windows) { version (LP_64) import core.stdc.stdlib; else // doesn't currently work b/c SEH remains present even in nothrow code void* alloca(size_t) { return null; } } else import core.stdc.stdlib; struct S { ~this() nothrow {} } S foo(void* p = alloca(1234)) { return S(); } int main() { foo(); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_1292.d0000644000175000017500000000027113200164641024635 0ustar matthiasmatthiasvoid main() { fun(); } void fun() { double x0 = 0, x1 = 1; asm nothrow @nogc { movlpd qword ptr x0, XMM0; movhpd qword ptr x1, XMM0; } }ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice8392.d0000644000175000017500000000017613200164641023146 0ustar matthiasmatthias// EXTRA_SOURCES: imports/a8392.d module ice8392; struct A { } auto fooa(alias handler)(A a) { return handler(null); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/protection.d0000644000175000017500000000573713200164641024256 0ustar matthiasmatthiasimport imports.protectionimp; alias TypeTuple(T...) = T; private { void localF() {} class localC {} struct localS {} union localU {} interface localI {} enum localE { foo } mixin template localMT() {} class localTC(T) {} struct localTS(T) {} union localTU(T) {} interface localTI(T) {} void localTF(T)() {} } void main() { // Private non-template declarations static assert(!__traits(compiles, privF())); static assert(!__traits(compiles, privC)); static assert(!__traits(compiles, privS)); static assert(!__traits(compiles, privU)); static assert(!__traits(compiles, privI)); static assert(!__traits(compiles, privE)); static assert(!__traits(compiles, privMT)); // Private local non-template declarations. static assert( __traits(compiles, localF())); static assert( __traits(compiles, localC)); static assert( __traits(compiles, localS)); static assert( __traits(compiles, localU)); static assert( __traits(compiles, localI)); static assert( __traits(compiles, localE)); static assert( __traits(compiles, localMT)); // Private template declarations. static assert(!__traits(compiles, privTF!int())); static assert(!__traits(compiles, privTC!int)); static assert(!__traits(compiles, privTS!int)); static assert(!__traits(compiles, privTU!int)); static assert(!__traits(compiles, privTI!int)); // Private local template declarations. static assert( __traits(compiles, localTF!int())); static assert( __traits(compiles, localTC!int)); static assert( __traits(compiles, localTS!int)); static assert( __traits(compiles, localTU!int)); static assert( __traits(compiles, localTI!int)); // Public template function with private type parameters. static assert(!__traits(compiles, publF!privC())); static assert(!__traits(compiles, publF!privS())); static assert(!__traits(compiles, publF!privU())); static assert(!__traits(compiles, publF!privI())); static assert(!__traits(compiles, publF!privE())); // Public template function with private alias parameters. static assert(!__traits(compiles, publFA!privC())); static assert(!__traits(compiles, publFA!privS())); static assert(!__traits(compiles, publFA!privU())); static assert(!__traits(compiles, publFA!privI())); static assert(!__traits(compiles, publFA!privE())); // Private alias. static assert(!__traits(compiles, privA)); // Public template mixin. static assert( __traits(compiles, publMT)); } /***************************************************/ // 14169 template staticMap14169(alias fun, T...) { static if (T.length > 0) alias staticMap14169 = TypeTuple!(fun!(T[0]), staticMap14169!(fun, T[1..$])); else alias staticMap14169 = TypeTuple!(); } class C14169 { private struct InnerStruct(string NameS) { alias Name = NameS; } alias DimensionNames = staticMap14169!(GetName14169, InnerStruct!"A"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test12979a.d0000644000175000017500000000011113200164641023601 0ustar matthiasmatthiasvoid parse() { asm pure nothrow @nogc @trusted {} asm @safe {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc7.d0000644000175000017500000000123213200164641023052 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 7 //----------------------------------------------- /// my enum enum E1 { A, /// element a B /// element b } /// my enum enum E2 { /// element a A, /// element b B } /// my enum enum E3 { A /// element a , B /// element b } /// my enum enum E4 { A /// element a , B /// element b } /// my enum enum E5 { /// element a A , /// element b B } /// Some doc void foo() {} /// More doc alias foo bar; /// asdf class C { /// Some doc abstract void foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test14781.d0000644000175000017500000000127413200164641023444 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: void impure() {} // impure auto fb1(T)() pure { int x; struct A(S) { void fc(T2)() { x = 1; // accessing pure function context is just ok impure(); // impure function call makes fc as impure } this(S a) {} } return A!int(); } auto fb2(T)() pure { int x; struct A(S) { void fc(T2)() { impure(); // impure function call makes fc as impure x = 1; // accessing pure function context is just ok } this(S a) {} } return A!int(); } void test1() { fb1!int().fc!int(); fb2!int().fc!int(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test12967.d0000644000175000017500000000437113200164641023451 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: void foo() {} alias F = typeof(foo); const { void block_c() {} } immutable { void block_i() {} } inout { void block_w() {} } shared { void block_s() {} } shared const { void block_sc() {} } shared inout { void block_sw() {} } static assert(is(typeof(block_c) == F)); static assert(is(typeof(block_i) == F)); static assert(is(typeof(block_w) == F)); static assert(is(typeof(block_s) == F)); static assert(is(typeof(block_sc) == F)); static assert(is(typeof(block_sw) == F)); version (all) { const: void label_c() {} } version (all) { immutable: void label_i() {} } version (all) { inout: void label_w() {} } version (all) { shared: void label_s() {} } version (all) { shared const: void label_sc() {} } version (all) { shared inout: void label_sw() {} } static assert(is(typeof(label_c) == F)); static assert(is(typeof(label_i) == F)); static assert(is(typeof(label_w) == F)); static assert(is(typeof(label_s) == F)); static assert(is(typeof(label_sc) == F)); static assert(is(typeof(label_sw) == F)); class C { const { static void block_c() {} } immutable { static void block_i() {} } inout { static void block_w() {} } shared { static void block_s() {} } shared const { static void block_sc() {} } shared inout { static void block_sw() {} } static assert(is(typeof(block_c) == F)); static assert(is(typeof(block_i) == F)); static assert(is(typeof(block_w) == F)); static assert(is(typeof(block_s) == F)); static assert(is(typeof(block_sc) == F)); static assert(is(typeof(block_sw) == F)); version (all) { const: static void label_c() {} } version (all) { immutable: static void label_i() {} } version (all) { inout: static void label_w() {} } version (all) { shared: static void label_s() {} } version (all) { shared const: static void label_sc() {} } version (all) { shared inout: static void label_sw() {} } static assert(is(typeof(label_c) == F)); static assert(is(typeof(label_i) == F)); static assert(is(typeof(label_w) == F)); static assert(is(typeof(label_s) == F)); static assert(is(typeof(label_sc) == F)); static assert(is(typeof(label_sw) == F)); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testheader12567a.d0000644000175000017500000000032113200164641024746 0ustar matthiasmatthias// REQUIRED_ARGS: -o- -H -Hf${RESULTS_DIR}/compilable/header12567a.di // PERMUTE_ARGS: // POST_SCRIPT: compilable/extra-files/header-postscript.sh header12567a deprecated module header12567a; void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8922e.d0000644000175000017500000000056113200164641023527 0ustar matthiasmatthias// PERMUTE_ARGS: import renamed = imports.bug8922; void test() { enum x = __traits(parent, renamed).stringof; static assert(x == "package imports"); static assert(!__traits(compiles, __traits(parent, imports))); static assert(!__traits(compiles, __traits(parent, bug8922))); static assert(!__traits(compiles, __traits(parent, imports.bug8922))); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test70.d0000644000175000017500000000015613200164641023204 0ustar matthiasmatthiasimport imports.test70 : foo; void foo(int) // overloads with selective import { } void bar() { foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test69.d0000644000175000017500000000265313200164641023220 0ustar matthiasmatthias// PERMUTE_ARGS: // ICE(expression.c) DMD 0.110 // http://www.digitalmars.com/d/archives/digitalmars/D/bugs/2966.html string str255() { return "\255"; } void fromFail49() { switch("abc") { case "": case str255(): break; default: break; } } // Bugzilla 5735 struct A {} void b() {} void foo(bool cond) {} void main() { A a; int i; static assert(!__traits(compiles, assert(a))); static assert(!__traits(compiles, assert(i || a))); static assert(!__traits(compiles, assert(0 || a))); static assert(!__traits(compiles, assert(i && a))); static assert(!__traits(compiles, assert(1 && a))); static assert(!__traits(compiles, foo(a))); static assert(!__traits(compiles, foo(i || a))); static assert(!__traits(compiles, foo(0 || a))); static assert(!__traits(compiles, foo(i && a))); static assert(!__traits(compiles, foo(1 && a))); static assert(!__traits(compiles, assert(b))); static assert(!__traits(compiles, assert(i || b))); static assert(!__traits(compiles, assert(0 || b))); static assert(!__traits(compiles, assert(i && b))); static assert(!__traits(compiles, assert(1 && b))); static assert(!__traits(compiles, foo(b))); static assert(!__traits(compiles, foo(i || b))); static assert(!__traits(compiles, foo(0 || b))); static assert(!__traits(compiles, foo(i && b))); static assert(!__traits(compiles, foo(1 && b))); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_461.d0000644000175000017500000000061013200164641024547 0ustar matthiasmatthiasimport std.stdio; void foo(bool[] err = null) { if (err !is null) { if (err[0]) { writeln(err); } else { writeln("Nothing to do."); } } else { writeln("Null input."); } } void main() { foo(); bool[] err = [false, false, false]; foo(err); err[0] = true; foo(err); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testDIP37_10421.d0000644000175000017500000000045513200164641024275 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -c -Icompilable/extra-files // EXTRA_SOURCES: extra-files/pkgDIP37_10421/algo/package.d // EXTRA_SOURCES: extra-files/pkgDIP37_10421/algo/mod.d // EXTRA_SOURCES: extra-files/pkgDIP37_10421/except.d module testDIP37_10421; import pkgDIP37_10421.algo; void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_421.d0000644000175000017500000000032313200164641024544 0ustar matthiasmatthiasint main() { import core.simd; float[16] a = 1.0; float4 t = 0, k = 2; auto b = cast(float4[])a; for (size_t i = 0; i < b.length; i++) t += b[i] * k; return cast(int)t.array[2]; }ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testfptr.d0000644000175000017500000003122213200164641023727 0ustar matthiasmatthias// PERMUTE_ARGS: ref int frvv(); class A {} class B : A {} B restrictedfunc(in const(int)) @safe pure nothrow; A relaxedfunc(in int); void bug3797() { // Cannot convert if the return type or parameters are different void function() vv; void function(int) vi; int function() iv; const(int) function() cv; immutable(int) function() xv; static assert( is(typeof( vv = vv ))); static assert(!is(typeof( vv = vi ))); static assert(!is(typeof( vv = iv ))); static assert(!is(typeof( vv = cv ))); static assert(!is(typeof( vv = xv ))); static assert(!is(typeof( vi = vv ))); static assert( is(typeof( vi = vi ))); static assert(!is(typeof( vi = iv ))); static assert(!is(typeof( vi = cv ))); static assert(!is(typeof( vi = cx ))); static assert(!is(typeof( iv = vv ))); static assert(!is(typeof( iv = vi ))); static assert( is(typeof( iv = iv ))); static assert( is(typeof( iv = cv ))); static assert( is(typeof( iv = xv ))); static assert(!is(typeof( cv = vv ))); static assert( is(typeof( cv = iv ))); static assert(!is(typeof( cv = vi ))); static assert( is(typeof( cv = cv ))); static assert( is(typeof( cv = xv ))); static assert(!is(typeof( xv = vv ))); static assert( is(typeof( xv = iv ))); static assert(!is(typeof( xv = vi ))); static assert( is(typeof( xv = cv ))); static assert( is(typeof( xv = xv ))); int* function() ipfunc; const(int*) function() cipfunc; static assert( is(typeof( cipfunc = ipfunc )) ); static assert(!is(typeof( ipfunc = cipfunc )) ); // functions with different linkages can't convert extern(C) void function() cfunc; extern(D) void function() dfunc; static assert(!is(typeof( cfunc = dfunc ))); static assert(!is(typeof( dfunc = cfunc ))); // ref return can't convert to non-ref return typeof(&frvv) rvv; static assert(!is(typeof( rvv = iv ))); static assert(!is(typeof( rvv = cv ))); static assert(!is(typeof( iv = rvv ))); static assert(!is(typeof( cv = rvv ))); // variadic functions don't mix void function(...) vf; static assert(!is(typeof( vf = vv ))); static assert(!is(typeof( vv = vf ))); // non-nothrow -> nothrow void function() nothrow ntf; static assert(!is(typeof( ntf = vv ))); static assert( is(typeof( vv = ntf ))); // @safe <-> @trusted -> @system void function() @system systemfunc; void function() @trusted trustedfunc; void function() @safe safefunc; static assert( is(typeof( trustedfunc = safefunc ))); static assert( is(typeof( systemfunc = trustedfunc ))); static assert( is(typeof( systemfunc = safefunc ))); static assert( is(typeof( safefunc = trustedfunc ))); static assert(!is(typeof( trustedfunc = systemfunc ))); static assert(!is(typeof( safefunc = systemfunc ))); // pure -> non-pure void function() nonpurefunc; void function() pure purefunc; static assert(!is(typeof( purefunc = nonpurefunc ))); static assert( is(typeof( nonpurefunc = purefunc ))); // Cannot convert parameter storage classes (except const to in and in to const) void function(const(int)) constfunc; void function(in int) infunc; void function(out int) outfunc; void function(ref int) reffunc; void function(lazy int) lazyfunc; static assert(is(typeof( infunc = constfunc ))); static assert(is(typeof( constfunc = infunc ))); static assert(!is(typeof( infunc = outfunc ))); static assert(!is(typeof( infunc = reffunc ))); static assert(!is(typeof( infunc = lazyfunc ))); static assert(!is(typeof( outfunc = infunc ))); static assert(!is(typeof( outfunc = reffunc ))); static assert(!is(typeof( outfunc = lazyfunc ))); static assert(!is(typeof( reffunc = infunc ))); static assert(!is(typeof( reffunc = outfunc ))); static assert(!is(typeof( reffunc = lazyfunc ))); static assert(!is(typeof( lazyfunc = infunc ))); static assert(!is(typeof( lazyfunc = outfunc ))); static assert(!is(typeof( lazyfunc = reffunc ))); // Test class covariance A function() afunc; B function() bfunc; static assert( is(typeof( afunc = bfunc ))); static assert(!is(typeof( bfunc = afunc ))); // Test all the conversions at once typeof(&restrictedfunc) prestrictedfunc; typeof(&relaxedfunc) prelaxedfunc = prestrictedfunc; } void bug3797dg() { ref int frvv() { return *(new int); } B restrictedfunc(in const(int)) @safe pure nothrow { return null; } A relaxedfunc(in int) { return null; } // Cannot convert if the return type or parameters are different void delegate() vv; void delegate(int) vi; int delegate() iv; const(int) delegate() cv; immutable(int) delegate() xv; static assert( is(typeof( vv = vv ))); static assert(!is(typeof( vv = vi ))); static assert(!is(typeof( vv = iv ))); static assert(!is(typeof( vv = cv ))); static assert(!is(typeof( vv = xv ))); static assert(!is(typeof( vi = vv ))); static assert( is(typeof( vi = vi ))); static assert(!is(typeof( vi = iv ))); static assert(!is(typeof( vi = cv ))); static assert(!is(typeof( vi = cx ))); static assert(!is(typeof( iv = vv ))); static assert(!is(typeof( iv = vi ))); static assert( is(typeof( iv = iv ))); static assert( is(typeof( iv = cv ))); static assert( is(typeof( iv = xv ))); static assert(!is(typeof( cv = vv ))); static assert( is(typeof( cv = iv ))); static assert(!is(typeof( cv = vi ))); static assert( is(typeof( cv = cv ))); static assert( is(typeof( cv = xv ))); static assert(!is(typeof( xv = vv ))); static assert( is(typeof( xv = iv ))); static assert(!is(typeof( xv = vi ))); static assert( is(typeof( xv = cv ))); static assert( is(typeof( xv = xv ))); int* delegate() ipfunc; const(int*) delegate() cipfunc; static assert( is(typeof( cipfunc = ipfunc )) ); static assert(!is(typeof( ipfunc = cipfunc )) ); // delegates with different linkages can't convert extern(C) void delegate() cfunc; extern(D) void delegate() dfunc; static assert(!is(typeof( cfunc = dfunc ))); static assert(!is(typeof( dfunc = cfunc ))); // ref return can't convert to non-ref return typeof(&frvv) rvv; static assert(!is(typeof( rvv = iv ))); static assert(!is(typeof( rvv = cv ))); static assert(!is(typeof( iv = rvv ))); static assert(!is(typeof( cv = rvv ))); // variadic delegates don't mix void delegate(...) vf; static assert(!is(typeof( vf = vv ))); static assert(!is(typeof( vv = vf ))); // non-nothrow -> nothrow void delegate() nothrow ntf; static assert(!is(typeof( ntf = vv ))); static assert( is(typeof( vv = ntf ))); // @safe <-> @trusted -> @system void delegate() @system systemfunc; void delegate() @trusted trustedfunc; void delegate() @safe safefunc; static assert( is(typeof( trustedfunc = safefunc ))); static assert( is(typeof( systemfunc = trustedfunc ))); static assert( is(typeof( systemfunc = safefunc ))); static assert( is(typeof( safefunc = trustedfunc ))); static assert(!is(typeof( trustedfunc = systemfunc ))); static assert(!is(typeof( safefunc = systemfunc ))); // pure -> non-pure void delegate() nonpurefunc; void delegate() pure purefunc; static assert(!is(typeof( purefunc = nonpurefunc ))); static assert( is(typeof( nonpurefunc = purefunc ))); // Cannot convert parameter storage classes (except const to in and in to const) void delegate(const(int)) constfunc; void delegate(in int) infunc; void delegate(out int) outfunc; void delegate(ref int) reffunc; void delegate(lazy int) lazyfunc; static assert(is(typeof( infunc = constfunc ))); static assert(is(typeof( constfunc = infunc ))); static assert(!is(typeof( infunc = outfunc ))); static assert(!is(typeof( infunc = reffunc ))); static assert(!is(typeof( infunc = lazyfunc ))); static assert(!is(typeof( outfunc = infunc ))); static assert(!is(typeof( outfunc = reffunc ))); static assert(!is(typeof( outfunc = lazyfunc ))); static assert(!is(typeof( reffunc = infunc ))); static assert(!is(typeof( reffunc = outfunc ))); static assert(!is(typeof( reffunc = lazyfunc ))); static assert(!is(typeof( lazyfunc = infunc ))); static assert(!is(typeof( lazyfunc = outfunc ))); static assert(!is(typeof( lazyfunc = reffunc ))); // Test class covariance A delegate() afunc; B delegate() bfunc; static assert( is(typeof( afunc = bfunc ))); static assert(!is(typeof( bfunc = afunc ))); // Test all the conversions at once typeof(&restrictedfunc) prestrictedfunc; typeof(&relaxedfunc) prelaxedfunc = prestrictedfunc; } void bug3268() { auto a = &bug3268; const b = a; assert(a == a); assert(a == b); assert(b == b); immutable c = cast(immutable)a; assert(a == c); assert(b == c); assert(c == c); static assert(is(typeof(*a) == typeof(*b))); static assert(is(typeof(*a) == typeof(*c))); } void bug3268dg() { void bug3268x() {} auto a = &bug3268x; const b = a; assert(a == a); assert(a == b); assert(b == b); immutable c = cast(immutable)a; assert(a == c); assert(b == c); assert(c == c); } void bug3833() { bool b; void function() func; void function() pure purefunc; void function() nothrow nothrowfunc; void function() @safe safefunc; void function() @trusted trustedfunc; static assert( is(typeof( b ? func : purefunc ) == typeof( func ))); static assert( is(typeof( b ? func : nothrowfunc ) == typeof( func ))); static assert( is(typeof( b ? func : safefunc ) == typeof( func ))); static assert( is(typeof( b ? func : trustedfunc ) == typeof( func ))); static assert( is(typeof( b ? purefunc : nothrowfunc ) == typeof( func ))); static assert( is(typeof( b ? purefunc : safefunc ) == typeof( func ))); static assert( is(typeof( b ? purefunc : trustedfunc ) == typeof( func ))); static assert( is(typeof( b ? nothrowfunc : safefunc ) == typeof( func ))); static assert( is(typeof( b ? nothrowfunc : trustedfunc ) == typeof( func ))); static assert( is(typeof( b ? safefunc : trustedfunc ) == typeof( trustedfunc ))); auto arr = [func, purefunc, nothrowfunc, safefunc, trustedfunc]; static assert( is(typeof( arr ) == typeof(func)[]) ); } void bug3833dg() { bool b; void delegate() func; void delegate() pure purefunc; void delegate() nothrow nothrowfunc; void delegate() @safe safefunc; void delegate() @trusted trustedfunc; static assert( is(typeof( b ? func : purefunc ) == typeof( func ))); static assert( is(typeof( b ? func : nothrowfunc ) == typeof( func ))); static assert( is(typeof( b ? func : safefunc ) == typeof( func ))); static assert( is(typeof( b ? func : trustedfunc ) == typeof( func ))); static assert( is(typeof( b ? purefunc : nothrowfunc ) == typeof( func ))); static assert( is(typeof( b ? purefunc : safefunc ) == typeof( func ))); static assert( is(typeof( b ? purefunc : trustedfunc ) == typeof( func ))); static assert( is(typeof( b ? nothrowfunc : safefunc ) == typeof( func ))); static assert( is(typeof( b ? nothrowfunc : trustedfunc ) == typeof( func ))); static assert( is(typeof( b ? safefunc : trustedfunc ) == typeof( trustedfunc ))); auto arr = [func, purefunc, nothrowfunc, safefunc, trustedfunc]; static assert( is(typeof( arr ) == typeof(func)[]) ); } void bug4838() { void delegate() const dgc; static assert(typeof(dgc).stringof == "void delegate() const"); void delegate() immutable dgi; static assert(typeof(dgi).stringof == "void delegate() immutable"); void delegate() shared dgs; static assert(typeof(dgs).stringof == "void delegate() shared"); void delegate() shared const dgsc; static assert(typeof(dgsc).stringof == "void delegate() shared const"); void delegate() inout dgw; static assert(typeof(dgw).stringof == "void delegate() inout"); void delegate() shared inout dgsw; static assert(typeof(dgsw).stringof == "void delegate() shared inout"); } void test8822() { struct S { void foo() const {} } S s; void delegate() const dg = &s.foo; // OK void foo(void delegate() const dg){} // OK struct Foo(T) {} alias Foo!(void delegate() const) X; // NG -> OK } void main() { static assert(is(typeof(&main) P : U*, U)); auto x = cast(void*)&main; const void * p = &main; __gshared void function() gp = null; __gshared void delegate() gp2 = null; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test1537.d0000644000175000017500000000345013200164641023355 0ustar matthiasmatthias// 1537 void foo(char[] s) { int x = -1; while (s.length) { char c = s[0]; if (c == '}') break; assert (c >= '0' && c <= '9', s[0..$]); if (x == -1) x = 0; } } /**************************************/ enum bug4732 = 42; static assert( __traits(identifier, bug4732) == "bug4732"); /**************************************/ template Compileable(int z) { bool OK=true;} int bug5245a(U)() { { enum T { a = 5 } T v; } { enum T { a = 6 } T w; } return 91; } int bug5245b(U)() { { struct T { int a = 2; } T v; } { union T { int a = 3; } T w; } return 91; } int bug5245c(U)() { { struct T { int a = 2; } T v; } { class T { int a = 3; } T w; } return 91; } int bug5245d(U)() { { enum T { a = 3 } T w; } { struct T { int a = 2; } T v; } return 91; } static assert(!is(typeof(Compileable!(bug5245a!(int)()).OK))); static assert(!is(typeof(Compileable!(bug5245b!(int)()).OK))); static assert(!is(typeof(Compileable!(bug5245c!(int)()).OK))); static assert(!is(typeof(Compileable!(bug5245d!(int)()).OK))); /**************************************/ class Bug5349(T) // segfault D2.051 { int x; static int g() { class B { int inner() { return x; // should not compile } } return (new B).inner(); } int y = g(); } static assert(!is(typeof(Bug5349!(int)))); /**************************************/ class Bug4033 {} class Template4033(T) { static assert(is(T : Bug4033)); } alias Template4033!(Z4033) Bla; class Z4033 : Bug4033 { } /**************************************/ struct Bug4322 { int[1] a = void; } void bug4322() { Bug4322 f = Bug4322(); Bug4322 g = Bug4322.init; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9676a.d0000644000175000017500000000035113200164641023461 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_SOURCES: /extra-files/ddoc9676a.ddoc // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9676a module ddoc9676a; /// deprecated void foo() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/interpret3.d0000644000175000017500000044573613200164641024176 0ustar matthiasmatthias// PERMUTE_ARGS: -inline template compiles(int T) { bool compiles = true; } alias TypeTuple(T...) = T; /************************************************** 3901 Arbitrary struct assignment, ref return **************************************************/ struct ArrayRet { int x; } int arrayRetTest(int z) { ArrayRet[6] w; int q = (w[3].x = z); return q; } static assert(arrayRetTest(51) == 51); // Bugzilla 3842 -- must not segfault int ice3842(int z) { ArrayRet w; return arrayRetTest((*(&w)).x); } static assert(true || is(typeof(compiles!(ice3842(51))))); int arrayret2() { int[5] a; int[3] b; b[] = a[1 .. $-1] = 5; return b[1]; } static assert(arrayret2() == 5); struct DotVarTest { ArrayRet z; } struct DotVarTest2 { ArrayRet z; DotVarTest p; } int dotvar1() { DotVarTest w; w.z.x = 3; return w.z.x; } static assert(dotvar1() == 3); int dotvar2() { DotVarTest2[4] m; m[2].z.x = 3; m[1].p.z.x = 5; return m[2].z.x + 7; } static assert(dotvar2() == 10); struct RetRefStruct { int x; char c; } // Return value reference tests, for D2 only. ref RetRefStruct reffunc1(ref RetRefStruct a) { int y = a.x; return a; } ref RetRefStruct reffunc2(ref RetRefStruct a) { RetRefStruct z = a; return reffunc1(a); } ref int reffunc7(ref RetRefStruct aa) { return reffunc1(aa).x; } ref int reffunc3(ref int a) { return a; } struct RefTestStruct { RetRefStruct r; ref RefTestStruct reffunc4(ref RetRefStruct[3] a) { return this; } ref int reffunc6() { return this.r.x; } } ref RetRefStruct reffunc5(ref RetRefStruct[3] a) { int t = 1; for (int i = 0; i < 10; ++i) { if (i == 7) ++t; } return a[reffunc3(t)]; } int retRefTest1() { RetRefStruct b = RetRefStruct(0, 'a'); reffunc1(b).x = 3; return b.x - 1; } int retRefTest2() { RetRefStruct b = RetRefStruct(0, 'a'); reffunc2(b).x = 3; RetRefStruct[3] z; RefTestStruct w; w.reffunc4(z).reffunc4(z).r.x = 4; assert(w.r.x == 4); w.reffunc6() = 218; assert(w.r.x == 218); z[2].x = 3; int q = 4; int u = reffunc5(z).x + reffunc3(q); assert(u == 7); reffunc5(z).x += 7; assert(z[2].x == 10); RetRefStruct m = RetRefStruct(7, 'c'); m.x = 6; reffunc7(m) += 3; assert(m.x == 9); return b.x - 1; } int retRefTest3() { RetRefStruct b = RetRefStruct(0, 'a'); auto deleg = function (RetRefStruct a){ return a; }; typeof(deleg)[3] z; z[] = deleg; auto y = deleg(b).x + 27; b.x = 5; assert(y == 27); y = z[1](b).x + 22; return y - 1; } int retRefTest4() { RetRefStruct b = RetRefStruct(0, 'a'); reffunc3(b.x) = 218; assert(b.x == 218); return b.x; } static assert(retRefTest1() == 2); static assert(retRefTest2() == 2); static assert(retRefTest3() == 26); static assert(retRefTest4() == 218); /************************************************** Bug 7887 assign to returned reference **************************************************/ bool test7887() { ref int f(ref int x) { return x; } int a; f(a) = 42; return (a == 42); } static assert(test7887()); /************************************************** Bug 7473 struct non-ref **************************************************/ struct S7473 { int i; } static assert({ S7473 s = S7473(1); assert(s.i == 1); bug7473(s); assert(s.i == 1); return true; }()); void bug7473(S7473 s) { s.i = 2; } struct S7473b { S7473 m; } static assert({ S7473b s = S7473b(S7473(7)); assert(s.m.i == 7); bug7473b(s); assert(s.m.i == 7); return true; }()); void bug7473b(S7473b s) { s.m.i = 2; } /************************************************** Bug 4389 **************************************************/ int bug4389() { string s; dchar c = '\u2348'; s ~= c; assert(s.length == 3); dchar d = 'D'; s ~= d; assert(s.length == 4); s = ""; s ~= c; assert(s.length == 3); s ~= d; assert(s.length == 4); string z; wchar w = '\u0300'; z ~= w; assert(z.length == 2); z = ""; z ~= w; assert(z.length == 2); return 1; } static assert(bug4389()); // ICE(constfold.c) int ice4389() { string s; dchar c = '\u2348'; s ~= c; s = s ~ "xxx"; return 1; } static assert(ice4389()); // ICE(expression.c) string ice4390() { string s; dchar c = '`'; s ~= c; s ~= c; return s; } static assert(mixin(ice4390()) == ``); // bug 5248 (D1 + D2) struct Leaf5248 { string Compile_not_ovloaded() { return "expression"; } } struct Matrix5248 { Leaf5248 Right; string Compile() { return Right.Compile_not_ovloaded(); } }; static assert(Matrix5248().Compile()); /************************************************** 4837 >>>= **************************************************/ bool bug4837() { ushort x = 0x89AB; x >>>= 4; assert(x == 0x89A); byte y = 0x7C; y >>>= 2; assert(y == 0x1F); return true; } static assert(bug4837()); /************************************************** 10252 shift out of range **************************************************/ int lshr10252(int shift) { int a = 5; return a << shift; } int rshr10252(int shift) { int a = 5; return a >> shift; } int ushr10252(int shift) { int a = 5; return a >>> shift; } static assert( is(typeof(compiles!(lshr10252( 4))))); static assert(!is(typeof(compiles!(lshr10252(60))))); static assert( is(typeof(compiles!(rshr10252( 4))))); static assert(!is(typeof(compiles!(rshr10252(80))))); static assert( is(typeof(compiles!(ushr10252( 2))))); static assert(!is(typeof(compiles!(ushr10252(60))))); /************************************************** 1982 CTFE null problems **************************************************/ enum a1982 = [1, 2, 3]; static assert(a1982 !is null); string foo1982() { return null; } static assert(foo1982() is null); static assert(!foo1982().length); static assert(null is null); /************************************************** 7988 CTFE return values should be allowed in compile-time expressions **************************************************/ class X7988 { int y; this() { y = 2; } } static assert((new X7988).y == 2); /************************************************** 8253 ICE: calling of member function of non-CTFE class variable **************************************************/ class Bug8253 { bool j() { return true; } } Bug8253 m8253; static assert(!is(typeof(compiles!(m8253.j())))); /************************************************** 8285 Issue with slice returned from CTFE function **************************************************/ string foo8285() { string s = "ab"; return s[0 .. $]; } template T8285b(string s) { } template T8285a() { enum s = foo8285(); alias T8285b!(s) t2; } int bar8285() { alias T8285a!() t1; return 0; } int baz8285(int x) { return 0; } static assert(baz8285(bar8285()) == 0); // test case 2 string xbar8285() { string s = "ab"; return s[0 .. $]; } template xT8285a() { enum xT8285a = xbar8285()[0 .. $]; } string xbaz8285() { return xT8285a!(); } string xfoo8285(string s) { return s; } static assert(xfoo8285(xbaz8285()) == "ab"); /************************************************** 'this' parameter bug revealed during refactoring **************************************************/ int thisbug1(int x) { return x; } struct ThisBug1 { int m = 1; int wut() { return thisbug1(m); } } int thisbug2() { ThisBug1 spec; return spec.wut(); } static assert(thisbug2()); /************************************************** 6972 ICE with cast()cast()assign **************************************************/ int bug6972() { ubyte n = 6; n /= 2u; return n; } static assert(bug6972() == 3); /************************************************** Bug 6164 **************************************************/ size_t bug6164() { int[] ctfe2(int n) { int[] r = []; if (n != 0) r ~= [1] ~ ctfe2(n - 1); return r; } return ctfe2(2).length; } static assert(bug6164() == 2); /************************************************** Interpreter code coverage tests **************************************************/ int cov1(int a) { a %= 15382; a /= 5; a = ~ a; bool c = (a == 0); bool b = true && c; assert(b == 0); b = false && c; assert(b == 0); b = false || c; assert(b == 0); a ^= 0x45349; a = ~ a; a &= 0xFF3F; a >>>= 1; a = a ^ 0x7393; a = a >> 1; a = a >>> 1; a = a | 0x010101; return a; } static assert(cov1(534564) == 71589); int cov2() { int i = 0; do { goto DOLABEL; DOLABEL: if (i != 0) { goto IFLABEL; IFLABEL: switch(i) { case 3: break; case 6: goto SWITCHLABEL; SWITCHLABEL: i = 27; goto case 3; default: assert(0); } return i; } i = 6; } while(true); return 88; // unreachable } static assert(cov2() == 27); template CovTuple(T...) { alias T CovTuple; } alias CovTuple!(int, long) TCov3; int cov3(TCov3 t) { TCov3 s; s = t; assert(s[0] == 1); assert(s[1] == 2); return 7; } static assert(cov3(1, 2) == 7); int badassert1(int z) { assert(z == 5, "xyz"); return 1; } size_t badslice1(int[] z) { return z[0 .. 3].length; } size_t badslice2(int[] z) { return z[0 .. badassert1(1)].length; } size_t badslice3(int[] z) { return z[badassert1(1) .. 2].length; } static assert(!is(typeof(compiles!(badassert1(67))))); static assert( is(typeof(compiles!(badassert1(5))))); static assert(!is(typeof(compiles!(badslice1([1,2]))))); static assert(!is(typeof(compiles!(badslice2([1,2]))))); static assert(!is(typeof(compiles!(badslice3([1,2,3]))))); /*******************************************/ int bug7894() { for (int k = 0; k < 2; ++k) { goto Lagain; Lagain: ; } int m = 1; do { ++m; goto Ldo; Ldo: ; } while (m < 3); assert(m == 3); return 1; } static assert(bug7894()); /*******************************************/ size_t bug5524(int x, int[] more...) { int[0] zz; assert(zz.length == 0); return 7 + more.length + x; } static assert(bug5524(3) == 10); // 5722 static assert(("" ~ "\©"[0]).length == 1); const char[] null5722 = null; static assert((null5722 ~ "\©"[0]).length == 1); static assert(("\©"[0] ~ null5722).length == 1); /******************************************* * Tests for CTFE Array support. * Including bugs 1330, 3801, 3835, 4050, * 4051, 5147, and major functionality *******************************************/ char[] bug1330StringIndex() { char[] blah = "foo".dup; assert(blah == "foo"); char[] s = blah[0 .. 2]; blah[0] = 'h'; assert(s == "ho"); s[0] = 'm'; return blah; } static assert(bug1330StringIndex() == "moo"); static assert(bug1330StringIndex() == "moo"); // check we haven't clobbered any string literals int[] bug1330ArrayIndex() { int[] blah = [1,2,3]; int[] s = blah; s = blah[0 .. 2]; int z = blah[0] = 6; assert(z == 6); assert(blah[0] == 6); assert(s[0] == 6); assert(s == [6, 2]); s[1] = 4; assert(z == 6); return blah; } static assert(bug1330ArrayIndex() == [6, 4, 3]); static assert(bug1330ArrayIndex() == [6, 4, 3]); // check we haven't clobbered any literals char[] bug1330StringSliceAssign() { char[] blah = "food".dup; assert(blah == "food"); char[] s = blah[1 .. 4]; blah[0 .. 2] = "hc"; assert(s == "cod"); s[0 .. 2] = ['a', 'b']; // Mix string + array literal assert(blah == "habd"); s[0 .. 2] = "mq"; return blah; } static assert(bug1330StringSliceAssign() == "hmqd"); static assert(bug1330StringSliceAssign() == "hmqd"); int[] bug1330ArraySliceAssign() { int[] blah = [1, 2, 3, 4]; int[] s = blah[1 .. 4]; blah[0 .. 2] = [7, 9]; assert(s == [9, 3, 4]); s[0 .. 2] = [8, 15]; return blah; } static assert(bug1330ArraySliceAssign() == [7, 8, 15, 4]); int[] bug1330ArrayBlockAssign() { int[] blah = [1, 2, 3, 4, 5]; int[] s = blah[1 .. 4]; blah[0 .. 2] = 17; assert(s == [17, 3, 4]); s[0 .. 2] = 9; return blah; } static assert(bug1330ArrayBlockAssign() == [17, 9, 9, 4, 5]); char[] bug1330StringBlockAssign() { char[] blah = "abcde".dup; char[] s = blah[1 .. 4]; blah[0 .. 2] = 'x'; assert(s == "xcd"); s[0 .. 2] = 'y'; return blah; } static assert(bug1330StringBlockAssign() == "xyyde"); int assignAA(int x) { int[int] aa; int[int] cc = aa; assert(cc.values.length == 0); assert(cc.keys.length == 0); aa[1] = 2; aa[x] = 6; int[int] bb = aa; assert(bb.keys.length == 2); assert(cc.keys.length == 0); // cc is not affected to aa, because it is null aa[500] = 65; assert(bb.keys.length == 3); // but bb is affected by changes to aa return aa[1] + aa[x]; } static assert(assignAA(12) == 8); template Compileable(int z) { bool OK; } int arraybounds(int j, int k) { int[] xxx = [1, 2, 3, 4, 5]; int[] s = xxx[1 .. $]; s = s[j .. k]; // slice of slice return s[$ - 1]; } static assert(!is(typeof(Compileable!(arraybounds(1, 14))))); static assert(!is(typeof(Compileable!(arraybounds(15, 3))))); static assert(arraybounds(2, 4) == 5); int arraybounds2(int j, int k) { int[] xxx = [1, 2, 3, 4, 5]; int[] s = xxx[j .. k]; // direct slice return 1; } static assert(!is(typeof(Compileable!(arraybounds2(1, 14))))); static assert(!is(typeof(Compileable!(arraybounds2(15, 3))))); static assert(arraybounds2(2, 4) == 1); int bug5147a() { int[1][2] a = 37; return a[0][0]; } static assert(bug5147a() == 37); int bug5147b() { int[4][2][3][17] a = 37; return a[0][0][0][0]; } static assert(bug5147b() == 37); int setlen() { int[][] zzz; zzz.length = 2; zzz[0].length = 10; assert(zzz.length == 2); assert(zzz[0].length == 10); assert(zzz[1].length == 0); return 2; } static assert(setlen() == 2); int[1][1] bug5147() { int[1][1] a = 1; return a; } static assert(bug5147() == [[1]]); enum int[1][1] enum5147 = bug5147(); static assert(enum5147 == [[1]]); immutable int[1][1] bug5147imm = bug5147(); // Index referencing int[2][2] indexref1() { int[2][2] a = 2; a[0] = 7; int[][] b = [null, null]; b[0 .. $] = a[0][0 .. 2]; assert(b[0][0] == 7); assert(b[0][1] == 7); int[] w; w = a[0]; assert(w[0] == 7); w[0 .. $] = 5; assert(a[0] != [7, 7]); assert(a[0] == [5, 5]); assert(b[0] == [5, 5]); return a; } int[2][2] indexref2() { int[2][2] a = 2; a[0] = 7; int[][2] b = null; b[0 .. $] = a[0]; assert(b[0][0] == 7); assert(b[0][1] == 7); assert(b == [[7, 7], [7, 7]]); int[] w; w = a[0]; assert(w[0] == 7); w[0 .. $] = 5; assert(a[0] != [7, 7]); assert(a[0] == [5, 5]); assert(b[0] == [5, 5]); return a; } int[2][2] indexref3() { int[2][2] a = 2; a[0]=7; int[][2] b = [null, null]; b[0 .. $] = a[0]; assert(b[0][0] == 7); assert(b[0][1] == 7); int[] w; w = a[0]; assert(w[0] == 7); w[0 .. $] = 5; assert(a[0] != [7, 7]); assert(a[0] == [5, 5]); assert(b[0] == [5, 5]); return a; } int[2][2] indexref4() { int[2][2] a = 2; a[0] = 7; int[][2] b =[[1, 2, 3], [1, 2, 3]]; // wrong code b[0] = a[0]; assert(b[0][0] == 7); assert(b[0][1] == 7); int[] w; w = a[0]; //[0 .. $]; assert(w[0] == 7); w[0 .. $] = 5; assert(a[0] != [7, 7]); assert(a[0] == [5, 5]); assert(b[0] == [5, 5]); return a; } static assert(indexref1() == [[5, 5], [2, 2]]); static assert(indexref2() == [[5, 5], [2, 2]]); static assert(indexref3() == [[5, 5], [2, 2]]); static assert(indexref4() == [[5, 5], [2, 2]]); int staticdynamic() { int[2][1] a = 2; assert(a == [[2, 2]]); int[][1] b = a[0][0 .. 1]; assert(b[0] == [2]); auto k = b[0]; auto m = a[0][0 .. 1]; assert(k == [2]); assert(m == k); return 0; } static assert(staticdynamic() == 0); int[] crashing() { int[12] cra; return (cra[2 .. $] = 3); } static assert(crashing()[9] == 3); int chainassign() { int[4] x = 6; int[] y = new int[4]; auto k = (y[] = (x[] = 2)); return k[0]; } static assert(chainassign() == 2); // index assignment struct S3801 { char c; int[3] arr; this(int x, int y) { c = 'x'; arr[0] = x; arr[1] = y; } } int bug3801() { S3801 xxx = S3801(17, 67); int[] w = xxx.arr; xxx.arr[1] = 89; assert(xxx.arr[0] == 17); assert(w[1] == 89); assert(w == [17, 89, 0]); return xxx.arr[1]; } enum : S3801 { bug3801e = S3801(17, 18) } static assert(bug3801e.arr == [17, 18, 0]); immutable S3801 bug3801u = S3801(17, 18); static assert(bug3801u.arr == [17, 18, 0]); static assert(bug3801() == 89); int bug3835() { int[4] arr; arr[] = 19; arr[0] = 4; int kk; foreach (ref el; arr) { el += 10; kk = el; } assert(arr[2] == 29); arr[0] += 3; return arr[0]; } static assert(bug3835() == 17); auto bug5852(const(string) s) { string[] r; r ~= s; assert(r.length == 1); return r[0].length; } static assert(bug5852("abc") == 3); // 7217 struct S7217 { int[] arr; } bool f7217() { auto s = S7217(); auto t = s.arr; return true; } static assert(f7217()); /******************************************* Set array length *******************************************/ static assert( { struct W { int[] z; } W w; w.z.length = 2; assert(w.z.length == 2); w.z.length = 6; assert(w.z.length == 6); return true; }()); // 7185 char[].length = n bool bug7185() { auto arr = new char[2]; auto arr2 = new char[2]; arr2[] = "ab"; arr.length = 1; arr2.length = 7; assert(arr.length == 1); assert(arr2.length == 7); assert(arr2[0 .. 2] == "ab"); return true; } static assert(bug7185()); bool bug9908() { static const int[3] sa = 1; return sa == [1, 1, 1]; } static assert(bug9908()); /******************************************* 6934 *******************************************/ struct Struct6934 { int[] x = [1, 2]; } void bar6934(ref int[] p) { p[0] = 12; assert(p[0] == 12); p[0 .. 1] = 17; assert(p[0] == 17); p = p[1 .. $]; } int bug6934() { Struct6934 q; bar6934(q.x); int[][] y = [[2, 5], [3, 6, 8]]; bar6934(y[0]); return 1; } static assert(bug6934()); /******************************************* Bug 5671 *******************************************/ static assert(['a', 'b'] ~ "c" == "abc"); /******************************************* 8624 *******************************************/ int evil8624() { long m = 0x1_0000_0000L; assert(m != 0); long[] a = [0x1_0000_0000L]; long[] b = [0x4_0000_0000L]; assert(a[] != b[]); return 1; } static assert(evil8624()); /******************************************* 8644 array literal >,< *******************************************/ int bug8644() { auto m = "a"; auto z = ['b']; auto c = "b7"; auto d = ['b', '6']; assert(m < z); assert(z > m); assert(z <= c); assert(c > z); assert(c > d); assert(d >= d); return true; } static assert(bug8644()); /******************************************* Bug 6159 *******************************************/ struct A6159 {} static assert({ return A6159.init is A6159.init; }()); static assert({ return [1] is [1]; }()); /******************************************* Bug 5685 *******************************************/ string bug5685() { return "xxx"; } struct Bug5865 { void test1() { enum file2 = (bug5685())[0 .. $]; } } /******************************************* 6235 - Regression ICE on $ in template *******************************************/ struct Bug6235(R) { enum XXX = is(typeof(R.init[0 .. $]) : const ubyte[]); } Bug6235!(ubyte[]) bug6235; /******************************************* 8673 ICE *******************************************/ enum dollar8673 = [0][(() => $ - 1)()]; /******************************************* Bug 5840 *******************************************/ struct Bug5840 { string g; int w; } int bug5840(int u) { // check for clobbering Bug5840 x = void; x.w = 4; x.g = "3gs"; if (u == 1) bug5840(2); if (u == 2) { x.g = "abc"; x.w = 3465; } else { assert(x.g == "3gs"); assert(x.w == 4); } return 56; } static assert(bug5840(1) == 56); /******************************************* 7810 *******************************************/ int bug7810() { int[1][3] x = void; x[0] = [2]; x[1] = [7]; assert(x[0][0] == 2); char[1][3] y = void; y[0] = "a"; y[1] = "b"; assert(y[0][0] == 'a'); return 1; } static assert(bug7810()); struct Bug7810 { int w; } int bug7810b(T)(T[] items...) { assert(items[0] == Bug7810(20)); return 42; } static assert(bug7810b(Bug7810(20), Bug7810(10)) == 42); /******************************************* std.datetime ICE (30 April 2011) *******************************************/ struct TimeOfDayZ { public: this(int hour) { } invariant() { } } const testTODsThrownZ = TimeOfDayZ(0); /******************************************* Bug 5954 *******************************************/ struct Bug5954 { int x; this(int xx) { this.x = xx; } } void bug5954() { enum f = Bug5954(10); static assert(f.x == 10); } /******************************************* Bug 5972 *******************************************/ int bug5972() { char[] z = "abc".dup; char[][] a = [null, null]; a[0] = z[0 .. 2]; char[] b = a[0]; assert(b == "ab"); a[0][1] = 'q'; assert(a[0] == "aq"); assert(b == "aq"); assert(b[1] == 'q'); //a[0][0 .. $ - 1][0 .. $] = a[0][0 .. $ - 1][0 .. $]; // overlap return 56; } static assert(bug5972() == 56); /******************************************* 2.053beta [CTFE]ICE 'global errors' *******************************************/ int wconcat(wstring replace) { wstring value; value = "A"w; value = value ~ replace; return 1; } static assert(wconcat("X"w)); /******************************************* 10397 string concat *******************************************/ static assert(!is(typeof(compiles!("abc" ~ undefined)))); static assert(!is(typeof(compiles!(otherundefined ~ "abc")))); /******************************************* 9634 struct concat *******************************************/ struct Bug9634 { int raw; } bool bug9634() { Bug9634[] jr = [Bug9634(42)]; Bug9634[] ir = null ~ jr; Bug9634[] kr = jr ~ null; Bug9634[] mr = jr ~ jr; jr[0].raw = 6; assert(ir[0].raw == 42); assert(kr[0].raw == 42); assert(jr[0].raw == 6); assert(&mr[0] != &mr[1]); return true; } static assert(bug9634()); /******************************************* Bug 4001: A Space Oddity *******************************************/ int space() { return 4001; } void oddity4001(int q) { const int bowie = space(); static assert(space() == 4001); static assert(bowie == 4001); } /******************************************* Bug 3779 *******************************************/ static const bug3779 = ["123"][0][$ - 1]; /******************************************* Bug 8893 ICE with bad struct literal *******************************************/ struct Foo8893 { char[3] data; } int bar8893(Foo8893 f) { return f.data[0]; } static assert(!is(typeof(compiles!(bar8893(Foo8893(['a','b'])))))); /******************************************* non-Cow struct literals *******************************************/ struct Zadok { int[3] z; char[4] s = void; ref int[] fog(ref int[] q) { return q; } int bfg() { z[0] = 56; auto zs = z[]; fog(zs) = [56, 6, 8]; assert(z[0] == 56); assert(z[1] == 61); assert(z[2] == 61); assert(zs[0] == 56); assert(zs[1] == 6); return zs[2]; } } struct Vug { Zadok p; int[] other; } int quop() { int[] heap = new int[5]; heap[] = 738; Zadok pong; pong.z = 3; int[] w = pong.z; assert(w[0] == 3); Zadok phong; phong.z = 61; pong = phong; assert(w[0] == 61); Vug b = Vug(Zadok(17, "abcd")); b = Vug(Zadok(17, "abcd"), heap); b.other[2] = 78; assert(heap[2] == 78); char[] y = b.p.s; assert(y[2] == 'c'); phong.s = ['z','x','f', 'g']; w = b.p.z; assert(y[2] == 'c'); assert(w[0] == 17); b.p = phong; assert(y[2] == 'f'); Zadok wok = Zadok(6, "xyzw"); b.p = wok; assert(y[2] == 'z'); b.p = phong; assert(w[0] == 61); Vug q; q.p = pong; return pong.bfg(); } static assert(quop() == 8); static assert(quop() == 8); // check for clobbering /************************************************** Bug 5676 tuple assign of struct that has void opAssign **************************************************/ struct S5676 { int x; void opAssign(S5676 rhs) { x = rhs.x; } } struct Tup5676(E...) { E g; void foo(E values) { g = values; } } bool ice5676() { Tup5676!(S5676) q; q.foo(S5676(3)); assert(q.g[0].x == 3); return true; } static assert(ice5676()); /************************************************** Bug 5682 Wrong CTFE with operator overloading **************************************************/ struct A { int n; auto opBinary(string op : "*")(A rhs) { return A(n * rhs.n); } } A foo(A[] lhs, A[] rhs) { A current; for (size_t k = 0; k < rhs.length; ++k) { current = lhs[k] * rhs[k]; } return current; } auto test() { return foo([A(1), A(2)], [A(3), A(4)]); } static assert(test().n == 8); /************************************************** Attempt to modify a read-only string literal **************************************************/ struct Xarg { char[] s; } int zfs(int n) { char[] m = "exy".dup; if (n == 1) { // it's OK to cast to const, then cast back string ss = cast(string)m; m = cast(char[])ss; m[2]='q'; return 56; } auto q = Xarg(cast(char[])"abc"); assert(q.s[1] == 'b'); if (n == 2) q.s[1] = 'p'; else if (n == 3) q.s[0 .. $] = 'p'; char* w = &q.s[2]; if (n == 4) *w = 'z'; return 76; } static assert(!is(typeof(compiles!(zfs(2))))); static assert(!is(typeof(compiles!(zfs(3))))); static assert(!is(typeof(compiles!(zfs(4))))); static assert( is(typeof(compiles!(zfs(1))))); static assert( is(typeof(compiles!(zfs(5))))); /************************************************** .dup must protect string literals **************************************************/ string mutateTheImmutable(immutable string _s) { char[] s = _s.dup; foreach (ref c; s) c = 'x'; return s.idup; } string doharm(immutable string _name) { return mutateTheImmutable(_name[2 .. $].idup); } enum victimLiteral = "CL_INVALID_CONTEXT"; enum thug = doharm(victimLiteral); static assert(victimLiteral == "CL_INVALID_CONTEXT"); /************************************************** Use $ in a slice of a dotvar slice **************************************************/ int sliceDollar() { Xarg z; z.s = new char[20]; z.s[] = 'b'; z.s = z.s[2 .. $ - 2]; z.s[$ - 2] = 'c'; return z.s[$ - 2]; } static assert(sliceDollar() == 'c'); /************************************************** Variation of 5972 which caused segfault **************************************************/ int bug5972crash() { char[] z = "abc".dup; char[][] a = [null, null]; a[0] = z[0 .. 2]; a[0][1] = 'q'; return 56; } static assert(bug5972crash() == 56); /************************************************** String slice assignment through ref parameter **************************************************/ void popft(A)(ref A a) { a = a[1 .. $]; } int sdfgasf() { auto scp = "abc".dup; popft(scp); return 1; } static assert(sdfgasf() == 1); /************************************************** 8830 slice of slice.ptr **************************************************/ string bug8830(string s) { auto ss = s[1 .. $]; return ss.ptr[0 .. 2]; } static assert(bug8830("hello") == "el"); /************************************************** 8608 ICE **************************************************/ void bug8608(ref int m) {} void test8608() { int z; int foo(bool b) { if (b) bug8608(z); return 1; } static assert( is(typeof(compiles!(foo(false))))); static assert(!is(typeof(compiles!(foo(true) )))); } /************************************************** Bug 7770 **************************************************/ immutable char[] foo7770 = "abcde"; int bug7770a(string a) { return 1; } bool bug7770b(char c) { return true; } static assert(bug7770a(foo7770[0 .. $])); static assert(bug7770b(foo7770[$ - 2])); void baz7770() { static assert(bug7770a(foo7770[0 .. $])); static assert(bug7770b(foo7770[$ - 2])); } /************************************************** 8601 ICE **************************************************/ dchar bug8601(dstring s) { dstring w = s[1 .. $]; return w[0]; } enum dstring e8601 = [cast(dchar)'o', 'n']; static assert(bug8601(e8601) == 'n'); /************************************************** Bug 6015 **************************************************/ struct Foo6015 { string field; } bool func6015(string input) { Foo6015 foo; foo.field = input[0 .. $]; assert(foo.field == "test"); foo.field = "test2"; assert(foo.field != "test"); assert(foo.field == "test2"); return true; } static assert(func6015("test")); /************************************************** Bug 6001 **************************************************/ void bug6001e(ref int[] s) { int[] r = s; s ~= 0; } bool bug6001f() { int[] s; bug6001e(s); return true; } static assert(bug6001f()); // Assignment to AAs void blah(int[char] as) { auto k = [6: as]; as = k[6]; } int blaz() { int[char] q; blah(q); return 67; } static assert(blaz() == 67); void bug6001g(ref int[] w) { w = [88]; bug6001e(w); w[0] = 23; } bool bug6001h() { int[] s; bug6001g(s); assert(s.length == 2); assert(s[1] == 0); assert(s[0] == 23); return true; } static assert(bug6001h()); /************************************************** 10243 wrong code *&arr as ref parameter 10551 wrong code (&arr)[0] as ref parameter **************************************************/ void bug10243(ref int n) { n = 3; } void bug10551(int* p) { bug10243(p[0]); } bool test10243() { int[1] arr; bug10243(*arr.ptr); assert(arr[0] == 3); int[1] arr2; bug10551(arr2.ptr); assert(arr2[0] == 3); int v; bug10551(&v); assert(v == 3); return true; } static assert(test10243()); /************************************************** Bug 4910 **************************************************/ int bug4910(int a) { return a; } static int var4910; static assert(!is(typeof(Compiles!(bug4910(var4910))))); static assert(bug4910(123)); /************************************************** Bug 5845 - Regression(2.041) **************************************************/ void test5845(ulong cols) {} uint solve(bool niv, ref ulong cols) { if (niv) solve(false, cols); else test5845(cols); return 65; } ulong nqueen(int n) { ulong cols = 0; return solve(true, cols); } static assert(nqueen(2) == 65); /************************************************** Bug 5258 **************************************************/ struct Foo5258 { int x; } void bar5258(int n, ref Foo5258 fong) { if (n) bar5258(n - 1, fong); else fong.x++; } int bug5258() { Foo5258 foo5258 = Foo5258(); bar5258(1, foo5258); return 45; } static assert(bug5258() == 45); struct Foo5258b { int[2] r; } void baqopY(int n, ref int[2] fongo) { if (n) baqopY(n - 1, fongo); else fongo[0]++; } int bug5258b() { Foo5258b qq; baqopY(1, qq.r); return 618; } static assert(bug5258b() == 618); // Notice that this case involving reassigning the dynamic array struct Foo5258c { int[] r; } void baqop(int n, ref int[] fongo) { if (n) baqop(n - 1, fongo); else { fongo = new int[20]; fongo[0]++; } } size_t bug5258c() { Foo5258c qq; qq.r = new int[30]; baqop(1, qq.r); return qq.r.length; } static assert(bug5258c() == 20); /************************************************** Bug 6049 **************************************************/ struct Bug6049 { int m; this(int x) { m = x; } invariant() { } } const Bug6049[] foo6049 = [Bug6049(6), Bug6049(17)]; static assert(foo6049[0].m == 6); /************************************************** Bug 6052 **************************************************/ struct Bug6052 { int a; } bool bug6052() { Bug6052[2] arr; for (int i = 0; i < 2; ++ i) { Bug6052 el = {i}; Bug6052 ek = el; arr[i] = el; el.a = i + 2; assert(ek.a == i); // ok assert(arr[i].a == i); // fail } assert(arr[1].a == 1); // ok assert(arr[0].a == 0); // fail return true; } static assert(bug6052()); bool bug6052b() { int[][1] arr; int[1] z = [7]; arr[0] = z; assert(arr[0][0] == 7); arr[0] = z; z[0] = 3; assert(arr[0][0] == 3); return true; } static assert(bug6052b()); struct Bug6052c { int x; this(int a) { x = a; } } int bug6052c() { Bug6052c[] pieces = []; for (int c = 0; c < 2; ++ c) pieces ~= Bug6052c(c); assert(pieces[1].x == 1); assert(pieces[0].x == 0); return 1; } static assert(bug6052c() == 1); static assert(bug6052c() == 1); static assert({ Bug6052c[] pieces = []; pieces.length = 2; int c = 0; pieces[0] = Bug6052c(c); ++c; pieces[1] = Bug6052c(c); assert(pieces[0].x == 0); return true; }()); static assert({ int[1][] pieces = []; pieces.length = 2; for (int c = 0; c < 2; ++ c) pieces[c][0] = c; assert(pieces[1][0] == 1); assert(pieces[0][0] == 0); return true; }()); static assert({ Bug6052c[] pieces = []; for (int c = 0; c < 2; ++ c) pieces ~= Bug6052c(c); assert(pieces[1].x == 1); assert(pieces[0].x == 0); return true; }()); static assert({ int[1] z = 7; int[1][] pieces = [z,z]; pieces[1][0]=3; assert(pieces[0][0] == 7); pieces = pieces ~ [z,z]; pieces[3][0] = 16; assert(pieces[2][0] == 7); pieces = [z,z] ~ pieces; pieces[5][0] = 16; assert(pieces[4][0] == 7); return true; }()); /************************************************** Bug 6749 **************************************************/ struct CtState { string code; } CtState bug6749() { CtState[] pieces; CtState r = CtState("correct"); pieces ~= r; r = CtState("clobbered"); return pieces[0]; } static assert(bug6749().code == "correct"); /************************************************** Index + slice assign to function returns **************************************************/ int[] funcRetArr(int[] a) { return a; } int testFuncRetAssign() { int[] x = new int[20]; funcRetArr(x)[2] = 4; assert(x[2] == 4); funcRetArr(x)[] = 27; assert(x[15] == 27); return 5; } static assert(testFuncRetAssign() == 5); int keyAssign() { int[int] pieces; pieces[3] = 1; pieces.keys[0] = 4; pieces.values[0] = 27; assert(pieces[3] == 1); return 5; } static assert(keyAssign() == 5); /************************************************** Bug 6054 -- AA literals **************************************************/ enum x6054 = { auto p = { int[string] pieces; pieces[['a'].idup] = 1; return pieces; }(); return p; }(); /************************************************** Bug 6077 **************************************************/ enum bug6077 = { string s; string t; return s ~ t; }(); /************************************************** Bug 6078 -- Pass null array by ref **************************************************/ struct Foo6078 { int[] bar; } static assert({ Foo6078 f; int i; foreach (ref e; f.bar) { i += e; } return i; }() == 0); int bug6078(ref int[] z) { int[] q = z; return 2; } static assert({ Foo6078 f; return bug6078(f.bar); }() == 2); /************************************************** Bug 6079 -- Array bounds checking **************************************************/ static assert(!is(typeof(compiles!({ int[] x = [1, 2, 3, 4]; x[4] = 1; return true; }() )))); /************************************************** Bug 6100 **************************************************/ struct S6100 { int a; } S6100 init6100(int x) { S6100 s = S6100(x); return s; } static const S6100[2] s6100a = [init6100(1), init6100(2)]; static assert(s6100a[0].a == 1); /************************************************** Bug 4825 -- failed with -inline **************************************************/ int a4825() { int r; return r; } int b4825() { return a4825(); } void c4825() { void d() { auto e = b4825(); } static const int f = b4825(); } /************************************************** Bug 5708 -- failed with -inline **************************************************/ string b5708(string s) { return s; } string a5708(string s) { return b5708(s); } void bug5708() { void m() { a5708("lit"); } static assert(a5708("foo") == "foo"); static assert(a5708("bar") == "bar"); } /************************************************** Bug 6120 -- failed with -inline **************************************************/ struct Bug6120(T) { this(int x) { } } static assert({ auto s = Bug6120!int(0); return true; }()); /************************************************** Bug 6123 -- failed with -inline **************************************************/ struct Bug6123(T) { void f() {} // can also trigger if the struct is normal but f is template } static assert({ auto piece = Bug6123!int(); piece.f(); return true; }()); /************************************************** Bug 6053 -- ICE involving pointers **************************************************/ static assert({ int* a = null; assert(a is null); assert(a == null); return true; }()); static assert({ int b; int* a = &b; assert(a !is null); *a = 7; assert(b == 7); assert(*a == 7); return true; }()); int dontbreak6053() { auto q = &dontbreak6053; void caz() {} auto tr = &caz; return 5; } static assert(dontbreak6053()); static assert({ int a; *(&a) = 15; assert(a == 15); assert(*(&a) == 15); return true; }()); static assert({ int a = 5, b = 6, c = 2; assert(*(c ? &a : &b) == 5); assert(*(!c ? &a : &b) == 6); return true; }()); static assert({ int a, b, c; (c ? a : b) = 1; return true; }()); static assert({ int a, b, c = 1; int* p = &a; (c ? *p : b) = 51; assert(a == 51); return true; }()); /************************************************** Pointer arithmetic, dereference, and comparison **************************************************/ // dereference null pointer static assert(!is(typeof(compiles!({ int a, b, c = 1; int* p; (c ? *p : b) = 51; return 6; }() )))); static assert(!is(typeof(compiles!({ int* a = null; assert(*a != 6); return 72; }() )))); // cannot <, > compare pointers to different arrays static assert(!is(typeof(compiles!({ int[5] a, b; bool c = (&a[0] > &b[0]); return 72; }() )))); // can ==, is, !is, != compare pointers for different arrays static assert({ int[5] a; int[5] b; assert(!(&a[0] == &b[0])); assert(&a[0] != &b[0]); assert(!(&a[0] is &b[0])); assert(&a[0] !is &b[0]); return 72; }()); static assert({ int[5] a; a[0] = 25; a[1] = 5; int* b = &a[1]; assert(*b == 5); *b = 34; int c = *b; *b += 6; assert(b == &a[1]); assert(b != &a[0]); assert(&a[0] < &a[1]); assert(&a[0] <= &a[1]); assert(!(&a[0] >= &a[1])); assert(&a[4] > &a[0]); assert(c == 34); assert(*b == 40); assert(a[1] == 40); return true; }()); static assert({ int[12] x; int* p = &x[10]; int* q = &x[4]; return p - q; }() == 6); static assert({ int[12] x; int* p = &x[10]; int* q = &x[4]; q = p; assert(p == q); q = &x[4]; assert(p != q); q = q + 6; assert(q is p); return 6; }() == 6); static assert({ int[12] x; int[] y = x[2 .. 8]; int* p = &y[4]; int* q = &x[6]; assert(p == q); p = &y[5]; assert(p > q); p = p + 5; // OK, as long as we don't dereference assert(p > q); return 6; }() == 6); static assert({ char[12] x; const(char)* p = "abcdef"; const (char)* q = p; q = q + 2; assert(*q == 'c'); assert(q > p); assert(q - p == 2); assert(p - q == -2); q = &x[7]; p = &x[1]; assert(q>p); return 6; }() == 6); // Relations involving null pointers bool nullptrcmp() { // null tests void* null1 = null, null2 = null; int x = 2; void* p = &x; assert(null1 == null2); assert(null1 is null2); assert(null1 <= null2); assert(null1 >= null2); assert(!(null1 > null2)); assert(!(null2 > null1)); assert(null1 != p); assert(null1 !is p); assert(p != null1); assert(p !is null1); assert(null1 <= p); assert(p >= null2); assert(p > null1); assert(!(null1 > p)); return true; } static assert(nullptrcmp()); /************************************************** 10840 null pointer in dotvar **************************************************/ struct Data10840 { bool xxx; } struct Bug10840 { Data10840* _data; } bool bug10840(int n) { Bug10840 stack; if (n == 1) { // detect deref through null pointer return stack._data.xxx; } // Wrong-code for ?: return stack._data ? false : true; } static assert(bug10840(0)); static assert(!is(typeof(Compileable!(bug10840(1))))); /************************************************** 8216 ptr inside a pointer range **************************************************/ // Four-pointer relations. Return true if [p1 .. p2] points inside [q1 .. q2] // (where the end points dont coincide). bool ptr4cmp(void* p1, void* p2, void* q1, void* q2) { // Each compare can be written with <, <=, >, or >=. // Either && or || can be used, giving 32 permutations. // Additionally each compare can be negated with !, yielding 128 in total. bool b1 = (p1 > q1 && p2 <= q2); bool b2 = (p1 > q1 && p2 < q2); bool b3 = (p1 >= q1 && p2 <= q2); bool b4 = (p1 >= q1 && p2 < q2); bool b5 = (q1 <= p1 && q2 > p2); bool b6 = (q1 <= p1 && q2 >= p2); bool b7 = (p2 <= q2 && p1 > q1); bool b8 = (!(p1 <= q1) && p2 <= q2); bool b9 = (!(p1 <= q1) && !(p2 > q2)); bool b10 = (!!!(p1 <= q1) && !(p2 > q2)); assert(b1 == b2 && b1 == b3 && b1 == b4 && b1 == b5 && b1 == b6); assert(b1 == b7 && b1 == b8 && b1 == b9 && b1 == b10); bool c1 = (p1 <= q1 || p2 > q2); assert(c1 == !b1); bool c2 = (p1 < q1 || p2 >= q2); bool c3 = (!(q1 <= p1) || !(q2 >= p2)); assert(c1 == c2 && c1 == c3); return b1; } bool bug8216() { int[4] a; int[13] b; int v; int* p = &v; assert(!ptr4cmp(&a[0], &a[3], p, p)); assert(!ptr4cmp(&b[2], &b[9], &a[1], &a[2])); assert(!ptr4cmp(&b[1], &b[9], &b[2], &b[8])); assert( ptr4cmp(&b[2], &b[8], &b[1], &b[9])); return 1; } static assert(bug8216()); /************************************************** 6517 ptr++, ptr-- **************************************************/ int bug6517() { int[] arr = [1, 2, 3]; auto startp = arr.ptr; auto endp = arr.ptr + arr.length; for (; startp < endp; startp++) {} startp = arr.ptr; assert(startp++ == arr.ptr); assert(startp != arr.ptr); assert(startp-- != arr.ptr); assert(startp == arr.ptr); return 84; } static assert(bug6517() == 84); /************************************************** Out-of-bounds pointer assignment and deference **************************************************/ int ptrDeref(int ofs, bool wantDeref) { int[5] a; int* b = &a[0]; b = b + ofs; // OK if (wantDeref) return *b; // out of bounds return 72; } static assert(!is(typeof(compiles!(ptrDeref(-1, true))))); static assert( is(typeof(compiles!(ptrDeref(4, true))))); static assert( is(typeof(compiles!(ptrDeref(5, false))))); static assert(!is(typeof(compiles!(ptrDeref(5, true))))); static assert(!is(typeof(compiles!(ptrDeref(6, false))))); static assert(!is(typeof(compiles!(ptrDeref(6, true))))); /************************************************** Pointer += **************************************************/ static assert({ int[12] x; int zzz; assert(&zzz); int* p = &x[10]; int* q = &x[4]; q = p; assert(p == q); q = &x[4]; assert(p != q); q += 4; assert(q == &x[8]); q = q - 2; q = q + 4; assert(q is p); return 6; }() == 6); /************************************************** Reduced version of bug 5615 **************************************************/ const(char)[] passthrough(const(char)[] x) { return x; } sizediff_t checkPass(Char1)(const(Char1)[] s) { const(Char1)[] balance = s[1 .. $]; return passthrough(balance).ptr - s.ptr; } static assert(checkPass("foobar") == 1); /************************************************** Pointers must not escape from CTFE **************************************************/ struct Toq { const(char)* m; } Toq ptrRet(bool b) { string x = "abc"; return Toq(b ? x[0 .. 1].ptr : null); } static assert(is(typeof(compiles!({ enum Toq boz = ptrRet(false); // OK - ptr is null Toq z = ptrRet(true); // OK -- ptr doesn't escape return 4; }() )))); static assert(!is(typeof(compiles!({ enum Toq boz = ptrRet(true); // fail - ptr escapes return 4; }() )))); /************************************************** Pointers to struct members **************************************************/ struct Qoz { int w; int[3] yof; } static assert({ int[3] gaz; gaz[2] = 3156; Toq z = ptrRet(true); auto p = z.m; assert(*z.m == 'a'); assert(*p == 'a'); auto q = &z.m; assert(*q == p); assert(**q == 'a'); Qoz g = Qoz(2, [5, 6, 7]); auto r = &g.w; assert(*r == 2); r = &g.yof[1]; assert(*r == 6); g.yof[0] = 15; ++r; assert(*r == 7); r -= 2; assert(*r == 15); r = &gaz[0]; r += 2; assert(*r == 3156); return *p; }() == 'a'); struct AList { AList* next; int value; static AList* newList() { AList[] z = new AList[1]; return &z[0]; } static AList* make(int i, int j) { auto r = newList(); r.next = (new AList[1]).ptr; r.value = 1; AList* z = r.next; (*z).value = 2; r.next.value = j; assert(r.value == 1); assert(r.next.value == 2); r.next.next = &(new AList[1])[0]; assert(r.next.next != null); assert(r.next.next); r.next.next.value = 3; assert(r.next.next.value == 3); r.next.next = newList(); r.next.next.value = 9; return r; } static int checkList() { auto r = make(1,2); assert(r.value == 1); assert(r.next.value == 2); assert(r.next.next.value == 9); return 2; } } static assert(AList.checkList() == 2); /************************************************** 7194 pointers as struct members **************************************************/ struct S7194 { int* p, p2; } int f7194() { assert(S7194().p == null); assert(!S7194().p); assert(S7194().p == S7194().p2); S7194 s = S7194(); assert(!s.p); assert(s.p == null); assert(s.p == s.p2); int x; s.p = &x; s.p2 = s.p; assert(s.p == &x); return 0; } int g7194() { auto s = S7194(); assert(s.p); // should fail return 0; } static assert(f7194() == 0); static assert(!is(typeof(compiles!(g7194())))); /************************************************** 7248 recursive struct pointers in array **************************************************/ struct S7248 { S7248* ptr; } bool bug7248() { S7248[2] sarr; sarr[0].ptr = &sarr[1]; sarr[0].ptr = null; S7248* t = sarr[0].ptr; return true; } static assert(bug7248()); /************************************************** 7216 calling a struct pointer member **************************************************/ struct S7216 { S7216* p; int t; void f() { } void g() { ++t; } } bool bug7216() { S7216 s0, s1; s1.t = 6; s0.p = &s1; s0.p.f(); s0.p.g(); assert(s1.t == 7); return true; } static assert(bug7216()); /************************************************** 10858 Wrong code with array of pointers **************************************************/ bool bug10858() { int*[4] x; x[0] = null; assert(x[0] == null); return true; } static assert(bug10858()); /************************************************** 12528 - painting inout type for value type literals **************************************************/ inout(T)[] dup12528(T)(inout(T)[] a) { inout(T)[] res; foreach (ref e; a) res ~= e; return res; } enum arr12528V1 = dup12528([0]); enum arr12528V2 = dup12528([0, 1]); static assert(arr12528V1 == [0]); static assert(arr12528V2 == [0, 1]); enum arr12528C1 = dup12528([new immutable Object]); enum arr12528C2 = dup12528([new immutable Object, new immutable Object]); static assert(arr12528C1.length == 1); static assert(arr12528C2.length == 2 && arr12528C2[0] !is arr12528C2[1]); /************************************************** 9745 Allow pointers to static variables **************************************************/ shared int x9745; shared int[5] y9745; shared(int)* bug9745(int m) { auto k = &x9745; auto j = &x9745; auto p = &y9745[0]; auto q = &y9745[3]; assert(j - k == 0); assert(j == k); assert(q - p == 3); --q; int a = 0; assert(p + 2 == q); if (m == 7) { auto z1 = y9745[0 .. 2]; // slice global pointer } if (m == 8) p[1] = 7; // modify through a pointer if (m == 9) a = p[1]; // read from a pointer if (m == 0) return &x9745; return &y9745[1]; } int test9745(int m) { bug9745(m); // type painting shared int* w = bug9745(0); return 1; } shared int* w9745a = bug9745(0); shared int* w9745b = bug9745(1); static assert( is(typeof(compiles!(test9745(6))))); static assert(!is(typeof(compiles!(test9745(7))))); static assert(!is(typeof(compiles!(test9745(8))))); static assert(!is(typeof(compiles!(test9745(9))))); // pointers cast from an absolute address // (mostly applies to fake pointers, eg Windows HANDLES) bool test9745b() { void* b6 = cast(void*)0xFEFEFEFE; void* b7 = cast(void*)0xFEFEFEFF; assert(b6 is b6); assert(b7 != b6); return true; } static assert(test9745b()); /************************************************** 9364 ICE with pointer to local struct **************************************************/ struct S9364 { int i; } bool bug9364() { S9364 s; auto k = (&s).i; return 1; } static assert(bug9364()); /************************************************** 10251 Pointers to const globals **************************************************/ static const int glob10251 = 7; const(int)* bug10251() { return &glob10251; } static a10251 = &glob10251; // OK static b10251 = bug10251(); /************************************************** 4065 [CTFE] AA "in" operator doesn't work **************************************************/ bool bug4065(string s) { enum int[string] aa = ["aa":14, "bb":2]; int* p = s in aa; if (s == "aa") assert(*p == 14); else if (s == "bb") assert(*p == 2); else assert(!p); int[string] zz; assert(!("xx" in zz)); bool c = !p; return cast(bool)(s in aa); } static assert(!bug4065("xx")); static assert( bug4065("aa")); static assert( bug4065("bb")); /************************************************** 12689 - assigning via pointer from 'in' expression **************************************************/ int g12689() { int[int] aa; aa[1] = 13; assert(*(1 in aa) == 13); *(1 in aa) = 42; return aa[1]; } static assert(g12689() == 42); /************************************************** Pointers in ? : **************************************************/ static assert({ int[2] x; int* p = &x[1]; return p ? true: false; }()); /************************************************** Pointer slicing **************************************************/ int ptrSlice() { auto arr = new int[5]; int* x = &arr[0]; int[] y = x[0 .. 5]; x[1 .. 3] = 6; ++x; x[1 .. 3] = 14; assert(arr[1] == 6); assert(arr[2] == 14); //x[-1 .. 4] = 5; // problematic because negative lower boundary will throw RangeError in runtime (x - 1)[0 .. 3] = 5; int[] z = arr[1 .. 2]; z.length = 4; z[$ - 1] = 17; assert(arr.length == 5); return 2; } static assert(ptrSlice() == 2); /************************************************** 6344 - create empty slice from null pointer **************************************************/ static assert({ char* c = null; auto m = c[0 .. 0]; return true; }()); /************************************************** 8365 - block assignment of enum arrays **************************************************/ enum E8365 { first = 7, second, third, fourth } static assert({ E8365[2] x; return x[0]; }() == E8365.first); static assert({ E8365[2][2] x; return x[0][0]; }() == E8365.first); static assert({ E8365[2][2][2] x; return x[0][0][0]; }() == E8365.first); /************************************************** 4448 - labelled break + continue **************************************************/ int bug4448() { int n = 2; L1: do { switch(n) { case 5: return 7; default: n = 5; break L1; } int w = 7; } while (0); return 3; } static assert(bug4448() == 3); int bug4448b() { int n = 2; L1: for (n = 2; n < 5; ++n) { for (int m = 1; m < 6; ++m) { if (n < 3) { assert(m == 1); continue L1; } } break; } return 3; } static assert(bug4448b() == 3); /************************************************** 6985 - non-constant case **************************************************/ int bug6985(int z) { int q = z * 2 - 6; switch(z) { case q: q = 87; break; default: } return q; } static assert(bug6985(6) == 87); /************************************************** 6281 - [CTFE] A null pointer '!is null' returns 'true' **************************************************/ static assert(!{ auto p = null; return p !is null; }()); static assert(!{ auto p = null; return p != null; }()); /************************************************** 6331 - evaluate SliceExp on if condition **************************************************/ bool bug6331(string s) { if (s[0 .. 1]) return true; return false; } static assert(bug6331("str")); /************************************************** 6283 - assign to AA with slice as index **************************************************/ static assert({ immutable p = "pp"; int[string] pieces = [p: 0]; pieces["qq"] = 1; return true; }()); static assert({ immutable renames = [0: "pp"]; int[string] pieces; pieces[true ? renames[0] : "qq"] = 1; pieces["anything"] = 1; return true; }()); static assert({ immutable qq = "qq"; string q = qq; int[string] pieces = ["a":1]; pieces[q] = 0; string w = "ab"; int z = pieces[w[0 .. 1]]; assert(z == 1); return true; }()); /************************************************** 6282 - dereference 'in' of an AA **************************************************/ static assert({ int[] w = new int[4]; w[2] = 6; auto c = [5: w]; auto kk = (*(5 in c))[2]; (*(5 in c))[2] = 8; (*(5 in c))[1 .. $ - 2] = 4; auto a = [4:"1"]; auto n = *(4 in a); return n; }() == "1"); /************************************************** 6337 - member function call on struct literal **************************************************/ struct Bug6337 { int k; void six() { k = 6; } int ctfe() { six(); return k; } } static assert(Bug6337().ctfe() == 6); /************************************************** 6603 call manifest function pointer **************************************************/ int f6603(int a) { return a + 5; } enum bug6603 = &f6603; static assert(bug6603(6) == 11); /************************************************** 6375 **************************************************/ struct D6375 { int[] arr; } A6375 a6375(int[] array) { return A6375(array); } struct A6375 { D6375* _data; this(int[] arr) { _data = new D6375; _data.arr = arr; } int[] data() { return _data.arr; } } static assert({ int[] a = [1, 2]; auto app2 = a6375(a); auto data = app2.data(); return true; }()); /************************************************** 6280 Converting pointers to bool **************************************************/ static assert({ if ((0 in [0:0])) {} if ((0 in [0:0]) && (0 in [0:0])) {} return true; }()); /************************************************** 6276 ~= **************************************************/ struct Bug6276 { int[] i; } static assert({ Bug6276 foo; foo.i ~= 1; foo.i ~= 2; return true; }()); /************************************************** 6374 ptr[n] = x, x = ptr[n] **************************************************/ static assert({ int[] arr = [1]; arr.ptr[0] = 2; auto k = arr.ptr[0]; assert(k == 2); return arr[0]; }() == 2); /************************************************** 6306 recursion and local variables **************************************************/ void recurse6306() { bug6306(false); } bool bug6306(bool b) { int x = 0; if (b) recurse6306(); assert(x == 0); x = 1; return true; } static assert(bug6306(true)); /************************************************** 6386 ICE on unsafe pointer cast **************************************************/ static assert(!is(typeof(compiles!({ int x = 123; int* p = &x; float z; float* q = cast(float*)p; return true; }() )))); static assert({ int[] x = [123, 456]; int* p = &x[0]; auto m = cast(const(int)*)p; auto q = p; return *q; }()); /************************************************** 6420 ICE on dereference of invalid pointer **************************************************/ static assert({ // Should compile, but pointer can't be dereferenced int x = 123; int* p = cast(int*)x; auto q = cast(char*)x; auto r = cast(char*)323; // Valid const-changing cast const float *m = cast(immutable float*)[1.2f,2.4f,3f]; return true; }() ); static assert(!is(typeof(compiles!({ int x = 123; int* p = cast(int*)x; int a = *p; return true; }() )))); static assert(!is(typeof(compiles!({ int* p = cast(int*)123; int a = *p; return true; }() )))); static assert(!is(typeof(compiles!({ auto k = cast(int*)45; *k = 1; return true; }() )))); static assert(!is(typeof(compiles!({ *cast(float*)"a" = 4.0; return true; }() )))); static assert(!is(typeof(compiles!({ float f = 2.8; long *p = &f; return true; }() )))); static assert(!is(typeof(compiles!({ long *p = cast(long*)[1.2f, 2.4f, 3f]; return true; }() )))); /************************************************** 6250 deref pointers to array **************************************************/ int[]* simple6250(int[]* x) { return x; } void swap6250(int[]* lhs, int[]* rhs) { int[] kk = *lhs; assert(simple6250(lhs) == lhs); lhs = simple6250(lhs); assert(kk[0] == 18); assert((*lhs)[0] == 18); assert((*rhs)[0] == 19); *lhs = *rhs; assert((*lhs)[0] == 19); *rhs = kk; assert(*rhs == kk); assert(kk[0] == 18); assert((*rhs)[0] == 18); } int ctfeSort6250() { int[][2] x; int[3] a = [17, 18, 19]; x[0] = a[1 .. 2]; x[1] = a[2 .. $]; assert(x[0][0] == 18); assert(x[0][1] == 19); swap6250(&x[0], &x[1]); assert(x[0][0] == 19); assert(x[1][0] == 18); a[1] = 57; assert(x[0][0] == 19); return x[1][0]; } static assert(ctfeSort6250() == 57); /************************************************** 6672 circular references in array **************************************************/ void bug6672(ref string lhs, ref string rhs) { auto tmp = lhs; lhs = rhs; rhs = tmp; } static assert({ auto kw = ["a"]; bug6672(kw[0], kw[0]); return true; }()); void slice6672(ref string[2] agg, ref string lhs) { agg[0 .. $] = lhs; } static assert({ string[2] kw = ["a", "b"]; slice6672(kw, kw[0]); assert(kw[0] == "a"); assert(kw[1] == "a"); return true; }()); // an unrelated rejects-valid bug static assert({ string[2] kw = ["a", "b"]; kw[0 .. 2] = "x"; return true; }()); void bug6672b(ref string lhs, ref string rhs) { auto tmp = lhs; assert(tmp == "a"); lhs = rhs; assert(tmp == "a"); rhs = tmp; } static assert({ auto kw=["a", "b"]; bug6672b(kw[0], kw[1]); assert(kw[0] == "b"); assert(kw[1] == "a"); return true; }()); /************************************************** 6399 (*p).length = n **************************************************/ struct A6399 { int[] arr; int subLen() { arr = [1, 2, 3, 4, 5]; arr.length -= 1; return cast(int)arr.length; } } static assert({ A6399 a; return a.subLen(); }() == 4); /************************************************** 7789 (*p).length++ where *p is null **************************************************/ struct S7789 { size_t foo() { _ary.length += 1; return _ary.length; } int[] _ary; } static assert(S7789().foo()); /************************************************** 6418 member named 'length' **************************************************/ struct Bug6418 { size_t length() { return 189; } } static assert(Bug6418.init.length == 189); /************************************************** 4021 rehash **************************************************/ bool bug4021() { int[int] aa = [1: 1]; aa.rehash; return true; } static assert(bug4021()); /************************************************** 11629 crash on AA.rehash **************************************************/ struct Base11629 { alias T = ubyte, Char = char; alias String = immutable(Char)[]; const Char[T] toChar; this(int _dummy) { Char[T] toCharTmp = [0:'A']; toChar = toCharTmp.rehash; } } enum ct11629 = Base11629(4); /************************************************** 3512 foreach (dchar; string) 6558 foreach (int, dchar; string) **************************************************/ bool test3512() { string s = "öhai"; int q = 0; foreach (wchar c; s) { if (q == 2) assert(c == 'a'); ++q; } assert(q == 4); // _aApplycd1 foreach (dchar c; s) { ++q; if (c == 'h') break; } assert(q == 6); // _aApplycw2 foreach (int i, wchar c; s) { assert(i >= 0 && i < s.length); } // _aApplycd2 foreach (int i, dchar c; s) { assert(i >= 0 && i < s.length); } wstring w = "xüm"; // _aApplywc1 foreach (char c; w) { ++q; } assert(q == 10); // _aApplywd1 foreach (dchar c; w) { ++q; } assert(q == 13); // _aApplywc2 foreach (int i, char c; w) { assert(i >= 0 && i < w.length); } // _aApplywd2 foreach (int i, dchar c; w) { assert(i >= 0 && i < w.length); } dstring d = "yäq"; // _aApplydc1 q = 0; foreach (char c; d) { ++q; } assert(q == 4); // _aApplydw1 q = 0; foreach (wchar c; d) { ++q; } assert(q == 3); // _aApplydc2 foreach (int i, char c; d) { assert(i >= 0 && i < d.length); } // _aApplydw2 foreach (int i, wchar c; d) { assert(i >= 0 && i < d.length); } dchar[] dr = "squop"d.dup; foreach (int n, char c; dr) { if (n == 2) break; assert(c != 'o'); } // _aApplyRdc1 foreach_reverse (char c; dr) {} // _aApplyRdw1 foreach_reverse (wchar c; dr) {} // _aApplyRdc2 foreach_reverse (int n, char c; dr) { if (n == 4) break; assert(c != 'o'); } // _aApplyRdw2 foreach_reverse (int i, wchar c; dr) { assert(i >= 0 && i < dr.length); } q = 0; wstring w2 = ['x', 'ü', 'm']; // foreach over array literals foreach_reverse (int n, char c; w2) { ++q; if (c == 'm') assert(n == 2 && q == 1); if (c == 'x') assert(n == 0 && q == 4); } return true; } static assert(test3512()); /************************************************** 6510 ICE only with -inline **************************************************/ struct Stack6510 { struct Proxy { void shrink() {} } Proxy stack; void pop() { stack.shrink(); } } int bug6510() { static int used() { Stack6510 junk; junk.pop(); return 3; } return used(); } void test6510() { static assert(bug6510() == 3); } /************************************************** 6511 arr[] shouldn't make a copy **************************************************/ T bug6511(T)() { T[1] a = [1]; a[] += a[]; return a[0]; } static assert(bug6511!ulong() == 2); static assert(bug6511!long() == 2); /************************************************** 6512 new T[][] **************************************************/ bool bug6512(int m) { auto x = new int[2][][](m, 5); assert(x.length == m); assert(x[0].length == 5); assert(x[0][0].length == 2); foreach (i; 0.. m) foreach (j; 0 .. 5) foreach (k; 0 .. 2) x[i][j][k] = k + j*10 + i*100; foreach (i; 0.. m) foreach (j; 0 .. 5) foreach (k; 0 .. 2) assert(x[i][j][k] == k + j*10 + i*100); return true; } static assert(bug6512(3)); /************************************************** 6516 ICE(constfold.c) **************************************************/ dstring bug6516() { return cast(dstring)new dchar[](0); } static assert(bug6516() == ""d); /************************************************** 6727 ICE(interpret.c) **************************************************/ const(char)* ice6727(const(char)* z) { return z; } static assert({ auto q = ice6727("a".dup.ptr); return true; }()); /************************************************** 6721 Cannot get pointer to start of char[] **************************************************/ static assert({ char[] c1 = "".dup; auto p = c1.ptr; string c2 = ""; auto p2 = c2.ptr; return 6; }() == 6); /************************************************** 6693 Assign to null AA **************************************************/ struct S6693 { int[int] m; } static assert({ int[int][int] aaa; aaa[3][1] = 4; int[int][3] aab; aab[2][1] = 4; S6693 s; s.m[2] = 4; return 6693; }() == 6693); /************************************************** 7602 Segfault AA.keys on null AA **************************************************/ string[] test7602() { int[string] array; return array.keys; } enum bug7602 = test7602(); /************************************************** 6739 Nested AA assignment **************************************************/ static assert({ int[int][int][int] aaa; aaa[3][1][6] = 14; return aaa[3][1][6]; }() == 14); static assert({ int[int][int] aaa; aaa[3][1] = 4; aaa[3][3] = 3; aaa[1][5] = 9; auto kk = aaa[1][5]; return kk; }() == 9); /************************************************** 6751 ref AA assignment **************************************************/ void bug6751(ref int[int] aa) { aa[1] = 2; } static assert({ int[int] aa; bug6751(aa); assert(aa[1] == 2); return true; }()); void bug6751b(ref int[int][int] aa) { aa[1][17] = 2; } struct S6751 { int[int][int] aa; int[int] bb; } static assert({ S6751 s; bug6751b(s.aa); assert(s.aa[1][17] == 2); return true; }()); static assert({ S6751 s; s.aa[7][56] = 57; bug6751b(s.aa); assert(s.aa[1][17] == 2); assert(s.aa[7][56] == 57); bug6751c(s.aa); assert(s.aa.keys.length == 1); assert(s.aa.values.length == 1); return true; }()); static assert({ S6751 s; s.bb[19] = 97; bug6751(s.bb); assert(s.bb[1] == 2); assert(s.bb[19] == 97); return true; }()); void bug6751c(ref int[int][int] aa) { aa = [38: [56 : 77]]; } /************************************************** 7790 AA foreach ref **************************************************/ struct S7790 { size_t id; } size_t bug7790(S7790[string] tree) { foreach (k, ref v; tree) v.id = 1; return tree["a"].id; } static assert(bug7790(["a":S7790(0)]) == 1); /************************************************** 6765 null AA.length **************************************************/ static assert({ int[int] w; return w.length; }() == 0); /************************************************** 6769 AA.keys, AA.values with -inline **************************************************/ static assert({ double[char[3]] w = ["abc" : 2.3]; double[] z = w.values; return w.keys.length; }() == 1); /************************************************** 4022 AA.get **************************************************/ static assert({ int[int] aa = [58: 13]; int r = aa.get(58, 1000); assert(r == 13); r = aa.get(59, 1000); return r; }() == 1000); /************************************************** 6775 AA.opApply **************************************************/ static assert({ int[int] aa = [58: 17, 45:6]; int valsum = 0; int keysum = 0; foreach (m; aa) // aaApply { valsum += m; } assert(valsum == 17 + 6); valsum = 0; foreach (n, m; aa) // aaApply2 { valsum += m; keysum += n; } assert(valsum == 17 + 6); assert(keysum == 58 + 45); // Check empty AA valsum = 0; int[int] bb; foreach (m; bb) { ++valsum; } assert(valsum == 0); return true; }()); /************************************************** 7890 segfault struct with AA field **************************************************/ struct S7890 { int[int] tab; } S7890 bug7890() { S7890 foo; foo.tab[0] = 0; return foo; } enum e7890 = bug7890(); /************************************************** AA.remove **************************************************/ static assert({ int[int] aa = [58: 17, 45:6]; aa.remove(45); assert(aa.length == 1); aa.remove(7); assert(aa.length == 1); aa.remove(58); assert(aa.length == 0); return true; }()); /************************************************** try, finally **************************************************/ static assert({ int n = 0; try { n = 1; } catch (Exception e) {} assert(n == 1); try { n = 2; } catch (Exception e) {} finally { assert(n == 2); n = 3; } assert(n == 3); return true; }()); /************************************************** 6800 bad pointer casts **************************************************/ bool badpointer(int k) { int m = 6; int* w = &m; assert(*w == 6); int[3] a = [17, 2, 21]; int* w2 = &a[2]; assert(*w2 == 21); // cast int* to uint* is OK uint* u1 = cast(uint*)w; assert(*u1 == 6); uint* u2 = cast(uint*)w2; assert(*u2 == 21); uint* u3 = cast(uint*)&m; assert(*u3 == 6); // cast int* to void* is OK void* v1 = cast(void*)w; void* v3 = &m; void* v4 = &a[0]; // cast from void* back to int* is OK int* t3 = cast(int*)v3; assert(*t3 == 6); int* t4 = cast(int*)v4; assert(*t4 == 17); // cast from void* to uint* is OK uint* t1 = cast(uint*)v1; assert(*t1 == 6); // and check that they're real pointers m = 18; assert(*t1 == 18); assert(*u3 == 18); int** p = &w; if (k == 1) // bad reinterpret double *d1 = cast(double*)w; if (k == 3) // bad reinterpret char* d3 = cast(char*)w2; if (k == 4) { void* q1 = cast(void*)p; // OK-void is int* void* *q = cast(void**)p; // OK-void is int } if (k == 5) void*** q = cast(void***)p; // bad: too many * if (k == 6) // bad reinterpret through void* double* d1 = cast(double*)v1; if (k == 7) double* d7 = cast(double*)v4; if (k == 8) ++v4; // can't do pointer arithmetic on void* return true; } static assert(badpointer(4)); static assert(!is(typeof(compiles!(badpointer(1))))); static assert( is(typeof(compiles!(badpointer(2))))); static assert(!is(typeof(compiles!(badpointer(3))))); static assert( is(typeof(compiles!(badpointer(4))))); static assert(!is(typeof(compiles!(badpointer(5))))); static assert(!is(typeof(compiles!(badpointer(6))))); static assert(!is(typeof(compiles!(badpointer(7))))); static assert(!is(typeof(compiles!(badpointer(8))))); /************************************************** 10211 Allow casts S**->D**, when S*->D* is OK **************************************************/ int bug10211() { int m = 7; int* x = &m; int** y = &x; assert(**y == 7); uint* p = cast(uint*)x; uint** q = cast(uint**)y; return 1; } static assert(bug10211()); /************************************************** 10568 CTFE rejects function pointer safety casts **************************************************/ @safe void safetyDance() {} int isItSafeToDance() { void function() @trusted yourfriends = &safetyDance; void function() @safe nofriendsOfMine = yourfriends; return 1; } static assert(isItSafeToDance()); /************************************************** 12296 CTFE rejects const compatible AA pointer cast **************************************************/ int test12296() { immutable x = [5 : 4]; auto aa = &x; const(int[int])* y = aa; return 1; } static assert(test12296()); /************************************************** 9170 Allow reinterpret casts float<->int **************************************************/ int f9170(float x) { return *(cast(int*)&x); } float i9170(int x) { return *(cast(float*)&x); } float u9170(uint x) { return *(cast(float*)&x); } int f9170arr(float[] x) { return *(cast(int*)&(x[1])); } long d9170(double x) { return *(cast(long*)&x); } int fref9170(ref float x) { return *(cast(int*)&x); } long dref9170(ref double x) { return *(cast(long*)&x); } bool bug9170() { float f = 1.25; double d = 1.25; assert(f9170(f) == 0x3FA0_0000); assert(fref9170(f) == 0x3FA0_0000); assert(d9170(d) == 0x3FF4_0000_0000_0000L); assert(dref9170(d) == 0x3FF4_0000_0000_0000L); float [3] farr = [0, 1.25, 0]; assert(f9170arr(farr) == 0x3FA0_0000); int i = 0x3FA0_0000; assert(i9170(i) == 1.25); uint u = 0x3FA0_0000; assert(u9170(u) == 1.25); return true; } static assert(bug9170()); /************************************************** 6792 ICE with pointer cast of indexed array **************************************************/ struct S6792 { int i; } static assert({ { void* p; p = [S6792(1)].ptr; S6792 s = *(cast(S6792*)p); assert(s.i == 1); } { void*[] ary; ary ~= [S6792(2)].ptr; S6792 s = *(cast(S6792*)ary[0]); assert(s.i == 2); } { void*[7] ary; ary[6]= [S6792(2)].ptr; S6792 s = *(cast(S6792*)ary[6]); assert(s.i == 2); } { void* p; p = [S6792(1)].ptr; void*[7] ary; ary[5]= p; S6792 s = *(cast(S6792*)ary[5]); assert(s.i == 1); } { S6792*[string] aa; aa["key"] = [S6792(3)].ptr; const(S6792) s = *(cast(const(S6792)*)aa["key"]); assert(s.i == 3); } { S6792[string] blah; blah["abc"] = S6792(6); S6792*[string] aa; aa["kuy"] = &blah["abc"]; const(S6792) s = *(cast(const(S6792)*)aa["kuy"]); assert(s.i == 6); void*[7] ary; ary[5]= &blah["abc"]; S6792 t = *(cast(S6792*)ary[5]); assert(t.i == 6); int q = 6; ary[3]= &q; int gg = *(cast(int*)(ary[3])); } return true; }()); /************************************************** 7780 array cast **************************************************/ int bug7780(int testnum) { int[] y = new int[2]; y[0] = 2000000; if (testnum == 1) { void[] x = y; return (cast(byte[])x)[1]; } if (testnum == 2) { int[] x = y[0 .. 1]; return (cast(byte[])x)[1]; } return 1; } static assert( is(typeof(compiles!(bug7780(0))))); static assert(!is(typeof(compiles!(bug7780(1))))); static assert(!is(typeof(compiles!(bug7780(2))))); /************************************************** 14028 - static array pointer that refers existing array elements. **************************************************/ int test14028a(size_t ofs)(bool ct) { int[4] a; int[2]* p; int num = ofs; if (ct) p = cast(int[2]*)&a[ofs]; // SymOffExp else p = cast(int[2]*)&a[num]; // CastExp + AddrExp // pointers comparison assert(cast(void*)a.ptr <= cast(void*)p); assert(cast(void*)a.ptr <= cast(void*)&(*p)[0]); assert(cast(void*)&a[0] <= cast(void*)p); return 1; } static assert(test14028a!0(true)); static assert(test14028a!0(false)); static assert(test14028a!3(true)); static assert(test14028a!3(false)); static assert(!is(typeof(compiles!(test14028a!4(true))))); static assert(!is(typeof(compiles!(test14028a!4(false))))); int test14028b(int num) { int[4] a; int[2]* p; if (num == 1) { p = cast(int[2]*)&a[0]; // &a[0..2]; (*p)[0] = 1; // a[0] = 1 (*p)[1] = 2; // a[1] = 2 assert(a == [1,2,0,0]); p = p + 1; // &a[0] -> &a[2] (*p)[0] = 3; // a[2] = 3 (*p)[1] = 4; // a[3] = 4 assert(a == [1,2,3,4]); } if (num == 2) { p = cast(int[2]*)&a[1]; // &a[1..3]; (*p)[0] = 1; // a[1] = 1 p = p + 1; // &a[1..3] -> &a[3..5] (*p)[0] = 2; // a[3] = 2 assert(a == [0,1,0,2]); } if (num == 3) { p = cast(int[2]*)&a[1]; // &a[1..3]; (*p)[0] = 1; // a[1] = 1 p = p + 1; // &a[1..3] -> &a[3..5] (*p)[0] = 2; // a[3] = 2 (*p)[1] = 3; // a[4] = 3 (CTFE error) } if (num == 4) { p = cast(int[2]*)&a[0]; // &a[0..2]; p = p + 1; // &a[0..2] -> &a[2..4] p = p + 1; // &a[2..4] -> &a[4..6] (ok) } if (num == 5) { p = cast(int[2]*)&a[1]; // &a[1..3]; p = p + 2; // &a[1..3] -> &a[5..7] (CTFE error) } return 1; } static assert(test14028b(1)); static assert(test14028b(2)); static assert(!is(typeof(compiles!(test14028b(3))))); static assert(test14028b(4)); static assert(!is(typeof(compiles!(test14028b(5))))); /************************************************** 10275 cast struct literals to immutable **************************************************/ struct Bug10275 { uint[] ivals; } Bug10275 bug10275() { return Bug10275([1, 2, 3]); } int test10275() { immutable(Bug10275) xxx = cast(immutable(Bug10275))bug10275(); return 1; } static assert(test10275()); /************************************************** 6851 passing pointer by argument **************************************************/ void set6851(int* pn) { *pn = 20; } void bug6851() { int n = 0; auto pn = &n; *pn = 10; assert(n == 10); set6851(&n); } static assert({ bug6851(); return true; }()); /************************************************** 7876 **************************************************/ int* bug7876(int n) { int x; auto ptr = &x; if (n == 2) ptr = null; return ptr; } struct S7876 { int* p; } S7876 bug7876b(int n) { int x; S7876 s; s.p = &x; if (n == 11) s.p = null; return s; } int test7876(int n) { if (n >= 10) { S7876 m = bug7876b(n); return 1; } int* p = bug7876(n); return 1; } static assert( is(typeof(compiles!(test7876(2))))); static assert(!is(typeof(compiles!(test7876(0))))); static assert( is(typeof(compiles!(test7876(11))))); static assert(!is(typeof(compiles!(test7876(10))))); /************************************************** 11824 **************************************************/ int f11824(T)() { T[] arr = new T[](1); T* getAddr(ref T a) { return &a; } getAddr(arr[0]); return 1; } static assert(f11824!int()); // OK static assert(f11824!(int[])()); // OK <- NG /************************************************** 6817 if converted to &&, only with -inline **************************************************/ static assert({ void toggle() { bool b; if (b) b = false; } toggle(); return true; }()); /************************************************** cast to void **************************************************/ static assert({ cast(void)(71); return true; }()); /************************************************** 6816 nested function can't access this **************************************************/ struct S6816 { size_t foo() { return (){ return value +1 ; }(); } size_t value; } enum s6816 = S6816().foo(); /************************************************** 7277 ICE nestedstruct.init.tupleof **************************************************/ struct Foo7277 { int a; int func() { int b; void nested() { b = 7; a = 10; } nested(); return a+b; } } static assert(Foo7277().func() == 17); /************************************************** 10217 ICE. CTFE version of 9315 **************************************************/ bool bug10217() { struct S { int i; void bar() {} } auto yyy = S.init.tupleof[$ - 1]; assert(!yyy); return 1; } static assert(bug10217()); /************************************************** 8276 ICE **************************************************/ void bug8676(int n) { const int X1 = 4 + n; const int X2 = 4; int X3 = 4; int bar1() { return X1; } int bar2() { return X2; } int bar3() { return X3; } static assert(!is(typeof(compiles!(bar1())))); static assert( is(typeof(compiles!(bar2())))); static assert(!is(typeof(compiles!(bar3())))); } /************************************************** classes and interfaces **************************************************/ interface SomeInterface { int daz(); float bar(char); int baz(); } interface SomeOtherInterface { int xxx(); } class TheBase : SomeInterface, SomeOtherInterface { int q = 88; int rad = 61; int a = 14; int somebaseclassfunc() { return 28; } int daz() { return 0; } int baz() { return 0; } int xxx() { return 762; } int foo() { return q; } float bar(char c) { return 3.6; } } class SomeClass : TheBase, SomeInterface { int gab = 9; int fab; int a = 17; int b = 23; override int foo() { return gab + a; } override float bar(char c) { return 2.6; } int something() { return 0; } override int daz() { return 0; } override int baz() { return 0; } } class Unrelated : TheBase { this(int x) { a = x; } } auto classtest1(int n) { SomeClass c = new SomeClass; assert(c.a == 17); assert(c.q == 88); TheBase d = c; assert(d.a == 14); assert(d.q == 88); if (n == 7) { // bad cast -- should fail Unrelated u = cast(Unrelated)d; assert(u is null); } SomeClass e = cast(SomeClass)d; d.q = 35; assert(c.q == 35); assert(c.foo() == 9 + 17); ++c.a; assert(c.foo() == 9 + 18); assert(d.foo() == 9 + 18); d = new TheBase; SomeInterface fc = c; SomeOtherInterface ot = c; assert(fc.bar('x') == 2.6); assert(ot.xxx() == 762); fc = d; ot = d; assert(fc.bar('x') == 3.6); assert(ot.xxx() == 762); Unrelated u2 = new Unrelated(7); assert(u2.a == 7); return 6; } static assert(classtest1(1)); static assert(classtest1(2)); static assert(classtest1(7)); // bug 7154 // can't initialize enum with not null class SomeClass classtest2(int n) { return n == 5 ? (new SomeClass) : null; } static assert( is(typeof((){ enum const(SomeClass) xx = classtest2(2);}()))); static assert(!is(typeof((){ enum const(SomeClass) xx = classtest2(5);}()))); class RecursiveClass { int x; this(int n) { x = n; } RecursiveClass b; void doit() { b = new RecursiveClass(7); b.x = 2;} } int classtest3() { RecursiveClass x = new RecursiveClass(17); x.doit(); RecursiveClass y = x.b; assert(y.x == 2); assert(x.x == 17); return 1; } static assert(classtest3()); /************************************************** 12016 class cast and qualifier reinterpret **************************************************/ class B12016 { } class C12016 : B12016 { } bool f12016(immutable B12016 b) { assert(b); return true; } static assert(f12016(new immutable C12016)); /************************************************** 10610 ice immutable implicit conversion **************************************************/ class Bug10610(T) { int baz() immutable { return 1; } static immutable(Bug10610!T) min = new Bug10610!T(); } void ice10610() { alias T10610 = Bug10610!(int); static assert (T10610.min.baz()); } /************************************************** 13141 regression fix caused by 10610 **************************************************/ struct MapResult13141(alias pred) { int[] range; @property empty() { return range.length == 0; } @property front() { return pred(range[0]); } void popFront() { range = range[1 .. $]; } } string[] array13141(R)(R r) { typeof(return) result; foreach (e; r) result ~= e; return result; } //immutable string[] splitterNames = [4].map!(e => "4").array(); immutable string[] splitterNames13141 = MapResult13141!(e => "4")([4]).array13141(); /************************************************** 11587 AA compare **************************************************/ static assert([1:2, 3:4] == [3:4, 1:2]); /************************************************** 14325 more AA comparisons **************************************************/ static assert([1:1] != [1:2, 2:1]); // OK static assert([1:1] != [1:2]); // OK static assert([1:1] != [2:1]); // OK <- Error static assert([1:1, 2:2] != [3:3, 4:4]); // OK <- Error /************************************************** 7147 typeid() **************************************************/ static assert({ TypeInfo xxx = typeid(Object); TypeInfo yyy = typeid(new Error("xxx")); return true; }()); int bug7147(int n) { Error err = n ? new Error("xxx") : null; TypeInfo qqq = typeid(err); return 1; } // Must not segfault if class is null static assert(!is(typeof(compiles!(bug7147(0))))); static assert( is(typeof(compiles!(bug7147(1))))); /************************************************** 14123 - identity TypeInfo objects **************************************************/ static assert({ bool eq(TypeInfo t1, TypeInfo t2) { return t1 is t2; } class C {} struct S {} assert( eq(typeid(C), typeid(C))); assert(!eq(typeid(C), typeid(Object))); assert( eq(typeid(S), typeid(S))); assert(!eq(typeid(S), typeid(int))); assert( eq(typeid(int), typeid(int))); assert(!eq(typeid(int), typeid(long))); Object o = new Object; Object c = new C; assert( eq(typeid(o), typeid(o))); assert(!eq(typeid(c), typeid(o))); assert(!eq(typeid(o), typeid(S))); return 1; }()); /************************************************** 6885 wrong code with new array **************************************************/ struct S6885 { int p; } int bug6885() { auto array = new double[1][2]; array[1][0] = 6; array[0][0] = 1; assert(array[1][0] == 6); auto barray = new S6885[2]; barray[1].p = 5; barray[0].p = 2; assert(barray[1].p == 5); return 1; } static assert(bug6885()); /************************************************** 6886 ICE with new array of dynamic arrays **************************************************/ int bug6886() { auto carray = new int[][2]; carray[1] = [6]; carray[0] = [4]; assert(carray[1][0] == 6); return 1; } static assert(bug6886()); /************************************************** 10198 Multidimensional struct block initializer **************************************************/ struct Block10198 { int val[3][4]; } int bug10198() { Block10198 pp = Block10198(67); assert(pp.val[2][3] == 67); assert(pp.val[1][3] == 67); return 1; } static assert(bug10198()); /************************************************** 14440 Multidimensional block initialization should create distinct arrays for each elements **************************************************/ struct Matrix14440(E, size_t row, size_t col) { E[col][row] array2D; @safe pure nothrow this(E[row * col] numbers...) { foreach (r; 0 .. row) { foreach (c; 0 .. col) { array2D[r][c] = numbers[r * col + c]; } } } } void test14440() { // Replace 'enum' with 'auto' here and it will work fine. enum matrix = Matrix14440!(int, 3, 3)( 1, 2, 3, 4, 5, 6, 7, 8, 9 ); static assert(matrix.array2D[0][0] == 1); static assert(matrix.array2D[0][1] == 2); static assert(matrix.array2D[0][2] == 3); static assert(matrix.array2D[1][0] == 4); static assert(matrix.array2D[1][1] == 5); static assert(matrix.array2D[1][2] == 6); static assert(matrix.array2D[2][0] == 7); static assert(matrix.array2D[2][1] == 8); static assert(matrix.array2D[2][2] == 9); } /**************************************************** * Exception chaining tests from xtest46.d ****************************************************/ class A75 { pure static void raise(string s) { throw new Exception(s); } } int test75() { int x = 0; try { A75.raise("a"); } catch (Exception e) { x = 1; } assert(x == 1); return 1; } static assert(test75()); /**************************************************** * Exception chaining tests from test4.d ****************************************************/ int test4_test54() { int status = 0; try { try { status++; assert(status == 1); throw new Exception("first"); } finally { status++; assert(status == 2); status++; throw new Exception("second"); } } catch (Exception e) { assert(e.msg == "first"); assert(e.next.msg == "second"); } return true; } static assert(test4_test54()); void foo55() { try { Exception x = new Exception("second"); throw x; } catch (Exception e) { assert(e.msg == "second"); } } int test4_test55() { int status = 0; try { try { status++; assert(status == 1); Exception x = new Exception("first"); throw x; } finally { status++; assert(status == 2); status++; foo55(); } } catch (Exception e) { assert(e.msg == "first"); assert(status == 3); } return 1; } static assert(test4_test55()); /**************************************************** * Exception chaining tests from eh.d ****************************************************/ void bug1513outer() { int result1513; void bug1513a() { throw new Exception("d"); } void bug1513b() { try { try { bug1513a(); } finally { result1513 |= 4; throw new Exception("f"); } } catch (Exception e) { assert(e.msg == "d"); assert(e.next.msg == "f"); assert(!e.next.next); } } void bug1513c() { try { try { throw new Exception("a"); } finally { result1513 |= 1; throw new Exception("b"); } } finally { bug1513b(); result1513 |= 2; throw new Exception("c"); } } void bug1513() { result1513 = 0; try { bug1513c(); } catch (Exception e) { assert(result1513 == 7); assert(e.msg == "a"); assert(e.next.msg == "b"); assert(e.next.next.msg == "c"); } } bug1513(); } void collideone() { try { throw new Exception("x"); } finally { throw new Exception("y"); } } void doublecollide() { try { try { try { throw new Exception("p"); } finally { throw new Exception("q"); } } finally { collideone(); } } catch (Exception e) { assert(e.msg == "p"); assert(e.next.msg == "q"); assert(e.next.next.msg == "x"); assert(e.next.next.next.msg == "y"); assert(!e.next.next.next.next); } } void collidetwo() { try { try { throw new Exception("p2"); } finally { throw new Exception("q2"); } } finally { collideone(); } } void collideMixed() { int works = 6; try { try { try { throw new Exception("e"); } finally { throw new Error("t"); } } catch (Exception f) { // Doesn't catch, because Error is chained to it. works += 2; } } catch (Error z) { works += 4; assert(z.msg == "t"); // Error comes first assert(z.next is null); assert(z.bypassedException.msg == "e"); } assert(works == 10); } class AnotherException : Exception { this(string s) { super(s); } } void multicollide() { try { try { try { try { throw new Exception("m2"); } finally { throw new AnotherException("n2"); } } catch (AnotherException s) { // Not caught -- we needed to catch the root cause "m2", not // just the collateral "n2" (which would leave m2 uncaught). assert(0); } } finally { collidetwo(); } } catch (Exception f) { assert(f.msg == "m2"); assert(f.next.msg == "n2"); Throwable e = f.next.next; assert(e.msg == "p2"); assert(e.next.msg == "q2"); assert(e.next.next.msg == "x"); assert(e.next.next.next.msg == "y"); assert(!e.next.next.next.next); } } int testsFromEH() { bug1513outer(); doublecollide(); collideMixed(); multicollide(); return 1; } static assert(testsFromEH()); /************************************************** With + synchronized statements + bug 6901 **************************************************/ struct With1 { int a; int b; } class Foo6 { } class Foo32 { struct Bar { int x; } } class Base56 { private string myfoo; private string mybar; // Get/set properties that will be overridden. void foo(string s) { myfoo = s; } string foo() { return myfoo; } // Get/set properties that will not be overridden. void bar(string s) { mybar = s; } string bar() { return mybar; } } class Derived56 : Base56 { alias Base56.foo foo; // Bring in Base56's foo getter. override void foo(string s) { super.foo = s; } // Override foo setter. } int testwith() { With1 x = With1(7); with (x) { a = 2; } assert(x.a == 2); // from test11.d Foo6 foo6 = new Foo6(); with (foo6) { int xx; xx = 4; } with (new Foo32) { Bar z; z.x = 5; } Derived56 d = new Derived56; with (d) { foo = "hi"; d.foo = "hi"; bar = "hi"; assert(foo == "hi"); assert(d.foo == "hi"); assert(bar == "hi"); } int w = 7; synchronized { ++w; } assert(w == 8); return 1; } static assert(testwith()); /************************************************** 9236 ICE switch with(EnumType) **************************************************/ enum Command9236 { Char, Any, }; bool bug9236(Command9236 cmd) { int n = 0; with (Command9236) switch (cmd) { case Any: n = 1; break; default: n = 2; } assert(n == 1); switch (cmd) with (Command9236) { case Any: return true; default: return false; } } static assert(bug9236(Command9236.Any)); /************************************************** 6416 static struct declaration **************************************************/ static assert({ static struct S { int y = 7; } S a; a.y += 6; assert(a.y == 13); return true; }()); /************************************************** 10499 static template struct declaration **************************************************/ static assert({ static struct Result() {} return true; }()); /************************************************** 13757 extern(C) alias declaration **************************************************/ static assert({ alias FP1 = extern(C) int function(); alias extern(C) int function() FP2; return true; }()); /************************************************** 6522 opAssign + foreach ref **************************************************/ struct Foo6522 { bool b = false; void opAssign(int x) { this.b = true; } } bool foo6522() { Foo6522[1] array; foreach (ref item; array) item = 1; return true; } static assert(foo6522()); /************************************************** 7245 pointers + foreach ref **************************************************/ int bug7245(int testnum) { int[3] arr; arr[0] = 4; arr[1] = 6; arr[2] = 8; int* ptr; foreach (i, ref p; arr) { if (i == 1) ptr = &p; if (testnum == 1) p = 5; } return *ptr; } static assert(bug7245(0) == 6); static assert(bug7245(1) == 5); /************************************************** 8498 modifying foreach 7658 foreach ref 8539 nested funcs, ref param, -inline **************************************************/ int bug8498() { foreach (ref i; 0 .. 5) { assert(i == 0); i = 100; } return 1; } static assert(bug8498()); string bug7658() { string[] children = ["0"]; foreach (ref child; children) child = "1"; return children[0]; } static assert(bug7658() == "1"); int bug8539() { static void one(ref int x) { x = 1; } static void go() { int y; one(y); assert(y == 1); // fails with -inline } go(); return 1; } static assert(bug8539()); /************************************************** 7874, 13297, 13740 - better lvalue handling **************************************************/ int bug7874(int x){ return ++x = 1; } static assert(bug7874(0) == 1); // ---- struct S13297 { int* p; } void f13297(ref int* p) { p = cast(int*) 1; assert(p); // passes } static assert( { S13297 s; f13297(s.p); return s.p != null; // false }()); // ---- class R13740 { int e; bool empty = false; @property ref front() { return e; } void popFront() { empty = true; } } static assert({ auto r = new R13740(); foreach (ref e; r) e = 42; assert(r.e == 42); /* fails in CTFE */ return true; }()); /************************************************** 6919 **************************************************/ void bug6919(int* val) { *val = 1; } void test6919() { int n; bug6919(&n); assert(n == 1); } static assert({ test6919(); return true; }()); void bug6919b(string* val) { *val = "1"; } void test6919b() { string val; bug6919b(&val); assert(val == "1"); } static assert({ test6919b(); return true; }()); /************************************************** 6995 **************************************************/ struct Foo6995 { static size_t index(size_t v)() { return v; } } static assert(Foo6995.index!(27)() == 27); /************************************************** 7043 ref with -inline **************************************************/ int bug7043(S)(ref int x) { return x; } static assert({ int i = 416; return bug7043!(char)(i); }() == 416); /************************************************** 6037 recursive ref **************************************************/ void bug6037(ref int x, bool b) { int w = 3; if (b) { bug6037(w, false); assert(w == 6); } else { x = 6; assert(w == 3); // fails } } int bug6037outer() { int q; bug6037(q, true); return 401; } static assert(bug6037outer() == 401); /************************************************** 14299 - [REG2.067a], more than one depth of recursive call with ref **************************************************/ string gen14299(int max, int idx, ref string name) { string ret; name = [cast(char)(idx + '0')]; ret ~= name; if (idx < max) { string subname; ret ~= gen14299(max, idx + 1, subname); } ret ~= name; return ret; } string test14299(int max) { string n; return gen14299(max, 0, n); } static assert(test14299(1) == "0110"); // OK <- fail static assert(test14299(2) == "012210"); // OK <- ICE static assert(test14299(3) == "01233210"); static assert(test14299(4) == "0123443210"); static assert(test14299(5) == "012345543210"); /************************************************** 7940 wrong code for complicated assign **************************************************/ struct Bug7940 { int m; } struct App7940 { Bug7940[] x; } int bug7940() { Bug7940[2] y; App7940 app; app.x = y[0 .. 1]; app.x[0].m = 12; assert(y[0].m == 12); assert(app.x[0].m == 12); return 1; } static assert(bug7940()); /************************************************** 10298 wrong code for struct array literal init **************************************************/ struct Bug10298 { int m; } int bug10298() { Bug10298[1] y = [Bug10298(78)]; y[0].m = 6; assert(y[0].m == 6); // Root cause Bug10298[1] x; x[] = [cast(const Bug10298)(Bug10298(78))]; assert(x[0].m == 78); return 1; } static assert(bug10298()); /************************************************** 7266 dotvar ref parameters **************************************************/ struct S7266 { int a; } bool bug7266() { S7266 s; s.a = 4; bar7266(s.a); assert(s.a == 5); out7266(s.a); assert(s.a == 7); return true; } void bar7266(ref int b) { b = 5; assert(b == 5); } void out7266(out int b) { b = 7; assert(b == 7); } static assert(bug7266()); /************************************************** 9982 dotvar assign through pointer **************************************************/ struct Bug9982 { int a; } int test9982() { Bug9982 x; int*q = &x.a; *q = 99; assert(x.a == 99); return 1; } static assert(test9982()); // 9982, rejects-valid case struct SS9982 { Bug9982 s2; this(Bug9982 s1) { s2.a = 6; emplace9982(&s2, s1); assert(s2.a == 3); } } void emplace9982(Bug9982* chunk, Bug9982 arg) { *chunk = arg; } enum s9982 = Bug9982(3); enum p9982 = SS9982(s9982); /************************************************** 11618 dotvar assign through casted pointer **************************************************/ struct Tuple11618(T...) { T field; alias field this; } static assert({ Tuple11618!(immutable dchar) result = void; auto addr = cast(dchar*)&result[0]; *addr = dchar.init; return (result[0] == dchar.init); }()); /************************************************** 7143 'is' for classes **************************************************/ class C7143 { int x; } int bug7143(int test) { C7143 c = new C7143; C7143 d = new C7143; if (test == 1) { if (c) return c.x + 8; return -1; } if (test == 2) { if (c is null) return -1; return c.x + 45; } if (test == 3) { if (c is c) return 58; } if (test == 4) { if (c !is c) return -1; else return 48; } if (test == 6) d = c; if (test == 5 || test == 6) { if (c is d) return 188; else return 48; } return -1; } static assert(bug7143(1) == 8); static assert(bug7143(2) == 45); static assert(bug7143(3) == 58); static assert(bug7143(4) == 48); static assert(bug7143(5) == 48); static assert(bug7143(6) == 188); /************************************************** 7147 virtual function calls from base class **************************************************/ class A7147 { int foo() { return 0; } int callfoo() { return foo(); } } class B7147 : A7147 { override int foo() { return 1; } } int test7147() { A7147 a = new B7147; return a.callfoo(); } static assert(test7147() == 1); /************************************************** 7158 **************************************************/ class C7158 { bool b() { return true; } } struct S7158 { C7158 c; } bool test7158() { S7158 s = S7158(new C7158); return s.c.b; } static assert(test7158()); /************************************************** 8484 **************************************************/ class C8484 { int n; int b() { return n + 3; } } struct S { C8484 c; } int t8484(ref C8484 c) { return c.b(); } int test8484() { auto s = S(new C8484); s.c.n = 4; return t8484(s.c); } static assert(test8484() == 7); /************************************************** 7419 **************************************************/ struct X7419 { double x; this(double x) { this.x = x; } } void bug7419() { enum x = { auto p = X7419(3); return p.x; }(); static assert(x == 3); } /************************************************** 9445 ice **************************************************/ template c9445(T...) { } void ice9445(void delegate() expr, void function() f2) { static assert(!is(typeof(c9445!(f2())))); static assert(!is(typeof(c9445!(expr())))); } /************************************************** 10452 delegate == **************************************************/ struct S10452 { bool func() { return true; } } struct Outer10452 { S10452 inner; } class C10452 { bool func() { return true; } } bool delegate() ref10452(ref S10452 s) { return &s.func; } bool test10452() { bool delegate() bar = () { return true; }; assert(bar !is null); assert(bar is bar); S10452 bag; S10452[6] bad; Outer10452 outer; C10452 tag = new C10452; auto rat = &outer.inner.func; assert(rat == rat); auto tat = &tag.func; assert(tat == tat); auto bat = &outer.inner.func; auto mat = &bad[2].func; assert(mat is mat); assert(rat == bat); auto zat = &bag.func; auto cat = &bag.func; assert(zat == zat); assert(zat == cat); auto drat = ref10452(bag); assert(cat == drat); assert(drat == drat); drat = ref10452(bad[2]); assert( drat == mat); assert(tat != rat); assert(zat != rat); assert(rat != cat); assert(zat != bar); assert(tat != cat); cat = bar; assert(cat == bar); return true; } static assert(test10452()); /************************************************** 7162 and 4711 **************************************************/ void f7162() { } bool ice7162() { false && f7162(); false || f7162(); false && f7162(); // bug 4711 true && f7162(); return true; } static assert(ice7162()); /************************************************** 8857, only with -inline (creates an &&) **************************************************/ struct Result8857 { char[] next; } void bug8857()() { Result8857 r; r.next = null; if (true) { auto next = r.next; } } static assert({ bug8857(); return true; }()); /************************************************** 7527 **************************************************/ struct Bug7527 { char[] data; } int bug7527() { auto app = Bug7527(); app.data.ptr[0 .. 1] = "x"; return 1; } static assert(!is(typeof(compiles!(bug7527())))); /************************************************** 7527 **************************************************/ int bug7380; static assert(!is(typeof( compiles!( (){ return &bug7380; }() )))); /************************************************** 7165 **************************************************/ struct S7165 { int* ptr; bool f() const { return !!ptr; } } static assert(!S7165().f()); /************************************************** 7187 **************************************************/ int[] f7187() { return [0]; } int[] f7187b(int n) { return [0]; } int g7187(int[] r) { auto t = r[0 .. 0]; return 1; } static assert(g7187(f7187())); static assert(g7187(f7187b(7))); struct S7187 { const(int)[] field; } const(int)[] f7187c() { auto s = S7187([0]); return s.field; } bool g7187c(const(int)[] r) { auto t = r[0 .. 0]; return true; } static assert(g7187c(f7187c())); /************************************************** 6933 struct destructors **************************************************/ struct Bug6933 { int x = 3; ~this() { } } int test6933() { Bug6933 q; assert(q.x == 3); return 3; } static assert(test6933()); /************************************************** 7197 **************************************************/ int foo7197(int[] x...) { return 1; } template bar7197(y...) { enum int bar7197 = foo7197(y); } enum int bug7197 = 7; static assert(bar7197!(bug7197)); /************************************************** Enum string compare **************************************************/ enum EScmp : string { a = "aaa" } bool testEScmp() { EScmp x = EScmp.a; assert(x < "abc"); return true; } static assert(testEScmp()); /************************************************** 7667 **************************************************/ bool baz7667(int[] vars...) { return true; } struct S7667 { static void his(int n) { static assert(baz7667(2)); } } bool bug7667() { S7667 unused; unused.his(7); return true; } enum e7667 = bug7667(); /************************************************** 7536 **************************************************/ bool bug7536(string expr) { return true; } void vop() { const string x7536 = "x"; static assert(bug7536(x7536)); } /************************************************** 6681 unions **************************************************/ struct S6681 { this(int a, int b) { this.a = b; this.b = a; } union { ulong g; struct { int a, b; }; } } static immutable S6681 s6681 = S6681(0, 1); bool bug6681(int test) { S6681 x = S6681(0, 1); x.g = 5; auto u = &x.g; auto v = &x.a; long w = *u; int z; assert(w == 5); if (test == 4) z = *v; // error x.a = 2; // invalidate g, and hence u. if (test == 1) w = *u; // error z = *v; assert(z == 2); x.g = 6; w = *u; assert(w == 6); if (test == 3) z = *v; return true; } static assert(bug6681(2)); static assert(!is(typeof(compiles!(bug6681(1))))); static assert(!is(typeof(compiles!(bug6681(3))))); static assert(!is(typeof(compiles!(bug6681(4))))); /************************************************** 9113 ICE with struct in union **************************************************/ union U9113 { struct M { int y; } int xx; } int bug9113(T)() { U9113 x; x.M.y = 10; // error, need 'this' return 1; } static assert(!is(typeof(compiles!(bug9113!(int)())))); /************************************************** Creation of unions **************************************************/ union UnionTest1 { int x; float y; } int uniontest1() { UnionTest1 u = UnionTest1(1); return 1; } static assert(uniontest1()); /************************************************** 6438 void **************************************************/ struct S6438 { int a; int b = void; } void fill6438(int[] arr, int testnum) { if (testnum == 2) { auto u = arr[0]; } foreach (ref x; arr) x = 7; auto r = arr[0]; S6438[2] s; auto p = &s[0].b; if (testnum == 3) { auto v = *p; } } bool bug6438(int testnum) { int[4] stackSpace = void; fill6438(stackSpace[], testnum); assert(stackSpace == [7, 7, 7, 7]); return true; } static assert( is(typeof(compiles!(bug6438(1))))); static assert(!is(typeof(compiles!(bug6438(2))))); static assert(!is(typeof(compiles!(bug6438(3))))); /************************************************** 10994 void static array members **************************************************/ struct Bug10994 { ubyte[2] buf = void; } static bug10994 = Bug10994.init; /************************************************** 10937 struct inside union **************************************************/ struct S10937 { union { ubyte[1] a; struct { ubyte b; } } this(ubyte B) { if (B > 6) this.b = B; else this.a[0] = B; } } enum test10937 = S10937(7); enum west10937 = S10937(2); /************************************************** 13831 **************************************************/ struct Vector13831() { } struct Coord13831 { union { struct { short x; } Vector13831!() vector; } } struct Chunk13831 { this(Coord13831) { coord = coord; } Coord13831 coord; static const Chunk13831* unknownChunk = new Chunk13831(Coord13831()); } /************************************************** 7732 **************************************************/ struct AssociativeArray { int* impl; int f() { if (impl !is null) auto x = *impl; return 1; } } int test7732() { AssociativeArray aa; return aa.f; } static assert(test7732()); /************************************************** 7784 **************************************************/ struct Foo7784 { void bug() { tab["A"] = Bar7784(&this); auto pbar = "A" in tab; auto bar = *pbar; } Bar7784[string] tab; } struct Bar7784 { Foo7784* foo; int val; } bool ctfe7784() { auto foo = Foo7784(); foo.bug(); return true; } static assert(ctfe7784()); /************************************************** 7781 **************************************************/ static assert(({ return; }(), true)); /************************************************** 7785 **************************************************/ bool bug7785(int n) { int val = 7; auto p = &val; if (n == 2) { auto ary = p[0 .. 1]; } auto x = p[0]; val = 6; assert(x == 7); if (n == 3) p[0 .. 1] = 1; return true; } static assert(bug7785(1)); static assert(!is(typeof(compiles!(bug7785(2))))); static assert(!is(typeof(compiles!(bug7785(3))))); /************************************************** 7987 **************************************************/ class C7987 { int m; } struct S7987 { int* p; C7987 c; } bool bug7987() { int[7] q; int[][2] b = q[0 .. 5]; assert(b == b); assert(b is b); C7987 c1 = new C7987; C7987 c2 = new C7987; S7987 s, t; s.p = &q[0]; t.p = &q[1]; assert(s != t); s.p = &q[1]; /*assert(s == t);*/ assert(s.p == t.p); s.c = c1; t.c = c2; /*assert(s != t);*/ assert(s.c !is t.c); assert(s !is t); s.c = c2; /*assert(s == t);*/ assert(s.p == t.p && s.c is t.c); assert(s is t); return true; } static assert(bug7987()); /************************************************** 10579 typeinfo.func() must not segfault **************************************************/ static assert(!is(typeof(compiles!(typeid(int).toString.length)))); class Bug10579 { int foo() { return 1; } } Bug10579 uninitialized10579; static assert(!is(typeof(compiles!(uninitialized10579.foo())))); /************************************************** 10804 mixin ArrayLiteralExp typed string **************************************************/ void test10804() { String identity(String)(String a) { return a; } string cfun() { char[] s; s.length = 8 + 2 + (2) + 1 + 2; s[] = "identity(`Ω`c)"c[]; return cast(string)s; // Return ArrayLiteralExp as the CTFE result } { enum a1 = "identity(`Ω`c)"c; enum a2 = cfun(); static assert(cast(ubyte[])mixin(a1) == [0xCE, 0xA9]); static assert(cast(ubyte[])mixin(a2) == [0xCE, 0xA9]); // should pass } wstring wfun() { wchar[] s; s.length = 8 + 2 + (2) + 1 + 2; s[] = "identity(`\U0002083A`w)"w[]; return cast(wstring)s; // Return ArrayLiteralExp as the CTFE result } { enum a1 = "identity(`\U0002083A`w)"w; enum a2 = wfun(); static assert(cast(ushort[])mixin(a1) == [0xD842, 0xDC3A]); static assert(cast(ushort[])mixin(a2) == [0xD842, 0xDC3A]); } dstring dfun() { dchar[] s; s.length = 8 + 2 + (1) + 1 + 2; s[] = "identity(`\U00101000`d)"d[]; return cast(dstring)s; // Return ArrayLiteralExp as the CTFE result } { enum a1 = "identity(`\U00101000`d)"d; enum a2 = dfun(); static assert(cast(uint[])mixin(a1) == [0x00101000]); static assert(cast(uint[])mixin(a2) == [0x00101000]); } } /******************************************************/ struct B73 {} struct C73 { B73 b; } C73 func73() { C73 b = void; b.b = B73(); return b; } C73 test73 = func73(); /******************************************************/ struct S74 { int n[1]; static S74 test(){ S74 ret = void; ret.n[0] = 0; return ret; } } enum Test74 = S74.test(); /******************************************************/ static bool bug8865() in { int x = 0; label: foreach (i; (++x) .. 3) { if (i == 1) continue label; // doesn't work. else break label; // doesn't work. } } out { int x = 0; label: foreach (i; (++x) .. 3) { if (i == 1) continue label; // doesn't work. else break label; // doesn't work. } } body { int x = 0; label: foreach (i; (++x) .. 3) { if (i == 1) continue label; // works. else break label; // works. } return true; } static assert(bug8865()); /******************************************************/ struct Test75 { this(int) pure {} } static assert( __traits(compiles, { static shared(Test75*) t75 = new shared(Test75)(0); return t75; })); static assert( __traits(compiles, { static shared(Test75)* t75 = new shared(Test75)(0); return t75; })); static assert( __traits(compiles, { static __gshared Test75* t75 = new Test75(0); return t75; })); static assert( __traits(compiles, { static const(Test75*) t75 = new const(Test75)(0); return t75; })); static assert( __traits(compiles, { static immutable Test75* t75 = new immutable(Test75)(0); return t75; })); static assert(!__traits(compiles, { static Test75* t75 = new Test75(0); return t75; })); /+ static assert(!__traits(compiles, { enum t75 = new shared(Test75)(0); return t75; })); static assert(!__traits(compiles, { enum t75 = new Test75(0); return t75; })); static assert(!__traits(compiles, { enum shared(Test75)* t75 = new shared(Test75)(0); return t75; })); static assert(!__traits(compiles, { enum Test75* t75 = new Test75(0); return t75; })); static assert( __traits(compiles, { enum t75 = new const(Test75)(0); return t75;})); static assert( __traits(compiles, { enum t75 = new immutable(Test75)(0); return t75;})); static assert( __traits(compiles, { enum const(Test75)* t75 = new const(Test75)(0); return t75;})); static assert( __traits(compiles, { enum immutable(Test75)* t75 = new immutable(Test75)(0); return t75;})); +/ /******************************************************/ class Test76 { this(int) pure {} } /+ static assert(!__traits(compiles, { enum t76 = new shared(Test76)(0); return t76;})); static assert(!__traits(compiles, { enum t76 = new Test76(0); return t76;})); static assert(!__traits(compiles, { enum shared(Test76) t76 = new shared(Test76)(0); return t76;})); static assert(!__traits(compiles, { enum Test76 t76 = new Test76(0); return t76;})); static assert( __traits(compiles, { enum t76 = new const(Test76)(0); return t76;})); static assert( __traits(compiles, { enum t76 = new immutable(Test76)(0); return t76;})); static assert( __traits(compiles, { enum const(Test76) t76 = new const(Test76)(0); return t76;})); static assert( __traits(compiles, { enum immutable(Test76) t76 = new immutable(Test76)(0); return t76;})); +/ /******************************************************/ static assert( __traits(compiles, { static shared Test76 t76 = new shared(Test76)(0); return t76; })); static assert( __traits(compiles, { static shared(Test76) t76 = new shared(Test76)(0); return t76; })); static assert( __traits(compiles, { static __gshared Test76 t76 = new Test76(0); return t76; })); static assert( __traits(compiles, { static const Test76 t76 = new const(Test76)(0); return t76; })); static assert( __traits(compiles, { static immutable Test76 t76 = new immutable Test76(0); return t76; })); static assert(!__traits(compiles, { static Test76 t76 = new Test76(0); return t76; })); /***** Bug 5678 *********************************/ struct Bug5678 { this(int) {} } static assert(!__traits(compiles, { enum const(Bug5678)* b5678 = new const(Bug5678)(0); return b5678; })); /************************************************** 10782 run semantic2 for class field **************************************************/ enum e10782 = 0; class C10782 { int x = e10782; } string f10782() { auto c = new C10782(); return ""; } mixin(f10782()); /************************************************** 10929 NRVO support in CTFE **************************************************/ struct S10929 { this(this) { postblitCount++; } ~this() { dtorCount++; } int payload; int dtorCount; int postblitCount; } auto makeS10929() { auto s = S10929(42, 0, 0); return s; } bool test10929() { auto s = makeS10929(); assert(s.postblitCount == 0); assert(s.dtorCount == 0); return true; }; static assert(test10929()); /************************************************** 9245 - support postblit call on array assignments **************************************************/ bool test9245() { int postblits = 0; struct S { this(this) { ++postblits; } } S s; S[2] a; assert(postblits == 0); { S[2] arr = s; assert(postblits == 2); arr[] = s; assert(postblits == 4); postblits = 0; S[2] arr2 = arr; assert(postblits == 2); arr2 = arr; assert(postblits == 4); postblits = 0; const S[2] constArr = s; assert(postblits == 2); postblits = 0; const S[2] constArr2 = arr; assert(postblits == 2); postblits = 0; } { S[2][2] arr = s; assert(postblits == 4); arr[] = a; assert(postblits == 8); postblits = 0; S[2][2] arr2 = arr; assert(postblits == 4); arr2 = arr; assert(postblits == 8); postblits = 0; const S[2][2] constArr = s; assert(postblits == 4); postblits = 0; const S[2][2] constArr2 = arr; assert(postblits == 4); postblits = 0; } return true; } static assert(test9245()); /************************************************** 12906 don't call postblit on blit initializing **************************************************/ struct S12906 { this(this) { assert(0); } } static assert({ S12906[1] arr; return true; }()); /************************************************** 11510 support overlapped field access in CTFE **************************************************/ struct S11510 { union { size_t x; int* y; // pointer field } } bool test11510() { S11510 s; s.y = [1,2,3].ptr; // writing overlapped pointer field is OK assert(s.y[0 .. 3] == [1,2,3]); // reading valid field is OK s.x = 10; assert(s.x == 10); // There's no reinterpretation between S.x and S.y return true; } static assert(test11510()); /************************************************** 11534 - subtitude inout **************************************************/ struct MultiArray11534 { this(size_t[] sizes...) { storage = new size_t[5]; } @property auto raw_ptr() inout { return storage.ptr + 1; } size_t[] storage; } enum test11534 = () { auto m = MultiArray11534(3,2,1); auto start = m.raw_ptr; //this trigger the bug //auto start = m.storage.ptr + 1; //this obviously works return 0; }(); /************************************************** 11941 - Regression of 11534 fix **************************************************/ void takeConst11941(const string[]) {} string[] identity11941(string[] x) { return x; } bool test11941a() { struct S { string[] a; } S s; takeConst11941(identity11941(s.a)); s.a ~= []; return true; } static assert(test11941a()); bool test11941b() { struct S { string[] a; } S s; takeConst11941(identity11941(s.a)); s.a ~= "foo"; /* Error refers to this line (15), */ string[] b = s.a[]; /* but only when this is here. */ return true; } static assert(test11941b()); /************************************************** 11535 - element-wise assignment from string to ubyte array literal **************************************************/ struct Hash11535 { ubyte[6] _buffer; void put(scope const(ubyte)[] data...) { uint i = 0, index = 0; auto inputLen = data.length; (&_buffer[index])[0 .. inputLen - i] = (&data[i])[0 .. inputLen - i]; } } auto md5_digest11535(T...)(scope const T data) { Hash11535 hash; hash.put(cast(const(ubyte[]))data[0]); return hash._buffer; } static assert(md5_digest11535(`TEST`) == [84, 69, 83, 84, 0, 0]); /************************************************** 11540 - goto label + try-catch-finally / with statement **************************************************/ static assert(() { // enter to TryCatchStatement.body { bool c = false; try { if (c) // need to bypass front-end optimization throw new Exception(""); else { goto Lx; L1: c = true; } } catch (Exception e) {} Lx: if (!c) goto L1; } // jump inside TryCatchStatement.body { bool c = false; try { if (c) // need to bypass front-end optimization throw new Exception(""); else goto L2; L2: ; } catch (Exception e) {} } // exit from TryCatchStatement.body { bool c = false; try { if (c) // need to bypass front-end optimization throw new Exception(""); else goto L3; } catch (Exception e) {} c = true; L3: assert(!c); } return 1; }()); static assert(() { // enter to TryCatchStatement.catches which has no exception variable { bool c = false; goto L1; try { c = true; } catch (Exception/* e*/) { L1: ; } assert(c == false); } // jump inside TryCatchStatement.catches { bool c = false; try { throw new Exception(""); } catch (Exception e) { goto L2; c = true; L2: ; } assert(c == false); } // exit from TryCatchStatement.catches { bool c = false; try { throw new Exception(""); } catch (Exception e) { goto L3; c = true; } L3: assert(c == false); } return 1; }()); static assert(() { // enter forward to TryFinallyStatement.body { bool c = false; goto L0; c = true; try { L0: ; } finally {} assert(!c); } // enter back to TryFinallyStatement.body { bool c = false; try { goto Lx; L1: c = true; } finally { } Lx: if (!c) goto L1; } // jump inside TryFinallyStatement.body { try { goto L2; L2: ; } finally {} } // exit from TryFinallyStatement.body { bool c = false; try { goto L3; } finally {} c = true; L3: assert(!c); } // enter in / exit out from finally block is rejected in semantic analysis // jump inside TryFinallyStatement.finalbody { bool c = false; try { } finally { goto L4; c = true; L4: assert(c == false); } } return 1; }()); static assert(() { { bool c = false; with (Object.init) { goto L2; c = true; L2: ; } assert(c == false); } { bool c = false; with (Object.init) { goto L3; c = true; } L3: assert(c == false); } return 1; }()); /************************************************** 11627 - cast dchar to char at compile time on AA assignment **************************************************/ bool test11627() { char[ubyte] toCharTmp; dchar letter = 'A'; //char c = cast(char)letter; // OK toCharTmp[0] = cast(char)letter; // NG return true; } static assert(test11627()); /************************************************** 11664 - ignore function local static variables **************************************************/ bool test11664() { static int x; static int y = 1; return true; } static assert(test11664()); /************************************************** 12110 - operand of dereferencing does not need to be an lvalue **************************************************/ struct SliceOverIndexed12110 { Uint24Array12110* arr; @property front(uint val) { arr.dupThisReference(); } } struct Uint24Array12110 { ubyte[] data; this(ubyte[] range) { data = range; SliceOverIndexed12110(&this).front = 0; assert(data.length == range.length * 2); } void dupThisReference() { auto new_data = new ubyte[data.length * 2]; data = new_data; } } static m12110 = Uint24Array12110([0x80]); /************************************************** 12310 - heap allocation for built-in sclar types **************************************************/ bool test12310() { auto p1 = new int, p2 = p1; assert(*p1 == 0); assert(*p2 == 0); *p1 = 10; assert(*p1 == 10); assert(*p2 == 10); auto q1 = new int(3), q2 = q1; assert(*q1 == 3); assert(*q2 == 3); *q1 = 20; assert(*q1 == 20); assert(*q2 == 20); return true; } static assert(test12310()); /************************************************** 12499 - initialize TupleDeclaraion in CTFE **************************************************/ auto f12499() { //Initialize 3 ints to 5. TypeTuple!(int, int, int) a = 5; return a[0]; //Error: variable _a_field_0 cannot be read at compile time } static assert(f12499() == 5); /************************************************** 12602 - slice in struct literal members **************************************************/ struct Result12602 { uint[] source; } auto wrap12602a(uint[] r) { return Result12602(r); } auto wrap12602b(uint[] r) { Result12602 x; x.source = r; return x; } auto testWrap12602a() { uint[] dest = [1, 2, 3, 4]; auto ra = wrap12602a(dest[0 .. 2]); auto rb = wrap12602a(dest[2 .. 4]); foreach (i; 0 .. 2) rb.source[i] = ra.source[i]; assert(ra.source == [1,2]); assert(rb.source == [1,2]); assert(&ra.source[0] == &dest[0]); assert(&rb.source[0] == &dest[2]); assert(dest == [1,2,1,2]); return dest; } auto testWrap12602b() { uint[] dest = [1, 2, 3, 4]; auto ra = wrap12602b(dest[0 .. 2]); auto rb = wrap12602b(dest[2 .. 4]); foreach (i; 0 .. 2) rb.source[i] = ra.source[i]; assert(ra.source == [1,2]); assert(rb.source == [1,2]); assert(&ra.source[0] == &dest[0]); assert(&rb.source[0] == &dest[2]); assert(dest == [1,2,1,2]); return dest; } auto testWrap12602c() { uint[] dest = [1, 2, 3, 4]; auto ra = Result12602(dest[0 .. 2]); auto rb = Result12602(dest[2 .. 4]); foreach (i; 0 .. 2) rb.source[i] = ra.source[i]; assert(ra.source == [1,2]); assert(rb.source == [1,2]); assert(&ra.source[0] == &dest[0]); assert(&rb.source[0] == &dest[2]); assert(dest == [1,2,1,2]); return dest; } auto testWrap12602d() { uint[] dest = [1, 2, 3, 4]; Result12602 ra; ra.source = dest[0 .. 2]; Result12602 rb; rb.source = dest[2 .. 4]; foreach (i; 0 .. 2) rb.source[i] = ra.source[i]; assert(ra.source == [1,2]); assert(rb.source == [1,2]); assert(&ra.source[0] == &dest[0]); assert(&rb.source[0] == &dest[2]); assert(dest == [1,2,1,2]); return dest; } static assert(testWrap12602a() == [1,2,1,2]); static assert(testWrap12602b() == [1,2,1,2]); static assert(testWrap12602c() == [1,2,1,2]); static assert(testWrap12602d() == [1,2,1,2]); /************************************************** 12677 - class type initializing from DotVarExp **************************************************/ final class C12677 { TypeTuple!(Object, int[]) _test; this() { auto t0 = _test[0]; // auto t1 = _test[1]; // assert(t0 is null); assert(t1 is null); } } struct S12677 { auto f = new C12677(); } /************************************************** 12851 - interpret function local const static array **************************************************/ void test12851() { const int[5] arr; alias staticZip = TypeTuple!(arr[0]); } /************************************************** 13630 - indexing and setting array element via pointer **************************************************/ struct S13630(T) { T[3] arr; this(A...)(auto ref in A args) { auto p = arr.ptr; foreach (ref v; args) { *p = 0; } } } enum s13630 = S13630!float(1); /************************************************** 13827 **************************************************/ struct Matrix13827(T, uint N) { private static defaultMatrix() { T arr[N]; return arr; } union { T[N] A = defaultMatrix; T[N] flat; } this(A...)(auto ref in A args) { uint k; foreach (ref v; args) flat[k++] = cast(T)v; } } enum m13827 = Matrix13827!(int, 3)(1, 2, 3); /************************************************** 13847 - support DotTypeExp **************************************************/ class B13847 { int foo() { return 1; } } class C13847 : B13847 { override int foo() { return 2; } final void test(int n) { assert(foo() == n); assert(B13847.foo() == 1); assert(C13847.foo() == 2); assert(this.B13847.foo() == 1); assert(this.C13847.foo() == 2); } } class D13847 : C13847 { override int foo() { return 3; } } static assert({ C13847 c = new C13847(); c.test(2); assert(c.B13847.foo() == 1); assert(c.C13847.foo() == 2); D13847 d = new D13847(); d.test(3); assert(d.B13847.foo() == 1); assert(d.C13847.foo() == 2); assert(d.D13847.foo() == 3); c = d; c.test(3); assert(c.B13847.foo() == 1); assert(c.C13847.foo() == 2); return true; }()); /************************************************** 12495 - cast from string to immutable(ubyte)[] **************************************************/ string getStr12495() { char[1] buf = void; // dummy starting point. string s = cast(string)buf[0..0]; // empty slice, .ptr points mutable. assert(buf.ptr == s.ptr); s ~= 'a'; // this should allocate. assert(buf.ptr != s.ptr); return s.idup; // this should allocate again, and // definitly point immutable memory. } auto indexOf12495(string s) { auto p1 = s.ptr; auto p2 = (cast(immutable(ubyte)[])s).ptr; assert(cast(void*)p1 == cast(void*)p2); // OK <- fails return cast(void*)p2 - cast(void*)p1; // OK <- "cannot subtract pointers ..." } static assert(indexOf12495(getStr12495()) == 0); /************************************************** 13992 - Repainting pointer arithmetic result **************************************************/ enum hash13992 = hashOf13992("abcd".ptr); @trusted hashOf13992(const void* buf) { auto data = cast(const(ubyte)*) buf; size_t hash; data += 2; // problematic pointer arithmetic hash += *data; // CTFE internal issue was shown by the dereference return hash; } /************************************************** 13739 - Precise copy for ArrayLiteralExp elements **************************************************/ static assert( { int[] a1 = [13]; int[][] a2 = [a1]; assert(a2[0] is a1); // OK assert(a2[0].ptr is a1.ptr); // OK <- NG a1[0] = 1; assert(a2[0][0] == 1); // OK <- NG a2[0][0] = 2; assert(a1[0] == 2); // OK <- NG return 1; }()); /************************************************** 14463 - ICE on slice assignment without postblit **************************************************/ struct Boo14463 { private int[1] c; this(int[] x) { c = x; } } immutable Boo14463 a14463 = Boo14463([1]); /************************************************** 13295 - Don't copy struct literal in VarExp::interpret() **************************************************/ struct S13295 { int n; } void f13295(ref const S13295 s) { *cast(int*) &s.n = 1; assert(s.n == 1); // OK <- fail } static assert( { S13295 s; f13295(s); return s.n == 1; // true <- false }()); int foo14061(int[] a) { foreach (immutable x; a) { auto b = a ~ x; return b == [1, 1]; } return 0; } static assert(foo14061([1])); /************************************************** 14024 - CTFE version **************************************************/ bool test14024() { string op; struct S { char x = 'x'; this(this) { op ~= x-0x20; } // upper case ~this() { op ~= x; } // lower case } S[4] mem; ref S[2] slice(int a, int b) { return mem[a .. b][0 .. 2]; } op = null; mem[0].x = 'a'; mem[1].x = 'b'; mem[2].x = 'x'; mem[3].x = 'y'; slice(0, 2) = slice(2, 4); // [ab] = [xy] assert(op == "XaYb", op); op = null; mem[0].x = 'x'; mem[1].x = 'y'; mem[2].x = 'a'; mem[3].x = 'b'; slice(2, 4) = slice(0, 2); // [ab] = [xy] assert(op == "XaYb", op); op = null; mem[0].x = 'a'; mem[1].x = 'b'; mem[2].x = 'c'; slice(0, 2) = slice(1, 3); // [ab] = [bc] assert(op == "BaCb", op); op = null; mem[0].x = 'x'; mem[1].x = 'y'; mem[2].x = 'z'; slice(1, 3) = slice(0, 2); // [yz] = [xy] assert(op == "YzXy", op); return true; } static assert(test14024()); /************************************************** 14304 - cache of static immutable value **************************************************/ immutable struct Bug14304 { string s_name; alias s_name this; string fun()() { return "fun"; } } class Buggy14304 { static string fun(string str)() { return str; } static immutable val = immutable Bug14304("val"); } void test14304() { enum kt = Buggy14304.fun!(Buggy14304.val); static assert(kt == "val"); enum bt = Buggy14304.val.fun(); static assert(bt == "fun"); } /************************************************** 14371 - evaluate BinAssignExp as lvalue **************************************************/ int test14371() { int x; ++(x += 1); return x; } static assert(test14371() == 2); /************************************************** 7151 - [CTFE] cannot compare classes with == **************************************************/ bool test7151() { auto a = new Object; return a == a && a != new Object; } static assert(test7151()); /************************************************** 12603 - [CTFE] goto does not correctly call dtors **************************************************/ struct S12603 { this(uint* dtorCalled) { *dtorCalled = 0; this.dtorCalled = dtorCalled; } @disable this(); ~this() { ++*dtorCalled; } uint* dtorCalled; } auto numDtorCallsByGotoWithinScope() { uint dtorCalled; { S12603 s = S12603(&dtorCalled); assert(dtorCalled == 0); goto L_abc; L_abc: assert(dtorCalled == 0); } assert(dtorCalled == 1); return dtorCalled; } static assert(numDtorCallsByGotoWithinScope() == 1); auto numDtorCallsByGotoOutOfScope() { uint dtorCalled; { S12603 s = S12603(&dtorCalled); assert(dtorCalled == 0); goto L_abc; } L_abc: assert(dtorCalled == 1); return dtorCalled; } static assert(numDtorCallsByGotoOutOfScope() == 1); uint numDtorCallsByGotoDifferentScopeAfter() { uint dtorCalled; { S12603 s = S12603(&dtorCalled); assert(dtorCalled == 0); } assert(dtorCalled == 1); goto L_abc; L_abc: assert(dtorCalled == 1); return dtorCalled; } static assert(numDtorCallsByGotoDifferentScopeAfter() == 1); auto numDtorCallsByGotoDifferentScopeBefore() { uint dtorCalled; assert(dtorCalled == 0); goto L_abc; L_abc: assert(dtorCalled == 0); { S12603 s = S12603(&dtorCalled); assert(dtorCalled == 0); } assert(dtorCalled == 1); return dtorCalled; } static assert(numDtorCallsByGotoDifferentScopeBefore() == 1); struct S12603_2 { ~this() { dtorCalled = true; } bool dtorCalled = false; } auto structInCaseScope() { auto charsets = S12603_2(); switch(1) { case 0: auto set = charsets; break; default: break; } return charsets.dtorCalled; } static assert(!structInCaseScope()); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9565.d0000644000175000017500000000615213200164641023370 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: template TypeTuple(T...) { alias TypeTuple = T; } bool startsWith(string s, string m) { return s[0 .. m.length] == m; } void main() { enum string castPrefix = "cast(" ~ size_t.stringof ~ ")"; // TypeSArray static assert((int[10]).stringof == "int[10]", T.stringof); int[] arr; // IndexExp { // index == IntegerExp static assert((arr[ 4 ]).stringof == "arr[4]"); static assert((arr[ 4U ]).stringof == "arr[4]"); static assert((arr[ 4L ]).stringof == "arr[4]"); static assert((arr[ 4LU]).stringof == "arr[4]"); // index == UAddExp static assert((arr[+4 ]).stringof == "arr[4]"); static assert((arr[+4U ]).stringof == "arr[4]"); static assert((arr[+4L ]).stringof == "arr[4]"); static assert((arr[+4LU]).stringof == "arr[4]"); // index == NegExp static assert((arr[-4 ]).stringof == "arr[" ~ castPrefix ~ "-4]"); static assert((arr[-4U ]).stringof == "arr[4294967292]"); static assert((arr[int.min] ).stringof == "arr[" ~ castPrefix ~ "-2147483648]"); static if (is(size_t == ulong)) { static assert((arr[-4L ]).stringof == "arr[" ~ castPrefix ~ "-4L]"); static assert((arr[-4LU]).stringof == "arr[-4LU]"); // IntegerLiteral needs suffix if the value is greater than long.max static assert((arr[long.max + 0]).stringof == "arr[9223372036854775807]"); static assert((arr[long.max + 1]).stringof == "arr[" ~ castPrefix ~ "(9223372036854775807L + 1L)]"); } foreach (Int; TypeTuple!(byte, ubyte, short, ushort, int, uint, long, ulong)) { enum Int p4 = +4; enum string result1 = (arr[p4]).stringof; static assert(result1 == "arr[4]"); enum string result2 = (arr[cast(Int)+4]).stringof; static assert(result2 == "arr[4]"); } foreach (Int; TypeTuple!(byte, short, int, long)) { // keep "cast(Type)" in the string representation enum Int m4 = -4; static if (is(typeof({ size_t x = m4; }))) { enum string result1 = (arr[m4]).stringof; static assert(result1.startsWith("arr[" ~ castPrefix)); } else static assert(!__traits(compiles, arr[m4])); enum string result2 = (arr[cast(Int)-4]).stringof; static assert(result2.startsWith("arr[" ~ castPrefix)); } } // SliceExp { // lwr,upr == IntegerExp static assert((arr[4 .. 8 ]).stringof == "arr[4..8]"); static assert((arr[4U .. 8U ]).stringof == "arr[4..8]"); static assert((arr[4L .. 8L ]).stringof == "arr[4..8]"); static assert((arr[4LU .. 8LU]).stringof == "arr[4..8]"); // lwr,upr == UAddExp static assert((arr[+4 .. +8 ]).stringof == "arr[4..8]"); static assert((arr[+4U .. +8U ]).stringof == "arr[4..8]"); static assert((arr[+4L .. +8L ]).stringof == "arr[4..8]"); static assert((arr[+4LU .. +8LU]).stringof == "arr[4..8]"); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9037.d0000644000175000017500000000034613200164641023313 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9037 module ddoc9037; /** Example: ---- D d = d; ---- ---- D d = d; ---- */ void test9037() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test14838.d0000644000175000017500000000553313200164641023451 0ustar matthiasmatthias// PERMUTE_ARGS: struct A(T) { ~this() {} } class C { A!int[1] array; } void test14838() pure nothrow @nogc @safe { C c; c.__xdtor(); // C.~this() will also be inferred to // pure nothrow @nogc @safe A!int[1] array; // scope destructor call does not cause attribute violation. } // ---- /* * This is a reduced test case comes from std.container.Array template, * to fix the semantic analysis order issue for correct destructor attribute inference. * * Before the bugfix: * 1. StructDeclaration('Array!int')->semantic() instantiates * RangeT!(Array!int) at the `alias Range = ...;`, but * StructDeclaration('RangeT!(Array!int)')->semantic() exits * with sizeok == SIZEOKfwd, because the size of _outer_ field is not yet determined. * 2. StructDeclaration('Array!int')->semantic() succeeds to determine the size * (sizeok = SIZEOKdone). * 3. StructDeclaration('Array!int')->buildOpAssign() will generate opAssign because * Array!int._data field has identity opAssign member function. * 4. The semantic3 will get called for the generated opAssign, then * 6-1. Array!int.~this() semantic3, and * 6-2. RefCounted!(Array!int.Payload).~this() semantic3 * will also get called to infer their attributes. * 5. In RefCounted!(Array!int.Payload).~this(), destroy(t) will be instantiated. * At that, TemplateInstance::expandMembers() will invoke runDeferredSemantic() * and it will re-run StructDeclaration('RangeT!(Array!int)')->semantic(). * 6. StructDeclaration('RangeT!(Array!int)')->semantic() determines the size * (sizeok = SIZEOKdone). Then, it will generate identity opAssign and run its semantic3. * It will need to infer RangeT!(Array!int).~this() attribute, then it requires the * correct attribute of Array!int.~this(). * * However, the Array!int.~this() attribute is not yet determined! [bug] * -> it's wongly handled as impure/system/throwable/gc-able. * * -> then, the attribute inference results for * RangeT!(Array!int).~this() and Array!int.~this() will be incorrect. * * After the bugfix: * In 6, StructDeclaration('RangeT!(Array!int)')->semantic() will check that: * all base struct types of the instance fields have completed addition of * special functions (dtor, opAssign, etc). * If not, it will defer the completion of its semantic pass. */ void destroy14838(S)(ref S s) if (is(S == struct)) { s.__xdtor(); } struct RefCounted14838(T) { ~this() { T t; .destroy14838(t); } void opAssign(typeof(this) rhs) {} } struct RangeT14838(A) { A[1] _outer_; } struct Array14838(T) { struct Payload { ~this() {} } RefCounted14838!Payload _data; alias Range = RangeT14838!Array14838; } class Test14838 { Array14838!int[1] field; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10186.d0000644000175000017500000000033113200164641023430 0ustar matthiasmatthiasstruct S { @disable this(); this(int i) { } } class C { this() { s = S(1); } S s; } class CR { S s; this() { s = S(1); } } void main() { auto c = new C; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc13270.d0000644000175000017500000000071513200164641023365 0ustar matthiasmatthias// PERMUTE_ARGS: -w // REQUIRED_ARGS: -o- -D -Dd${RESULTS_DIR}/compilable // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 13270 module ddoc13270; /** * My overloaded function. * * Params: * task = String description of stuff to do. * tasks = Array of descriptions of stuff to do. * maxJobs = Max parallel jobs to run while doing stuff. */ void doStuff(string task) {} /// ditto void doStuff(string[] tasks, int maxJobs) {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8696.d0000644000175000017500000000021313200164641023364 0ustar matthiasmatthias// REQUIRED_ARGS: -w // 8696: incorrect dangling else with version(): version (all): version (linux) { } else version (OSX) { } else { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/sw_transition_complex.d0000644000175000017500000001432313200164641026511 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -c -transition=complex /* TEST_OUTPUT: --- compilable/sw_transition_complex.d(15): use of complex type 'creal' is scheduled for deprecation, use 'std.complex.Complex!(real)' instead compilable/sw_transition_complex.d(16): use of complex type 'cdouble' is scheduled for deprecation, use 'std.complex.Complex!(double)' instead compilable/sw_transition_complex.d(17): use of complex type 'cfloat' is scheduled for deprecation, use 'std.complex.Complex!(float)' instead compilable/sw_transition_complex.d(19): use of imaginary type 'ireal' is scheduled for deprecation, use 'real' instead compilable/sw_transition_complex.d(20): use of imaginary type 'idouble' is scheduled for deprecation, use 'double' instead compilable/sw_transition_complex.d(21): use of imaginary type 'ifloat' is scheduled for deprecation, use 'float' instead --- */ creal c80value; cdouble c64value; cfloat c32value; ireal i80value; idouble i64value; ifloat i32value; /* TEST_OUTPUT: --- compilable/sw_transition_complex.d(34): use of complex type 'creal*' is scheduled for deprecation, use 'std.complex.Complex!(real)' instead compilable/sw_transition_complex.d(35): use of complex type 'cdouble*' is scheduled for deprecation, use 'std.complex.Complex!(double)' instead compilable/sw_transition_complex.d(36): use of complex type 'cfloat*' is scheduled for deprecation, use 'std.complex.Complex!(float)' instead compilable/sw_transition_complex.d(38): use of imaginary type 'ireal*' is scheduled for deprecation, use 'real' instead compilable/sw_transition_complex.d(39): use of imaginary type 'idouble*' is scheduled for deprecation, use 'double' instead compilable/sw_transition_complex.d(40): use of imaginary type 'ifloat*' is scheduled for deprecation, use 'float' instead --- */ creal* c80pointer; cdouble* c64pointer; cfloat* c32pointer; ireal* i80pointer; idouble* i64pointer; ifloat* i32pointer; /* TEST_OUTPUT: --- compilable/sw_transition_complex.d(53): use of complex type 'creal[]*' is scheduled for deprecation, use 'std.complex.Complex!(real)' instead compilable/sw_transition_complex.d(54): use of complex type 'cdouble[]*' is scheduled for deprecation, use 'std.complex.Complex!(double)' instead compilable/sw_transition_complex.d(55): use of complex type 'cfloat[]*' is scheduled for deprecation, use 'std.complex.Complex!(float)' instead compilable/sw_transition_complex.d(57): use of imaginary type 'ireal[]*' is scheduled for deprecation, use 'real' instead compilable/sw_transition_complex.d(58): use of imaginary type 'idouble[]*' is scheduled for deprecation, use 'double' instead compilable/sw_transition_complex.d(59): use of imaginary type 'ifloat[]*' is scheduled for deprecation, use 'float' instead --- */ creal[]* c80arrayp; cdouble[]* d64arrayp; cfloat[]* c32arrayp; ireal[]* i80arrayp; idouble[]* i64arrayp; ifloat[]* i32arrayp; /* TEST_OUTPUT: --- compilable/sw_transition_complex.d(72): use of complex type 'creal[4][]*' is scheduled for deprecation, use 'std.complex.Complex!(real)' instead compilable/sw_transition_complex.d(73): use of complex type 'cdouble[4][]*' is scheduled for deprecation, use 'std.complex.Complex!(double)' instead compilable/sw_transition_complex.d(74): use of complex type 'cfloat[4][]*' is scheduled for deprecation, use 'std.complex.Complex!(float)' instead compilable/sw_transition_complex.d(76): use of imaginary type 'ireal[4][]*' is scheduled for deprecation, use 'real' instead compilable/sw_transition_complex.d(77): use of imaginary type 'idouble[4][]*' is scheduled for deprecation, use 'double' instead compilable/sw_transition_complex.d(78): use of imaginary type 'ifloat[4][]*' is scheduled for deprecation, use 'float' instead --- */ creal[4][]* c80sarrayp; cdouble[4][]* c64sarrayp; cfloat[4][]* c32sarrayp; ireal[4][]* i80sarrayp; idouble[4][]* i64sarrayp; ifloat[4][]* i32sarrayp; /* TEST_OUTPUT: --- compilable/sw_transition_complex.d(96): use of complex type 'creal' is scheduled for deprecation, use 'std.complex.Complex!(real)' instead compilable/sw_transition_complex.d(97): use of complex type 'creal*' is scheduled for deprecation, use 'std.complex.Complex!(real)' instead compilable/sw_transition_complex.d(98): use of complex type 'creal[]' is scheduled for deprecation, use 'std.complex.Complex!(real)' instead compilable/sw_transition_complex.d(99): use of complex type 'creal[4]' is scheduled for deprecation, use 'std.complex.Complex!(real)' instead compilable/sw_transition_complex.d(101): use of imaginary type 'ireal' is scheduled for deprecation, use 'real' instead compilable/sw_transition_complex.d(102): use of imaginary type 'ireal*' is scheduled for deprecation, use 'real' instead compilable/sw_transition_complex.d(103): use of imaginary type 'ireal[]' is scheduled for deprecation, use 'real' instead compilable/sw_transition_complex.d(104): use of imaginary type 'ireal[4]' is scheduled for deprecation, use 'real' instead --- */ alias C14488 = creal; alias I14488 = ireal; C14488 calias1; C14488* calias2; C14488[] calias3; C14488[4] calias4; I14488 ialias1; I14488* ialias2; I14488[] ialias3; I14488[4] ialias4; /* TEST_OUTPUT: --- compilable/sw_transition_complex.d(115): use of complex type 'cdouble' is scheduled for deprecation, use 'std.complex.Complex!(double)' instead compilable/sw_transition_complex.d(116): use of imaginary type 'idouble' is scheduled for deprecation, use 'double' instead compilable/sw_transition_complex.d(117): use of complex type 'cdouble' is scheduled for deprecation, use 'std.complex.Complex!(double)' instead compilable/sw_transition_complex.d(118): use of complex type 'cdouble[]' is scheduled for deprecation, use 'std.complex.Complex!(double)' instead --- */ auto cauto = 1 + 0i; auto iauto = 1i; size_t c64sizeof = (cdouble).sizeof; TypeInfo c64ti = typeid(cdouble[]); /* TEST_OUTPUT: --- compilable/sw_transition_complex.d(128): use of complex type 'creal*' is scheduled for deprecation, use 'std.complex.Complex!(real)' instead compilable/sw_transition_complex.d(128): use of imaginary type 'ireal' is scheduled for deprecation, use 'real' instead compilable/sw_transition_complex.d(132): use of complex type 'creal' is scheduled for deprecation, use 'std.complex.Complex!(real)' instead --- */ void test14488a(creal *p, real r, ireal i) { } creal test14488b() { return 1 + 0i; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc13.d0000644000175000017500000000074613200164641023140 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 13 /// struct doc struct Bug4107(T) { /// templated function doc void foo(U)(U u) { } } /// alpha struct Bug4107b(T) { /// beta struct B(U) { /// gamma struct C(V) { /// delta struct D(W) { /// epsilon B!W e(X)(C!V c, X[] x...) {} } } } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testparse.d0000644000175000017500000000757013200164641024077 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -o- /***************************************************/ // 6719 pragma(msg, __traits(compiles, mixin("(const(A))[0..0]"))); /***************************************************/ // 9232 struct Foo9232 { void bar(T)() {} void baz() {} } void test9232() { Foo9232 foo; (foo).bar!int(); // OK <- Error: found '!' when expecting ';' following statement ((foo)).bar!int(); // OK foo.bar!int(); // OK (foo).baz(); // OK } /***************************************************/ // 9401 struct S9401a { ~this() nothrow pure @safe { } } struct S9401b { @safe ~this() pure nothrow { } } void test9401() nothrow pure @safe { S9401a s1; S9401b s2; } /***************************************************/ // 9649 class Outer9649 { class Inner { } } void test9649() { Outer9649 outer9649; (outer9649).new Inner(); } /***************************************************/ // 9679 void test9679(inout int = 0) { if ( auto n = 1) { static assert(is(typeof(n) == int)); } if ( const n = 1) { static assert(is(typeof(n) == const int)); } if ( immutable n = 1) { static assert(is(typeof(n) == immutable int)); } if (shared n = 1) { static assert(is(typeof(n) == shared int)); } if (shared const n = 1) { static assert(is(typeof(n) == shared const int)); } if ( inout n = 1) { static assert(is(typeof(n) == inout int)); } if (shared inout n = 1) { static assert(is(typeof(n) == shared inout int)); } if ( const int n = 1) { static assert(is(typeof(n) == const int)); } if ( immutable int n = 1) { static assert(is(typeof(n) == immutable int)); } if (shared int n = 1) { static assert(is(typeof(n) == shared int)); } if (shared const int n = 1) { static assert(is(typeof(n) == shared const int)); } if ( inout int n = 1) { static assert(is(typeof(n) == inout int)); } if (shared inout int n = 1) { static assert(is(typeof(n) == shared inout int)); } if ( const(int) n = 1) { static assert(is(typeof(n) == const int)); } if ( immutable(int) n = 1) { static assert(is(typeof(n) == immutable int)); } if (shared (int) n = 1) { static assert(is(typeof(n) == shared int)); } if (shared const(int) n = 1) { static assert(is(typeof(n) == shared const int)); } if ( inout(int) n = 1) { static assert(is(typeof(n) == inout int)); } if (shared inout(int) n = 1) { static assert(is(typeof(n) == shared inout int)); } if (immutable(int)[] n = [1]) { static assert(is(typeof(n) == immutable(int)[])); } } /***************************************************/ // 9901 template isGood9901(T) { enum isGood9901 = true; } void test9901() { string foo(R)(R data) if (isGood9901!R) { return ""; } foo(1); } /***************************************************/ // 10199 void test10199() { goto label; label: } /***************************************************/ // 12460 void f12460(T)() { static if (is(T == int)) { goto end; } end: } void test12460() { f12460!int(); } /***************************************************/ // 11689 void test11689() { deprecated void foo() {} } /***************************************************/ // 11751 static assert(is(float == typeof(0x0.1p1F))); /***************************************************/ // 11957 extern(C++) class C11957 { void x() {} } void test11957() { extern(C++) class D : C11957 { override void x() {} } } /***************************************************/ // 13049 enum mangle13049(T) = T.mangleof; alias FP13049 = void function(scope int); // OK static assert(mangle13049!FP13049 == mangle13049!(void function(scope int))); // OK <- NG ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test14973.d0000644000175000017500000000175313200164641023451 0ustar matthiasmatthiastemplate map(fun...) { auto map(R)(R r) { return MapResult!(fun, R)(r); } } struct MapResult(alias fun, R) { R _input; @property bool empty() { return _input.length == 0; } @property auto front() { return fun(_input[0]); } void popFront() { _input = _input[1..$]; } } class Foo { int baz() { return 1; } void bar() { auto s = [1].map!(i => baz()); // compiles auto r = [1].map!( // lambda1 i => [1].map!( // lambda2 j => baz() ) ); // compiles <- error } } class Bar { int baz; void bar() { auto s = [1].map!(i => baz); // compiles auto r = [1].map!( // lambda1 i => [1].map!( // lambda2 j => baz ) ); // compiles <- error } } void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice13874.d0000644000175000017500000000073713200164641023232 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: template FunctionTypeOf(func...) if (func.length == 1) { static if (is(typeof(& func[0]) Fsym : Fsym*) && is(Fsym == function) || is(typeof(& func[0]) Fsym == delegate)) { alias Fsym FunctionTypeOf; } else static if (is(typeof(& func[0].opCall) Fobj == delegate)) { alias Fobj FunctionTypeOf; } else static assert(0); } enum DummyEnum; static assert(!is(FunctionTypeOf!DummyEnum)); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc5446b.d0000644000175000017500000000016713200164641023456 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- module ddoc5446b; /** */ enum A_Enum_New { x } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test11824.d0000644000175000017500000000233113200164641023432 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: struct Take(R) { public R source; private size_t _maxAvailable; alias R Source; @property bool empty() { return _maxAvailable == 0 || source.empty; } @property auto ref front() { return source.front; } void popFront() { source.popFront(); --_maxAvailable; } @property size_t length() const { return _maxAvailable; } } struct Repeat(T) { private T _value; enum bool empty = false; @property inout(T) front() inout { return _value; } void popFront() {} } Take!(Repeat!T) repeat(T)(T value, size_t n) { return typeof(return)(Repeat!T(value), n); } auto array(Range)(Range r) { alias E = typeof(r.front); //static if (hasLength!Range) { if (r.length == 0) return null; auto result = new E[](r.length); size_t i; static auto trustedGetAddr(T)(ref T t) @trusted nothrow pure { return &t; } foreach (e; r) { *trustedGetAddr(result[i]) = e; ++i; } return cast(E[])result; } } enum r = [1].repeat(1).array; static assert(r == [[1]]); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/depsOutput9948.d0000644000175000017500000000045113200164641024566 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -deps=${RESULTS_DIR}/compilable/depsOutput9948.deps // POST_SCRIPT: compilable/extra-files/depsOutput.sh // EXTRA_SOURCES: /extra-files/depsOutput9948a.d module depsOutput9948; import depsOutput9948a; void main() { templateFunc!("import std.string;")(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testprofile.d0000644000175000017500000000102213200164641024407 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -profile template LaLa(E...) { class LaLa { this() { } } } void main() { // doesn't work new LaLa!("lala", "lalalalala", "lala", "lala", "lala", "lala", "lalalala", "lala", "lala", "lala", "lalala", "lala", "lala", "lala", "lala", "lala", "lala", "lala", "lala", "lala", "lala", "lala", "lala", "lala", "lala", "lala", "lala"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9278a.d0000644000175000017500000000033213200164641023524 0ustar matthiasmatthias// PREMUTE_ARGS: // Works fine here struct datum { float num = 0.0; } datum emitOne() { datum t; return t; } const dataArr = [emitOne()]; // A very bad day //struct datum { float num = 0.0; } void main(){} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_247.d0000644000175000017500000000007413200164641024555 0ustar matthiasmatthiasimport imports.ldc_github_247a; class A { Value!double v; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test1.d0000644000175000017500000000025313200164641023114 0ustar matthiasmatthias// PERMUTE_ARGS: class File { import imports.test1imp; static char[] read(char[] name) { DWORD size; // DWORD is defined in test1imp return null; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test68.d0000644000175000017500000000032013200164641023204 0ustar matthiasmatthias// PERMUTE_ARGS: // Bugzilla 4278 import imports.test68a; class Foo : OtherModuleClass { override void foo() { super.foo(); } } void main() { new Foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc11823.d0000644000175000017500000000040713200164641023365 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 11823 module ddoc11823; /// file function name is _file, arg defaults to __FILE__ but not __something__ void file(string arg) { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc11.d0000644000175000017500000000171513200164641023133 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 11 /// The various floating point exceptions enum { FE_INVALID = 1, /// FE_DENORMAL = 2, /// FE_DIVBYZERO = 4, /// FE_OVERFLOW = 8, /// FE_UNDERFLOW = 0x10, /// FE_INEXACT = 0x20, /// FE_ALL_EXCEPT = 0x3F, /// Mask of all the exceptions } alias int myint; /// myint bar; /// myint foo(myint x = myint.max) { return x; } /// class Foo { /// this(string s) { } } extern (C): /// struct div_t { int quot,rem; } /// struct ldiv_t { int quot,rem; } /// struct lldiv_t { long quot,rem; } div_t div(int,int); /// ldiv_t ldiv(int,int); /// lldiv_t lldiv(long, long); /// void *calloc(size_t, size_t); /// void *malloc(size_t); /// dittx /** Example: --- private: int i = 0; --- */ void test1() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice13920.d0000644000175000017500000000071213200164641023213 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: class Foo { void foo() { foreach (f; __traits(getOverloads, typeof(this), "bar")) { auto dg = &f; } foreach (f; __traits(getVirtualMethods, typeof(this), "bar")) { auto dg = &f; } foreach (f; __traits(getVirtualFunctions, typeof(this), "bar")) { auto dg = &f; } } uint bar() { return 0; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice13886.d0000644000175000017500000000026413200164641023230 0ustar matthiasmatthias// REQUIRED__ARGS: // PERMUTE_ARGS: struct Y() { this() {} ~this() { this = null; } ref opAssign(S)(S) { } } void main() { static if (is(typeof({ Y!(); }))) {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/deprecate14283.d0000644000175000017500000000072413200164641024415 0ustar matthiasmatthias// REQUIRED_ARGS: -dw /* TEST_OUTPUT: --- compilable/deprecate14283.d(17): Deprecation: this is not an lvalue compilable/deprecate14283.d(18): Deprecation: super is not an lvalue --- */ class C { void bug() { autoref(this); // suppress warning for auto ref autoref(super); // suppress warning for auto ref ref_(this); // still warns ref_(super); // still warns } } void autoref(T)(auto ref T t) {} void ref_(T)(ref T) {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc5446.d0000644000175000017500000000203213200164641023305 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 5446 module ddoc5446; import ddoc5446a; private import ddoc5446b; /** */ alias A_Foo This_Foo; /** */ alias A_Foo_Alias This_Foo_Alias; /** */ alias int This_Int; /** */ alias A_Enum This_Enum; /** */ deprecated alias ddoc5446b.A_Enum_New A_Enum_New; struct Nested { } /** */ struct Bar { /** */ alias A_Foo Bar_A_Foo; /** */ alias A_Foo_Alias Bar_A_Foo_Alias; /** */ alias A_Int Bar_A_Int; /** */ alias This_Foo Bar_This_Foo; /** */ alias This_Foo_Alias Bar_This_Foo_Alias; /** */ alias This_Int Bar_This_Int; /** */ alias Nested Nested_Alias; /** */ alias .Nested Fake_Nested; /** */ struct Nested { /** */ alias Bar Bar_Nested_Bar_Alias; /** */ alias .Bar Bar_Alias; /** */ struct Bar { } } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc4.d0000644000175000017500000000024513200164641023052 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 4 /** a */ enum { ONE } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9497b.d0000644000175000017500000000037413200164641023470 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/ddoc9497b.ddoc // PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9497b /** foo function. Args: $(XYZ arg1, arg2) */ void foo() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/b1215.d0000644000175000017500000000655013200164641022614 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -o- struct A(Args...) { enum i = 1; // base use case. Args[0].T mBase; static assert(is(typeof(mBase) == B.T)); // chained types Args[0].T.TT mChain; static assert(is(typeof(mChain) == B.T.TT)); // chained packs Args[1+1].FArgs[0] mChainPack; static assert(is(typeof(mChainPack) == B)); // expr enum mExpr = Args[1].i; static assert(mExpr == B.i); // Nested + index eval Args[Args[0].i2].T mNested; static assert(is(typeof(mNested) == B.T)); // index with constexpr Args[i].T mCEIndex; static assert(is(typeof(mCEIndex) == B.T)); // Nested + index with constexpr Args[Args[i].i2].T mNestedCE; static assert(is(typeof(mNestedCE) == B.T)); // alias, base use case alias UBase = Args[0].T; static assert(is(UBase == B.T)); // alias, chained types alias UChain = Args[0].T.TT; static assert(is(UChain == B.T.TT)); // alias, chained packs alias UChainPack = Args[1+1].FArgs[0]; static assert(is(UChainPack == B)); // alias, expr alias uExpr = Args[1].i; static assert(uExpr == B.i); // alias, Nested + index eval alias UNested = Args[Args[0].i2].T; static assert(is(UNested == B.T)); // alias, index with constexpr alias UCEIndex = Args[i].T; static assert(is(UCEIndex == B.T)); // alias, Nested + index with constexpr alias UNextedCE = Args[Args[i].i2].T; static assert(is(UNextedCE == B.T)); } struct B { struct T { struct TT { } } enum i = 6; enum i2 = 0; } struct C(Args...) { alias FArgs = Args; } alias Z = A!(B,B,C!(B,B)); /***************************************************/ // 14889 struct A14889(alias Exc) { alias ExceptionType = Exc; } alias TT14889(Args...) = Args; alias X14889a = TT14889!(A14889!Throwable()); alias Y14889a = X14889a[0].ExceptionType; alias X14889b = TT14889!(A14889!Throwable); alias Y14889b = X14889b[0].ExceptionType; /***************************************************/ // 14889 alias TypeTuple14900(T...) = T; struct S14900 { alias T = int; alias U = TypeTuple14900!(long,string); } alias Types14900 = TypeTuple14900!(S14900, S14900); Types14900[0].T a14900; // Types[0] == S, then typeof(a) == S.T == int Types14900[0].U[1] b14900; // Types[0].U == S.U, then typeof(b) == S.U[1] == string void test14900() { Types14900[0].T a; // Types[0] == S, then typeof(a) == S.T == int Types14900[0].U[1] b; // Types[0].U == S.U, then typeof(b) == S.U[1] == string } /***************************************************/ // 14911 void test14911() { struct S {} int* buf1 = new int[2].ptr; // OK S* buf2 = (new S[2]).ptr; // OK S* buf3 = new S[2].ptr; // OK <- broken } /***************************************************/ // 14986 alias Id14986(alias a) = a; struct Foo14986 { int tsize; } struct Bar14986 { enum Foo14986[] arr = [Foo14986()]; } Bar14986 test14986() { Foo14986[] types; auto a1 = new void[types[0].tsize]; // TypeIdentifier::toExpression auto a2 = new void[Id14986!types[0].tsize]; // TypeInstance::toExpression Bar14986 bar; auto a3 = Id14986!(typeof(bar).arr[0].tsize); // TypeTypeof::resolve auto a4 = Id14986!(typeof(return).arr[0].tsize); // TypeReturn::resolve return Bar14986(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc12.d0000644000175000017500000000064213200164641023132 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 12 int ruhred; /// This documents correctly. int rühred; /// This should too /** * BUG: The parameters are not listed under Params in the generated output * * Params: * ü = first * ÅŸ = second * ÄŸ = third * */ int foo(int ü, int ÅŸ, int ÄŸ) { return ÄŸ; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_821.d0000644000175000017500000000012413200164641024547 0ustar matthiasmatthias// EXTRA_SOURCES: imports/ldc_github_821a.d import imports.ldc_github_821a; S* s; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test14666.d0000644000175000017500000000015513200164641023443 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: module test14666; struct Location { import imports.test14666a; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_739.d0000644000175000017500000000047013200164641024563 0ustar matthiasmatthias// EXTRA_SOURCES: imports/ldc_github_739b.d module ldc_github_739; import imports.ldc_github_739a; template map(fun...) { auto map(Range)(Range) { return MapResult!(fun, Range)(); } } struct MapResult(alias fun, R) { R _input; MapResult opSlice() { return MapResult(); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8922c.d0000644000175000017500000000045313200164641023525 0ustar matthiasmatthias// PERMUTE_ARGS: static import imports.bug8922; void test() { static assert(!__traits(compiles, __traits(parent, imports))); static assert(!__traits(compiles, __traits(parent, bug8922))); enum x = __traits(parent, imports.bug8922).stringof; static assert(x == "package imports"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test14317.d0000644000175000017500000000036313200164641023435 0ustar matthiasmatthias // REQUIRED_ARGS: -O -profile -inline struct Range { private string s; char charAt(int unused1) { return s[0]; } } bool count(Range* r, int* unused2) { *unused2 = 0; int unused3; char c = r.charAt(0); return true; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testInference.d0000644000175000017500000005271413200164641024663 0ustar matthiasmatthias /***************************************************/ // 6265. pure nothrow @safe int h6265() { return 1; } int f6265a(alias g)() { return g(); } pure nothrow @safe int i6265a() { return f6265a!h6265(); } int f6265b()() { return h6265(); } pure nothrow @safe int i6265b() { return f6265b(); } pure nothrow @safe int i6265c() { return { return h6265(); }(); } /***************************************************/ // Make sure a function is not infered as pure if it isn't. int fNPa() { return 1; } int gNPa()() { return fNPa(); } static assert( __traits(compiles, function int () { return gNPa(); })); static assert(!__traits(compiles, function int () pure { return gNPa(); })); static assert(!__traits(compiles, function int () nothrow { return gNPa(); })); static assert(!__traits(compiles, function int () @safe { return gNPa(); })); /***************************************************/ // Need to ensure the comment in Expression::checkPurity is not violated. void fECPa() { void g()() { void h() { } h(); } static assert( is(typeof(&g!()) == void delegate() pure nothrow @nogc @safe)); static assert(!is(typeof(&g!()) == void delegate())); } void fECPb() { void g()() { void h() { } fECPb(); } static assert(!is(typeof(&g!()) == void delegate() pure)); static assert( is(typeof(&g!()) == void delegate())); } /***************************************************/ // 5635 pure bool foo5635(R = int)(string x) { bool result = false; foreach (dchar d; x) result = true; return result; } void test5635() { foo5635("hi"); } /***************************************************/ // 5936 auto bug5936c(R)(R i) @safe pure nothrow { return true; } static assert( bug5936c(0) ); /***************************************************/ // 6351 void bug6351(alias dg)() { dg(); } void test6351() { void delegate(int[] a...) deleg6351 = (int[] a...){}; alias bug6351!(deleg6351) baz6531; } /***************************************************/ // 6359 void impure6359() nothrow @safe @nogc {} void throwable6359() pure @safe @nogc {} void system6359() pure nothrow @nogc {} void gcable6359() pure nothrow @safe {} int global6359; void f6359() pure nothrow @safe @nogc { static assert(!__traits(compiles, impure6359())); static assert(!__traits(compiles, throwable6359())); static assert(!__traits(compiles, system6359())); static assert(!__traits(compiles, gcable6359())); static assert(!__traits(compiles, global6359++)); static assert(!__traits(compiles, { impure6359(); }())); static assert(!__traits(compiles, { throwable6359(); }())); static assert(!__traits(compiles, { system6359(); }())); static assert(!__traits(compiles, { gcable6359(); }())); static assert(!__traits(compiles, { global6359++; }())); } void g6359()() pure nothrow @safe @nogc { static assert(!__traits(compiles, impure6359())); static assert(!__traits(compiles, throwable6359())); static assert(!__traits(compiles, system6359())); static assert(!__traits(compiles, gcable6359())); static assert(!__traits(compiles, global6359++)); static assert(!__traits(compiles, { impure6359(); }())); static assert(!__traits(compiles, { throwable6359(); }())); static assert(!__traits(compiles, { system6359(); }())); static assert(!__traits(compiles, { gcable6359(); }())); static assert(!__traits(compiles, { global6359++; }())); } // attribute inference is not affected by the expressions inside __traits(compiles) void h6359()() { static assert( __traits(compiles, impure6359())); static assert( __traits(compiles, throwable6359())); static assert( __traits(compiles, system6359())); static assert( __traits(compiles, gcable6359())); static assert( __traits(compiles, global6359++)); static assert( __traits(compiles, { impure6359(); }())); static assert( __traits(compiles, { throwable6359(); }())); static assert( __traits(compiles, { system6359(); }())); static assert( __traits(compiles, { gcable6359(); }())); static assert( __traits(compiles, { global6359++; }())); } void test6359() pure nothrow @safe @nogc { f6359(); g6359(); h6359(); } /***************************************************/ // 7017 template map7017(fun...) if (fun.length >= 1) { auto map7017() { struct Result { this(int dummy){} // impure member function -> inferred to pure by fixing issue 10329 } return Result(0); // impure call -> inferred to pure by fixing issue 10329 } } int foo7017(immutable int x) pure nothrow { return 1; } void test7017a() pure { int bar7017(immutable int x) pure nothrow { return 1; } static assert(__traits(compiles, map7017!((){})())); static assert(__traits(compiles, map7017!q{ 1 }())); static assert(__traits(compiles, map7017!foo7017())); static assert(__traits(compiles, map7017!bar7017())); } /***************************************************/ // 7017 (little simpler cases) auto map7017a(alias fun)() { return fun(); } // depends on purity of fun auto map7017b(alias fun)() { return; } // always pure auto map7017c(alias fun)() { return yyy7017(); } // always impure int xxx7017() pure { return 1; } int yyy7017() { return 1; } void test7017b() pure { static assert( __traits(compiles, map7017a!xxx7017() )); static assert(!__traits(compiles, map7017a!yyy7017() )); static assert( __traits(compiles, map7017b!xxx7017() )); static assert( __traits(compiles, map7017b!yyy7017() )); static assert(!__traits(compiles, map7017c!xxx7017() )); static assert(!__traits(compiles, map7017c!yyy7017() )); } /***************************************************/ // Test case from std.process auto escapeArgumentImpl(alias allocator)() { return allocator(); } auto escapeShellArgument(alias allocator)() { return escapeArgumentImpl!allocator(); } pure string escapeShellArguments() { char[] allocator() { return new char[1]; } /* Both escape!allocator and escapeImpl!allocator are impure, * but they are nested template function that instantiated here. * Then calling them from here doesn't break purity. */ return escapeShellArgument!allocator(); } /***************************************************/ // 8234 void test8234() { immutable int x = 0; alias FP = typeof({ enum e = x; return e; }); static assert(is(FP : int function())); auto fp = { enum e = x; return e; }; static assert(is(typeof(fp) : int function())); alias DG = typeof({ auto e = x; return e; }); static assert(is(DG : int delegate())); auto dg = { auto e = x; return e; }; static assert(is(typeof(dg) : int delegate())); } /***************************************************/ // 8504 void foo8504()() { static assert(typeof(foo8504!()).stringof == "void()"); static assert(typeof(foo8504!()).mangleof == "FZv"); static assert(foo8504!().mangleof == "_D13testInference12__T7foo8504Z7foo8504FZv"); } auto toDelegate8504a(F)(auto ref F fp) { return fp; } F toDelegate8504b(F)(auto ref F fp) { return fp; } extern(C) void testC8504() {} void test8504() { static assert(typeof(foo8504!()).stringof == "pure nothrow @nogc @safe void()"); static assert(typeof(foo8504!()).mangleof == "FNaNbNiNfZv"); static assert(foo8504!().mangleof == "_D13testInference12__T7foo8504Z7foo8504FNaNbNiNfZv"); auto fp1 = toDelegate8504a(&testC8504); auto fp2 = toDelegate8504b(&testC8504); static assert(is(typeof(fp1) == typeof(fp2))); static assert(typeof(fp1).stringof == "extern (C) void function()"); static assert(typeof(fp2).stringof == "extern (C) void function()"); static assert(typeof(fp1).mangleof == "PUZv"); static assert(typeof(fp2).mangleof == "PUZv"); } /***************************************************/ // 8751 alias bool delegate(in int) pure Bar8751; Bar8751 foo8751a(immutable int x) pure { return y => x > y; // OK } Bar8751 foo8751b(const int x) pure { return y => x > y; // error -> OK } /***************************************************/ // 8793 alias bool delegate(in int) pure Dg8793; alias bool function(in int) pure Fp8793; Dg8793 foo8793fp1(immutable Fp8793 f) pure { return x => (*f)(x); } // OK Dg8793 foo8793fp2( const Fp8793 f) pure { return x => (*f)(x); } // OK Dg8793 foo8793dg1(immutable Dg8793 f) pure { return x => f(x); } // OK Dg8793 foo8793dg2( const Dg8793 f) pure { return x => f(x); } // OK <- error Dg8793 foo8793pfp1(immutable Fp8793* f) pure { return x => (*f)(x); } // OK Dg8793 foo8793pdg1(immutable Dg8793* f) pure { return x => (*f)(x); } // OK Dg8793 foo8793pfp2(const Fp8793* f) pure { return x => (*f)(x); } // OK <- error Dg8793 foo8793pdg2(const Dg8793* f) pure { return x => (*f)(x); } // OK <- error // general case for the hasPointer type Dg8793 foo8793ptr1(immutable int* p) pure { return x => *p == x; } // OK Dg8793 foo8793ptr2(const int* p) pure { return x => *p == x; } // OK <- error /***************************************************/ // 9072 struct A9072(T) { this(U)(U x) {} ~this() {} } void test9072() { A9072!int a = A9072!short(); } /***************************************************/ // 5933 + Issue 8504 - Template attribute inferrence doesn't work int foo5933()(int a) { return a*a; } struct S5933 { double foo()(double a) { return a * a; } } // outside function static assert(typeof(foo5933!()).stringof == "pure nothrow @nogc @safe int(int a)"); static assert(typeof(S5933.init.foo!()).stringof == "pure nothrow @nogc @safe double(double a)"); void test5933() { // inside function static assert(typeof(foo5933!()).stringof == "pure nothrow @nogc @safe int(int a)"); static assert(typeof(S5933.init.foo!()).stringof == "pure nothrow @nogc @safe double(double a)"); } /***************************************************/ // 9148 void test9148a() pure { static int g; int x; void foo1() /+pure+/ { static assert(!__traits(compiles, g++)); x++; } void foo2() pure { static assert(!__traits(compiles, g++)); x++; } foo1(); static assert(is(typeof(&foo1) == void delegate() pure)); foo2(); static assert(is(typeof(&foo2) == void delegate() pure)); void bar1() immutable /+pure+/ { static assert(!__traits(compiles, g++)); static assert(!__traits(compiles, x++)); } void bar2() immutable pure { static assert(!__traits(compiles, g++)); static assert(!__traits(compiles, x++)); } bar1(); static assert(is(typeof(&bar1) == void delegate() pure immutable)); bar2(); static assert(is(typeof(&bar2) == void delegate() pure immutable)); struct S { void foo1() /+pure+/ { static assert(!__traits(compiles, g++)); x++; } void foo2() pure { static assert(!__traits(compiles, g++)); x++; } void bar1() immutable /+pure+/ { static assert(!__traits(compiles, g++)); static assert(!__traits(compiles, x++)); } void bar2() immutable pure { static assert(!__traits(compiles, g++)); static assert(!__traits(compiles, x++)); } } S sm; sm.foo1(); static assert(is(typeof(&sm.foo1) == void delegate() pure)); sm.foo2(); static assert(is(typeof(&sm.foo2) == void delegate() pure)); immutable S si; si.bar1(); static assert(is(typeof(&si.bar1) == void delegate() pure immutable)); si.bar2(); static assert(is(typeof(&si.bar2) == void delegate() pure immutable)); } // ---- // inheritance of pure and @safe void test9148b() pure nothrow @nogc @safe { void nf() {} static assert(is(typeof(&nf) == void delegate() @safe pure)); struct NS { void mf() {} static void sf() {} } NS ns; static assert(is(typeof(&ns.mf) == void delegate() @safe pure)); static assert(is(typeof(&NS.sf) == void function() @safe)); static void sf() {} static assert(is(typeof(&sf) == void function() @safe)); static struct SS { void mf() {} static void sf() {} } SS ss; static assert(is(typeof(&ss.mf) == void delegate() @safe)); static assert(is(typeof(&SS.sf) == void function() @safe)); } void impureSystem9148b() {} void func9148b()() { void bar() // do not inherit PUREfwdref { static assert(is(typeof(&bar) == void delegate())); impureSystem9148b(); } static assert(is(typeof(&bar) == void delegate())); } static assert(is(typeof(&func9148b!()) == void function() pure nothrow @nogc @safe)); // ---- // from fail_compilation/fail283.d pure int double_sqr9148c(int x) { int y = x; void do_sqr() pure { y *= y; } do_sqr(); return y; } void test9148c() { assert(double_sqr9148c(10) == 100); } // ---- // from fail_compilation/fail348.d void test9148d() pure { void g() // implicitly marked as 'pure' { void h() pure { // i() and j() are implicitly marked as 'pure' void i() { } void j() { i(); g(); } // can call i() and g() } } } void test9148e() { int x; static assert(is(typeof((int a){ return a + x; }) == int delegate(int) pure nothrow @nogc @safe)); auto dg = (int a){ return a + x; }; static assert(is(typeof(dg) == int delegate(int) pure nothrow @nogc @safe)); } /***************************************************/ // 12912 struct S12912(alias fun) { void f() { fun(); } } class C12912 { int n; void f() pure { S12912!(() => n) s; // Here lambda should be inferred to weak purity. s.f(); // And this call will be a pure member function call. } } /***************************************************/ // 10002 void impure10002() {} void remove10002(alias pred, bool impure = false, Range)(Range range) { pred(range[0]); static if (impure) impure10002(); } class Node10002 { Node10002 parent; Node10002[] children; void foo() pure { parent.children.remove10002!(n => n is parent)(); remove10002!(n => n is parent)(parent.children); static assert(!__traits(compiles, parent.children.remove10002x!(n => n is parent, true)())); static assert(!__traits(compiles, remove10002x!(n => n is parent, true)(parent.children))); Node10002 p; p.children.remove10002!(n => n is p)(); remove10002!(n => n is p)(p.children); static assert(!__traits(compiles, p.children.remove10002x!(n => n is p, true)())); static assert(!__traits(compiles, remove10002x!(n => n is p, true)(p.children))); } } /***************************************************/ // 10148 void fa10148() {} // fa is @system auto fb10148(T)() { struct A(S) { // [4] Parent function fb is already inferred to @safe, then // fc is forcely marked @safe on default until 2.052. // But fc should keep attribute inference ability // by overriding the inherited @safe-ty from its parent. void fc(T2)() { // [5] During semantic3 process, fc is not @safe on default. static assert(is(typeof(&fc) == void delegate())); fa10148(); } // [1] this is now inferred to @safe by implementing issue 7511 this(S a) {} } // [2] A!int(0) is now calling @safe function, then fb!T also be inferred to @safe return A!int(0); } void test10148() { fb10148!int.fc!int; // [0] instantiate fb // [3] instantiate fc // [6] Afer semantic3 done, fc!int is deduced to @system. static assert(is(typeof(&fb10148!int.fc!int) == void delegate() @system)); } /***************************************************/ // 10289 void test10289() { void foo(E)() { throw new E(""); } void bar(E1, E2)() { throw new E1(""); throw new E2(""); } void baz(E1, E2)(bool cond) { if (cond) throw new E1(""); else throw new E2(""); } import core.exception; static class MyException : Exception { this(string) @safe pure nothrow { super(""); } } static assert( __traits(compiles, () nothrow { foo!Error(); })); static assert( __traits(compiles, () nothrow { foo!AssertError(); })); static assert(!__traits(compiles, () nothrow { foo!Exception(); })); static assert(!__traits(compiles, () nothrow { foo!MyException(); })); static assert( __traits(compiles, () nothrow { bar!(Error, Exception)(); })); static assert(!__traits(compiles, () nothrow { bar!(Exception, Error)(); })); static assert(!__traits(compiles, () nothrow { baz!(Error, Exception)(); })); static assert(!__traits(compiles, () nothrow { baz!(Exception, Error)(); })); } /***************************************************/ // 10296 void foo10296()() { int[3] a; void bar()() { a[1] = 2; } bar(); pragma(msg, typeof(bar!())); // nothrow @safe void() } pure void test10296() { foo10296(); } /***************************************************/ // 12025 struct Foo12025 { int[5] bar; } void test12025a() pure { enum n1 = typeof(Foo12025.bar).length; // OK enum n2 = Foo12025.bar .length; // OK <- error auto x1 = typeof(Foo12025.bar).length; // OK auto x2 = Foo12025.bar .length; // OK <- error } void test12025b() pure { static int[5] bar; enum n1 = typeof(bar).length; // OK enum n2 = bar .length; // OK <- error auto x1 = typeof(bar).length; // OK auto x2 = bar .length; // OK <- error } /***************************************************/ // 12542 int logOf12542(T)(T n) { if (n) return 1 + logOf12542(n/2); return 0; } void test12542() @safe nothrow pure { int log = logOf12542(9); } /***************************************************/ // 12704 void foo12704() @system; alias FP12704 = typeof(function() { foo12704(); }); static assert(is(FP12704 == void function() @system)); /***************************************************/ // 12970 @system { @safe void f12970a() {} } @system { void f12970b() @safe {} } static assert(is(typeof(&f12970a) == void function() @safe)); static assert(is(typeof(&f12970b) == void function() @safe)); @system { @trusted void f12970c() {} } @system { void f12970d() @trusted {} } static assert(is(typeof(&f12970c) == void function() @trusted)); static assert(is(typeof(&f12970d) == void function() @trusted)); @safe { @system void f12970e() {} } @safe { void f12970f() @system {} } static assert(is(typeof(&f12970e) == void function() @system)); static assert(is(typeof(&f12970f) == void function() @system)); @safe { @trusted void f12970g() {} } @safe { void f12970h() @trusted {} } static assert(is(typeof(&f12970g) == void function() @trusted)); static assert(is(typeof(&f12970h) == void function() @trusted)); @trusted { @safe void f12970i() {} } @trusted { void f12970j() @safe {} } static assert(is(typeof(&f12970i) == void function() @safe)); static assert(is(typeof(&f12970j) == void function() @safe)); @trusted { @system void f12970k() {} } @trusted { void f12970l() @system {} } static assert(is(typeof(&f12970k) == void function() @system)); static assert(is(typeof(&f12970l) == void function() @system)); /***************************************************/ // Parsing prefix STC_FUNCATTR for variable declaration __gshared immutable pure nothrow @property @nogc @safe void function() prefix_qualified_fp1; __gshared{immutable{pure{nothrow{@property{@nogc{@safe{void function() prefix_qualified_fp2;}}}}}}} static assert(typeof(prefix_qualified_fp1).stringof == typeof(prefix_qualified_fp2).stringof); static assert(typeof(prefix_qualified_fp1).stringof == "immutable(void function() pure nothrow @nogc @property @safe)"); const pure nothrow @property @nogc @safe void function()[] prefix_qualified_fp_array1; const{pure{nothrow{@property{@nogc{@safe{void function()[] prefix_qualified_fp_array2;}}}}}} static assert(typeof(prefix_qualified_fp_array1).stringof == typeof(prefix_qualified_fp_array2).stringof); static assert(typeof(prefix_qualified_fp_array1).stringof == "const(void function() pure nothrow @nogc @property @safe[])"); /***************************************************/ // Parsing prefix, intermediate, or postfix @safe for alias declaration @safe alias void function() AliasDecl_FP1; alias @safe void function() AliasDecl_FP2; // is not @safe alias void function() @safe AliasDecl_FP3; static assert(AliasDecl_FP1.stringof == "void function() @safe"); static assert(AliasDecl_FP2.stringof == "void function()"); static assert(AliasDecl_FP3.stringof == "void function() @safe"); /***************************************************/ // 13217 void writeln13217(string) {} nothrow void a13217(T)(T x) { try { () { writeln13217("a"); } (); } catch (Exception e) {} } void test13217() { a13217(1); } /***************************************************/ // 13840 struct Foo13840 { int opApply(int delegate(int)) { return 0; } } void func13840() { } void test13840() nothrow { try { foreach (i; Foo13840()) // generated delegate is throwable { func13840(); // throwable function call } } catch {} } // Add more tests regarding inferences later. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/defa.d0000644000175000017500000000031713200164641022754 0ustar matthiasmatthias// PERMUTE_ARGS: module defa; private import imports.defaa; public abstract class A { Display d; int style; this() {} public this(A parent, int style) { this.style = style; d = parent.d; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10695.d0000644000175000017500000000023213200164641023435 0ustar matthiasmatthias// PERMUTE_ARGS: module a; void main() { mixin("string mod1 = __MODULE__;"); mixin("enum mod2 = __MODULE__;"); static assert(mod2 == "a"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc10869.d0000644000175000017500000000062513200164641023400 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 10869 module ddoc10869; /// class C { const { /// void c1Foo() const { } /// void i1Foo() immutable { } } immutable { /// void c2Foo() const { } /// void i2Foo() immutable { } } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice10486.d0000644000175000017500000000010113200164641023207 0ustar matthiasmatthiasvoid main() { typeof(null) null_; int[1] sarr = null_; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testheader1i.d0000644000175000017500000000033713200164641024441 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/header1.d // REQUIRED_ARGS: -o- -H -Hf${RESULTS_DIR}/compilable/header1i.di -inline // PERMUTE_ARGS: -d -dw // POST_SCRIPT: compilable/extra-files/header-postscript.sh header1i void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_841.d0000644000175000017500000000020613200164641024552 0ustar matthiasmatthiasstruct Foo { static union Bar { bool b; ulong l; } Bar bar; } static this() { Foo foo = Foo(); }ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/empty_file.d0000644000175000017500000000000013200164641024177 0ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testVRP.d0000644000175000017500000001612613200164641023431 0ustar matthiasmatthias// PERMUTE_ARGS: -O -inline // Test value-range propagation. // See Bug 3147, Bug 6000, Bug 5225. void add() { byte x, y; short a = x + y; } void leftShift() { byte x, y; short z = x << 1; } void leftShiftFail() { ubyte x, y; ushort z; static assert(!__traits(compiles, z = x << y)); // 1 << 31 surely overflows the range of 'ushort'. } void rightShiftFail() { short x; byte y, z; static assert(!__traits(compiles, z = x >> y)); // [this passes in 2.053.] } void rightShift() { ushort x; ubyte y = x >> 16; } void unsignedRightShiftFail() { int x; ubyte y; static assert(!__traits(compiles, y = x >>> 2)); // [this passes in 2.053.] } void subtract() { ubyte x, y; short z = x - y; } void multiply() { byte x, y; short z = x * y; } void subMulFail() { ubyte x, y; ubyte z; static assert(!__traits(compiles, z = x - y)); static assert(!__traits(compiles, z = x * y)); // [these pass in 2.053.] } void multiplyNeg1() { byte b; b = -1 + (b * -1); static assert(!__traits(compiles, b = -1 + b * ulong.max)); } void divide() { short w; byte y = w / 300; } void divideFail() { short w; byte y; static assert(!__traits(compiles, y = w / -1)); } void plus1Fail() { byte u, v; static assert(!__traits(compiles, v = u + 1)); // [these pass in 2.053.] } void modulus() { int x; byte u = x % 128; } void modulus_bug6000a() { ulong t; uint u = t % 16; } void modulus_bug6000b() { long n = 10520; ubyte b; static assert(!__traits(compiles, b = n % 10)); } void modulus2() { short s; byte b = byte.max; byte c = s % b; } void modulus3() { int i; short s = short.max; short t = i % s; } void modulus4() { uint i; ushort s; short t; static assert(!__traits(compiles, t = i % s)); } void modulusFail() { int i; short s; byte b; static assert(!__traits(compiles, b = i % s)); static assert(!__traits(compiles, b = i % 257)); // [these pass in 2.053.] } void bitwise() { ubyte a, b, c; uint d; c = a & b; c = a | b; c = a ^ b; c = d & 0xff; // [these pass in 2.053.] } void bitAnd() { byte c; int d; c = (0x3ff_ffffU << (0&c)) & (0x4000_0000U << (0&c)); // the result of the above is always 0 :). } void bitOrFail() { ubyte c; static assert(!__traits(compiles, c = c | 0x100)); // [this passes in 2.053.] } void bitAndOr() { ubyte c; c = (c | 0x1000) & ~0x1000; } void bitAndFail() { int d; short s; byte c; static assert(!__traits(compiles, c = d & s)); static assert(!__traits(compiles, c = d & 256)); // [these pass in 2.053.] } void bitXor() { ushort s; ubyte c; c = (0xffff << (s&0)) ^ 0xff00; } void bitComplement() { int i; ubyte b = ~(i | ~0xff); } void bitComplementFail() { ubyte b; static assert(!__traits(compiles, b = ~(b | 1))); // [this passes in 2.053.] } void negation() { int x; byte b = -(x & 0x7); } void negationFail() { int x; byte b; static assert(!__traits(compiles, b = -(x & 255))); // [this passes in 2.053.] } short bug5225(short a) { return a>>1; } short bug1977_comment5(byte i) { byte t = 1; short o = t - i; return o; } void testDchar() { dchar d; uint i; /+ static assert(!__traits(compiles, d = i)); static assert(!__traits(compiles, d = i & 0x1fffff)); +/ d = i % 0x110000; } void bug1977_comment11() { uint a; byte b = a & 1; // [this passes in 2.053.] } void bug1977_comment20() { long a; int b = a % 1000; } /******************************************/ // 9617 void test9617() { void f1(int) {} void f2(short) {} void f3(byte) {} // Why these calls are accepted? static assert(!__traits(compiles, f1(ulong.max))); static assert(!__traits(compiles, f2(ulong.max))); static assert(!__traits(compiles, f3(ulong.max))); // But, if argument is not constant value, compilation fails. ulong x; static assert(!__traits(compiles, f1(x))); // is not callable using argument types (ulong) static assert(!__traits(compiles, f2(x))); // is not callable using argument types (ulong) static assert(!__traits(compiles, f3(x))); // is not callable using argument types (ulong) void f4(uint) {} void f5(ushort) {} void f6(ubyte) {} // If parameter type is unsigned, it is collectly rejected static assert(!__traits(compiles, f4(ulong.max))); // is not callable using argument types (ulong) static assert(!__traits(compiles, f5(ulong.max))); // is not callable using argument types (ulong) static assert(!__traits(compiles, f6(ulong.max))); // is not callable using argument types (ulong) } //import std.typetuple; template TypeTuple(T...) { alias TypeTuple = T; } template staticIota(size_t end) { static if (0 < end) alias staticIota = TypeTuple!(staticIota!(end - 1), end - 1); else alias staticIota = TypeTuple!(); } void test9617a() { alias Repr = TypeTuple!( byte, "127", // T and literal representation of T.max ubyte, "255", short, "32767", ushort, "65535", int, "2147483647", uint, "4294967295", long, "9223372036854775807", ulong, "18446744073709551615" // "" or "L" -> "signed integral overflow" ); alias Indices = staticIota!(Repr.length / 2); foreach (t; Indices) { alias T = Repr[t * 2]; void func(T)(T) {} alias func!T f; foreach (r; Indices) { alias S = Repr[r * 2]; S src = S.max; enum x = Repr[r * 2 + 1]; foreach (repr; TypeTuple!(S.stringof~".max", x~"", x~"U", x~"L", x~"LU")) { static if (S.sizeof != T.sizeof) static if (is(typeof(mixin(repr)) R)) { // "Compilable" test should be equal, even if // the given argument is either constant or runtime variable. enum ct = __traits(compiles, f( mixin(repr) )); enum rt = __traits(compiles, f( src )); static assert(ct == rt); //import std.string; //enum msg = format("%6s.max to %-6s variable/constant = %d/%d, constant_repr = (%s) %s", // S.stringof, T.stringof, rt, ct, R.stringof, repr); //static if (ct != rt) pragma(msg, msg); } } } } } void test10018(ubyte value) { const int c = value; ubyte b = c; static assert(!__traits(compiles, b = c - 1)); static assert(!__traits(compiles, b = c + 1)); immutable int i = value; b = i; static assert(!__traits(compiles, b = i - 1)); static assert(!__traits(compiles, b = i + 1)); } void test13001(bool unknown) { foreach (const i; 0..unknown?2:3) { ubyte b = i; static assert(!__traits(compiles, b = i - 1)); b = i + 253; static assert(!__traits(compiles, b = i + 254)); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test13281.d0000644000175000017500000000210113200164641023424 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: /* TEST_OUTPUT: --- 123 123u 123L 123LU 123.4 123.4F 123.4L 123.4i 123.4Fi 123.4Li (123.4+5.6i) (123.4F+5.6Fi) (123.4L+5.6Li) --- */ pragma(msg, 123); pragma(msg, 123u); pragma(msg, 123L); pragma(msg, 123uL); pragma(msg, 123.4); pragma(msg, 123.4f); pragma(msg, 123.4L); pragma(msg, 123.4i); pragma(msg, 123.4fi); pragma(msg, 123.4Li); pragma(msg, 123.4 +5.6i); pragma(msg, 123.4f+5.6fi); pragma(msg, 123.4L+5.6Li); static assert((123 ).stringof == "123"); static assert((123u ).stringof == "123u"); static assert((123L ).stringof == "123L"); static assert((123uL).stringof == "123LU"); static assert((123.4 ).stringof == "123.4"); static assert((123.4f ).stringof == "123.4F"); static assert((123.4L ).stringof == "123.4L"); static assert((123.4i ).stringof == "123.4i"); static assert((123.4fi).stringof == "123.4Fi"); static assert((123.4Li).stringof == "123.4Li"); static assert((123.4 +5.6i ).stringof == "123.4 + 5.6i"); static assert((123.4f+5.6fi).stringof == "123.4F + 5.6Fi"); static assert((123.4L+5.6Li).stringof == "123.4L + 5.6Li"); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9919.d0000644000175000017500000000016013200164641023364 0ustar matthiasmatthias// REQUIRED_ARGS: -o- module test9919; public { import imports.test9919a; import imports.test9919b; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/callconv.d0000644000175000017500000000147313200164641023662 0ustar matthiasmatthias// PERMUTE_ARGS: import core.stdc.stdarg; struct ABC { int x[4]; } ABC abc; int x,y,z; extern (Pascal): ABC test1(int xx, int yy, int zz) { x = xx; y = yy; z = zz; return abc; } extern (Pascal): ABC test1v(int xx, int yy, int zz, ...) { x = xx; y = yy; z = zz; return abc; } extern (C): ABC test2v(int xx, int yy, int zz, ...) { x = xx; y = yy; z = zz; return abc; } extern (C++): ABC test3(int xx, int yy, int zz) { x = xx; y = yy; z = zz; return abc; } ABC test3v(int xx, int yy, int zz, ...) { x = xx; y = yy; z = zz; return abc; } extern (D): ABC test4(int xx, int yy, int zz) { x = xx; y = yy; z = zz; return abc; } ABC test4v(int xx, int yy, int zz, ...) { x = xx; y = yy; z = zz; return abc; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test11914.d0000644000175000017500000000452413200164641023440 0ustar matthiasmatthias// std.array @property bool empty(T)(in T[] a) { return !a.length; } @property ref T front(T)(T[] a) { return a[0]; } void popFront(T)(ref T[] a) { a = a[1 .. $]; } // std.typecons struct Tuple(T...) { T field; alias field this; } Tuple!T tuple(T...)(T args) { return typeof(return)(args); } // std.range template ElementType(R) { static if (is(typeof(R.init.front.init) T)) alias T ElementType; else alias void ElementType; } struct Repeat(T) { private T _value; enum bool empty = false; @property inout(T) front() inout { return _value; } void popFront() {} } Repeat!T repeat(T)(T value) { return Repeat!T(value); } struct Zip(R...) { //alias Tuple!(staticMap!(.ElementType, R)) ElementType; static if (R.length == 3) alias Tuple!(int, int, int) ElementType; static if (R.length == 2) alias Tuple!(int, int) ElementType; R ranges; this(R rs) { foreach (i, Unused; R) { ranges[i] = rs[i]; } } @property bool empty() { foreach (i, Unused; R) { if (ranges[i].empty) return true; } return false; } @property ElementType front() { ElementType result; return result; } void popFront() { foreach (i, Unused; R) { ranges[i].popFront(); } } ElementType opIndex(size_t n) { ElementType result; return result; } } auto zip(Rs...)(Rs ranges) { return Zip!Rs(ranges); } // std.algorithm template map(fun...) { auto map(Range)(Range r) { return MapResult!(fun, Range)(r); } } private struct MapResult(alias fun, R) { R _input; this(R input) { _input = input; } @property bool empty() { return _input.empty; } @property auto ref front() { return fun(_input.front); } void popFront() { _input.popFront(); } } auto cartesianProduct(R1, R2)(R1 range1, R2 range2) { return range2.map!((ElementType!R2 a) => zip(range1, repeat(a))); } auto cartesianProduct(R1, R2, RR...)(R1 range1, R2 range2, RR otherRanges) { return map!(a => tuple(a[0], a[1][0], a[1][1]))( cartesianProduct(range1, cartesianProduct(range2, otherRanges)) ); } // test void main() { foreach (i, j, k; cartesianProduct([1], [1], [1])) {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9639.d0000644000175000017500000000105313200164641023365 0ustar matthiasmatthiasclass A { this(A) {} } class B {} class C {} // two sibling nested functions in main typeof(null) foo(alias fn)(A a) { fn(a); return foo!fn(B.init); } typeof(null) foo(alias fn)(B b) { return foo!fn(A.init); } // three sibling nested functions in main typeof(null) bar(alias fn)(A a) { fn(a); return bar!fn(B.init); } typeof(null) bar(alias fn)(B b) { return bar!fn(C.init); } typeof(null) bar(alias fn)(C c) { return bar!fn(A.init); } void main() { A a; foo!((stuff){ new A(a); })(a); bar!((stuff){ new A(a); })(a); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test7190.d0000644000175000017500000000024313200164641023353 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -c -Icompilable/extra-files import example7190.controllers.HomeController; import example7190.models.HomeModel; void main(){} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9209.d0000644000175000017500000000025113200164641023355 0ustar matthiasmatthias// PERMUTE_ARGS: // 9209 auto array(T)(T t){ return t; } auto bar()(in int* x) { if (true) return 0; return array(bar(x)); } void main () { bar(null); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testDIP37.d0000644000175000017500000000126113200164641023542 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -c -Icompilable/extra-files void test1() { import pkgDIP37.datetime; def(); pkgDIP37.datetime.def(); pkgDIP37.datetime.common.def(); } void test3() { import pkgDIP37.datetime.common; def(); pkgDIP37.datetime.def(); pkgDIP37.datetime.common.def(); } void test4() { import pkgDIP37.datetime : def; def(); static assert(!__traits(compiles, pkgDIP37.datetime.def())); static assert(!__traits(compiles, pkgDIP37.datetime.common.def())); } void test7() { static import pkgDIP37.datetime; static assert(!__traits(compiles, def())); pkgDIP37.datetime.def(); pkgDIP37.datetime.common.def(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/aliasdecl.d0000644000175000017500000000230713200164641023777 0ustar matthiasmatthiastemplate Test(T){ alias Type = T; } alias X1 = int; static assert(is(X1 == int)); alias X2 = immutable(long)[], X3 = shared const double[int]; static assert(is(X2 == immutable(long)[])); static assert(is(X3 == shared const double[int])); alias X4 = void delegate() const, X5 = Test!int; static assert(is(X4 == void delegate() const)); static assert(is(X5.Type == int)); alias FP5 = extern(C) pure nothrow @safe @nogc void function(), DG5 = extern(D) pure nothrow @safe @nogc void delegate(); static assert(FP5.stringof == "extern (C) void function() pure nothrow " /* ~ "@safe " */ ~ "@nogc"); static assert(DG5.stringof == "void delegate() pure nothrow " /* ~ "@safe " */ ~ "@nogc"); void main() { alias Y1 = int; static assert(is(Y1 == int)); alias Y2 = immutable(long)[], Y3 = shared const double[int]; static assert(is(Y2 == immutable(long)[])); static assert(is(Y3 == shared const double[int])); alias Y4 = void delegate() const, Y5 = Test!int; static assert(is(Y4 == void delegate() const)); static assert(is(Y5.Type == int)); /+ struct S { int value; alias this = value; } auto s = S(10); int n = s; assert(n == 10); +/ } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice13245.d0000644000175000017500000000016513200164641023215 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: template T(alias f) {} static assert(!is(T!( (int x){ return invalid; } ))); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9764.sh0000755000175000017500000000044213200164641023511 0ustar matthiasmatthias#!/usr/bin/env bash name=`basename $0 .sh` dir=${RESULTS_DIR}/compilable output_file=${dir}/${name}.html rm -f ${output_file} $DMD -m${MODEL} -D -o- compilable/extra-files/ddoc9764.dd -Df${output_file} compilable/extra-files/ddocAny-postscript.sh 9764 && touch ${dir}/`basename $0`.out ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testheader2i.d0000644000175000017500000000033013200164641024433 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/header2.d // REQUIRED_ARGS: -o- -H -Hf${RESULTS_DIR}/compilable/header2i.di -inline // PERMUTE_ARGS: // POST_SCRIPT: compilable/extra-files/header-postscript.sh header2i void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_1308.d0000644000175000017500000000016213200164641024632 0ustar matthiasmatthiasinterface Foo { package @property bool baz() { return true; } } bool consumer(Foo f) { return f.baz(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9369.d0000644000175000017500000000036613200164641023325 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_SOURCES: /extra-files/ddoc9369.ddoc // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9369 /** Sample: --- a=1; writeln(&a); ! ? --- */ void foo() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10981.d0000644000175000017500000000052713200164641023442 0ustar matthiasmatthiasvoid foo(int i) in { class X1 { void in_nested() pure in { assert(i); } // OK <- NG out { assert(i); } // OK <- NG body {} } } out { class X2 { void out_nested() pure in { assert(i); } // OK <- NG out { assert(i); } // OK <- NG body {} } } body { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc5446a.d0000644000175000017500000000030613200164641023450 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- module ddoc5446a; /** */ struct A_Foo { } /** */ alias A_Foo A_Foo_Alias; /** */ alias int A_Int; /** */ enum A_Enum { x } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test13193.d0000644000175000017500000000400413200164641023432 0ustar matthiasmatthias// REQUIRED_ARGS: -O -inline -c final class SharedLib { void getSymbol() {return getSymbolImpl();} void getSymbolImpl() {return getSymbol_();} /* add more intermediate functions to go slower */ void getSymbol_() {} } void test13193() { SharedLib ssllib; void bindFunc() {ssllib.getSymbol();} bindFunc(); /* add more of these to go slower */ bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); /* 10 */ bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); /* 20 */ bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); /* 30 */ bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); /* 40 */ bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); /* 50 */ bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); /* 60 */ bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); /* 70 */ bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); /* 80 */ bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); /* 90 */ bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); bindFunc(); /* 100 */ } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testheader1.d0000644000175000017500000000033713200164641024270 0ustar matthiasmatthias// EXTRA_SOURCES: extra-files/header1.d // REQUIRED_ARGS: -o- -unittest -H -Hf${RESULTS_DIR}/compilable/header1.di // PERMUTE_ARGS: -d -dw // POST_SCRIPT: compilable/extra-files/header-postscript.sh header1 void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/line.d0000644000175000017500000000062313200164641023004 0ustar matthiasmatthiasmodule line; static assert(__LINE__ == 3); int #line 10 x; static assert(__LINE__ == 12); version(Windows) static assert(__FILE__ == "compilable\\line.d"); else static assert(__FILE__ == "compilable/line.d"); #line 100 "newfile.d" static assert(__LINE__ == 101); static assert(__FILE__ == "newfile.d"); # line 200 static assert(__LINE__ == 201); static assert(__FILE__ == "newfile.d"); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc10.d0000644000175000017500000000566513200164641023142 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 10 // 294 /// The foo struct Foo(T) { } /// ditto struct Foo(T,U) { } /** This basic case doesn't work very well. The template signature is * documented twice, but the function signature (argument names and return * type) is not documented at all. This comment is also repeated twice. */ int func1(T)(T x) {} /** This comment is also repeated twice, and the second function signature is * not very well documented. */ int func2(T,U)(T x, U y) {} /// ditto int func2(T)(T x) {} /// Separate overload item. int func2()() {} /// template func3(T,U) { /** This used to work adequately and documented both func3 templates * simultaneously. Now, it documents the first template twice and * no longer documents the function argument and return types.*/ int func3(T x, U y) {} } /// ditto deprecated template func3(T, U=int, V:long) { private int func3(T x) {} } /** * blah */ void map(char rs) { } /// Ditto void map(int rs) { } /** * blah */ void map2()(char rs) { } /// Ditto void map2()(int rs) { } /** * blah http://www.map3.com map3 */ void map3(char rs) { } /** * blah http://www.map.com map */ void map4(string s)(char rs) { } /** * blah http://www.map.com map */ template map5(string s) { } /** blah */ struct bar6 { int blah; } /** template bodies */ struct Foo7(T) { /**Attempt one: Doc outside static if.*/ static if(is(T == uint)) { /**Attempt two: Inside.*/ void bar() {} } else { /**Attempt two: else.*/ void bar() {} } /** the abc function should be static */ static void abc() { } } /** show abstract */ abstract class Foo8 { } /// a stray $(RPAREN) mustn't foul the macros void bug4878(string a = ")") {} /**** */ struct S { /**** */ this(long ticks) const pure nothrow { } /**** */ const pure nothrow this(this) { } /**** */ const pure nothrow ~this() { } /**** */ void foo(long ticks) const pure nothrow { } } /** Produces something in (a;b] */ float f10(float a, float b) { return (a+b)/2.0; } /** Produces something in [a;b) */ float h10(float a, float b) { return (a+b)/2.0; } /// void bug6090(string f="$(B b)", char g=')')(string h="$(", string i="$)") {} /**** */ struct T { /**** */ this(A...)(A args) { } /// this(int){} } // 14547 /// doc-comment int x14547 = 1; /// ditto enum int y14547 = 2; /// doc-comment enum isInt14547(T) = is(T == int); /// ditto enum bool isString14547(T) = is(T == string); /// ditto static immutable typeName14547(T) = T.stringof; /// ditto int storageFor14547(T) = 0; /// doc-comment template foo14547(T) { enum int foo14547 = T.stringof.length; } /// ditto template bar14547(T) if (is(T == int)) { enum int bar14547 = T.stringof.length; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/art4769.d0000644000175000017500000000054513200164641023200 0ustar matthiasmatthias// http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.bugs&article_id=4769 // EXTRA_SOURCES: imports/art4769a.d imports/art4769b.d // PERMUTE_ARGS: module art4769; private import imports.art4769a; struct Vector(T) { DataStreamability!(T).footype f; static if (DataStreamability!(T).isStreamable) void writeTo() { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test14275.d0000644000175000017500000000011013200164641023426 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: import protection.bug.bug14275; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test13008.d0000644000175000017500000000026213200164641023427 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: -d -de -dw /* TEST_OUTPUT* --- --- */ deprecated class Dep { } deprecated Dep depFunc1(); // error deprecated void depFunc2(Dep); // error ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/0000755000175000017500000000000013200164642023405 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/ice10598a.d0000644000175000017500000000031113200164641025054 0ustar matthiasmatthiasmodule imports.ice10598a; template TypeTuple(TL...) { alias TL TypeTuple; } alias TypeTuple!(__traits(getMember, imports.ice10598b, (__traits(allMembers, imports.ice10598b)[1])))[0] notImportedType; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/typecons4003.d0000644000175000017500000000100413200164641025717 0ustar matthiasmatthiasmodule imports.typecons4003; struct Tuple(T...) { alias T Types; Types field; ref Tuple!(Types[from .. to]) slice(uint from, uint to)() { return *cast(typeof(return) *) &(field[from]); } void test() //unittest { .Tuple!(int, string, float, double) a; a.field[1] = "abc"; a.field[2] = 4.5; auto s = a.slice!(1, 3); static assert(is(typeof(s) == Tuple!(string, float))); //assert(s.field[0] == "abc" && s.field[1] == 4.5); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/ice10598b.d0000644000175000017500000000005713200164641025064 0ustar matthiasmatthiasmodule imports.ice10598b; struct LocalType {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9919b.d0000644000175000017500000000034313200164641025226 0ustar matthiasmatthiasmodule imports.test9919b; class Event { mixin genToString; // @BUG@ } class MouseEvent : Event { enum Action { A, B } } mixin template genToString() { override string toString() { return ""; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test10375a.d0000644000175000017500000000011713200164641025270 0ustar matthiasmatthiasmodule imports.test10375a; private template Pack(T...) { alias T tuple; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/art4769b.d0000644000175000017500000000017413200164641025035 0ustar matthiasmatthiasprivate import imports.art4769a; private import art4769; int main(char [][] args) { Vector!(wchar) str; return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test6013.d0000644000175000017500000000044613200164641025046 0ustar matthiasmatthiasmodule imports.test6013; int value; int func() { return 0; }; public alias value public_alias_value; private alias value private_alias_value; public alias func public_alias_func; private alias func private_alias_func; public alias int public_alias_type; private alias int private_alias_type; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test66a.d0000644000175000017500000000007513200164641025047 0ustar matthiasmatthiasmodule imports.test66a; import test66; class A : Lexer { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test7491b.d0000644000175000017500000000003213200164641025212 0ustar matthiasmatthiasmodule imports.test7491b; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/jsonimport3.d0000644000175000017500000000007413200164641026041 0ustar matthiasmatthiasmodule imports.jsonimport3; int target1, target2, target3; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9436interp.d0000644000175000017500000000037313200164641026303 0ustar matthiasmatthiasmodule imports.test9436interp; import imports.test9436type; import imports.test9436aggr; class ReferenceValueT(T) { void doCast() { auto x = Type.ConversionFlags.kAllowBaseClass; } } class ClassValue : ReferenceValueT!Class { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/testcov1a.d0000644000175000017500000000011613200164641025460 0ustar matthiasmatthiasmodule testcov1a; import testcov1b; alias ArraySet!(int,3) IntegerSet; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test1imp.d0000644000175000017500000000002713200164641025316 0ustar matthiasmatthias alias uint DWORD; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9436aggr.d0000644000175000017500000000015013200164641025713 0ustar matthiasmatthiasmodule imports.test9436aggr; import imports.test9436type; class Aggregate : Type { } class Class { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/protectionimp.d0000644000175000017500000000104313200164642026444 0ustar matthiasmatthiasprivate { void privF() {} class privC {} struct privS {} union privU {} interface privI {} enum privE { foo } mixin template privMT() {} void privTF(T)() {} class privTC(T) {} struct privTS(T) {} union privTU(T) {} interface privTI(T) {} } void publF(T)() {} void publFA(alias A)() {} private alias privC privA; public mixin template publMT() {} /***************************************************/ // 14169 template GetName14169(TemplateParam) { enum GetName14169 = TemplateParam.Name; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/imp12242a2.d0000644000175000017500000000024113200164642025152 0ustar matthiasmatthiasmodule imports.imp12242a2; // std.algorithm.strip auto stripA(R, E)(R range, E element) { return 2; } auto stripA(alias pred, R)(R range) { return 3; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9276expr.d0000644000175000017500000000026013200164642025756 0ustar matthiasmatthiasmodule imports.test9276expr; import imports.test9276parser; import imports.test9276util; class Node { mixin DownCastMethods!Declaration; } class Expression : Node { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test11225c.d0000644000175000017500000000004413200164642025265 0ustar matthiasmatthiasmodule imports.test11225c; // empty ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test25b.d0000644000175000017500000000013213200164642025036 0ustar matthiasmatthiasmodule imports.test25b; import imports.test25a; import core.stdc.stdio; class Bfoo { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/ldc_github_662d.d0000644000175000017500000000024013200164642026413 0ustar matthiasmatthiasmodule imports.ldc_github_662d; template RCounted() { void release() { this.destroy; } } struct RC(T) { ~this() { _rc_ptr.release; } T _rc_ptr; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/b33a.d0000644000175000017500000000054613200164642024307 0ustar matthiasmatthiasmodule imports.b33a; struct IsEqual( T ) { bool opCall( char p1, char p2 ) { return p1 == p2; } } template find_( Elem, Pred = IsEqual!(Elem) ) { size_t fn( char[] buf, Pred pred = Pred.init ) { return 3; } } template find() { size_t find( char[3] buf ) { return find_!(char).fn( buf ); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/fwdref9514.d0000644000175000017500000000007313200164642025352 0ustar matthiasmatthiasbool find9514(alias pred, R)(R range) { return true; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test11225b.d0000644000175000017500000000053113200164642025265 0ustar matthiasmatthiasmodule imports.test11225b; import test11225a; interface J : I {} // remove this line to make it work static assert(is(typeof({ import imports.test11225c; }))); // OK pragma(msg, B!().result); // just instantiates the template template B() { static assert(is(typeof({ import imports.test11225c; }))); // FAILS enum result = "WORKS"; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test68a.d0000644000175000017500000000014613200164642025051 0ustar matthiasmatthiasmodule imports.test68a; class OtherModuleClass { protected void foo() { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/b3682.d0000644000175000017500000000007613200164642024321 0ustar matthiasmatthiasmodule imports.b3682; import a3682; alias Tuple!(int) tint; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9399a.d0000644000175000017500000000007513200164642025232 0ustar matthiasmatthiasmodule imports.test9399a; void call(alias n)() { n(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/jsonimport4.d0000644000175000017500000000003413200164642026037 0ustar matthiasmatthiasmodule imports.jsonimport4; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test14666a.d0000644000175000017500000000016613200164642025304 0ustar matthiasmatthiasmodule imports.test14666a; auto getNames() { import imports.test14666b; return ""; } enum Names = getNames; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test72a.d0000644000175000017500000000006713200164642025046 0ustar matthiasmatthiasmodule imports.test72a; public import imports.test72b; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9692b.d0000644000175000017500000000004113200164642025220 0ustar matthiasmatthiasmodule imports.test9692b; int j; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test55a.d0000644000175000017500000000025613200164642025047 0ustar matthiasmatthiasmodule imports.test55a; import test55; class Arm { alias int ListHead; MessageQueue.ListHead mqueue; } class Arm2 { alias int ListHead; Queue2.ListHead mqueue; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/defad.d0000644000175000017500000000024613200164642024617 0ustar matthiasmatthias module imports.defad; private import imports.defac; private import imports.defab; public class D : C { B [] tabList; this() {} this(D parent, int style){ } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/testcov1b.d0000644000175000017500000000044413200164642025466 0ustar matthiasmatthiasmodule testcov1b; class ArraySet(Key, int div = 1) { private Key[][div] polje; public this(in ArraySet a) { foreach(Key k, uint i; a) this.add(k); } public void add(Key elem) { } int opApply(int delegate(ref Key x, ref uint y) dg) const { return 0; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/jsonimport2.d0000644000175000017500000000006313200164642026037 0ustar matthiasmatthiasmodule imports.jsonimport2; int target1, target2; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9276hash.d0000644000175000017500000000003513200164642025723 0ustar matthiasmatthiasmodule imports.test9276hash; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/ldc_github_739b.d0000644000175000017500000000036013200164642026421 0ustar matthiasmatthiasmodule imports.ldc_github_739b; import ldc_github_739; import imports.ldc_github_739a; struct MatchTree { struct TerminalTag {} TerminalTag[] m_terminalTags; void print() { m_terminalTags.map!(t => "").array; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/ldc_github_247a.d0000644000175000017500000000050413200164642026412 0ustar matthiasmatthiasmodule imports.ldc_github_247a; class ReadValue(T = int){ void get_value(){ if( ctrl.active ){} } } class Value(T) : ReadValue!(T) { auto opAssign(T value){ // <<<=== change to Value!T to solve the ice return this; } } static Controller ctrl; class Controller { bool active; Value!(int) pulse; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test4003a.d0000644000175000017500000000011413200164642025175 0ustar matthiasmatthiasmodule imports.test4003a; import imports.typecons4003; Tuple!(string) t; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/imp12242a1.d0000644000175000017500000000021713200164642025154 0ustar matthiasmatthiasmodule imports.imp12242a1; // std.string.strip int stripA(C)(C[] str) @safe pure if (is(immutable C == immutable char)) { return 1; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/defac.d0000644000175000017500000000024113200164642024611 0ustar matthiasmatthias module imports.defac; private import imports.defab; public abstract class C : B { private import imports.defad; this() {} this(D parent, int style) {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/defab.d0000644000175000017500000000017613200164642024617 0ustar matthiasmatthias module imports.defab; private import defa; public class B : A { private import imports.defad; D parent; this() {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9436type.d0000644000175000017500000000024713200164642025764 0ustar matthiasmatthiasmodule imports.test9436type; import imports.test9436node; class Type { mixin ForwardCtor!(); enum ConversionFlags { kAllowBaseClass = 0 } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test10752.d0000644000175000017500000000005413200164642025127 0ustar matthiasmatthiasmodule imports.test10752; private int priv; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test59a.d0000644000175000017500000000006413200164642025050 0ustar matthiasmatthiasmodule imports.test59a; import test59; HRESULT h; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test11563std_array.d0000644000175000017500000000020413200164642027036 0ustar matthiasmatthiasmodule imports.test11563std_array; void popFront(S)(ref S str)// @trusted pure nothrow { import imports.test11563core_bitop; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/a14528.d0000644000175000017500000000007113200164642024374 0ustar matthiasmatthiasmodule imports.a14528; void foo(alias f)() { f(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test11563std_traits.d0000644000175000017500000000054013200164642027231 0ustar matthiasmatthiasmodule imports.test11563std_traits; import imports.test11563std_range; bool startsWith(R1, R2)(R1 doesThisStart, R2 withThis) if (isInputRange!R1) { return true; } template moduleName(alias T) { static if (T.stringof.startsWith("module ")) { enum moduleName = "b"; } else { pragma(msg, "--error--"); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9276type.d0000644000175000017500000000022113200164642025756 0ustar matthiasmatthiasmodule imports.test9276type; import imports.test9276parser; class Type : Expression // <- note to Walter. { } class BasicType : Type { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test25a.d0000644000175000017500000000021413200164642025036 0ustar matthiasmatthiasmodule imports.test25a; import imports.test25b; import core.stdc.stdio; class Afoo { static this() { printf("Afoo()\n"); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test70.d0000644000175000017500000000004713200164642024701 0ustar matthiasmatthiasmodule imports.test70; void foo() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/imp12242b2.d0000644000175000017500000000024113200164642025153 0ustar matthiasmatthiasmodule imports.imp12242b2; // std.algorithm.strip auto stripB(R, E)(R range, E element) { return 2; } auto stripB(alias pred, R)(R range) { return 3; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/stdio4003.d0000644000175000017500000000007013200164642025200 0ustar matthiasmatthiasmodule imports.stdio4003; import imports.typecons4003; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/a8392.d0000644000175000017500000000022213200164642024314 0ustar matthiasmatthiasmodule imports.a8392; import ice8392; class B { this(B); } void foob(A a, B b) { a.fooa!((arg){ return new B(b); }); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test67a.d0000644000175000017500000000027013200164642025046 0ustar matthiasmatthiasmodule imports.test67a; import test67; class Base { I create() { return null; } } class Derived : Base { override SubI create() { return null; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/art4769a.d0000644000175000017500000000031313200164642025030 0ustar matthiasmatthiasmodule imports.art4769a; import core.stdc.stdio; template DataStreamability(T) { const int isStreamable = true; alias T footype; void write() { printf("hallo\n"); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9276decl.d0000644000175000017500000000035113200164642025710 0ustar matthiasmatthiasmodule imports.test9276decl; import imports.test9276sem, imports.test9276visitors, imports.test9276util; class Declaration { mixin DownCastMethods!TemplateDecl; } class TemplateDecl : OverloadableDecl { mixin Visitors; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test72b.d0000644000175000017500000000007613200164642025047 0ustar matthiasmatthiasmodule imports.test72b; private import imports.test72c : foo; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/ice13403a.d0000644000175000017500000000012113200164642025040 0ustar matthiasmatthiasmodule imports.ice13403a; package(imports): template BacktrackingMatcher() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/a13226.d0000644000175000017500000000054313200164642024372 0ustar matthiasmatthiasmodule imports.a13226; enum isFunction(alias f) = is(typeof(f) == function); enum isIntField(alias f) = is(typeof(f) == int); string t(alias cls, string method)() { static if (isFunction!(mixin("cls."~method))) {} return ""; } string u(alias cls, string member)() { static if (isIntField!(mixin("cls."~member))) {} return ""; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9276parser.d0000644000175000017500000000013313200164642026273 0ustar matthiasmatthiasmodule imports.test9276parser; public import imports.test9276expr, imports.test9276decl; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/ldc_github_662c.d0000644000175000017500000000007013200164642026413 0ustar matthiasmatthiasmodule imports.ldc_github_662c; import ldc_github_662; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/imp12242a.d0000644000175000017500000000043713200164642025077 0ustar matthiasmatthiasmodule imports.imp12242a; public: import imports.imp12242a1; // std.string import imports.imp12242a2; // std.algorithm private mixin template MixTmp(T, int x) { template foo(U) if (is(U == T)) { enum foo = x; } } mixin MixTmp!(int, 1); mixin MixTmp!(long, 2); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9672a.d0000644000175000017500000000070613200164642025225 0ustar matthiasmatthiasmodule imports.test9672a; // interpret import test9672; // node class Type { mixin ForwardCtor!(); } //BasicType only created for standard types associated with tokens class BasicType : Type { static Type createType() { return null; } } class ValueT(T) { Type getType() { return BasicType.createType(); } } class CharValue : ValueT!char { string toStr() { return null; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/imp12242b.d0000644000175000017500000000044113200164642025073 0ustar matthiasmatthiasmodule imports.imp12242b; public: import imports.imp12242b1; // std.string import imports.imp12242b2; // std.algorithm private mixin template MixTmp(T, int x) { template foo(U) if (is(U == T)) { enum foo = x; } } mixin MixTmp!(float, 3); mixin MixTmp!(real, 4); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test14666b.d0000644000175000017500000000012713200164642025302 0ustar matthiasmatthiasmodule imports.test14666b; import test14666; struct Token { Location location; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9919a.d0000644000175000017500000000006513200164642025227 0ustar matthiasmatthiasmodule imports.test9919a; import imports.test9919c; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test72c.d0000644000175000017500000000005013200164642025040 0ustar matthiasmatthiasmodule imports.test72c; void foo() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/a12567.d0000644000175000017500000000014313200164642024375 0ustar matthiasmatthiasdeprecated("This module will be removed in future release.") module imports.a12567; void foo() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/bug8922.d0000644000175000017500000000003013200164642024645 0ustar matthiasmatthiasmodule imports.bug8922; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9276util.d0000644000175000017500000000027013200164642025756 0ustar matthiasmatthiasmodule imports.test9276util; string _dgliteral(T...)() { foreach (t; T) return t.stringof; assert(0); } template DownCastMethods(T...) { enum x = _dgliteral!T; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test7491a.d0000644000175000017500000000003213200164642025212 0ustar matthiasmatthiasmodule imports.test7491a; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9436node.d0000644000175000017500000000012713200164642025725 0ustar matthiasmatthiasmodule imports.test9436node; import imports.test9436aggr; template ForwardCtor() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test11563std_range.d0000644000175000017500000000031513200164642027017 0ustar matthiasmatthiasmodule imports.test11563std_range; public import imports.test11563std_array; template isInputRange(R) { enum bool isInputRange = is(typeof( { R r = void; r.popFront(); })); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test63a.d0000644000175000017500000000012513200164642025041 0ustar matthiasmatthiasmodule imports.test63a; private import test63; struct s { char a[ SIZE ]; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9276sem.d0000644000175000017500000000036613200164642025573 0ustar matthiasmatthiasmodule imports.test9276sem; class Declaration { mixin Visitors; } template Semantic(T) { private: struct { import imports.test9276hash; } } import imports.test9276visitors; class OverloadableDecl : Declaration { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/fwdref12201a.d0000644000175000017500000000002013200164642025546 0ustar matthiasmatthiasalias int FILE; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test59b.d0000644000175000017500000000005413200164642025050 0ustar matthiasmatthiasmodule imports.test59b; alias int HRESULT; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/ldc_github_739a.d0000644000175000017500000000007613200164642026424 0ustar matthiasmatthiasmodule imports.ldc_github_739a; void array(Range)(Range r) {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/ldc_github_662b.d0000644000175000017500000000045213200164642026416 0ustar matthiasmatthiasmodule imports.ldc_github_662b; import imports.ldc_github_662c; import imports.ldc_github_662d; import std.range; class Font { mixin RCounted; auto makeTextData(string s) { // split text by spaces auto arr = s.splitter.array; } } class Engine { RC!Font font; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/udamodule2a.d0000644000175000017500000000006713200164642025757 0ustar matthiasmatthiasmodule imports.udamodule2a; struct UDA { int a; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9276visitors.d0000644000175000017500000000034513200164642026666 0ustar matthiasmatthiasmodule imports.test9276visitors; template Visitors() { mixin Semantic!(typeof(this)); mixin DeepDup!(typeof(this)); } import imports.test9276type; template DeepDup(T) if (is(T : BasicType)) {} template DeepDup(T) {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/ldc_github_821a.d0000755000175000017500000000005513200164642026414 0ustar matthiasmatthiasmodule imports.ldc_github_821a; struct S {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/imp12242b1.d0000644000175000017500000000021713200164642025155 0ustar matthiasmatthiasmodule imports.imp12242b1; // std.string.strip int stripB(C)(C[] str) @safe pure if (is(immutable C == immutable char)) { return 1; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test50a.d0000644000175000017500000000010113200164642025027 0ustar matthiasmatthiasmodule imports.test50a; class Foo { protected int a; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/defaa.d0000644000175000017500000000015413200164642024612 0ustar matthiasmatthias module imports.defaa; class Display { private import imports.defab; B lastHittestB; this() { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/udamodule2.d0000644000175000017500000000013013200164642025605 0ustar matthiasmatthias@UDA(1) @UDA(2) module imports.udamodule2; import imports.udamodule2a; void foo() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/ice11054a.d0000644000175000017500000000051113200164642025043 0ustar matthiasmatthiastemplate Tuple() { string injectNamedFields() { formatNthX(); return ""; } } Tuple!T tuple(T...)() { } void formatNthX(A...)(A) { static gencode(size_t count)() { result ~= ""; // comment out this line will remove the ICE return ""; } mixin(gencode!(A.length)()); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test71.d0000644000175000017500000000010013200164642024670 0ustar matthiasmatthiasmodule imports_test71; import imports = object; void foo() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test11563core_bitop.d0000644000175000017500000000003413200164642027174 0ustar matthiasmatthiasmodule test11563core_bitop; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test9919c.d0000644000175000017500000000010713200164642025226 0ustar matthiasmatthiasmodule imports.test9919c; import test9919; MouseEvent.Action action; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/a12506.d0000644000175000017500000000010413200164642024363 0ustar matthiasmatthiasmodule imports.a12506; auto f12506(alias fun)() { return fun(1); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/udamodule1.d0000644000175000017500000000014013200164642025605 0ustar matthiasmatthias@(1) deprecated("This module will be removed.") @(2) module imports.udamodule1; void foo() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test61a.d0000644000175000017500000000010113200164642025031 0ustar matthiasmatthiasmodule imports.test61a; enum FooA { fooA }; void bar(FooA x) {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/jsonimport1.d0000644000175000017500000000006313200164642026036 0ustar matthiasmatthiasmodule imports.jsonimport1; int target1, target2; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/imports/test62a.d0000644000175000017500000000017313200164642025043 0ustar matthiasmatthiasmodule imports.test62a; import test62; struct T() { struct Nested { S member; } } alias T!() instance; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9057.d0000644000175000017500000000035313200164642023362 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -c -Icompilable/extra-files struct Bug9057(T) { T x; } void test9507() { import imp9057; Bug9057!(BugInt) xxx; } void test9507_2() { import imp9057_2; Bug9057!(BugInt) xxx; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice6538.d0000644000175000017500000000123613200164642023145 0ustar matthiasmatthias /**************************************/ // 6538 template allSatisfy(alias F, T...) { enum bool allSatisfy = true; } template isIntegral(T) { enum bool isIntegral = true; } void foo(I...)(I sizes) if (allSatisfy!(isIntegral, sizes)) {} void test6538a() { foo(42, 86); } void bar(T1, T2)(T1 t1, T2 t2) if (allSatisfy!(isIntegral, t1, t2)) {} void test6538b() { bar(42, 86); } /**************************************/ // 9361 template Sym(alias A) { enum Sym = true; } struct S { void foo()() if (Sym!(this)) {} void bar()() { static assert(Sym!(this)); } // OK } void test9361a() { S s; s.foo(); // fail s.bar(); // OK } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_1211.d0000644000175000017500000000017213200164642024625 0ustar matthiasmatthiasstruct Foo { long baz; } Foo foo(long x) { struct Bar { long y; } return cast(Foo)Bar(x); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/diag4596.d0000644000175000017500000000074113200164642023313 0ustar matthiasmatthias/* TEST_OUTPUT: --- compilable/diag4596.d(15): Deprecation: this is not an lvalue compilable/diag4596.d(16): Deprecation: 1 ? this : this is not an lvalue compilable/diag4596.d(18): Deprecation: super is not an lvalue compilable/diag4596.d(19): Deprecation: 1 ? super : super is not an lvalue --- */ class NoGo4596 { void fun() { this = new NoGo4596; (1?this:this) = new NoGo4596; super = new Object; (1?super:super) = new Object; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc10334.d0000644000175000017500000000254713200164642023371 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 10334 module ddoc10334; template Foo10334(T) if (Bar10334!()) {} /// template Foo10334(T) if (Bar10334!100) {} /// template Foo10334(T) if (Bar10334!3.14) {} /// template Foo10334(T) if (Bar10334!"str") {} /// template Foo10334(T) if (Bar10334!1.4i) {} /// template Foo10334(T) if (Bar10334!null) {} /// template Foo10334(T) if (Bar10334!true) {} /// template Foo10334(T) if (Bar10334!false) {} /// template Foo10334(T) if (Bar10334!'A') {} /// template Foo10334(T) if (Bar10334!int) {} /// template Foo10334(T) if (Bar10334!string) {} /// template Foo10334(T) if (Bar10334!([1,2,3])) {} /// template Foo10334(T) if (Bar10334!(Baz10334!())) {} /// template Foo10334(T) if (Bar10334!(Baz10334!T)) {} /// template Foo10334(T) if (Bar10334!(Baz10334!100)) {} /// template Foo10334(T) if (Bar10334!(.foo)) {} /// template Foo10334(T) if (Bar10334!(const int)) {} /// template Foo10334(T) if (Bar10334!(shared T)) {} /// template Test10334(T...) {} /// mixin Test10334!int a; /// mixin Test10334!(int,long) b; /// mixin Test10334!"str" c; /// ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10312.d0000644000175000017500000000021513200164642023421 0ustar matthiasmatthias version(D_SIMD) { const __vector(float[4]) si = [1f, 1f, 1f, 1f]; void main() { auto arr = si; return; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_378.d0000644000175000017500000000104413200164642024561 0ustar matthiasmatthiasstring find(alias pred)(string haystack) { for (; !pred(haystack); ) {} return haystack; } bool any(alias pred)() if (is(typeof(find!pred("")))) { return !find!pred(""); } struct StaticRegex(Char) { bool function(BacktrackingMatcher!Char) MatchFn; } struct BacktrackingMatcher(Char) { StaticRegex!Char re; size_t lastState = 0; } auto match(RegEx)(RegEx ) { return ""; } auto match(RegEx)(RegEx ) if(is(RegEx == StaticRegex!(typeof({})))) {} void applyNoRemoveRegex() { if (any!((a){return !match(a);})()){} } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test13226.d0000644000175000017500000000132213200164642023430 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: -version=bug import imports.a13226; class C { // class C member m is not accessible version(bug) mixin(t!(typeof(this), "f")); else {} version(bug) mixin(u!(typeof(this), "v")); else {} void f() {} int v; // here is ok version(bug) {} else mixin(t!(typeof(this), "f")); version(bug) {} else mixin(u!(typeof(this), "v")); } struct S { // struct S member m is not accessible version(bug) mixin(t!(typeof(this), "f")); else {} version(bug) mixin(u!(typeof(this), "v")); else {} void f() {} int v; // here is ok version(bug) {} else mixin(t!(typeof(this), "f")); version(bug) {} else mixin(u!(typeof(this), "v")); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9475.d0000644000175000017500000000056613200164642023326 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -w -o- -c -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9475 module ddoc9475; /// foo void foo() { } /// unittest { // comment 1 foreach (i; 0 .. 10) { // comment 2 documentedFunction(); } } /// bar void bar() { } /// unittest { // bar comment } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_662.d0000644000175000017500000000004013200164642024550 0ustar matthiasmatthiasimport imports.ldc_github_662b; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc10236b.d0000644000175000017500000000253013200164642023524 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -w -o- /* TEST_OUTPUT: --- compilable/ddoc10236b.d(43): Warning: Ddoc: parameter count mismatch compilable/ddoc10236b.d(55): Warning: Ddoc: function declaration has no parameter 'y' compilable/ddoc10236b.d(67): Warning: Ddoc: function declaration has no parameter 'y' compilable/ddoc10236b.d(67): Warning: Ddoc: parameter count mismatch --- */ /*********************************** * foo_good does this. * Params: * x = is for this * and not for that * y = is for that */ void foo_good(int x)(int y) { } /*********************************** * foo_good2 does this. * Params: * y = is for that */ void foo_good2(int x)(int y) { } /*********************************** * foo_count_mismatch does this. * Params: * x = is for this * and not for that */ void foo_count_mismatch(int x)(int y) // Warning: Ddoc: parameter count mismatch { } /*********************************** * foo_no_param_y does this. * Params: * x = is for this * and not for that * y = is for that */ void foo_no_param_y(int x)(int z) // Warning: Ddoc: function declaration has no parameter 'y' { } /*********************************** * foo_count_mismatch_no_param_y does this. * Params: * x = is for this * and not for that * y = is for that */ void foo_count_mismatch_no_param_y(int x)() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc11511.d0000644000175000017500000000053413200164642023361 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -w -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 11511 module ddoc11511; /** Params: abcd = none1 bcdef = none23 ... = doo */ void foo(int abcd, int bcdef, ...); /** Params: abcd = none1 bcdef = none23 arr = doo */ void foo(int abcd, int bcdef, int[] arr...); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9276.d0000644000175000017500000000016513200164642023366 0ustar matthiasmatthias// REQUIRED_ARGS: compilable/imports/test9276parser.d // This is a dummy module for compilable test void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test14894.sh0000755000175000017500000000060513200164642023641 0ustar matthiasmatthias#!/usr/bin/env bash name=`basename $0 .sh` dir=${RESULTS_DIR}/compilable src=compilable/extra-files $DMD -c -m${MODEL} -of${dir}/${name}a${OBJ} -I${src} ${src}/${name}a.d || exit 1 $DMD -unittest -m${MODEL} -od${dir} -I${src} ${src}/${name}main.d ${dir}/${name}a${OBJ} || exit 1 rm -f ${dir}/{${name}a${OBJ} ${name}main${EXE} ${name}main${OBJ}} echo Success >${dir}/`basename $0`.out ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test13600.d0000644000175000017500000000024413200164642023426 0ustar matthiasmatthias// REQUIRED_ARGS: -g class Retry { alias bool delegate ( lazy void ) SuccessDecider; SuccessDecider success_decide; void on_retry ( ) { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/forward1.d0000644000175000017500000000015513200164642023603 0ustar matthiasmatthias// REQUIRED_ARGS: -g // 104. fails only with -g Foofunc f; alias int Foo; alias int function(Foo) Foofunc; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/debuginfo.d0000644000175000017500000000027013200164642024016 0ustar matthiasmatthias// REQUIRED_ARGS: -g struct Bug7127a { const(Bug7127a)* self; } struct Bug7127b { void function(const(Bug7127b) self) foo; } void main() { Bug7127a a; Bug7127b b; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8959.d0000644000175000017500000000322113200164642023371 0ustar matthiasmatthias/* TEST_OUTPUT: --- U1 = int U2 = int V1 = long, K1 = string V2 = long, K2 = string TL1 = (int, string) TL2 = (int, string) U3 = int U4 = int V3 = long, K3 = string V4 = long, K4 = string TL3 = (int, string) TL4 = (int, string) --- */ static if (is(int* == U1*, U1)) { pragma(msg, "U1 = ", U1); } static if (is(int* : U2*, U2)) { pragma(msg, "U2 = ", U2); } static assert(is(int* == U*, U)); static assert(is(int* : U*, U)); alias AA = long[string]; static if (is(AA == V1[K1], V1, K1)) { pragma(msg, "V1 = ", V1, ", K1 = ", K1); } static if (is(AA : V2[K2], V2, K2)) { pragma(msg, "V2 = ", V2, ", K2 = ", K2); } static assert(is(AA == V[K], V, K)); static assert(is(AA : V[K], V, K)); class B(TL...) {} class C(TL...) : B!TL {} alias X = C!(int, string); static if (is(X == C!TL1, TL1...)) { pragma(msg, "TL1 = ", TL1); } static if (is(X : B!TL2, TL2...)) { pragma(msg, "TL2 = ", TL2); } static assert(is(X == C!TL, TL...)); static assert(is(X : B!TL, TL...)); void test8959() { static if (is(int* == U3*, U3)) { pragma(msg, "U3 = ", U3); } static if (is(int* : U4*, U4)) { pragma(msg, "U4 = ", U4); } static assert(is(int* == U*, U)); static assert(is(int* : U*, U)); static if (is(AA == V3[K3], V3, K3)) { pragma(msg, "V3 = ", V3, ", K3 = ", K3); } static if (is(AA : V4[K4], V4, K4)) { pragma(msg, "V4 = ", V4, ", K4 = ", K4); } static assert(is(AA == V[K], V, K)); static assert(is(AA : V[K], V, K)); static if (is(X == C!TL3, TL3...)) { pragma(msg, "TL3 = ", TL3); } static if (is(X : B!TL4, TL4...)) { pragma(msg, "TL4 = ", TL4); } static assert(is(X == C!TL, TL...)); static assert(is(X : B!TL, TL...)); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc14.d0000644000175000017500000000640213200164642023135 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 14 alias void V; alias double* P; /// -1 struct Structure { public P variable; /// 0 V mNone(lazy P p) {} /// 1 pure nothrow V mPrefix(lazy P p) {} /// 2 V mSuffix(lazy P p) pure nothrow {} /// 3 // pure nothrow V mPrefixTemplate(T)(lazy P p, T[] t...) {} /// 4 V mSuffixTemplate(T)(lazy P p, T[] t...) pure nothrow {} /// 5 pure nothrow { V mScoped(lazy P p) {} /// 6 } pure nothrow auto mAutoPrefix(ref P p) { return p; } /// 7 // pure nothrow auto mAutoTemplatePrefix(alias T)(ref T t) { return p; } /// 8 auto mAutoTemplateSuffix(alias T)(ref T t) pure nothrow { return p; } /// 9 pure nothrow: V mColon(lazy P p) {} /// 10 } /// -1 class Class { public P variable; /// 0 V mNone(lazy P p) {} /// 1 pure nothrow V mPrefix(lazy P p) {} /// 2 V mSuffix(lazy P p) pure nothrow {} /// 3 // pure nothrow V mPrefixTemplate(T)(lazy P p, T[] t...) {} /// 4 V mSuffixTemplate(T)(lazy P p, T[] t...) pure nothrow {} /// 5 pure nothrow { V mScoped(lazy P p) {} /// 6 } pure nothrow auto mAutoPrefix(ref P p) { return p; } /// 7 // pure nothrow auto mAutoTemplatePrefix(alias T)(ref T t) { return p; } /// 8 auto mAutoTemplateSuffix(alias T)(ref T t) pure nothrow { return p; } /// 9 pure nothrow: V mColon(lazy P p) {} /// 10 } /+ /// -1 struct StructTemplate() { public P variable; /// 0 V mNone(lazy P p) {} /// 1 pure nothrow V mPrefix(lazy P p) {} /// 2 V mSuffix(lazy P p) pure nothrow {} /// 3 // pure nothrow V mPrefixTemplate(T)(lazy P p, T[] t...) {} /// 4 V mSuffixTemplate(T)(lazy P p, T[] t...) pure nothrow {} /// 5 pure nothrow { V mScoped(lazy P p) {} /// 6 } pure nothrow auto mAutoPrefix(ref P p) { return p; } /// 7 // pure nothrow auto mAutoTemplatePrefix(alias T)(ref T t) { return p; } /// 8 auto mAutoTemplateSuffix(alias T)(ref T t) pure nothrow { return p; } /// 9 pure nothrow: V mColon(lazy P p) {} /// 10 } /// -1 interface Interface { V mNone(lazy P p) ; /// 1 pure nothrow V mPrefix(lazy P p) ; /// 2 V mSuffix(lazy P p) pure nothrow ; /// 3 // pure nothrow V mPrefixTemplate(T)(lazy P p, T[] t...) ; /// 4 V mSuffixTemplate(T)(lazy P p, T[] t...) pure nothrow ; /// 5 pure nothrow { V mScoped(lazy P p) ; /// 6 } // pure nothrow auto mAutoTemplatePrefix(alias T)(ref T t) { return p; } /// 8 auto mAutoTemplateSuffix(alias T)(ref T t) pure nothrow { return p; } /// 9 pure nothrow: V mColon(lazy P p) ; /// 10 } +/ public P variable; /// 0 V mNone(lazy P p) {} /// 1 pure nothrow V mPrefix(lazy P p) {} /// 2 V mSuffix(lazy P p) pure nothrow {} /// 3 // pure nothrow V mPrefixTemplate(T)(lazy P p, T[] t...) {} /// 4 V mSuffixTemplate(T)(lazy P p, T[] t...) pure nothrow {} /// 5 pure nothrow { V mScoped(lazy P p) {} /// 6 } pure nothrow auto mAutoPrefix(ref P p) { return p; } /// 7 // pure nothrow auto mAutoTemplatePrefix(alias T)(ref T t) { return p; } /// 8 auto mAutoTemplateSuffix(alias T)(ref T t) pure nothrow { return p; } /// 9 pure nothrow: V mColon(lazy P p) {} /// 10 ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10993.d0000644000175000017500000000103013200164642023434 0ustar matthiasmatthiasmodule test10993; auto foo(T)(T a) { static immutable typeof(a) q; // pragma(msg, "foo: " ~ typeof(q).mangleof); return q; } struct test(alias fn) { bool ini = true; void* p; } auto fun() { auto x = foo!()(test!(a=>a)()); // pragma(msg, "fun: " ~ typeof(x).mangleof); return x; } void main() { const x = fun(); enum mangle_x = typeof(x).mangleof; // pragma(msg, "x : " ~ mangle_x); auto y = cast()x; enum mangle_y = typeof(y).mangleof; // pragma(msg, "y : " ~ mangle_y); static assert (mangle_y == mangle_x[1..$]); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_965.d0000644000175000017500000000010313200164642024556 0ustar matthiasmatthiasclass A{} void fun() { A a; auto b=a?typeid(a):typeid(a); }ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/0000755000175000017500000000000013200164642024133 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc11479.html0000644000175000017500000000264713200164642026351 0ustar matthiasmatthias ddoc11479

ddoc11479



struct S1(T);


int a;


int b;


int c;


struct S2(T);


int a;


int b;


int c;


int d;


struct S3(T);


int a;


int b;


int c;


int d;


int e;



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc7656.html0000644000175000017500000000150613200164642026264 0ustar matthiasmatthias ddoc7656

ddoc7656



void main();
int x; // This is a $ comment (and here is some
int y; // more information about that comment)


int add(int a, int b);
(Regression check)

Example:
assert(add(1, 1) == 2);



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc8271.html0000644000175000017500000000061713200164642026260 0ustar matthiasmatthias ddoc8271

ddoc8271



void ddoc8271();
Macro


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc13645.html0000644000175000017500000000051113200164642026332 0ustar matthiasmatthias ddoc13645

ddoc13645

Documentation comment on module


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc8.html0000644000175000017500000000060313200164642026021 0ustar matthiasmatthias ddoc8

ddoc8



class Foo(T): Bar;
foo


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/testheaderudamodule.di0000644000175000017500000000011513200164642030476 0ustar matthiasmatthias@(1, UDA(2)) module testheaderudamodule; struct UDA { int a; } void main(); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc10325.html0000644000175000017500000000102013200164642026316 0ustar matthiasmatthias ddoc10325

ddoc10325



template templ(T...) if (someConstraint!T)


void foo(T)(T t) if (someConstraint!T);



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc6491.html0000644000175000017500000000071713200164642026263 0ustar matthiasmatthias ddoc6491

ddoc6491



void bug6491a(int a = ddoc6491.c6491, string b = core.cpuid.vendor);
test


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/header12567b.di0000644000175000017500000000007013200164642026445 0ustar matthiasmatthiasdeprecated("message") module header12567b; void main(); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37_10354/0000755000175000017500000000000013200164642026157 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37_10354/mbar.d0000644000175000017500000000005513200164642027245 0ustar matthiasmatthiasmodule pkgDIP37_10354.mbar; void bar(T)() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37_10354/mfoo.d0000644000175000017500000000005513200164642027264 0ustar matthiasmatthiasmodule pkgDIP37_10354.mfoo; void foo(T)() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37_10354/package.d0000644000175000017500000000013513200164642027716 0ustar matthiasmatthiasmodule pkgDIP37_10354; public import pkgDIP37_10354.mfoo; public import pkgDIP37_10354.mbar; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/header2.di0000644000175000017500000000246313200164642025770 0ustar matthiasmatthiasclass C { } void foo(const C c, const(char)[] s, const int* q, const(int*) p); void bar(in void* p); void f(void function() f2); class C2; void foo2(const C2 c); struct Foo3 { int k; ~this(); this(this); } class C3 { @property int get(); } T foo3(T)() { } struct S4A(T) { T x; } struct S4B(T) if (1) { T x; } union U4A(T) { T x; } union U4B(T) if (2 * 4 == 8) { T x; } class C4A(T) { T x; } class C4B(T) if (true) { T x; } class C4C(T) if (!false) : C4A!int { T x; } class C4D(T) if (!false) : C4B!long, C4C!(int[]) { T x; } interface I4(T) if ((int[1]).length == 1) { T x; } template MyClass4(T) if (is(typeof(T.subtype))) { alias HelperSymbol = T.subtype; class MyClass4 { } } enum isInt(T) = is(T == int); enum bool isString(T) = is(T == string); static immutable typeName(T) = T.stringof; int storageFor(T) = 0; enum int templateVariableFoo(T) = T.stringof.length; template templateVariableBar(T) if (is(T == int)) { enum int templateVariableBar = T.stringof.length; } auto flit = 3 / 2.00000; void foo11217()(const int[] arr) { } void foo11217()(immutable int[] arr) { } void foo11217()(ref int[] arr) { } void foo11217()(lazy int[] arr) { } void foo11217()(auto ref int[] arr) { } void foo11217()(scope int[] arr) { } void foo11217()(in int[] arr) { } void foo11217()(inout int[] arr) { } void test13275(); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/depsOutput9948a.d0000644000175000017500000000012513200164642027151 0ustar matthiasmatthiasmodule depsOutput9948a; void templateFunc(string myImport)() { mixin(myImport); }ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/header1.d0000644000175000017500000001666213200164642025624 0ustar matthiasmatthiasmodule foo.bar; import core.vararg; import std.stdio; pragma(lib, "test"); pragma(msg, "Hello World"); static assert(true, "message"); alias double mydbl; int testmain() in { assert(1+(2+3) == -(1 - 2*3)); } out (result) { assert(result == 0); } body { float f = float.infinity; int i = cast(int) f; writeln((i,1),2); writeln(cast(int)float.max); assert(i == cast(int)float.max); assert(i == 0x80000000); return 0; } struct S { int m, n; } template Foo(T, int V) { void foo(...) { static if (is(Object _ : X!TL, alias X, TL...)) {} // Bugzilla 10044 auto x = __traits(hasMember, Object, "noMember"); auto y = is(Object : X!TL, alias X, TL...); assert(!x && !y, "message"); S s = { 1,2 }; auto a = [1, 2, 3]; auto aa = [1:1, 2:2, 3:3]; int n,m; } int bar(double d, int x) { if (d) { d++; } else d--; asm { naked ; mov EAX, 3; } for (;;) { d = d + 1; } for (int i = 0; i < 10; i++) { d = i ? d + 1 : 5; } char[] s; foreach (char c; s) { d *= 2; if (d) break; else continue; } switch (V) { case 1: case 2: break; case 3: goto case 1; case 4: goto default; default: d /= 8; break; } enum Label { A, B, C }; void fswitch(Label l) { final switch (l) { case A: break; case B: break; case C: break; } } loop: while (x) { x--; if (x) break loop; else continue loop; } do { x++; } while (x < 10); try { bar(1, 2); } catch (Object o) { x++; } finally { x--; } Object o; synchronized (o) { x = ~x; } synchronized { x = x < 3; } with (o) { toString(); } } } static this() { } static ~this() { } pure nothrow @safe @nogc static this() {} pure nothrow @safe @nogc static ~this() {} static this() pure nothrow @safe @nogc {} static ~this() pure nothrow @safe @nogc {} pure nothrow @safe @nogc shared static this() {} pure nothrow @safe @nogc shared static ~this() {} shared static this() pure nothrow @safe @nogc {} shared static ~this() pure nothrow @safe @nogc {} interface iFoo{} class xFoo: iFoo{} interface iFoo2{} class xFoo2: iFoo, iFoo2{} class Foo3 { this(int a, ...){} this(int* a){} } alias int myint; static notquit = 1; class Test { void a() {} void b() {} void c() {} void d() {} void e() {} void f() {} void g() {} void h() {} void i() {} void j() {} void k() {} void l() {} void m() {} void n() {} void o() {} void p() {} void q() {} void r() {} void s() {} void t() {} void u() {} void v() {} void w() {} void x() {} void y() {} void z() {} void aa() {} void bb() {} void cc() {} void dd() {} void ee() {} // Try adding or removing some functions here to see the effect. template A(T) { } alias A!(uint) getHUint; alias A!(int) getHInt; alias A!(float) getHFloat; alias A!(ulong) getHUlong; alias A!(long) getHLong; alias A!(double) getHDouble; alias A!(byte) getHByte; alias A!(ubyte) getHUbyte; alias A!(short) getHShort; alias A!(ushort) getHUShort; alias A!(real) getHReal; alias void F(); pure nothrow @safe @nogc unittest {} pure nothrow @safe @nogc invariant {} pure nothrow @safe @nogc new (size_t sz) { return null; } pure nothrow @safe @nogc delete (void* p) { } } template templ( T ) { void templ( T val ) { pragma( msg, "Invalid destination type." ); } } static char[] charArray = [ '\"', '\'' ]; class Point { auto x = 10; uint y = 20; } template Foo2(bool bar) { void test() { static if(bar) { int i; } else { } static if(!bar) { } else { } } } template Foo4() { void bar() { } } template Foo4x( T... ) {} class Baz4 { mixin Foo4 foo; mixin Foo4x!(int, "str") foox; alias foo.bar baz; } int test(T)(T t) { if (auto o = cast(Object)t) return 1; return 0; } enum x6 = 1; bool foo6(int a, int b, int c, int d) { return (a < b) != (c < d); } auto foo7(int x) { return 5; } class D8{} void func8() { scope a= new D8(); } T func9(T)() if (true) { T i; scope(exit) i= 1; scope(success) i = 2; scope(failure) i = 3; return i; } template V10(T) { void func() { for(int i,j=4; i<3;i++) { } } } int foo11(int function() fn) { return fn(); } int bar11(T)() { return foo11(function int (){ return 0; }); } struct S6360 { @property long weeks1() const pure nothrow { return 0; } @property const pure nothrow long weeks2() { return 0; } } struct S12 { /// postfix storage class and constructor this(int n) nothrow{} /// prefix storage class (==StorageClassDeclaration) and constructor nothrow this(string s){} } /// dummy struct T12 { /// postfix storage class and template constructor this()(int args) immutable { } /// prefix storage class (==StorageClassDeclaration) and template constructor immutable this(A...)(A args){ } } // 6591 import std.stdio : writeln, F = File; void foo6591()() { import std.stdio : writeln, F = File; } // 8081 version(unittest) { pure nothrow unittest {} pure nothrow unittest {} public unittest {} extern(C) unittest {} align unittest {} } // 10334 template Foo10334(T) if (Bar10334!()) {} /// template Foo10334(T) if (Bar10334!100) {} /// template Foo10334(T) if (Bar10334!3.14) {} /// template Foo10334(T) if (Bar10334!"str") {} /// template Foo10334(T) if (Bar10334!1.4i) {} /// template Foo10334(T) if (Bar10334!null) {} /// template Foo10334(T) if (Bar10334!true) {} /// template Foo10334(T) if (Bar10334!false) {} /// template Foo10334(T) if (Bar10334!'A') {} /// template Foo10334(T) if (Bar10334!int) {} /// template Foo10334(T) if (Bar10334!string) {} /// template Foo10334(T) if (Bar10334!wstring) {} /// template Foo10334(T) if (Bar10334!dstring) {} /// template Foo10334(T) if (Bar10334!this) {} /// template Foo10334(T) if (Bar10334!([1,2,3])) {} /// template Foo10334(T) if (Bar10334!(Baz10334!())) {} /// template Foo10334(T) if (Bar10334!(Baz10334!T)) {} /// template Foo10334(T) if (Bar10334!(Baz10334!100)) {} /// template Foo10334(T) if (Bar10334!(.foo)) {} /// template Foo10334(T) if (Bar10334!(const int)) {} /// template Foo10334(T) if (Bar10334!(shared T)) {} /// template Test10334(T...) {} /// mixin Test10334!int a; /// mixin Test10334!(int,long) b; /// mixin Test10334!"str" c; /// // 12266 auto clamp12266a(T1, T2, T3)(T1 x, T2 min_val, T3 max_val) { return 0; } pure clamp12266b(T1, T2, T3)(T1 x, T2 min_val, T3 max_val) { return 0; } @disable pure clamp12266c(T1, T2, T3)(T1 x, T2 min_val, T3 max_val) { return 0; } // 13832 alias Dg13832 = ref int delegate(); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc2.html0000644000175000017500000000234013200164642026013 0ustar matthiasmatthias std.test

std.test

Summary

Description1

Description2

Description3

See Also:
Things to see also.

And more things.

class StreamException: object.Exception;
A base class for stream exceptions.

this(string msg, int foo);
Construct a StreamException with given error message msg.

Params:
string msg the red blue green yellow.
int foo next parameter which is a much longer message spanning multiple lines.

int stars;
stars


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddocunittest.html0000644000175000017500000002422513200164642027537 0ustar matthiasmatthias ddocunittest

ddocunittest



int foo(int a, int b);
foo function - 1 example

Examples:
assert(foo(1, 1) == 2);


bool bar();
bar function - 1 example

Examples:
// documented
assert(bar());


Examples:
placeholder

void doo();
doo function - no examples

int add(int a, int b);
add function - 3 examples

Examples:
assert(add(1, 1) == 2);


Examples:
// documented
assert(add(3, 3) == 6);
assert(add(4, 4) == 8);


Examples:
// documented
assert(add(5, 5) == 10);
assert(add(6, 6) == 12);


class Foo;
class Foo

Examples:
Foo foo = new Foo;


class SomeClass;
some class - 1 example

Examples:
SomeClass sc = new SomeClass;


class Outer;
Outer - 1 example

Examples:
Outer outer = new Outer;


class Inner;
Inner

Examples:
Inner inner = new Inner;


void foobar();
foobar - no examples

void foo(int x);
func - 4 examples

Examples:
foo(1);


Examples:
foo(2);


Examples:
foo(2);


Examples:
foo(4);


void fooImport();
Examples:
test
fooImport();


void fooStaticImport();
Examples:
test
fooStaticImport();


void fooPublicImport();
Examples:
test
fooPublicImport();


void fooSelectiveImport();
Examples:
test
fooSelectiveImport();


void fooRenamedImport();
Examples:
test
fooRenamedImport();


void fooConditionalDecl1a();
Examples:
int x1a;


void fooConditionalDecl1b();
Examples:
int x1b;


void fooConditionalDecl3a();


void fooConditionalDecl3b();


void barConditionalDecl4a();
Examples:
int x4a;


void barConditionalDecl4b();
Examples:
int x4b;


void barConditionalDecl6a();
Examples:
int x6a;


void barConditionalDecl6b();
Examples:
int x6b;


void foo9474();
Examples:
Example
foo9474();


void bar9474();
doc

Examples:
Example
bar9474();


struct S9474;
Examples:
S9474 s;


int autovar9474;
Examples:
int v = autovar9474;


auto autofun9474();
Examples:
int n = autofun9474();


template Template9474()
Examples:
alias Template9474!() T;


void foo();
Shouldn't link following unittest to here

void fooNoDescription();
Examples:
fooNoDescription();


Examples:
if (true) {fooNoDescription(); } /* comment */


void foo9757();
void bar9757();
void baz9757();
test for bugzilla 9757

Examples:
foo9757(); bar9757();


Examples:
bar9757(); foo9757();


auto redBlackTree(E)(E[] elems...);
auto redBlackTree(bool allowDuplicates, E)(E[] elems...);
auto redBlackTree(alias less, E)(E[] elems...);
with template functions

Examples:
auto rbt1 = redBlackTree(0, 1, 5, 7);
auto rbt2 = redBlackTree!string("hello", "world");
auto rbt3 = redBlackTree!true(0, 1, 5, 7, 5);
auto rbt4 = redBlackTree!"a > b"(0, 1, 5, 7);


void foo();
test

Examples:


bool balancedParens10519(string, char, char);
Examples:
auto s = "1 + (2 * (3 + 1 / 2)";
assert(!balancedParens10519(s, '(', ')'));


struct S12097;
void f12097();
struct T12097(T);
declaration

Examples:
ddoc code 1
int a = 1;


Examples:
ddoc code 2
int[] arr;


void foo();
method

void fun14594a()();
testA

Examples:
fun14594a();


void fun14594b()();
void fun14594b(T)(T);
testB

Examples:
fun14594b(); fun14594b(1);


void fun14594c()();
void fun14594c(T)(T);
testC

Examples:
fun14594c(); fun14594c(1);


void fun14594d()();
void fun14594d(T)(T);
testD

Examples:
fun14594d();


Examples:
fun14594d(1);


void fun14594e()();
testE

concatenated doc-comment fun14594e

Examples:
doc-unittest fun14594e
fun14594e();


void fun14594f()();
void fun14594f(T)(T);
testF

concatenated doc-comment fun14594f

Examples:
doc-unittest fun14594f
fun14594f();



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc13.html0000644000175000017500000000206013200164642026074 0ustar matthiasmatthias ddoc13

ddoc13



struct Bug4107(T);
struct doc

void foo(U)(U u);
templated function doc

struct Bug4107b(T);
alpha

struct B(U);
beta

struct C(V);
gamma

struct D(W);
delta

B!W e(X)(C!V c, X[] x...);
epsilon


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc5446.html0000644000175000017500000000431313200164642026256 0ustar matthiasmatthias ddoc5446

ddoc5446



alias This_Foo = ddoc5446a.A_Foo;


alias This_Foo_Alias = ddoc5446a.A_Foo;


alias This_Int = int;


alias This_Enum = ddoc5446a.A_Enum;


deprecated alias A_Enum_New = ddoc5446b.A_Enum_New;


struct Bar;


alias Bar_A_Foo = ddoc5446a.A_Foo;


alias Bar_A_Foo_Alias = ddoc5446a.A_Foo;


alias Bar_A_Int = int;


alias Bar_This_Foo = ddoc5446a.A_Foo;


alias Bar_This_Foo_Alias = ddoc5446a.A_Foo;


alias Bar_This_Int = int;


alias Nested_Alias = Nested;


alias Fake_Nested = .Nested;


struct Nested;


alias Bar_Nested_Bar_Alias = Bar;


alias Bar_Alias = .Bar;


struct Bar;



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9676a.html0000644000175000017500000000062613200164642026433 0ustar matthiasmatthias ddoc9676a

ddoc9676a



deprecated void foo();



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc7.html0000644000175000017500000000357713200164642026035 0ustar matthiasmatthias ddoc7

ddoc7



enum E1: int;
my enum

A
element a

B
element b

enum E2: int;
my enum

A
element a

B
element b

enum E3: int;
my enum

A
element a

B
element b

enum E4: int;
my enum

A
element a

B
element b

enum E5: int;
my enum

A
element a

B
element b

void foo();
Some doc

alias bar = foo;
More doc

abstract class C;
asdf

abstract void foo();
Some doc


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9497b.ddoc0000644000175000017500000000004613200164642026376 0ustar matthiasmatthiasDDOC_UNDEFINED_MACRO=$(DOLLAR)($1 $+) ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc12706.html0000644000175000017500000000065413200164642026337 0ustar matthiasmatthias ddoc12706

ddoc12706



void test()(string[] args) if (args[$]);



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/test6461/0000755000175000017500000000000013200164642025433 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/test6461/main.d0000644000175000017500000000013213200164642026520 0ustar matthiasmatthiasimport a, b; void main() { auto t1 = a.fun(); auto t2 = b.fun(); assert(t1 != t2); }ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/test6461/a.d0000644000175000017500000000010613200164642026015 0ustar matthiasmatthiasmodule a; import tmpl; TypeInfo fun() { return typeid(Tmpl!int()); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/test6461/b.d0000644000175000017500000000010713200164642026017 0ustar matthiasmatthiasmodule b; import tmpl; TypeInfo fun() { return typeid(Tmpl!long()); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/test6461/tmpl.d0000644000175000017500000000004713200164642026555 0ustar matthiasmatthiasmodule tmpl; struct Tmpl(T) { T a; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc7715.html0000644000175000017500000000110313200164642026251 0ustar matthiasmatthias ddoc7656

ddoc7656



void foo();
$1 $2
string s = "$1$2 $ &#36;4";


void test(string a = ")");



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9.html0000644000175000017500000000163313200164642026026 0ustar matthiasmatthias ddoc9

ddoc9



template Template(T)
Template Documentation (OK)

void Function(T)(T x);
Function Documentation (Not included at all by DDoc)

class Class(T);
Class Documentation (OK)

struct Struct(T);
Struct Documentation

union Union(T);
Union Documentation


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddocbackticks.html0000644000175000017500000000235213200164642027613 0ustar matthiasmatthias ddocbackticks

ddocbackticks

Closely related to std.datetime is
core.time
, and some of the time types used in std.datetime come from there - such as , , and . core.time is publically imported into std.datetime, it isn't necessary to import it separately.

void test();
This should produce
inline code
.

void test2();
But `this should NOT be inline'

However, restarting on a new line should be
inline again
.

void foo();
This
int foo;
should show highlight on foo, but not int.


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc3.ddoc0000644000175000017500000000003413200164642025757 0ustar matthiasmatthiasHELLO = world UNUSED=unusedldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc4.html0000644000175000017500000000044113200164642026015 0ustar matthiasmatthias ddoc4

ddoc4




Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9789.html0000644000175000017500000000070613200164642026276 0ustar matthiasmatthias ddoc9789

ddoc9789



struct S;


alias A = S;



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc11511.html0000644000175000017500000000160413200164642026324 0ustar matthiasmatthias ddoc11511

ddoc11511



void foo(int abcd, int bcdef, ...);
Params:
int abcd none1
int bcdef none23
... doo

void foo(int abcd, int bcdef, int[] arr...);
Params:
int abcd none1
int bcdef none23
int[] arr doo


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc10869.html0000644000175000017500000000136513200164642026347 0ustar matthiasmatthias ddoc10869

ddoc10869



class C;


const void c1Foo();


immutable void i1Foo();


immutable void c2Foo();


immutable void i2Foo();



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/test14894a.d0000644000175000017500000000022313200164642026027 0ustar matthiasmatthiasmodule imports.test14894a; mixin template Protocol() { void onReceive() {} } struct Foo { mixin Protocol!(); unittest { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9369.html0000644000175000017500000000074113200164642026267 0ustar matthiasmatthias ddoc9369

ddoc9369



void foo();
Sample:
a=1;
writeln(AddressOf!a);
Exclamation
QuestionMark



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc6.html0000644000175000017500000000060513200164642026021 0ustar matthiasmatthias ddoc6

ddoc6



struct MyStruct(T);



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9497a.ddoc0000644000175000017500000000005613200164642026376 0ustar matthiasmatthiasDDOC_UNDEFINED_MACRO=ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc11823.html0000644000175000017500000000075313200164642026336 0ustar matthiasmatthias ddoc11823

ddoc11823



void file(string arg);
file function name is file, arg defaults to __FILE__ but not _something__


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/test7754.di0000644000175000017500000000010313200164642025751 0ustar matthiasmatthiasstruct Foo(T) { shared static this() { } static this() { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc198.ddoc0000644000175000017500000000030113200164642026133 0ustar matthiasmatthiasDDOC_PSYMBOL = $0 DDOC_PSUPER_SYMBOL = $0 ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc8739.html0000644000175000017500000000123613200164642026267 0ustar matthiasmatthias ddoc8739

ddoc8739



void delegate(int a) dg;


void delegate(int b) dg2;


void delegate(int c)[] dg3;


void delegate(int d)* dg4;



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc10367.html0000644000175000017500000000213313200164642026332 0ustar matthiasmatthias ddoc10367

ddoc10367



enum A: int;
A

a
a

b
b

enum B: long;
B

a
a

b
b

enum C: string;
C

a
a

b
b


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/test7754-postscript.sh0000755000175000017500000000050513200164642030210 0ustar matthiasmatthias#!/usr/bin/env bash grep -v "D import file generated from" ${RESULTS_DIR}/compilable/test7754.di > ${RESULTS_DIR}/compilable/test7754.di.2 diff --strip-trailing-cr compilable/extra-files/test7754.di ${RESULTS_DIR}/compilable/test7754.di.2 if [ $? -ne 0 ]; then exit 1; fi rm ${RESULTS_DIR}/compilable/test7754.di{,.2} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9764.dd0000644000175000017500000000012013200164642025700 0ustar matthiasmatthiasDdoc Check ddoc9764 document. ---- // Check ddoc9764 comment. ddoc9764(); ---- ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9497d.ddoc0000644000175000017500000000006113200164642026375 0ustar matthiasmatthiasDDOC_UNDEFINED_MACRO=ERROR_UNDEFINED_MACRO: "$1" ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/serenity7190/0000755000175000017500000000000013156012230026311 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/serenity7190/core/0000755000175000017500000000000013200164642027246 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/serenity7190/core/Model.d0000644000175000017500000000023713200164642030455 0ustar matthiasmatthiasclass SqlitePersister(T) { static assert(T.tupleof.length > 0, T.stringof ~ `(` ~ (T.tupleof.length + '0') ~ `): ` ~ T.tupleof.stringof); } class Model {}ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/serenity7190/core/Controller.d0000644000175000017500000000057713200164642031547 0ustar matthiasmatthiasclass Controller { mixin template register(T : Controller) { enum _s_pkg = __traits(parent, __traits(parent, __traits(parent, T))).stringof["package ".length .. $]; enum _s_model = T.stringof[0 .. $-`Controller`.length] ~ `Model`; mixin(q{enum _ = is(} ~ _s_pkg ~ q{.models.} ~ _s_model ~ q{.} ~ _s_model ~ q{ : serenity7190.core.Model.Model);}); } }ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc10367.ddoc0000644000175000017500000000003713200164642026300 0ustar matthiasmatthiasDDOC_ENUM_BASETYPE = $(RED $0) ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc10366.html0000644000175000017500000000124513200164642026334 0ustar matthiasmatthias ddoc10366

ddoc10366



struct S(T);


void method();


struct Nested;


void nestedMethod();



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/example7190/0000755000175000017500000000000013156012230026102 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/example7190/controllers/0000755000175000017500000000000013200164642030455 5ustar matthiasmatthias././@LongLink0000644000000000000000000000014600000000000011604 Lustar rootrootldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/example7190/controllers/HomeController.dldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/example7190/controllers/HomeController.0000644000175000017500000000024113200164642033407 0ustar matthiasmatthiasmodule example7190.controllers.HomeController; import serenity7190.core.Controller; class HomeController : Controller { mixin register!(HomeController); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/example7190/models/0000755000175000017500000000000013200164642027372 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/example7190/models/HomeModel.d0000644000175000017500000000026313200164642031411 0ustar matthiasmatthiasmodule example7190.models.HomeModel; import serenity7190.core.Model; struct Article { ulong id; } class HomeModel : Model { private SqlitePersister!Article mArticles; }ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9497c.html0000644000175000017500000000067213200164642026437 0ustar matthiasmatthias ddoc9497c

ddoc9497c



void foo();
foo function.

Args:
arg1, arg2


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddocYear-postscript.sh0000755000175000017500000000071413200164642030436 0ustar matthiasmatthias#!/usr/bin/env bash YEAR=$(date +%Y) sed "s/__YEAR__/${YEAR}/" compilable/extra-files/ddocYear.html > ${RESULTS_DIR}/compilable/ddocYear.html.1 grep -v "Generated by Ddoc from" ${RESULTS_DIR}/compilable/ddocYear.html > ${RESULTS_DIR}/compilable/ddocYear.html.2 diff --strip-trailing-cr ${RESULTS_DIR}/compilable/ddocYear.html.1 ${RESULTS_DIR}/compilable/ddocYear.html.2 if [ $? -ne 0 ]; then exit 1; fi rm ${RESULTS_DIR}/compilable/ddocYear.html{,.1,.2} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc3.html0000644000175000017500000000325313200164642026020 0ustar matthiasmatthias std.test

std.test

Summary

Description1

Description2

Description3

See Also:
Things to see also.

And more things
'arg1, arg2, arg3' : arg1, arg2, arg3.
'arg2, arg3' : arg2, arg3.
'arg1' : arg1.
'arg2' : arg2.
'arg3' : arg3.


Things to see also world.

1 2 3
4 5 6


      pragma( name );
      pragma( name , option [ option ] );
      (
  


class StreamException: object.Exception;
A base class for stream exceptions.

this(string msg, int foo);
Construct a StreamException with given error message msg.

Params:
string msg the red blue green yellow.
int foo next parameter which is a much longer message spanning multiple lines.

int stars;
stars


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc4162.html0000644000175000017500000000110613200164642026245 0ustar matthiasmatthias ddoc4162

ddoc4162



interface A;


static void staticHello();


final void hello();



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc198.html0000644000175000017500000000273713200164642026205 0ustar matthiasmatthias ddoc198

ddoc198



interface I1;


class C1;


class Foo: ddoc198.C1, ddoc198.I1;


enum X: int;


enum Y: X;


struct S1;


enum enS: S1;



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc12.html0000644000175000017500000000157213200164642026102 0ustar matthiasmatthias ddoc12

ddoc12



int ruhred;
This documents correctly.

int rühred;
This should too

int foo(int ü, int ş, int ğ);
BUG:
The parameters are not listed under Params in the generated output

Params:
int ü first
int ÅŸ second
int ÄŸ third


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc1.html0000644000175000017500000000472313200164642026021 0ustar matthiasmatthias abc

abc

This module is for ABC

alias myint = int;


myint f;
windy city

paragraph 2 about of F
#include <stdio.h>
void main()
{
	printf("hello\n");
}


Copyright:
1998

enum E: int;
comment1

int g;
comment2

wchar LS;
UTF line separator

wchar PS;
wchar _XX;
wchar YY;
UTF paragraph separator

int foo(char c, int argulid, char u);
Function foo takes argument c and adds it to argulid.

Then it munges argulid, u underline.

Params:
char c the character which adds c to argulid
int argulid the argument
char u the other argument

int barr();
doc for barr()

class Bar;
The Class Bar

int x;
member X

int y;
member Y

protected int z;
member Z

enum Easy: int;
The Enum Easy

red
the Red

blue
the Blue

green
the Green


Page generated by Ddoc. Copyright © ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/header-postscript.sh0000755000175000017500000000044713200164642030137 0ustar matthiasmatthias#!/usr/bin/env bash grep -v "D import file generated from" ${RESULTS_DIR}/compilable/$1.di > ${RESULTS_DIR}/compilable/$1.di.2 diff --strip-trailing-cr compilable/extra-files/$1.di ${RESULTS_DIR}/compilable/$1.di.2 if [ $? -ne 0 ]; then exit 1; fi rm ${RESULTS_DIR}/compilable/$1.di{,.2} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/test9680dllmain.d0000644000175000017500000000021113200164642027141 0ustar matthiasmatthiasimport core.sys.windows.windows; extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved) { return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9369.ddoc0000644000175000017500000000011613200164642026230 0ustar matthiasmatthiasESCAPES = /&/AddressOf!/ /!/Exclamation/ /?/QuestionMark/ ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/test9680winmain.d0000644000175000017500000000023413200164642027170 0ustar matthiasmatthiasimport core.sys.windows.windows; extern(Windows) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc5.html0000644000175000017500000000127313200164642026022 0ustar matthiasmatthias test

test

Test module

class TestMembers(TemplateArg);
class to test DDOC on members

static void PublicStaticMethod(int idx);
a static method

Params:
int idx index


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc11.html0000644000175000017500000000421113200164642026072 0ustar matthiasmatthias ddoc11

ddoc11



FE_INVALID


FE_DENORMAL


FE_DIVBYZERO


FE_OVERFLOW


FE_UNDERFLOW


FE_INEXACT


FE_ALL_EXCEPT
Mask of all the exceptions

myint bar;


myint foo(myint x = myint.max);


class Foo;


this(string s);


struct div_t;


struct ldiv_t;


struct lldiv_t;


div_t div(int, int);


ldiv_t ldiv(int, int);


lldiv_t lldiv(long, long);


void* calloc(size_t, size_t);


void* malloc(size_t);
dittx

void test1();
Example:
private:
    int i = 0;



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddocAny-postscript.sh0000755000175000017500000000047713200164642030273 0ustar matthiasmatthias#!/usr/bin/env bash grep -v "Generated by Ddoc from" ${RESULTS_DIR}/compilable/ddoc$1.html > ${RESULTS_DIR}/compilable/ddoc$1.html.2 diff --strip-trailing-cr compilable/extra-files/ddoc$1.html ${RESULTS_DIR}/compilable/ddoc$1.html.2 if [ $? -ne 0 ]; then exit 1; fi rm ${RESULTS_DIR}/compilable/ddoc$1.html{,.2} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc14.html0000644000175000017500000000727113200164642026106 0ustar matthiasmatthias ddoc14

ddoc14



struct Structure;
-1

P variable;
0

V mNone(lazy P p);
1

pure nothrow V mPrefix(lazy P p);
2

pure nothrow V mSuffix(lazy P p);
3

pure nothrow V mSuffixTemplate(T)(lazy P p, T[] t...);
5

pure nothrow V mScoped(lazy P p);
6

pure nothrow auto mAutoPrefix(ref P p);
7

pure nothrow auto mAutoTemplateSuffix(alias T)(ref T t);
9

pure nothrow V mColon(lazy P p);
10

class Class;
-1

P variable;
0

V mNone(lazy P p);
1

pure nothrow V mPrefix(lazy P p);
2

pure nothrow V mSuffix(lazy P p);
3

pure nothrow V mSuffixTemplate(T)(lazy P p, T[] t...);
5

pure nothrow V mScoped(lazy P p);
6

pure nothrow auto mAutoPrefix(ref P p);
7

pure nothrow auto mAutoTemplateSuffix(alias T)(ref T t);
9

pure nothrow V mColon(lazy P p);
10

P variable;
0

V mNone(lazy P p);
1

pure nothrow V mPrefix(lazy P p);
2

pure nothrow V mSuffix(lazy P p);
3

pure nothrow V mSuffixTemplate(T)(lazy P p, T[] t...);
5

pure nothrow V mScoped(lazy P p);
6

pure nothrow auto mAutoPrefix(ref P p);
7

pure nothrow auto mAutoTemplateSuffix(alias T)(ref T t);
9

pure nothrow V mColon(lazy P p);
10


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9497b.html0000644000175000017500000000071613200164642026435 0ustar matthiasmatthias ddoc9497b

ddoc9497b



void foo();
foo function.

Args:
$(XYZ arg1, arg2)


Page generated by Ddoc. $(COPYRIGHT ) ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc10870.html0000644000175000017500000000073513200164642026337 0ustar matthiasmatthias ddoc10870

ddoc10870



interface I;


abstract void f();



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc7795.html0000644000175000017500000000100213200164642026257 0ustar matthiasmatthias ddoc7795

ddoc7795



struct DateTime;


this(TimeValue t = TimeValue(0, 0));



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/c6395.d0000644000175000017500000000044213200164642025051 0ustar matthiasmatthias// 6395 template map(alias fun) { auto map(Range)(Range r) { struct Result { @property auto ref front() { return fun("a"); } } return Result(); } } Range find(alias pred, Range)(Range haystack) { pred(haystack.front); return haystack; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/imp9057_2.d0000644000175000017500000000005213200164642025630 0ustar matthiasmatthiasstruct BugInt { uint[] data = [0]; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9037.html0000644000175000017500000000074513200164642026263 0ustar matthiasmatthias ddoc9037

ddoc9037



void test9037();
Example:
D d = d;
D d = d;



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/header2i.di0000644000175000017500000000445313200164642026142 0ustar matthiasmatthiasclass C { } void foo(const C c, const(char)[] s, const int* q, const(int*) p) { } void bar(in void* p) { } void f(void function() f2); class C2; void foo2(const C2 c); struct Foo3 { int k; ~this() { k = 1; } this(this) { k = 2; } } class C3 { @property int get() { return 0; } } T foo3(T)() { } struct S4A(T) { T x; } struct S4B(T) if (1) { T x; } union U4A(T) { T x; } union U4B(T) if (2 * 4 == 8) { T x; } class C4A(T) { T x; } class C4B(T) if (true) { T x; } class C4C(T) if (!false) : C4A!int { T x; } class C4D(T) if (!false) : C4B!long, C4C!(int[]) { T x; } interface I4(T) if ((int[1]).length == 1) { T x; } template MyClass4(T) if (is(typeof(T.subtype))) { alias HelperSymbol = T.subtype; class MyClass4 { } } enum isInt(T) = is(T == int); enum bool isString(T) = is(T == string); static immutable typeName(T) = T.stringof; int storageFor(T) = 0; enum int templateVariableFoo(T) = T.stringof.length; template templateVariableBar(T) if (is(T == int)) { enum int templateVariableBar = T.stringof.length; } auto flit = 3 / 2.00000; void foo11217()(const int[] arr) { } void foo11217()(immutable int[] arr) { } void foo11217()(ref int[] arr) { } void foo11217()(lazy int[] arr) { } void foo11217()(auto ref int[] arr) { } void foo11217()(scope int[] arr) { } void foo11217()(in int[] arr) { } void foo11217()(inout int[] arr) { } void test13275() { if (auto n = 1) { } if (const n = 1) { } if (immutable n = 1) { } if (shared n = 1) { } if (const shared n = 1) { } if (int n = 1) { } if (const int n = 1) { } if (immutable int n = 1) { } if (shared int n = 1) { } if (const shared int n = 1) { } if (const(int) n = 1) { } if (immutable(int) n = 1) { } if (shared(int) n = 1) { } if (shared const(int) n = 1) { } foreach (e; [1, 2]) { } foreach (const e; [1, 2]) { } foreach (immutable e; [1, 2]) { } foreach (shared e; [1, 2]) { } foreach (const shared e; [1, 2]) { } foreach (int e; [1, 2]) { } foreach (const int e; [1, 2]) { } foreach (immutable int e; [1, 2]) { } foreach (shared int e; [1, 2]) { } foreach (const shared int e; [1, 2]) { } foreach (int e; [1, 2]) { } foreach (const(int) e; [1, 2]) { } foreach (immutable(int) e; [1, 2]) { } foreach (shared(int) e; [1, 2]) { } foreach (shared const(int) e; [1, 2]) { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9497d.html0000644000175000017500000000075613200164642026443 0ustar matthiasmatthias ddoc9497d

ddoc9497d



void foo();
foo function.

Args:
ERROR_UNDEFINED_MACRO: "XYZ"


Page generated by Ddoc. ERROR_UNDEFINED_MACRO: "COPYRIGHT" ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9155.html0000644000175000017500000000374213200164642026264 0ustar matthiasmatthias ddoc9155

ddoc9155



void foo();
Note:
test document note 2nd line

Example:
import std.stdio;   //&
writeln("Hello world!");
if (test) {
  writefln("D programming language");
}

    algorithm;

xxx;    //comment
    yyy;
/* test
 * comment
 */

// Create MIME Base64 with CRLF, per line 76.
File f = File("./text.txt", "r");
uint line = 0;
// The ElementType of data is not aggregation type
foreach (encoded; Base64.encoder(data))


wstring ws;
transcode("hello world",ws);
    // transcode from UTF-8 to UTF-16


Example:
import std.stdio;   //&
writeln("Hello world!");
if (test) {
  writefln("D programming language");
}

    algorithm;

xxx;    //comment
    yyy;
/+ test
 + comment
 +/


#!/usr/bin/env rdmd
// Computes average line length for standard input.
import std.stdio;


writefln(q"EOS
This
is a multi-line
heredoc string
EOS"
);



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9727.html0000644000175000017500000000130413200164642026261 0ustar matthiasmatthias ddoc9727

ddoc9727



void foo(int x);
The function foo.

Examples:
foo(1);


Examples:
foo can be used like this:
foo(2);


Examples:
foo can also be used like this:
foo(3);



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/json-postscript.sh0000755000175000017500000000047713200164642027663 0ustar matthiasmatthias#!/usr/bin/env bash grep -v "\"file\" : " ${RESULTS_DIR}/compilable/json.out | grep -v "\"offset\" : " > ${RESULTS_DIR}/compilable/json.out.2 diff --strip-trailing-cr compilable/extra-files/json.out ${RESULTS_DIR}/compilable/json.out.2 if [ $? -ne 0 ]; then exit 1; fi rm ${RESULTS_DIR}/compilable/json.out{,.2} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9764.html0000644000175000017500000000062413200164642026266 0ustar matthiasmatthias ddoc9764

ddoc9764

Check ddoc9764 document.
// Check ddoc9764 comment.
ddoc9764();

Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/header12567a.di0000644000175000017500000000005513200164642026447 0ustar matthiasmatthiasdeprecated module header12567a; void main(); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37/0000755000175000017500000000000013156012230025416 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37/datetime/0000755000175000017500000000000013200164642027217 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37/datetime/package.d0000644000175000017500000000014713200164642030761 0ustar matthiasmatthiasmodule pkgDIP37.datetime; public import pkgDIP37.datetime.common; //alias std.datetime.common.def def; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37/datetime/common.d0000644000175000017500000000005613200164642030655 0ustar matthiasmatthiasmodule pkgDIP37.datetime.common; void def(); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9497c.ddoc0000644000175000017500000000003013200164642026370 0ustar matthiasmatthiasDDOC_UNDEFINED_MACRO=$+ ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc10.html0000644000175000017500000001053513200164642026077 0ustar matthiasmatthias ddoc10

ddoc10



struct Foo(T);
struct Foo(T, U);
The foo

int func1(T)(T x);
This basic case doesn't work very well. The template signature is documented twice, but the function signature (argument names and return type) is not documented at all. This comment is also repeated twice.

int func2(T, U)(T x, U y);
int func2(T)(T x);
This comment is also repeated twice, and the second function signature is not very well documented.

int func2()();
Separate overload item.

int func3(T, U)(T x, U y);
int func3(T, U = int, V : long)(T x);
This used to work adequately and documented both func3 templates simultaneously. Now, it documents the first template twice and no longer documents the function argument and return types.

void map(char rs);
void map(int rs);
blah

void map2()(char rs);
void map2()(int rs);
blah

void map3(char rs);
blah http://www.map3.com map3

void map4(string s)(char rs);
blah http://www.map.com map

template map5(string s)
blah http://www.map.com map

struct bar6;
blah

struct Foo7(T);
template bodies

void bar();
Attempt two: Inside.

Attempt one: Doc outside static if.

static void abc();
the abc function should be static

abstract class Foo8;
show abstract

void bug4878(string a = ")");
a stray ) mustn't foul the macros

struct S;


const pure nothrow this(long ticks);


const pure nothrow void foo(long ticks);


float f10(float a, float b);
Produces something in (a;b]

float h10(float a, float b);
Produces something in [a;b)

void bug6090(string f = "$(B b)", char g = ')')(string h = "$(", string i = "$)");


struct T;


this(A...)(A args);


this(int);


int x14547;
enum int y14547;
doc-comment

enum isInt14547(T);
enum bool isString14547(T);
static immutable typeName14547(T);
int storageFor14547(T);
doc-comment

enum int foo14547(T);
template bar14547(T) if (is(T == int))
doc-comment


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc12745.html0000644000175000017500000000113213200164642026332 0ustar matthiasmatthias ddoc12745

ddoc12745



int i;
i underlined
i not underlined
_i force underscore

0 not underscored
_0 force underscored

1 underscore:
1_1
1_a
a_1
a_a

2 underscores:
1__a
2__b


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/header2.d0000644000175000017500000000513713200164642025620 0ustar matthiasmatthias// for D 2.0 only class C { } void foo(const C c, const(char)[] s, const int* q, const (int*) p) { } void bar(in void *p) { } void f(void function() f2); class C2; void foo2(const C2 c); struct Foo3 { int k; ~this() { k = 1; } this(this) { k = 2; } } class C3 { @property int get() { return 0; } } T foo3(T)() {} struct S4A(T) { T x; } struct S4B(T) if (1) { T x; } union U4A(T) { T x; } union U4B(T) if (2*4 == 8) { T x; } class C4A(T) { T x; } class C4B(T) if (true) { T x; } class C4C(T) : C4A!int if (!false) { T x; } class C4D(T) if (!false) : C4B!long, C4C!(int[]) { T x; } interface I4(T) if ((int[1]).length == 1) { T x; } // eponymous template case template MyClass4(T) if (is(typeof(T.subtype))) { alias HelperSymbol = T.subtype; class MyClass4 {} } enum isInt(T) = is(T == int); enum bool isString(T) = is(T == string); static immutable typeName(T) = T.stringof; int storageFor(T) = 0; template templateVariableFoo(T) { enum int templateVariableFoo = T.stringof.length; } template templateVariableBar(T) if (is(T == int)) { enum int templateVariableBar = T.stringof.length; } auto flit = 3 / 2.0; // 11217 void foo11217()( const int[] arr) {} void foo11217()(immutable int[] arr) {} void foo11217()( ref int[] arr) {} void foo11217()( lazy int[] arr) {} void foo11217()( auto ref int[] arr) {} void foo11217()( scope int[] arr) {} void foo11217()( in int[] arr) {} void foo11217()( inout int[] arr) {} // 13275 void test13275() { if ( auto n = 1) {} if ( const n = 1) {} if ( immutable n = 1) {} if (shared n = 1) {} if (shared const n = 1) {} if ( int n = 1) {} if ( const int n = 1) {} if ( immutable int n = 1) {} if (shared int n = 1) {} if (shared const int n = 1) {} if ( const(int) n = 1) {} if ( immutable(int) n = 1) {} if (shared (int) n = 1) {} if (shared const(int) n = 1) {} foreach ( e; [1,2]) {} foreach ( const e; [1,2]) {} foreach ( immutable e; [1,2]) {} foreach (shared e; [1,2]) {} foreach (shared const e; [1,2]) {} foreach ( int e; [1,2]) {} foreach ( const int e; [1,2]) {} foreach ( immutable int e; [1,2]) {} foreach (shared int e; [1,2]) {} foreach (shared const int e; [1,2]) {} foreach ( int e; [1,2]) {} foreach ( const(int) e; [1,2]) {} foreach ( immutable(int) e; [1,2]) {} foreach (shared (int) e; [1,2]) {} foreach (shared const(int) e; [1,2]) {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9497a.html0000644000175000017500000000074013200164642026431 0ustar matthiasmatthias ddoc9497a

ddoc9497a



void foo();
foo function.

Args:



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37_10421/0000755000175000017500000000000013200164642026152 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37_10421/algo/0000755000175000017500000000000013200164642027074 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37_10421/algo/package.d0000644000175000017500000000022513200164642030633 0ustar matthiasmatthiasmodule pkgDIP37_10421.algo; public import pkgDIP37_10421.algo.mod; package { void foo() {} void bar() { foo(); } // should be accessible } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37_10421/algo/mod.d0000644000175000017500000000030613200164642030017 0ustar matthiasmatthiasmodule pkgDIP37_10421.algo.mod; import pkgDIP37_10421.algo; // foo import pkgDIP37_10421.except; // baz void test() { foo(); // should be accessible baz(); // should be accessible } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37_10421/except.d0000644000175000017500000000006513200164642027610 0ustar matthiasmatthiasmodule pkgDIP37_10421.except; package void baz() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc10334.html0000644000175000017500000000463113200164642026331 0ustar matthiasmatthias ddoc10334

ddoc10334



template Foo10334(T) if (Bar10334!())


template Foo10334(T) if (Bar10334!100)


template Foo10334(T) if (Bar10334!3.14)


template Foo10334(T) if (Bar10334!"str")


template Foo10334(T) if (Bar10334!1.4i)


template Foo10334(T) if (Bar10334!null)


template Foo10334(T) if (Bar10334!true)


template Foo10334(T) if (Bar10334!false)


template Foo10334(T) if (Bar10334!'A')


template Foo10334(T) if (Bar10334!int)


template Foo10334(T) if (Bar10334!string)


template Foo10334(T) if (Bar10334!([1, 2, 3]))


template Foo10334(T) if (Bar10334!(Baz10334!()))


template Foo10334(T) if (Bar10334!(Baz10334!T))


template Foo10334(T) if (Bar10334!(Baz10334!100))


template Foo10334(T) if (Bar10334!(.foo))


template Foo10334(T) if (Bar10334!(const(int)))


template Foo10334(T) if (Bar10334!(shared(T)))


template Test10334(T...)



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/depsOutput.sh0000755000175000017500000000062713200164642026653 0ustar matthiasmatthias#!/usr/bin/env bash grep 'depsOutput9948 (.*depsOutput9948.d) : private : std.string' ${RESULTS_DIR}/compilable/depsOutput9948.deps || exit 1 grep 'depsOutput9948a (.*depsOutput9948a.d) : private : std.string' ${RESULTS_DIR}/compilable/depsOutput9948.deps && exit 1 grep '__entrypoint' ${RESULTS_DIR}/compilable/depsOutput9948.deps && exit 1 rm -f ${RESULTS_DIR}/compilable/depsOutput9948.deps exit 0 ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9676b.html0000644000175000017500000000061313200164642026430 0ustar matthiasmatthias ddoc9676b

ddoc9676b



deprecated void foo();



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37_10302/0000755000175000017500000000000013200164642026150 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37_10302/liba.d0000644000175000017500000000005213200164642027221 0ustar matthiasmatthiasmodule pkgDIP37_10302.liba; void foo() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37_10302/package.d0000644000175000017500000000007213200164642027707 0ustar matthiasmatthiasmodule pkgDIP37_10302; public import pkgDIP37_10302.liba; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/pkgDIP37_10302/libb.d0000644000175000017500000000031113200164642027220 0ustar matthiasmatthiasmodule pkgDIP37_10302.libb; import pkgDIP37_10302.liba; void bar() { foo(); // should be error, but unfortunately this works by bug 314 now. //lib.foo(); pkgDIP37_10302.liba.foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/header1i.di0000644000175000017500000001361213200164642026136 0ustar matthiasmatthiasmodule foo.bar; import core.vararg; import std.stdio; pragma (lib, "test"); pragma (msg, "Hello World"); static assert(true, "message"); alias mydbl = double; int testmain() in { assert(1 + (2 + 3) == -(1 - 2 * 3)); } out(result) { assert(result == 0); } body { float f = (float).infinity; int i = cast(int)f; writeln((i , 1), 2); writeln(cast(int)(float).max); assert(i == cast(int)(float).max); assert(i == 2147483648u); return 0; } struct S { int m; int n; } template Foo(T, int V) { void foo(...) { static if (is(Object _ : X!TL, alias X, TL...)) { } auto x = __traits(hasMember, Object, "noMember"); auto y = is(Object : X!TL, alias X, TL...); assert(!x && !y, "message"); S s = {1, 2}; auto a = [1, 2, 3]; auto aa = [1:1, 2:2, 3:3]; int n, m; } int bar(double d, int x) { if (d) { d++; } else d--; asm { naked; } asm { mov EAX,3; } for (;;) { { d = d + 1; } } for (int i = 0; i < 10; i++) { { d = i ? d + 1 : 5; } } char[] s; foreach (char c; s) { d *= 2; if (d) break; else continue; } switch (V) { case 1: { } case 2: { break; } case 3: { goto case 1; } case 4: { goto default; } default: { d /= 8; break; } } enum Label { A, B, C, } ; void fswitch(Label l) { final switch (l) { case A: { break; } case B: { break; } case C: { break; } } } loop: while (x) { x--; if (x) break loop; else continue loop; } do { x++; } while (x < 10); try { try { bar(1, 2); } catch(Object o) { x++; } } finally { x--; } Object o; synchronized(o) { x = ~x; } synchronized { x = x < 3; } with (o) { toString(); } } } static this(); nothrow pure @nogc @safe static this(); nothrow pure @nogc @safe static this(); nothrow pure @nogc @safe shared static this(); nothrow pure @nogc @safe shared static this(); interface iFoo { } class xFoo : iFoo { } interface iFoo2 { } class xFoo2 : iFoo, iFoo2 { } class Foo3 { this(int a, ...) { } this(int* a) { } } alias myint = int; static notquit = 1; class Test { void a() { } void b() { } void c() { } void d() { } void e() { } void f() { } void g() { } void h() { } void i() { } void j() { } void k() { } void l() { } void m() { } void n() { } void o() { } void p() { } void q() { } void r() { } void s() { } void t() { } void u() { } void v() { } void w() { } void x() { } void y() { } void z() { } void aa() { } void bb() { } void cc() { } void dd() { } void ee() { } template A(T) { } alias getHUint = A!uint; alias getHInt = A!int; alias getHFloat = A!float; alias getHUlong = A!ulong; alias getHLong = A!long; alias getHDouble = A!double; alias getHByte = A!byte; alias getHUbyte = A!ubyte; alias getHShort = A!short; alias getHUShort = A!ushort; alias getHReal = A!real; alias void F(); nothrow pure @nogc @safe new(size_t sz) { return null; } nothrow pure @nogc @safe delete(void* p) { } } void templ(T)(T val) { pragma (msg, "Invalid destination type."); } static char[] charArray = ['"', '\'']; class Point { auto x = 10; uint y = 20; } template Foo2(bool bar) { void test() { static if (bar) { int i; } else { } static if (!bar) { } else { } } } template Foo4() { void bar() { } } template Foo4x(T...) { } class Baz4 { mixin Foo4!() foo; mixin Foo4x!(int, "str") foox; alias baz = foo.bar; } int test(T)(T t) { if (auto o = cast(Object)t) return 1; return 0; } enum x6 = 1; bool foo6(int a, int b, int c, int d) { return (a < b) != (c < d); } auto foo7(int x) { return 5; } class D8 { } void func8() { scope a = new D8; } T func9(T)() if (true) { T i; scope(exit) i = 1; scope(success) i = 2; scope(failure) i = 3; return i; } template V10(T) { void func() { for (int i, j = 4; i < 3; i++) { { } } } } int foo11(int function() fn) { return fn(); } int bar11(T)() { return foo11(function int() { return 0; } ); } struct S6360 { const pure nothrow @property long weeks1() { return 0; } const pure nothrow @property long weeks2() { return 0; } } struct S12 { nothrow this(int n) { } nothrow this(string s) { } } struct T12 { immutable this()(int args) { } immutable this(A...)(A args) { } } import std.stdio : writeln, F = File; void foo6591()() { import std.stdio : writeln, F = File; } version (unittest) { public {} extern (C) {} align{} } template Foo10334(T) if (Bar10334!()) { } template Foo10334(T) if (Bar10334!100) { } template Foo10334(T) if (Bar10334!3.14) { } template Foo10334(T) if (Bar10334!"str") { } template Foo10334(T) if (Bar10334!1.4i) { } template Foo10334(T) if (Bar10334!null) { } template Foo10334(T) if (Bar10334!true) { } template Foo10334(T) if (Bar10334!false) { } template Foo10334(T) if (Bar10334!'A') { } template Foo10334(T) if (Bar10334!int) { } template Foo10334(T) if (Bar10334!string) { } template Foo10334(T) if (Bar10334!wstring) { } template Foo10334(T) if (Bar10334!dstring) { } template Foo10334(T) if (Bar10334!this) { } template Foo10334(T) if (Bar10334!([1, 2, 3])) { } template Foo10334(T) if (Bar10334!(Baz10334!())) { } template Foo10334(T) if (Bar10334!(Baz10334!T)) { } template Foo10334(T) if (Bar10334!(Baz10334!100)) { } template Foo10334(T) if (Bar10334!(.foo)) { } template Foo10334(T) if (Bar10334!(const(int))) { } template Foo10334(T) if (Bar10334!(shared(T))) { } template Test10334(T...) { } mixin Test10334!int a; mixin Test10334!(int, long) b; mixin Test10334!"str" c; auto clamp12266a(T1, T2, T3)(T1 x, T2 min_val, T3 max_val) { return 0; } pure clamp12266b(T1, T2, T3)(T1 x, T2 min_val, T3 max_val) { return 0; } @disable pure clamp12266c(T1, T2, T3)(T1 x, T2 min_val, T3 max_val) { return 0; } alias Dg13832 = ref int delegate(); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9903.html0000644000175000017500000000222113200164642026254 0ustar matthiasmatthias ddoc9903

ddoc9903



struct S9903X;
struct S9903Y;
sss

class C9903X;
class C9903Y;
ccc

union U9903X;
union U9903Y;
uuu

interface I9903X;
interface I9903Y;
iii

enum E9903X: int;
enum E9903Y: int;
eee

a9903
b9903
ea

c9903
ec


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/imp9057.d0000644000175000017500000000010713200164642025410 0ustar matthiasmatthiasstruct BugInt { uint[] data = ZEROX; } enum uint [] ZEROX = [0]; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/json.out0000644000175000017500000002404713200164642025644 0ustar matthiasmatthias[ { "name" : "json", "kind" : "module", "members" : [ { "name" : "_staticCtor1", "kind" : "function", "line" : 8, "char" : 1, "storageClass" : [ "static" ], "deco" : "FZv", "endline" : 8, "endchar" : 16 }, { "name" : "_staticDtor2", "kind" : "function", "line" : 10, "char" : 1, "storageClass" : [ "static" ], "deco" : "FZv", "endline" : 10, "endchar" : 17 }, { "name" : "myInt", "kind" : "alias", "line" : 13, "char" : 11, "deco" : "i" }, { "name" : "x", "kind" : "variable", "line" : 14, "char" : 7, "deco" : "i", "originalType" : "myInt" }, { "kind" : "template", "line" : 16, "char" : 1, "name" : "Foo", "parameters" : [ { "name" : "T", "kind" : "type" } ], "members" : [ { "name" : "Foo", "kind" : "struct", "line" : 16, "char" : 1, "members" : [ { "name" : "t", "kind" : "variable", "line" : 16, "char" : 19, "type" : "T" } ] } ] }, { "kind" : "template", "line" : 17, "char" : 1, "name" : "Bar", "parameters" : [ { "name" : "T", "kind" : "value", "deco" : "i" } ], "members" : [ { "name" : "Bar", "kind" : "class", "line" : 17, "char" : 1, "members" : [ { "name" : "t", "kind" : "variable", "line" : 17, "char" : 25, "deco" : "i", "init" : "T" } ] } ] }, { "kind" : "template", "line" : 18, "char" : 1, "name" : "Baz", "parameters" : [ { "name" : "T", "kind" : "tuple" } ], "members" : [ { "name" : "Baz", "kind" : "interface", "line" : 18, "char" : 1, "members" : [ { "name" : "t", "kind" : "function", "line" : 18, "char" : 28, "type" : "const T[0]()" } ] } ] }, { "kind" : "template", "line" : 20, "char" : 1, "name" : "P", "parameters" : [ { "name" : "T", "kind" : "alias" } ], "members" : [] }, { "name" : "Bar2", "kind" : "class", "line" : 22, "char" : 1, "base" : "json.Bar!1.Bar", "interfaces" : [ "json.Baz!(int, 2, null).Baz" ], "members" : [ { "name" : "this", "kind" : "constructor", "line" : 23, "char" : 5, "deco" : "FZC4json4Bar2", "originalType" : "()", "endline" : 23, "endchar" : 13 }, { "name" : "~this", "kind" : "destructor", "line" : 24, "char" : 5, "deco" : "FZv", "endline" : 24, "endchar" : 14 }, { "name" : "foo", "kind" : "function", "line" : 26, "char" : 12, "storageClass" : [ "static" ], "deco" : "FNaNbNiNfZv", "originalType" : "()", "endline" : 26, "endchar" : 19 }, { "name" : "baz", "kind" : "function", "protection" : "protected", "line" : 27, "char" : 32, "storageClass" : [ "abstract" ], "deco" : "FZS4json10__T3FooTiZ3Foo" }, { "name" : "t", "kind" : "function", "line" : 28, "char" : 18, "storageClass" : [ "override" ], "deco" : "xFZi", "endline" : 28, "endchar" : 40, "overrides" : [ "json.Baz!(int, 2, null).Baz.t" ] }, { "name" : "__xdtor", "kind" : "alias" } ] }, { "name" : "Bar3", "kind" : "class", "line" : 31, "char" : 1, "base" : "json.Bar2", "members" : [ { "name" : "val", "kind" : "variable", "protection" : "private", "line" : 32, "char" : 14, "deco" : "i", }, { "name" : "this", "kind" : "constructor", "line" : 33, "char" : 5, "deco" : "FiZC4json4Bar3", "originalType" : "(int i)", "parameters" : [ { "name" : "i", "deco" : "i" } ], "endline" : 33, "endchar" : 28 }, { "name" : "baz", "kind" : "function", "protection" : "protected", "line" : 35, "char" : 32, "storageClass" : [ "override" ], "deco" : "FZS4json10__T3FooTiZ3Foo", "endline" : 35, "endchar" : 61, "overrides" : [ "json.Bar2.baz" ] } ] }, { "name" : "Foo2", "kind" : "struct", "line" : 38, "char" : 1, "members" : [ { "name" : "bar2", "kind" : "variable", "line" : 39, "char" : 7, "deco" : "C4json4Bar2", "originalType" : "Bar2", }, { "name" : "U", "kind" : "union", "line" : 40, "char" : 2, "members" : [ { "name" : "s", "kind" : "variable", "line" : 42, "char" : 10, "deco" : "s", }, { "name" : "i", "kind" : "variable", "line" : 43, "char" : 8, "deco" : "i", }, { "name" : "o", "kind" : "variable", "line" : 45, "char" : 10, "deco" : "C6Object", "originalType" : "Object", } ] } ] }, { "name" : "bar", "kind" : "function", "line" : 52, "char" : 16, "deco" : "FNeKkC4json4Bar2Zi", "originalType" : "@trusted myInt(ref uint blah, Bar2 foo = new Bar3(7))", "parameters" : [ { "name" : "blah", "deco" : "k", "storageClass" : [ "ref" ] }, { "name" : "foo", "deco" : "C4json4Bar2", "default" : "new Bar3(7)" } ], "endline" : 55, "endchar" : 1 }, { "name" : "outer", "kind" : "function", "line" : 57, "char" : 15, "deco" : "FNbNdZi", "endline" : 74, "endchar" : 1 }, { "name" : "imports.jsonimport1", "kind" : "import", "line" : 77, "char" : 8, "protection" : "private", "selective" : [ "target1", "target2" ] }, { "name" : "imports.jsonimport2", "kind" : "import", "line" : 78, "char" : 8, "protection" : "private", "renamed" : { "alias1" : "target1", "alias2" : "target2" } }, { "name" : "imports.jsonimport3", "kind" : "import", "line" : 79, "char" : 8, "protection" : "private", "renamed" : { "alias3" : "target1", "alias4" : "target2" }, "selective" : [ "target3" ] }, { "name" : "imports.jsonimport4", "kind" : "import", "line" : 80, "char" : 8, "protection" : "private" }, { "name" : "S", "kind" : "struct", "line" : 82, "char" : 1, "members" : [ { "kind" : "template", "line" : 85, "char" : 5, "name" : "this", "parameters" : [ { "name" : "T", "kind" : "type" } ], "members" : [ { "name" : "this", "kind" : "constructor", "line" : 85, "char" : 5, "type" : "(T t)", "parameters" : [ { "name" : "t", "type" : "T" } ], "endline" : 85, "endchar" : 20 } ] } ] }, { "kind" : "template", "protection" : "private", "line" : 89, "char" : 9, "name" : "S1_9755", "parameters" : [ { "name" : "T", "kind" : "type" } ], "members" : [ { "name" : "S1_9755", "kind" : "struct", "line" : 89, "char" : 9, "members" : [] } ] }, { "kind" : "template", "protection" : "package", "line" : 90, "char" : 9, "name" : "S2_9755", "parameters" : [ { "name" : "T", "kind" : "type" } ], "members" : [ { "name" : "S2_9755", "kind" : "struct", "line" : 90, "char" : 9, "members" : [] } ] }, { "name" : "C_9755", "kind" : "class", "line" : 92, "char" : 1, "members" : [ { "kind" : "template", "protection" : "protected", "line" : 94, "char" : 22, "name" : "CI_9755", "parameters" : [ { "name" : "T", "kind" : "type" } ], "members" : [ { "name" : "CI_9755", "kind" : "class", "line" : 94, "char" : 22, "members" : [] } ] } ] }, { "name" : "c_10011", "kind" : "variable", "line" : 98, "char" : 14, "storageClass" : [ "const" ], "deco" : "xC6Object", "originalType" : "Object", "init" : "Object()" }, { "name" : "Numbers", "kind" : "enum", "line" : 101, "char" : 1, "baseDeco" : "i", "members" : [ { "name" : "unspecified1", "kind" : "enum member", "value" : "0", "line" : 103, "char" : 5 }, { "name" : "one", "kind" : "enum member", "value" : "2", "line" : 104, "char" : 5 }, { "name" : "two", "kind" : "enum member", "value" : "3", "line" : 105, "char" : 5 }, { "name" : "FILE_NOT_FOUND", "kind" : "enum member", "value" : "101", "line" : 106, "char" : 5 }, { "name" : "unspecified3", "kind" : "enum member", "value" : "102", "line" : 107, "char" : 5 }, { "name" : "unspecified4", "kind" : "enum member", "value" : "103", "line" : 108, "char" : 5 }, { "name" : "four", "kind" : "enum member", "value" : "4", "line" : 109, "char" : 5 } ] }, { "kind" : "template", "line" : 112, "char" : 1, "name" : "IncludeConstraint", "parameters" : [ { "name" : "T", "kind" : "type" } ], "constraint" : "T == string", "members" : [] } ] } ] ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc648.html0000644000175000017500000000455413200164642026204 0ustar matthiasmatthias ddoc648

ddoc648



template Mixin1()
Mixin declaration

struct S;
struct S

class A;
class A

int x;
field x

struct S;
struct S

class AB;
class AB

int x;
field x

template Mixin2()
Mixin declaration2

struct S2;
struct S2

template Mixin3()
Mixin declaration3

int f;
another field

class B1;
class B1

int f;
another field

struct S2;
struct S2

template Mixin4()
Mixin declaration3

int f;
another field

class B2;
class B2

int f;
another field

int f;
another field

struct S2;
struct S2

struct TS(T);


int field;



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9475.html0000644000175000017500000000142613200164642026266 0ustar matthiasmatthias ddoc9475

ddoc9475



void foo();
foo

Examples:
// comment 1
foreach (i; 0 .. 10)
{
    // comment 2
    documentedFunction();
}


void bar();
bar

Examples:
// bar comment



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/test11237.sh0000755000175000017500000000025013200164642026044 0ustar matthiasmatthias#!/usr/bin/env bash if [[ $OS == linux || $OS == freebsd ]]; then nm -S ${RESULTS_DIR}/compilable/test11237_0.o | grep "00010000 B _D9test112376Buffer6__initZ" fi ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddocYear.html0000644000175000017500000000060613200164642026555 0ustar matthiasmatthias ddocYear

ddocYear



int year;
__YEAR__


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/test14894main.d0000644000175000017500000000010613200164642026533 0ustar matthiasmatthiasimport test14894a; void main() { Foo foo; foo.onReceive(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc13270.html0000644000175000017500000000144013200164642026326 0ustar matthiasmatthias ddoc13270

ddoc13270



void doStuff(string task);
void doStuff(string[] tasks, int maxJobs);
My overloaded function.

Params:
string task String description of stuff to do.
string[] tasks Array of descriptions of stuff to do.
int maxJobs Max parallel jobs to run while doing stuff.


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9305.html0000644000175000017500000000346213200164642026260 0ustar matthiasmatthias ddoc9305

ddoc9305



void foo(alias p = (a) => a)();
foo()

template X(alias pred = (x) => x)
template X(alias pred = (x) { int y; return y; } )
template X(alias pred = (int x) => x)
template X(alias pred = (int x) { int y; return y; } )


template X(alias pred = function (x) => x)
template X(alias pred = function (x) { return x + 1; } )
template X(alias pred = function (int x) => x)
template X(alias pred = function (int x) { return x + 1; } )
template X(alias pred = function int(x) => x)
template X(alias pred = function int(x) { return x + 1; } )
template X(alias pred = function int(int x) => x)
template X(alias pred = function int(int x) { return x + 1; } )


template X(alias pred = delegate (x) => x)
template X(alias pred = delegate (x) { return x + 1; } )
template X(alias pred = delegate (int x) => x)
template X(alias pred = delegate (int x) { return x + 1; } )
template X(alias pred = delegate int(x) => x)
template X(alias pred = delegate int(x) { return x + 1; } )
template X(alias pred = delegate int(int x) => x)
template X(alias pred = delegate int(int x) { return x + 1; } )



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/header1.di0000644000175000017500000001227413200164642025770 0ustar matthiasmatthiasmodule foo.bar; import core.vararg; import std.stdio; pragma (lib, "test"); pragma (msg, "Hello World"); static assert(true, "message"); alias mydbl = double; int testmain(); struct S { int m; int n; } template Foo(T, int V) { void foo(...) { static if (is(Object _ : X!TL, alias X, TL...)) { } auto x = __traits(hasMember, Object, "noMember"); auto y = is(Object : X!TL, alias X, TL...); assert(!x && !y, "message"); S s = {1, 2}; auto a = [1, 2, 3]; auto aa = [1:1, 2:2, 3:3]; int n, m; } int bar(double d, int x) { if (d) { d++; } else d--; asm { naked; } asm { mov EAX,3; } for (;;) { { d = d + 1; } } for (int i = 0; i < 10; i++) { { d = i ? d + 1 : 5; } } char[] s; foreach (char c; s) { d *= 2; if (d) break; else continue; } switch (V) { case 1: { } case 2: { break; } case 3: { goto case 1; } case 4: { goto default; } default: { d /= 8; break; } } enum Label { A, B, C, } ; void fswitch(Label l); loop: while (x) { x--; if (x) break loop; else continue loop; } do { x++; } while (x < 10); try { try { bar(1, 2); } catch(Object o) { x++; } } finally { x--; } Object o; synchronized(o) { x = ~x; } synchronized { x = x < 3; } with (o) { toString(); } } } static this(); nothrow pure @nogc @safe static this(); nothrow pure @nogc @safe static this(); nothrow pure @nogc @safe shared static this(); nothrow pure @nogc @safe shared static this(); interface iFoo { } class xFoo : iFoo { } interface iFoo2 { } class xFoo2 : iFoo, iFoo2 { } class Foo3 { this(int a, ...); this(int* a); } alias myint = int; static notquit = 1; class Test { void a(); void b(); void c(); void d(); void e(); void f(); void g(); void h(); void i(); void j(); void k(); void l(); void m(); void n(); void o(); void p(); void q(); void r(); void s(); void t(); void u(); void v(); void w(); void x(); void y(); void z(); void aa(); void bb(); void cc(); void dd(); void ee(); template A(T) { } alias getHUint = A!uint; alias getHInt = A!int; alias getHFloat = A!float; alias getHUlong = A!ulong; alias getHLong = A!long; alias getHDouble = A!double; alias getHByte = A!byte; alias getHUbyte = A!ubyte; alias getHShort = A!short; alias getHUShort = A!ushort; alias getHReal = A!real; alias void F(); nothrow pure @nogc @safe new(size_t sz); nothrow pure @nogc @safe delete(void* p); } void templ(T)(T val) { pragma (msg, "Invalid destination type."); } static char[] charArray = ['"', '\'']; class Point { auto x = 10; uint y = 20; } template Foo2(bool bar) { void test() { static if (bar) { int i; } else { } static if (!bar) { } else { } } } template Foo4() { void bar() { } } template Foo4x(T...) { } class Baz4 { mixin Foo4!() foo; mixin Foo4x!(int, "str") foox; alias baz = foo.bar; } int test(T)(T t) { if (auto o = cast(Object)t) return 1; return 0; } enum x6 = 1; bool foo6(int a, int b, int c, int d); auto foo7(int x) { return 5; } class D8 { } void func8(); T func9(T)() if (true) { T i; scope(exit) i = 1; scope(success) i = 2; scope(failure) i = 3; return i; } template V10(T) { void func() { for (int i, j = 4; i < 3; i++) { { } } } } int foo11(int function() fn); int bar11(T)() { return foo11(function int() { return 0; } ); } struct S6360 { const pure nothrow @property long weeks1(); const pure nothrow @property long weeks2(); } struct S12 { nothrow this(int n); nothrow this(string s); } struct T12 { immutable this()(int args) { } immutable this(A...)(A args) { } } import std.stdio : writeln, F = File; void foo6591()() { import std.stdio : writeln, F = File; } version (unittest) { public {} extern (C) {} align{} } template Foo10334(T) if (Bar10334!()) { } template Foo10334(T) if (Bar10334!100) { } template Foo10334(T) if (Bar10334!3.14) { } template Foo10334(T) if (Bar10334!"str") { } template Foo10334(T) if (Bar10334!1.4i) { } template Foo10334(T) if (Bar10334!null) { } template Foo10334(T) if (Bar10334!true) { } template Foo10334(T) if (Bar10334!false) { } template Foo10334(T) if (Bar10334!'A') { } template Foo10334(T) if (Bar10334!int) { } template Foo10334(T) if (Bar10334!string) { } template Foo10334(T) if (Bar10334!wstring) { } template Foo10334(T) if (Bar10334!dstring) { } template Foo10334(T) if (Bar10334!this) { } template Foo10334(T) if (Bar10334!([1, 2, 3])) { } template Foo10334(T) if (Bar10334!(Baz10334!())) { } template Foo10334(T) if (Bar10334!(Baz10334!T)) { } template Foo10334(T) if (Bar10334!(Baz10334!100)) { } template Foo10334(T) if (Bar10334!(.foo)) { } template Foo10334(T) if (Bar10334!(const(int))) { } template Foo10334(T) if (Bar10334!(shared(T))) { } template Test10334(T...) { } mixin Test10334!int a; mixin Test10334!(int, long) b; mixin Test10334!"str" c; auto clamp12266a(T1, T2, T3)(T1 x, T2 min_val, T3 max_val) { return 0; } pure clamp12266b(T1, T2, T3)(T1 x, T2 min_val, T3 max_val) { return 0; } @disable pure clamp12266c(T1, T2, T3)(T1 x, T2 min_val, T3 max_val) { return 0; } alias Dg13832 = ref int delegate(); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc7555.html0000644000175000017500000000132213200164642026256 0ustar matthiasmatthias ddoc7555

ddoc7555



void dummy();
Dummy doc.

DelimitedString TokenString

DelimitedString TokenString

HexString HexString

HexString HexString

HexString HexString

HexString HexString

HexString HexString

HexString HexString

HexString HexString

HexString HexString


Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc9676a.ddoc0000644000175000017500000000003313200164642026370 0ustar matthiasmatthiasDEPRECATED = $0 ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/ddoc2273.html0000644000175000017500000000214413200164642026251 0ustar matthiasmatthias ddoc2273

ddoc2273



interface B: ddoc2273.C, ddoc2273.D;


class Foo: ddoc2273.A, ddoc2273.B;


MinType!(T1, T2, T) min(T1, T2, T...)(T1 a, T2 b, T xs);


Templ!([1, 2, 3]) max(T...)();


template Base64Impl(char Map62th, char Map63th, char Padding)


int sqlite3_config(int, ...);


alias IndexOf = staticIndexOf(T, TList...);



Page generated by Ddoc. ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/extra-files/test9680main.d0000644000175000017500000000002013200164642026443 0ustar matthiasmatthiasvoid main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_497.d0000644000175000017500000000041513200164642024564 0ustar matthiasmatthiasimport std.algorithm : all, canFind; struct Foo { float a, b, c; auto opDispatch(string swiz)() if (swiz.all!(x => "abc".canFind(x))) { return mixin("Foo(" ~ swiz[0] ~ "," ~ swiz[1] ~ "," ~ swiz[2] ~ ")"); } } auto f(Foo f) { return f.cab; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_823.d0000644000175000017500000000006313200164642024554 0ustar matthiasmatthiascdouble bar; ref cdouble foo() { return bar; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9692a.d0000644000175000017500000000003113200164642023521 0ustar matthiasmatthiasmodule test9692a; int j; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test25.d0000644000175000017500000000020013200164642023173 0ustar matthiasmatthias// PERMUTE_ARGS: import imports.test25a, imports.test25b; import std.stdio; void main() { std.stdio.writefln("hello"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8675.d0000644000175000017500000000030713200164642023366 0ustar matthiasmatthiasclass MyError : Error { this(string msg) { super(msg); } } void foo() nothrow { throw new Error("Some error"); } void bar() nothrow { throw new MyError("Some error"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test12567a.d0000644000175000017500000000015413200164642023602 0ustar matthiasmatthias// REQUIRED_ARGS: // PERMUTE_ARGS: /* TEST_OUTPUT: --- --- */ deprecated module test12567a; void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test72.d0000644000175000017500000000012413200164642023202 0ustar matthiasmatthiasmodule test72; import imports.test72a, imports.test72c; void bar() { foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/vgc2.d0000644000175000017500000000446413200164642022726 0ustar matthiasmatthias// REQUIRED_ARGS: -vgc -o- // PERMUTE_ARGS: /***************** CatExp *******************/ /* TEST_OUTPUT: --- compilable/vgc2.d(21): vgc: operator ~ may cause GC allocation compilable/vgc2.d(22): vgc: operator ~ may cause GC allocation compilable/vgc2.d(23): vgc: operator ~ may cause GC allocation compilable/vgc2.d(25): vgc: operator ~ may cause GC allocation compilable/vgc2.d(26): vgc: operator ~ may cause GC allocation compilable/vgc2.d(27): vgc: operator ~ may cause GC allocation compilable/vgc2.d(28): vgc: operator ~ may cause GC allocation compilable/vgc2.d(29): vgc: operator ~ may cause GC allocation --- */ void testCat(int[] a, string s) { int[] a1 = a ~ a; int[] a2 = a ~ 1; int[] a3 = 1 ~ a; string s1 = s ~ s; string s2 = s ~ "a"; string s3 = "a" ~ s; string s4 = s ~ 'c'; string s5 = 'c' ~ s; string s6 = "a" ~ "b"; // no error string s7 = "a" ~ 'c'; // no error string s8 = 'c' ~ "b"; // no error } /***************** CatAssignExp *******************/ /* TEST_OUTPUT: --- compilable/vgc2.d(48): vgc: operator ~= may cause GC allocation compilable/vgc2.d(50): vgc: operator ~= may cause GC allocation compilable/vgc2.d(51): vgc: operator ~= may cause GC allocation --- */ void testCatAssign(int[] a, string s) { a ~= 1; s ~= "a"; s ~= 'c'; } /***************** ArrayLiteralExp *******************/ int* barA(); /* TEST_OUTPUT: --- compilable/vgc2.d(70): vgc: array literal may cause GC allocation compilable/vgc2.d(71): vgc: array literal may cause GC allocation --- */ void testArray() { enum arrLiteral = [null, null]; int* p; auto a = [p, p, barA()]; a = arrLiteral; } /***************** AssocArrayLiteralExp *******************/ /* TEST_OUTPUT: --- compilable/vgc2.d(87): vgc: associative array literal may cause GC allocation compilable/vgc2.d(88): vgc: associative array literal may cause GC allocation --- */ void testAssocArray() { enum aaLiteral = [10: 100]; auto aa = [1:1, 2:3, 4:5]; aa = aaLiteral; } /***************** IndexExp *******************/ /* TEST_OUTPUT: --- compilable/vgc2.d(102): vgc: indexing an associative array may cause GC allocation compilable/vgc2.d(103): vgc: indexing an associative array may cause GC allocation --- */ void testIndex(int[int] aa) { aa[1] = 0; int n = aa[1]; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice13403.d0000644000175000017500000000012113200164642023202 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -o- import imports.ice13403a; void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test13053.d0000644000175000017500000000013013200164642023422 0ustar matthiasmatthias// PERMUTE_ARGS: -w -wi /* TEST_OUTPUT: --- --- */ @system: struct S { int[] a; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test12523.d0000644000175000017500000000043713200164642023435 0ustar matthiasmatthiasvoid test12523(inout(int)) { void check(T)() { T[] a; foreach (ref e; a) static assert(is(typeof(e) == T)); } check!(int)(); check!(inout(int))(); check!(inout(const(int)))(); check!(const(int))(); check!(immutable(int))(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice10431a.d0000644000175000017500000000047313200164642023353 0ustar matthiasmatthiasmixin ADT!(); struct Tuple(TL...) { TL expand; } template Seq(T...) { alias T Seq; } template ADT() { mixin(q{ struct ListI { private { size_t tag; union { Seq!(Tuple!()*, Tuple!(int,ListI,)*,) data; } } } }); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9570.d0000644000175000017500000000665113200164642023371 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: void main() { ubyte[256] data; foreach (immutable i; 0..256) data[i] = i; foreach ( const i; 0..256) data[i] = i; foreach ( i; 0..256) static assert(!__traits(compiles, (data[i] = i))); foreach (immutable int i; 0..256) data[i] = i; foreach ( const int i; 0..256) data[i] = i; foreach ( int i; 0..256) static assert(!__traits(compiles, (data[i] = i))); foreach (immutable(int) i; 0..256) data[i] = i; foreach ( const(int) i; 0..256) data[i] = i; foreach ( int i; 0..256) static assert(!__traits(compiles, (data[i] = i))); foreach (immutable(ulong) i; 0..256) data[i] = i; foreach ( const(ulong) i; 0..256) data[i] = i; foreach ( ulong i; 0..256) static assert(!__traits(compiles, (data[i] = i))); foreach (immutable i, x; data) data[i] = i; foreach ( const i, x; data) data[i] = i; foreach ( i, x; data) static assert(!__traits(compiles, (data[i] = i))); foreach (immutable int i, x; data) data[i] = i; foreach ( const int i, x; data) data[i] = i; foreach ( int i, x; data) static assert(!__traits(compiles, (data[i] = i))); foreach (immutable(int) i, x; data) data[i] = i; foreach ( const(int) i, x; data) data[i] = i; foreach ( int i, x; data) static assert(!__traits(compiles, (data[i] = i))); foreach (immutable(ulong) i, x; data) data[i] = i; foreach ( const(ulong) i, x; data) data[i] = i; foreach ( ulong i, x; data) static assert(!__traits(compiles, (data[i] = i))); foreach_reverse (immutable i; 0..256) data[i] = i; foreach_reverse ( const i; 0..256) data[i] = i; foreach_reverse ( i; 0..256) static assert(!__traits(compiles, (data[i] = i))); foreach_reverse (immutable int i; 0..256) data[i] = i; foreach_reverse ( const int i; 0..256) data[i] = i; foreach_reverse ( int i; 0..256) static assert(!__traits(compiles, (data[i] = i))); foreach_reverse (immutable(int) i; 0..256) data[i] = i; foreach_reverse ( const(int) i; 0..256) data[i] = i; foreach_reverse ( int i; 0..256) static assert(!__traits(compiles, (data[i] = i))); foreach_reverse (immutable(ulong) i; 0..256) data[i] = i; foreach_reverse ( const(ulong) i; 0..256) data[i] = i; foreach_reverse ( ulong i; 0..256) static assert(!__traits(compiles, (data[i] = i))); foreach_reverse (immutable i, x; data) data[i] = i; foreach_reverse ( const i, x; data) data[i] = i; foreach_reverse ( i, x; data) static assert(!__traits(compiles, (data[i] = i))); //foreach_reverse (immutable int i, x; data) data[i] = i; //foreach_reverse ( const int i, x; data) data[i] = i; //foreach_reverse ( int i, x; data) static assert(!__traits(compiles, (data[i] = i))); //foreach_reverse (immutable(int) i, x; data) data[i] = i; //foreach_reverse ( const(int) i, x; data) data[i] = i; //foreach_reverse ( int i, x; data) static assert(!__traits(compiles, (data[i] = i))); foreach_reverse (immutable(ulong) i, x; data) data[i] = i; foreach_reverse ( const(ulong) i, x; data) data[i] = i; foreach_reverse ( ulong i, x; data) static assert(!__traits(compiles, (data[i] = i))); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10520.d0000644000175000017500000000037013200164642023424 0ustar matthiasmatthias// REQUIRED_ARGS: -debug -profile // Issue 10520 [profile+nothrow] Building with profiler results in "is not nothrow" error on some contracts void f() { } void g()() in { f(); } // OK <- Error: 'main.f' is not nothrow body { } alias gi = g!(); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test602.d0000644000175000017500000001406313200164642023270 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: // Disallow skipping variable decl static assert(!__traits(compiles, (bool b) { if (b) goto label; int x; label: {} assert(!x); })); // Disallow skipping variable in block backwards static assert(!__traits(compiles, (bool b) { { int x; label: {} assert(!x); } if (b) goto label; })); // Disallow skipping backwards int block static assert(!__traits(compiles, (bool b) { { int x; label: {} assert(!x); } if (b) goto label; })); // Variable inside try block static assert(!__traits(compiles, (bool b) { if (b) goto label; try { int x; label: {} assert(!x); } catch { } })); // Variable inside catch block static assert(!__traits(compiles, (bool b) { if (b) goto label; try { } catch { int x; label: {} assert(!x); } })); // Goto into catch block with unnamed exception static assert(__traits(compiles, (bool b) { if (b) goto label; try { } catch(Exception) { label: {} } })); // Goto into catch block with named exception static assert(!__traits(compiles, (bool b) { if (b) goto label; try { } catch(Exception e) { label: {} assert(e); } })); // Goto into finally block static assert(!__traits(compiles, (bool b) { if (b) goto label; try { } finally { label: {} } })); // Goto into variable with block static assert(!__traits(compiles, (bool b) { if (b) goto label; struct S { int x; } with (S()) { label: {} assert(!x); } })); // Goto backwards into variable with block static assert(!__traits(compiles, (bool b) { struct S { int x; } with (S()) { label: {} assert(!x); } if (b) goto label; })); // Goto into symbolic with block static assert(__traits(compiles, (bool b) { if (b) goto label; struct S { int x; } with (S) { label: {} } })); // Goto backwards into symbolic with block static assert(__traits(compiles, (bool b) { struct S { int x; } with (S) { label: {} } if (b) goto label; })); // Goto into for loop static assert(!__traits(compiles, (bool b) { if (b) goto label; for (int i = 0; i < 8; ++i) { label: {} assert(i); } })); // Goto into for loop backwards static assert(!__traits(compiles, (bool b) { for (int i = 0; i < 8; ++i) { label: {} assert(i); } if (b) goto label; })); // Goto into foreach loop static assert(!__traits(compiles, (bool b) { if (b) goto label; foreach(i; 0..8) { label: {} assert(i); } })); // Goto into foreach loop backwards static assert(!__traits(compiles, (bool b) { foreach(i; 0..8) { label: {} assert(i); } if (b) goto label; })); // Goto into if block with variable static assert(!__traits(compiles, (bool b) { if (b) goto label; if (auto x = b) { label: {} assert(x); } })); // Goto backwards into if block with variable static assert(!__traits(compiles, (bool b) { if (auto x = b) { label: {} assert(x); } if (b) goto label; })); // Goto into if block without variable static assert(__traits(compiles, (bool b) { if (b) goto label; if (b) { label: {} } })); // Goto into else block static assert(__traits(compiles, (bool b) { if (b) goto label; if (auto x = b) { } else { label: {} } })); // Goto backwards into else with variable static assert(!__traits(compiles, (bool b) { if (auto x = b) { } else { int y; label: {} } if (b) goto label; })); // Goto into while block static assert(__traits(compiles, (bool b) { if (b) goto label; while (b) { label: {} } })); // Goto into while block with internal variable static assert(!__traits(compiles, (bool b) { if (b) goto label; while (b) { int x; label: {} assert(!x); } })); // Goto into do block static assert(__traits(compiles, (bool b) { if (b) goto label; do { label: {} } while (b); })); // Goto over switch variable static assert(!__traits(compiles, (bool b) { if (b) goto label; switch(0) { default: break; int x; label: {} } })); // Goto over switch variable static assert(!__traits(compiles, (bool b) { if (b) goto label; switch(0) { default: break; case 0: int x; label: {} } })); // Goto into synchronized statement static assert(!__traits(compiles, (bool b) { if (b) goto label; synchronized { label: {} } })); // Goto into scope(success) with variable static assert(!__traits(compiles, (bool b) { scope(success) { int x; label: {} assert(!x); } if (b) goto label; })); // Goto into scope(failure) static assert(!__traits(compiles, (bool b) { if (b) goto label; scope(failure) { label: {} } })); // Goto into scope(failure) with variable static assert(!__traits(compiles, (bool b) { scope(failure) { int x; label: {} assert(!x); } if (b) goto label; })); // Goto into scope(exit) static assert(!__traits(compiles, (bool b) { if (b) goto label; scope(exit) { label: {} } })); // Goto into scope(exit) static assert(!__traits(compiles, (bool b) { scope(exit) { label: {} } if (b) goto label; })); // Goto into scope(exit) with variable static assert(!__traits(compiles, (bool b) { scope(exit) { int x; label: {} assert(!x); } if (b) goto label; })); /***************************************************/ // 11659 int test11659() { goto LABEL; enum expr = "0"; LABEL: return mixin(expr); } /***************************************************/ // 13321 void test13321(bool b) { static struct Foo { this(int) {} } Foo x; if (b) goto EXIT; x = Foo(1); EXIT: } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test61.d0000644000175000017500000000026713200164642023210 0ustar matthiasmatthias// PERMUTE_ARGS: import imports.test61a; alias imports.test61a.bar bar; mixin(` enum FooB { fooB }; void bar(FooB x) {} `); void test() { bar(FooA.fooA); bar(FooB.fooB); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8509.d0000644000175000017500000000036513200164642023366 0ustar matthiasmatthiasmodule test8509; enum E : string { a = "hello", b = "world" } struct S { E opCat(S s) { return E.a; } E opCat(string s) { return E.a; } } void main() { E e3 = S() ~ S(); E e4 = S() ~ "a"; assert(e3 == E.a); assert(e4 == E.a); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9613.d0000644000175000017500000000165713200164642023370 0ustar matthiasmatthias// PREMUTE_ARGS: struct S9613 { int f( const(byte) a = const(byte).init, immutable(byte) b = immutable(byte).init, shared(byte) c = shared(byte).init, inout(byte) d = inout(byte).init, ) inout { assert(a == byte.init); assert(b == byte.init); assert(c == byte.init); assert(d == byte.init); static assert(const(byte).init == byte.init); static assert(immutable(byte).init == byte.init); static assert(shared(byte).init == byte.init); static assert(inout(byte).init == byte.init); return 0; } } void main() { static assert(const(byte).init == byte.init); static assert(immutable(byte).init == byte.init); static assert(shared(byte).init == byte.init); static assert(const(byte).init.sizeof == byte.sizeof); static assert(const(byte[2]).init[0] == byte.init); enum s = S9613(); enum v = s.f(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/udamodule2.d0000644000175000017500000000025613200164642024121 0ustar matthiasmatthiasimport imports.udamodule2; import imports.udamodule2a; enum Attrib = __traits(getAttributes, imports.udamodule2); static assert(Attrib[0] == UDA(1) && Attrib[1] == UDA(2)); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test63.d0000644000175000017500000000015413200164642023205 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test63a.d // PERMUTE_ARGS: private import imports.test63a; const int SIZE = 7; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test6056c.d0000644000175000017500000000013513200164642023517 0ustar matthiasmatthiasalias int T; static assert( is( T** : const(T**) )); static assert( is( T* : const(T* ) )); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9399.d0000644000175000017500000000027313200164642023374 0ustar matthiasmatthias// REQUIRED_ARGS: -c -inline -Icompilable/imports compilable/imports/test9399a import imports.test9399a; void fun(int a) { void nested() { a = 42; } call!nested(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test11371.d0000644000175000017500000000021713200164642023431 0ustar matthiasmatthias version(D_SIMD) { __vector(long[2]) f() { __vector(long[2]) q; return q; } enum __vector(long[2]) v = f(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc2273.d0000644000175000017500000000114113200164642023301 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 2273 // REQUIRED_ARGS: -m32 module ddoc2273; interface A { } interface C { } interface D { } /// interface B : C, D { } /// class Foo : A, B { } /// MinType!(T1, T2, T) min(T1, T2, T...)(T1 a, T2 b, T xs) { } /// Templ!([1, 2, 3]) max(T...)() { } /// template Base64Impl(char Map62th, char Map63th, char Padding) { } /// int sqlite3_config(int,...); template staticIndexOf(T, TList...) { alias int staticIndexOf; } /// alias staticIndexOf IndexOf; void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9554.d0000644000175000017500000000133013200164642023360 0ustar matthiasmatthias// REQUIRED_ARGS: -o- module pkg.test9554; alias mod = pkg.test9554; template Test(alias name) { enum Test = name; } void fun() {} static assert(fun.stringof == Test!(fun.stringof)); static assert(fun.stringof == "fun()"); static assert(fun.mangleof == Test!(fun.mangleof)); static assert(fun.mangleof == "_D3pkg8test95543funFZv"); static assert(mod.stringof == Test!(mod.stringof)); static assert(mod.stringof == "module test9554"); static assert(mod.mangleof == Test!(mod.mangleof)); static assert(mod.mangleof == "3pkg8test9554"); static assert(pkg.stringof == Test!(pkg.stringof)); static assert(pkg.stringof == "package pkg"); static assert(pkg.mangleof == Test!(pkg.mangleof)); static assert(pkg.mangleof == "3pkg"); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice13968.d0000644000175000017500000000021313200164642023224 0ustar matthiasmatthias// REQUIRED_ARGS: // PERMUTE_ARGS: union U { bool a; long b; } U test1() { return U(); } U* test2() { return new U(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc10367.d0000644000175000017500000000062113200164642023366 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 10367 // REQUIRED_ARGS: -m32 // EXTRA_SOURCES: extra-files/ddoc10367.ddoc module ddoc10367; /// A enum A { a = 1, /// a b = 2 /// b } /// B enum B : long { a = 1, /// a b = 2 /// b } /// C enum C : string { a = "a", /// a b = "b" /// b } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc8271.d0000644000175000017500000000040313200164642023305 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 8271 module ddoc8271; /** $(ã¾ãã‚) Macros: ã¾ãã‚ = $(マクロ) マクロ = Macro */ void ddoc8271() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test11559upgradeoptlink.d0000644000175000017500000000035213200164642026412 0ustar matthiasmatthias// REQUIRED_ARGS: -g // If this is failing, you need optlink 8.00.14 or higher string gen() { string m; foreach(i; 0..4096) m ~= "mixin(\"assert(0);\n\n\n\n\");\n"; return m; } void main() { mixin(gen()); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test6056b.d0000644000175000017500000000016213200164642023516 0ustar matthiasmatthiastemplate X(T) { alias T X; } alias const(X!char*) A; alias const(X!int*) B; static assert(is(B == const(int*))); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/diag11066.d0000644000175000017500000000022613200164642023357 0ustar matthiasmatthias// REQUIRED_ARGS: -w -profile /* TEST_OUTPUT: --- --- */ void main() { string s; foreach (dchar c; s) // affected by dchar return; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice13323.d0000644000175000017500000000013713200164642023212 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: struct UDA {} struct S { @UDA: import object; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test71.d0000644000175000017500000000010113200164642023174 0ustar matthiasmatthiasimport imports.test71; void bar() { imports.test71.foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_266.d0000644000175000017500000000026413200164642024560 0ustar matthiasmatthiastemplate Tuple(Stuff ...) { alias Stuff Tuple; } struct S { int i; alias Tuple!i t; void a() { auto x = t; } void b() { auto x = t; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9789.d0000644000175000017500000000031013200164642023321 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -w -o- -c -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9789 module ddoc9789; /// struct S {} /// alias A = S; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc11479.d0000644000175000017500000000155313200164642023400 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 11479 module ddoc11479; /// struct S1(T) { /// int a; /// private: int x; private: /// int y; /// public: int b; public: /// int c; } /// struct S2(T) { /// int a; /// private int x; /// int b; /// public int c; public /// int d; } /// struct S3(T) { /// int a; /// private { int x; } /// int b; /// private { int y; public { int c; } } private { int z; /// public { int d; } } private { int w; public { /// int e; } } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc13502.d0000644000175000017500000000146213200164642023364 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -w -o- /* TEST_OUTPUT: --- compilable/ddoc13502.d(14): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses. compilable/ddoc13502.d(17): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses. compilable/ddoc13502.d(21): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses. compilable/ddoc13502.d(24): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses. --- */ /// ( enum isSomeString(T) = true; /// ( enum bool isArray(T) = true; /// ( extern(C) alias int T1; /// ( extern(C) alias T2 = int; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8802.d0000644000175000017500000000053113200164642023355 0ustar matthiasmatthias// PERMUTE_ARGS: enum A : typeof(null)* { a = null } enum B : typeof(null)** { a = null } enum C : void* { a = null } enum D : void** { a = null } enum NullEn : void* { z = null } enum E : NullEn { a = null } void main() { auto a = A.a; auto b = B.a; auto c = C.a; auto d = D.a; auto e = E.a; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test7252.d0000644000175000017500000000020113200164642023345 0ustar matthiasmatthiasalias char* function() Func; alias const char* function() CFunc; void to(S)(S) { } void foo(CFunc cFunc) { to(cFunc()); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/deprecate2.d0000644000175000017500000000110213200164642024065 0ustar matthiasmatthias// REQUIRED_ARGS: -d // PERMUTE_ARGS: -dw // Test cases using deprecated features /************************************************** Segfault. From compile1.d http://www.digitalmars.com/d/archives/6376.html **************************************************/ alias float[2] vector2; alias vector2 point2; // if I change this typedef to alias it works fine float distance(point2 a, point2 b) { point2 d; d[0] = b[0] - a[0]; // if I comment out this line it won't crash return 0.0f; } class A3836 { void fun() {} } class B3836 : A3836 { void fun() {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testheaderudamodule.d0000644000175000017500000000040313200164642026102 0ustar matthiasmatthias// REQUIRED_ARGS: -o- -H -Hf${RESULTS_DIR}/compilable/testheaderudamodule.di // PERMUTE_ARGS: // POST_SCRIPT: compilable/extra-files/header-postscript.sh testheaderudamodule @(1, UDA(2)) module testheaderudamodule; struct UDA { int a; } void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test6552.d0000644000175000017500000000050113200164642023352 0ustar matthiasmatthias// REQUIRED_ARGS: -w void main() { int i; switch (i) { case 1, 2: case 3, 4: break; default: break; } char ch; switch (ch) { case 'U', 'u': case 'L', 'l': default: } switch (i) { default: case 1: case 3,4: } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test59.d0000644000175000017500000000012013200164642023203 0ustar matthiasmatthias// PERMUTE_ARGS: public import imports.test59a; public import imports.test59b; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/b6395.d0000644000175000017500000000046113200164642022626 0ustar matthiasmatthias// REQUIRED_ARGS: -c -Icompilable/extra-files // 6395 import c6395; int regex(string pattern) { return 0; } bool match(string r) { return true; } void applyNoRemoveRegex() { void scan(string[] noRemoveStr, string e) { auto a = find!((a){return match(e);})(map!regex(noRemoveStr)); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/cppmangle.d0000644000175000017500000001455513200164642024035 0ustar matthiasmatthias // Test C++ name mangling. // See Bugs 4059, 5148, 7024, 10058 version(linux): import core.stdc.stdio; extern (C++) int foob(int i, int j, int k); class C { extern (C++) int bar(int i, int j, int k) { printf("this = %p\n", this); printf("i = %d\n", i); printf("j = %d\n", j); printf("k = %d\n", k); return 1; } } extern (C++) int foo(int i, int j, int k) { printf("i = %d\n", i); printf("j = %d\n", j); printf("k = %d\n", k); assert(i == 1); assert(j == 2); assert(k == 3); return 1; } void test1() { foo(1, 2, 3); auto i = foob(1, 2, 3); assert(i == 7); C c = new C(); c.bar(4, 5, 6); } static assert(foo.mangleof == "_Z3fooiii"); static assert(foob.mangleof == "_Z4foobiii"); static assert(C.bar.mangleof == "_ZN1C3barEiii"); /****************************************/ extern (C++) interface D { int bar(int i, int j, int k); } extern (C++) D getD(); void test2() { D d = getD(); int i = d.bar(9,10,11); assert(i == 8); } static assert (getD.mangleof == "_Z4getDv"); static assert (D.bar.mangleof == "_ZN1D3barEiii"); /****************************************/ extern (C++) int callE(E); extern (C++) interface E { int bar(int i, int j, int k); } class F : E { extern (C++) int bar(int i, int j, int k) { printf("F.bar: i = %d\n", i); printf("F.bar: j = %d\n", j); printf("F.bar: k = %d\n", k); assert(i == 11); assert(j == 12); assert(k == 13); return 8; } } void test3() { F f = new F(); int i = callE(f); assert(i == 8); } static assert (callE.mangleof == "_Z5callEP1E"); static assert (E.bar.mangleof == "_ZN1E3barEiii"); static assert (F.bar.mangleof == "_ZN1F3barEiii"); /****************************************/ extern (C++) void foo4(char* p); void test4() { foo4(null); } static assert(foo4.mangleof == "_Z4foo4Pc"); /****************************************/ extern(C++) { struct foo5 { int i; int j; void* p; } interface bar5{ foo5 getFoo(int i); } bar5 newBar(); } void test5() { bar5 b = newBar(); foo5 f = b.getFoo(4); printf("f.p = %p, b = %p\n", f.p, cast(void*)b); assert(f.p == cast(void*)b); } static assert(bar5.getFoo.mangleof == "_ZN4bar56getFooEi"); static assert (newBar.mangleof == "_Z6newBarv"); /****************************************/ extern(C++) { struct S6 { int i; double d; } S6 foo6(); } extern (C) int foosize6(); void test6() { S6 f = foo6(); printf("%d %d\n", foosize6(), S6.sizeof); assert(foosize6() == S6.sizeof); assert(f.i == 42); printf("f.d = %g\n", f.d); assert(f.d == 2.5); } static assert (foo6.mangleof == "_Z4foo6v"); /****************************************/ extern (C) int foo7(); struct S { int i; long l; } void test7() { printf("%d %d\n", foo7(), S.sizeof); assert(foo7() == S.sizeof); } /****************************************/ extern (C++) void foo8(const char *); void test8() { char c; foo8(&c); } static assert(foo8.mangleof == "_Z4foo8PKc"); /****************************************/ // 4059 struct elem9 { } extern(C++) void foobar9(elem9*, elem9*); void test9() { elem9 *a; foobar9(a, a); } static assert(foobar9.mangleof == "_Z7foobar9P5elem9S0_"); /****************************************/ // 5148 extern (C++) { void foo10(const char*, const char*); void foo10(const int, const int); void foo10(const char, const char); struct MyStructType { } void foo10(const MyStructType s, const MyStructType t); enum MyEnumType { onemember } void foo10(const MyEnumType s, const MyEnumType t); } void test10() { char* p; foo10(p, p); foo10(1,2); foo10('c','d'); MyStructType s; foo10(s,s); MyEnumType e; foo10(e,e); } /**************************************/ // 10058 extern (C++) { void test10058a(void*) { } void test10058b(void function(void*)) { } void test10058c(void* function(void*)) { } void test10058d(void function(void*), void*) { } void test10058e(void* function(void*), void*) { } void test10058f(void* function(void*), void* function(void*)) { } void test10058g(void function(void*), void*, void*) { } void test10058h(void* function(void*), void*, void*) { } void test10058i(void* function(void*), void* function(void*), void*) { } void test10058j(void* function(void*), void* function(void*), void* function(void*)) { } void test10058k(void* function(void*), void* function(const (void)*)) { } void test10058l(void* function(void*), void* function(const (void)*), const(void)* function(void*)) { } } static assert(test10058a.mangleof == "_Z10test10058aPv"); static assert(test10058b.mangleof == "_Z10test10058bPFvPvE"); static assert(test10058c.mangleof == "_Z10test10058cPFPvS_E"); static assert(test10058d.mangleof == "_Z10test10058dPFvPvES_"); static assert(test10058e.mangleof == "_Z10test10058ePFPvS_ES_"); static assert(test10058f.mangleof == "_Z10test10058fPFPvS_ES1_"); static assert(test10058g.mangleof == "_Z10test10058gPFvPvES_S_"); static assert(test10058h.mangleof == "_Z10test10058hPFPvS_ES_S_"); static assert(test10058i.mangleof == "_Z10test10058iPFPvS_ES1_S_"); static assert(test10058j.mangleof == "_Z10test10058jPFPvS_ES1_S1_"); static assert(test10058k.mangleof == "_Z10test10058kPFPvS_EPFS_PKvE"); static assert(test10058l.mangleof == "_Z10test10058lPFPvS_EPFS_PKvEPFS3_S_E"); /**************************************/ // 11696 class Expression; struct Loc {} extern(C++) class CallExp { static void test11696a(Loc, Expression, Expression); static void test11696b(Loc, Expression, Expression*); static void test11696c(Loc, Expression*, Expression); static void test11696d(Loc, Expression*, Expression*); } static assert(CallExp.test11696a.mangleof == "_ZN7CallExp10test11696aE3LocP10ExpressionS2_"); static assert(CallExp.test11696b.mangleof == "_ZN7CallExp10test11696bE3LocP10ExpressionPS2_"); static assert(CallExp.test11696c.mangleof == "_ZN7CallExp10test11696cE3LocPP10ExpressionS2_"); static assert(CallExp.test11696d.mangleof == "_ZN7CallExp10test11696dE3LocPP10ExpressionS3_"); /**************************************/ // 13337 extern(C++, N13337a.N13337b.N13337c) { struct S13337{} void foo13337(S13337 s); } static assert(foo13337.mangleof == "_ZN7N13337a7N13337b7N13337c8foo13337ENS1_6S13337E"); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test6461.sh0000755000175000017500000000104013200164642023542 0ustar matthiasmatthias#!/usr/bin/env bash name=`basename $0 .sh` dir=${RESULTS_DIR}/compilable src=compilable/extra-files/${name} if [ "${OS}" == "win32" -o "${OS}" == "win64" ]; then LIBEXT=.lib else LIBEXT=.a fi $DMD -lib -m${MODEL} -of${dir}/a${LIBEXT} -I${src} ${src}/a.d || exit 1 $DMD -lib -m${MODEL} -of${dir}/b${LIBEXT} -I${src} ${src}/b.d || exit 1 $DMD -m${MODEL} -od${dir} -I${src} ${src}/main.d ${dir}/a${LIBEXT} ${dir}/b${LIBEXT} || exit 1 rm -f ${dir}/{a${LIBEXT} b${LIBEXT} main${EXE} main${OBJ}} echo Success >${dir}/`basename $0`.out ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc8.d0000644000175000017500000000025213200164642023055 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 8 /** foo */ class Foo(T) : Bar { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/testexpression.d0000644000175000017500000000611113200164642025153 0ustar matthiasmatthias template TT(T...) { alias T TT; } void TestOpAssign(Tx, Ux, ops)() { foreach(T; Tx.x) foreach(U; Ux.x) foreach(op; ops.x) { T a = cast(T)1; mixin("a " ~ op ~ " cast(U)1;"); } } void TestOpAssignAssign(Tx, Ux, ops)() { foreach(T; Tx.x) foreach(U; Ux.x) foreach(op; ops.x) { T a = cast(T)1; U b = cast(U)1; T r; mixin("r = a " ~ op ~ " cast(U)1;"); } } void TestOpAssignAuto(Tx, Ux, ops)() { foreach(T; Tx.x) foreach(U; Ux.x) static if (U.sizeof <= T.sizeof) foreach(op; ops.x) { T a = cast(T)1; U b = cast(U)1; mixin("auto r = a " ~ op ~ " cast(U)1;"); } } void TestOpAndAssign(Tx, Ux, ops)() { foreach(T; Tx.x) foreach(U; Ux.x) static if (U.sizeof <= T.sizeof && T.sizeof >= 4) foreach(op; ops.x) { T a = cast(T)1; U b = cast(U)1; mixin("a = a " ~ op[0..$-1] ~ " cast(U)1;"); } } struct boolean { alias TT!(bool) x; } struct integral { alias TT!(byte, ubyte, short, ushort, int, uint, long, ulong) x; } struct floating { alias TT!(float, double, real) x; } struct imaginary { alias TT!(ifloat, idouble, ireal) x; } struct complex { alias TT!(cfloat, cdouble, creal) x; } struct all { alias TT!("+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>=", ">>>=") x; } struct arith { alias TT!("+=", "-=", "*=", "/=", "%=") x; } struct bitwise { alias TT!("&=", "|=", "^=") x; } struct shift { alias TT!("<<=", ">>=", ">>>=") x; } struct addsub { alias TT!("+=", "-=") x; } struct muldivmod { alias TT!("*=", "/=", "%=") x; } struct nomod { alias TT!("+=", "-=", "*=", "/=") x; } void OpAssignCases(alias X)() { X!(boolean, boolean, bitwise)(); X!(integral, boolean, all)(); X!(integral, integral, all)(); X!(integral, floating, arith)(); X!(floating, boolean, arith)(); X!(floating, integral, arith)(); X!(floating, floating, arith)(); X!(imaginary, boolean, muldivmod)(); X!(imaginary, integral, muldivmod)(); X!(imaginary, floating, muldivmod)(); X!(imaginary, imaginary, addsub)(); X!(complex, boolean, arith)(); X!(complex, integral, arith)(); X!(complex, floating, arith)(); X!(complex, imaginary, arith)(); X!(complex, complex, nomod)(); } void OpReAssignCases(alias X)() { X!(boolean, boolean, bitwise)(); X!(integral, boolean, all)(); X!(integral, integral, all)(); X!(floating, boolean, arith)(); X!(floating, integral, arith)(); X!(floating, floating, arith)(); X!(imaginary, boolean, muldivmod)(); X!(imaginary, integral, muldivmod)(); X!(imaginary, floating, muldivmod)(); X!(imaginary, imaginary, addsub)(); X!(complex, boolean, arith)(); X!(complex, integral, arith)(); X!(complex, floating, arith)(); X!(complex, imaginary, arith)(); X!(complex, complex, nomod)(); } void main() { OpAssignCases!TestOpAssign(); //OpAssignCases!TestOpAssignAssign(); // disabled due to bug 7436 //OpAssignCases!TestOpAssignAuto(); // 5181 OpReAssignCases!TestOpAndAssign(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ldc_github_419.d0000644000175000017500000000015013200164642024552 0ustar matthiasmatthiasimport core.simd; static ubyte16 v = ['a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a']; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9676b.d0000644000175000017500000000027313200164642023466 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9676b module ddoc9676b; /// deprecated void foo() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test9818.d0000644000175000017500000000323313200164642023367 0ustar matthiasmatthias/************************************/ // 9818 /* TEST_OUTPUT: --- sa1: [1, 1, 1] ea1: [1, 1, 1] sa2: [1, 1, 1] ea2: [1, 1, 1] eas: [1, 1, 1] eac: [1, 1, 1] sa3: [1, 1, 1] ea3: [1, 1, 1] sa4: [1, 1, 1] ea4: [1, 1, 1] --- */ static const int[3] sa1 = 1; pragma(msg, "sa1: ", sa1); // doesn't work static assert(sa1 == [1, 1, 1]); // doesn't work enum int[3] ea1 = 1; pragma(msg, "ea1: ", ea1); // prints "1" - bad static assert(ea1 == [1, 1, 1]); // doesn't work struct X { static const int[3] sa2 = 1; pragma(msg, "sa2: ", sa1); // doesn't work static assert(sa2 == [1, 1, 1]); // doesn't work enum int[3] ea2 = 1; pragma(msg, "ea2: ", ea2); // prints "1" - bad static assert(ea2 == [1, 1, 1]); // doesn't work } struct S { enum int[3] eas = 1; } pragma(msg, "eas: ", S.eas); static assert(S.eas == [1, 1, 1]); class C { enum int[3] eac = 1; } pragma(msg, "eac: ", C.eac); static assert(C.eac == [1, 1, 1]); void test() { static const int[3] sa3 = 1; pragma(msg, "sa3: ", sa3); // doesn't work static assert(sa3 == [1, 1, 1]); // doesn't work enum int[3] ea3 = 1; pragma(msg, "ea3: ", ea3); // prints "1" - bad static assert(ea3 == [1, 1, 1]); // doesn't work struct Y { static const int[3] sa4 = 1; pragma(msg, "sa4: ", sa4); // doesn't work static assert(sa4 == [1, 1, 1]); // doesn't work enum int[3] ea4 = 1; pragma(msg, "ea4: ", ea4); // prints "1" - bad static assert(ea4 == [1, 1, 1]); // doesn't work } } /************************************/ void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test14375.d0000644000175000017500000000050613200164642023441 0ustar matthiasmatthias/* TEST_OUTPUT: --- --- */ interface IKeysAPI(string greetings) { static assert(greetings == "Hello world", greetings); } void main() { foreach (method; __traits(allMembers, IKeysAPI!("Hello world"))) { static assert (method.length, "Empty string from the compiler ??"); pragma(msg, method); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice11777.d0000644000175000017500000000061313200164642023224 0ustar matthiasmatthiasvoid f(void delegate(int)) {} class C { int i; this() { f((a){}); /* (a){} is a template lambda, so FuncExp::semantic -> TemplateDeclaration::semantic * will save the scope in TemplateDeclaration::scope with fieldinit. Later push/pop * of the scope for template lambda body semantics will violate the assertion in Scope::pop(). */ } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice854.d0000644000175000017500000000274213200164642023063 0ustar matthiasmatthias// Issue 854 - TypeTuple in anonymous delegate causes ice in glue.c /* 854 VOTE PATCH (=2863, =2251?) Assertion failure: '0' on line 935 in file 'glue.c' I haven't checked this patch myself. --- dmd/func.c 2009-03-05 01:56:46.000000000 +0100 +++ dmd-fixed/func.c 2009-03-30 00:39:41.000000000 +0200 @@ -756,6 +756,27 @@ } } + if (f->parameters) + { + for (size_t i = 0; i < Argument::dim(f->parameters); i++) + { + Argument *arg = (Argument *)Argument::getNth(f->parameters, i); + Type* nw = arg->type->semantic(0, sc); + if (arg->type != nw) { + arg->type = nw; + // Examine this index again. + // This is important if it turned into a tuple. + // In particular, the empty tuple should be handled or the + // next parameter will be skipped. + // FIXME: Maybe we only need to do this for tuples, + // and can add tuple.length after decrement? + i--; + } + } + // update nparams to include expanded tuples + nparams = Argument::dim(f->parameters); + } + // Propagate storage class from tuple parameters to their element-parameters. if (f->parameters) { */ template Foo(T...) { alias T Foo; } void main() { auto y = (Foo!(int) x){ return 0; }; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8898.d0000644000175000017500000000012513200164642023373 0ustar matthiasmatthias// REQUIRED_ARGS: -w // PERMUTE_ARGS: static if (true): version (Foo) { } else { } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test12593.d0000644000175000017500000000037013200164642023440 0ustar matthiasmatthiasint[R] aa; // Place before the declaration of key struct struct R { int opCmp(ref const R) const { return 0; } //bool opEquals(ref const R) const { return true; } //size_t toHash() const nothrow @safe { return 0; } } void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8922d.d0000644000175000017500000000045713200164642023533 0ustar matthiasmatthias// PERMUTE_ARGS: void test() { static import imports.bug8922; static assert(!__traits(compiles, __traits(parent, imports))); static assert(!__traits(compiles, __traits(parent, bug8922))); enum x = __traits(parent, imports.bug8922).stringof; static assert(x == "package imports"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc1.d0000644000175000017500000000235013200164642023047 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 1 // REQUIRED_ARGS: -d /** This module is for ABC * Copyright: Copyright © */ module abc; string foos = "foo"; alias int myint; /// alias int mytypedefint; /** windy * city * * paragraph 2 about of F $$(NAME) * ----- * #include * void main() * { * printf("hello\n"); * } * ----- * Copyright: 1998 */ myint f; enum E { e } /// comment1 int g; /// comment2 private int h; /// comment for H static int i; int j; wchar LS = 0x2028; /// UTF line separator wchar PS = 0x2029; /// UTF paragraph separator wchar _XX; /// ditto wchar YY; /// ditto /** Function foo takes argument c and adds it to argulid. * * Then it munges argulid, u underline. * Params: * c = the character which adds c to argulid * argulid = the argument * u = the other argument */ int foo(char c, int argulid, char u); int barr() { return 3; } /// doc for barr() /++ The Class Bar +/ class Bar { int x; /// member X int y; /// member Y protected int z; /// member Z } /++ The Enum Easy +/ enum Easy : int { red, /// the Red blue, /// the Blue green, /// the Green } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test13902.d0000644000175000017500000000014013200164642023426 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: void foo() { int a; int* bar() { return &a; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test8937.d0000644000175000017500000000254713200164642023377 0ustar matthiasmatthias mixin template X8937() { int value; } debug = test; void main() { // (static) import statement { static assert(!__traits(compiles, cos(0))); if (true) { static assert(!__traits(compiles, cos(0))); import core.stdc.math; static assert( __traits(compiles, cos(0))); } static assert(!__traits(compiles, cos(0))); if (true) import core.stdc.math; static assert(!__traits(compiles, cos(0))); // fails if (true) static import core.stdc.math; static assert(!__traits(compiles, core.stdc.math.cos(0))); // fails } static assert(!__traits(compiles, cos(0))); // mixin statement { if (true) mixin X8937!(); static assert(!__traits(compiles, value)); // fails } // enum declaration { if (true) enum E { x = 10 } static assert(!__traits(compiles, E)); // fails } // conditional declarations { if (true) static if (true) struct S1 {} static assert(!__traits(compiles, S1)); // fails if (true) version (all) struct S2 {} static assert(!__traits(compiles, S2)); // fails if (true) debug (test) struct S3 {} static assert(!__traits(compiles, S3)); // fails } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/udamodule1.d0000644000175000017500000000034113200164642024113 0ustar matthiasmatthias// REQUIRED_ARGS: // PERMUTE_ARGS: /* TEST_OUTPUT: --- compilable/udamodule1.d(9): Deprecation: module imports.udamodule1 is deprecated - This module will be removed. --- */ import imports.udamodule1; void main() { foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test13668.d0000644000175000017500000000136413200164642023450 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: /* TEST_OUTPUT: --- tuple("id", "toString", "toHash", "opCmp", "opEquals", "Monitor", "factory") genProps --- */ class User : Entity!User { int id; } class Entity(T) { pragma(msg, generateProperties!T); /* Compiler runs pragma(msg) in semantic() phase, but it does not insert any members * in this class. Therefore getting __traits(allMembers, User) while evaluating * generateProperties!User should work. */ } template generateProperties(alias To) { string getProperties(alias Ta)() { string toRet = "genProps"; // This line is bad pragma(msg, __traits(allMembers, Ta)); return toRet; } enum generateProperties = getProperties!(To); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ice12554.d0000644000175000017500000000153013200164642023215 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMUTE_ARGS: void main() pure { int[] foo; // if indirectly instantiated aggregate is struct (== MapResultS) foo.map!(MapResultS, x => foo.map!(MapResultS, y => x).array); // if indirectly instantiated aggregate is class (== MapResultC) foo.map!(MapResultC, x => foo.map!(MapResultC, y => x).array); } T array(T)(T a) { static int g; g = 1; // impure operation return a; } template map(alias MapResult, fun...) { auto map(Range)(Range r) { alias AppliedReturnType(alias f) = typeof(f(r[0])); static assert(!is(AppliedReturnType!fun == void)); return MapResult!(fun).init; } } struct MapResultS(alias fun) { @property front() { return fun(1); } } class MapResultC(alias fun) { @property front() { return fun(1); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test7524.d0000644000175000017500000000003613200164642023355 0ustar matthiasmatthias// 7524 #line __LINE__ "y.d" ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc13645.d0000644000175000017500000000033313200164642023370 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 13645 /** Documentation comment on module */ deprecated("msg") @(1) module ddoc13645; ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test10726.d0000644000175000017500000000205113200164642023432 0ustar matthiasmatthias// PERMUTE_ARGS: public struct CirBuff(T) { private T[] data; private size_t head = 0; private size_t size = 0; public size_t length() const { return size; } public bool opEquals(CirBuff!T d) @trusted { if (length != d.length) return false; for (size_t i=0; i!=size; ++i) { if (this.data[(this.head+i) % this.data.length] != d.data[(d.head + i) % d.data.length]) { return false; } } return true; } } class Once { Foo!Bar _bar; } class Bar { static Once _once; mixin(sync!(Once, "_once")); } class Foo(T = int) { CirBuff!T _buff; } template sync(T, string U = "this", size_t ITER = 0) { static if (ITER == __traits(derivedMembers, T).length) enum sync = ""; else { enum string mem = __traits(derivedMembers, T)[ITER]; enum string sync = "static if(! __traits(isVirtualMethod, " ~ U ~ "." ~ mem ~ ")) { }" ~ sync!(T, U, ITER+1); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test11656.d0000644000175000017500000000021313200164642023433 0ustar matthiasmatthias version(D_SIMD) { struct Foo { __vector(float[4]) x; } static assert(Foo.x.offsetof == 0); static assert(Foo.x.stringof == "x"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc12745.d0000644000175000017500000000061513200164642023373 0ustar matthiasmatthias// EXTRA_SOURCES: // PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 12745 /** i underlined $(BR) _i not underlined $(BR) __i force underscore $(BR) $(BR) _0 not underscored $(BR) __0 force underscored 1 underscore: $(BR) 1_1 $(BR) 1_a $(BR) a_1 $(BR) a_a $(BR) $(BR) 2 underscores: $(BR) 1__a $(BR) 2__b */ int i;ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test12567c.d0000644000175000017500000000035313200164642023605 0ustar matthiasmatthias// REQUIRED_ARGS: // PERMUTE_ARGS: /* TEST_OUTPUT: --- compilable/test12567c.d(9): Deprecation: module imports.a12567 is deprecated - This module will be removed in future release. --- */ import imports.a12567; void main() { foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/vgc1.d0000644000175000017500000000375013200164642022722 0ustar matthiasmatthias// REQUIRED_ARGS: -vgc -o- // PERMUTE_ARGS: /***************** NewExp *******************/ struct S1 { } struct S2 { this(int); } struct S3 { this(int) @nogc; } struct S4 { new(size_t); } struct S5 { @nogc new(size_t); } /* TEST_OUTPUT: --- compilable/vgc1.d(27): vgc: 'new' causes GC allocation compilable/vgc1.d(29): vgc: 'new' causes GC allocation compilable/vgc1.d(30): vgc: 'new' causes GC allocation compilable/vgc1.d(32): vgc: 'new' causes GC allocation compilable/vgc1.d(33): vgc: 'new' causes GC allocation compilable/vgc1.d(34): vgc: 'new' causes GC allocation compilable/vgc1.d(38): vgc: 'new' causes GC allocation --- */ void testNew() { int* p1 = new int; int[] a1 = new int[3]; int[][] a2 = new int[][](2, 3); S1* ps1 = new S1(); S2* ps2 = new S2(1); S3* ps3 = new S3(1); S4* ps4 = new S4; // no error S5* ps5 = new S5; // no error Object o1 = new Object(); } /* TEST_OUTPUT: --- compilable/vgc1.d(55): vgc: 'new' causes GC allocation compilable/vgc1.d(57): vgc: 'new' causes GC allocation compilable/vgc1.d(58): vgc: 'new' causes GC allocation compilable/vgc1.d(60): vgc: 'new' causes GC allocation compilable/vgc1.d(61): vgc: 'new' causes GC allocation compilable/vgc1.d(62): vgc: 'new' causes GC allocation --- */ void testNewScope() { scope int* p1 = new int; scope int[] a1 = new int[3]; scope int[][] a2 = new int[][](2, 3); scope S1* ps1 = new S1(); scope S2* ps2 = new S2(1); scope S3* ps3 = new S3(1); scope S4* ps4 = new S4; // no error scope S5* ps5 = new S5; // no error scope Object o1 = new Object(); // no error scope o2 = new Object(); // no error } /***************** DeleteExp *******************/ /* TEST_OUTPUT: --- compilable/vgc1.d(82): vgc: 'delete' requires GC compilable/vgc1.d(83): vgc: 'delete' requires GC compilable/vgc1.d(84): vgc: 'delete' requires GC --- */ void testDelete(int* p, Object o, S1* s) { delete p; delete o; delete s; } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/ddoc9903.d0000644000175000017500000000074013200164642023314 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9903 /// sss struct S9903X {} /// Ditto struct S9903Y {} /// ccc class C9903X {} /// Ditto class C9903Y {} /// uuu union U9903X {} /// Ditto union U9903Y {} /// iii interface I9903X {} /// Ditto interface I9903Y {} /// eee enum E9903X { a } /// Ditto enum E9903Y { a } /// enum { a9903, /// ea b9903, /// Ditto c9903, /// ec } ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test3775.d0000644000175000017500000000016213200164642023361 0ustar matthiasmatthias// 3775 struct Bug3775 { static int byLine()() { return 1; } } static assert(cast(int)Bug3775.byLine == 1); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test7399.d0000644000175000017500000000021613200164642023367 0ustar matthiasmatthias// 7399 static assert(!__traits(compiles, { import non.existing.file; })); // 7400 static assert(!is(typeof({import non_existing_file;}))); ldc-0.17.5-src/tests/d2/dmd-testsuite/compilable/test14528.d0000644000175000017500000000024013200164642023434 0ustar matthiasmatthias// REQUIRED_ARGS: -o- // PERMTE_ARGS: import imports.a14528; class C { protected static void func() {} void test() { foo!func(); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/d_do_test.d0000755000175000017500000005434313200164642021726 0ustar matthiasmatthiasmodule d_do_test; import std.algorithm; import std.array; import std.conv; import std.exception; import std.file; import std.format; import std.process; import std.random; import std.regex; import std.stdio; import std.string; import core.sys.posix.sys.wait; void usage() { write("d_do_test \n" "\n" " input_dir: one of: compilable, fail_compilation, runnable\n" " test_name: basename of test case to run\n" " test_extension: one of: d, html, or sh\n" "\n" " example: d_do_test runnable pi d\n" "\n" " relevant environment variables:\n" " ARGS: set to execute all combinations of\n" " REQUIRED_ARGS: arguments always passed to the compiler\n" " DMD: compiler to use, ex: ../src/dmd\n" " CC: C++ compiler to use, ex: dmc, g++\n" " OS: win32, win64, linux, freebsd, osx\n" " RESULTS_DIR: base directory for test results\n" " windows vs non-windows portability env vars:\n" " DSEP: \\\\ or /\n" " SEP: \\ or /\n" " OBJ: .obj or .o\n" " EXE: .exe or \n"); } enum TestMode { COMPILE, FAIL_COMPILE, RUN } struct TestArgs { TestMode mode; bool compileSeparately; string executeArgs; string[] sources; string[] cppSources; string[] objcSources; string permuteArgs; string compileOutput; string gdbScript; string gdbMatch; string postScript; string requiredArgs; string requiredArgsForLink; // reason for disabling the test (if empty, the test is not disabled) string disabled_reason; @property bool disabled() { return disabled_reason != ""; } } struct EnvData { string all_args; string dmd; string results_dir; string sep; string dsep; string obj; string exe; string os; string compiler; string ccompiler; string model; string required_args; bool dobjc; bool noArchVariant; } bool findTestParameter(string file, string token, ref string result) { auto tokenStart = std.string.indexOf(file, token); if (tokenStart == -1) return false; auto lineEndR = std.string.indexOf(file[tokenStart .. $], "\r"); auto lineEndN = std.string.indexOf(file[tokenStart .. $], "\n"); auto lineEnd = lineEndR == -1 ? (lineEndN == -1 ? file.length : lineEndN) : (lineEndN == -1 ? lineEndR : min(lineEndR, lineEndN)); //writeln("found ", token, " in line: ", file.length, ", ", tokenStart, ", ", tokenStart+lineEnd); //writeln("found ", token, " in line: '", file[tokenStart .. tokenStart+lineEnd], "'"); result = strip(file[tokenStart+token.length .. tokenStart+lineEnd]); // skips the :, if present if (result.length > 0 && result[0] == ':') result = strip(result[1 .. $]); //writeln("arg: '", result, "'"); string result2; if (findTestParameter(file[tokenStart+lineEnd..$], token, result2)) result ~= " " ~ result2; return true; } bool findOutputParameter(string file, string token, out string result, string sep) { bool found = false; while (true) { auto istart = std.string.indexOf(file, token); if (istart == -1) break; found = true; // skips the :, if present if (file[istart] == ':') ++istart; enum embed_sep = "---"; auto n = std.string.indexOf(file[istart .. $], embed_sep); enforce(n != -1, "invalid "~token~" format"); istart += n + embed_sep.length; while (file[istart] == '-') ++istart; if (file[istart] == '\r') ++istart; if (file[istart] == '\n') ++istart; auto iend = std.string.indexOf(file[istart .. $], embed_sep); enforce(iend != -1, "invalid TEST_OUTPUT format"); iend += istart; result ~= file[istart .. iend]; while (file[iend] == '-') ++iend; file = file[iend .. $]; } if (found) { result = std.string.strip(result); result = result.unifyNewLine().unifyDirSep(sep); result = result ? result : ""; // keep non-null } return found; } void replaceResultsDir(ref string arguments, const ref EnvData envData) { // Bash would expand this automatically on Posix, but we need to manually // perform the replacement for Windows compatibility. arguments = replace(arguments, "${RESULTS_DIR}", envData.results_dir); } bool gatherTestParameters(ref TestArgs testArgs, string input_dir, string input_file, const ref EnvData envData) { string file = cast(string)std.file.read(input_file); findTestParameter(file, "REQUIRED_ARGS", testArgs.requiredArgs); if(envData.required_args.length) testArgs.requiredArgs ~= " " ~ envData.required_args; replaceResultsDir(testArgs.requiredArgs, envData); if (! findTestParameter(file, "PERMUTE_ARGS", testArgs.permuteArgs)) { if (testArgs.mode != TestMode.FAIL_COMPILE) testArgs.permuteArgs = envData.all_args; string unittestJunk; if(!findTestParameter(file, "unittest", unittestJunk)) testArgs.permuteArgs = replace(testArgs.permuteArgs, "-unittest", ""); } replaceResultsDir(testArgs.permuteArgs, envData); // win(32|64) doesn't support pic if (envData.os == "win32" || envData.os == "win64") { auto index = std.string.indexOf(testArgs.permuteArgs, "-fPIC"); if (index != -1) testArgs.permuteArgs = testArgs.permuteArgs[0 .. index] ~ testArgs.permuteArgs[index+5 .. $]; } // clean up extra spaces testArgs.permuteArgs = strip(replace(testArgs.permuteArgs, " ", " ")); findTestParameter(file, "EXECUTE_ARGS", testArgs.executeArgs); replaceResultsDir(testArgs.executeArgs, envData); string extraSourcesStr; findTestParameter(file, "EXTRA_SOURCES", extraSourcesStr); testArgs.sources = [input_file]; // prepend input_dir to each extra source file foreach(s; split(extraSourcesStr)) testArgs.sources ~= input_dir ~ "/" ~ s; string extraCppSourcesStr; findTestParameter(file, "EXTRA_CPP_SOURCES", extraCppSourcesStr); testArgs.cppSources = []; // prepend input_dir to each extra source file foreach(s; split(extraCppSourcesStr)) testArgs.cppSources ~= s; string extraObjcSourcesStr; auto objc = findTestParameter(file, "EXTRA_OBJC_SOURCES", extraObjcSourcesStr); if (objc && !envData.dobjc) return false; testArgs.objcSources = []; // prepend input_dir to each extra source file foreach(s; split(extraObjcSourcesStr)) testArgs.objcSources ~= s; // swap / with $SEP if (envData.sep && envData.sep != "/") foreach (ref s; testArgs.sources) s = replace(s, "/", to!string(envData.sep)); //writeln ("sources: ", testArgs.sources); // COMPILE_SEPARATELY can take optional compiler switches when link .o files testArgs.compileSeparately = findTestParameter(file, "COMPILE_SEPARATELY", testArgs.requiredArgsForLink); findTestParameter(file, "DISABLED", testArgs.disabled_reason); findOutputParameter(file, "TEST_OUTPUT", testArgs.compileOutput, envData.sep); findOutputParameter(file, "GDB_SCRIPT", testArgs.gdbScript, envData.sep); findTestParameter(file, "GDB_MATCH", testArgs.gdbMatch); if (findTestParameter(file, "POST_SCRIPT", testArgs.postScript)) testArgs.postScript = replace(testArgs.postScript, "/", to!string(envData.sep)); return true; } string[] combinations(string argstr) { string[] results; string[] args = split(argstr); long combinations = 1 << args.length; for (size_t i = 0; i < combinations; i++) { string r; bool printed = false; for (size_t j = 0; j < args.length; j++) { if (i & 1 << j) { if (printed) r ~= " "; r ~= args[j]; printed = true; } } results ~= r; } return results; } string genTempFilename(string result_path) { auto a = appender!string(); a.put(result_path); foreach (ref e; 0 .. 8) { formattedWrite(a, "%x", rndGen.front); rndGen.popFront(); } return a.data; } int system(string command) { if (!command) return core.stdc.stdlib.system(null); const commandz = toStringz(command); auto status = core.stdc.stdlib.system(commandz); if (status == -1) return status; version (Windows) status <<= 8; return status; } version(Windows) { extern (D) bool WIFEXITED( int status ) { return ( status & 0x7F ) == 0; } extern (D) int WEXITSTATUS( int status ) { return ( status & 0xFF00 ) >> 8; } extern (D) int WTERMSIG( int status ) { return status & 0x7F; } extern (D) bool WIFSIGNALED( int status ) { return ( cast(byte) ( ( status & 0x7F ) + 1 ) >> 1 ) > 0; } } void removeIfExists(in char[] filename) { if (std.file.exists(filename)) std.file.remove(filename); } string execute(ref File f, string command, bool expectpass, string result_path) { auto filename = genTempFilename(result_path); scope(exit) removeIfExists(filename); version (Windows) { command = command.replace("${RESULTS_DIR}", result_path); } auto rc = system(command ~ " > " ~ filename ~ " 2>&1"); string output = readText(filename); f.writeln(command); f.write(output); if (WIFSIGNALED(rc)) { auto value = WTERMSIG(rc); enforce(0 == value, "caught signal: " ~ to!string(value)); } else if (WIFEXITED(rc)) { auto value = WEXITSTATUS(rc); if (expectpass) enforce(0 == value, "expected rc == 0, exited with rc == " ~ to!string(value)); else enforce(1 == value, "expected rc == 1, but exited with rc == " ~ to!string(value)); } return output; } string unifyNewLine(string str) { return std.regex.replace(str, regex(`\r\n|\r|\n`, "g"), "\n"); } string unifyDirSep(string str, string sep) { return std.regex.replace(str, regex(`(?<=[-\w][-\w]*)/(?=[-\w][-\w/]*\.di?\b)`, "g"), sep); } unittest { assert(`fail_compilation/test.d(1) Error: dummy error message for 'test'`.unifyDirSep(`\`) == `fail_compilation\test.d(1) Error: dummy error message for 'test'`); assert(`fail_compilation/test.d(1) Error: at fail_compilation/test.d(2)`.unifyDirSep(`\`) == `fail_compilation\test.d(1) Error: at fail_compilation\test.d(2)`); assert(`fail_compilation/test.d(1) Error: at fail_compilation/imports/test.d(2)`.unifyDirSep(`\`) == `fail_compilation\test.d(1) Error: at fail_compilation\imports\test.d(2)`); assert(`fail_compilation/diag.d(2): Error: fail_compilation/imports/fail.d must be imported`.unifyDirSep(`\`) == `fail_compilation\diag.d(2): Error: fail_compilation\imports\fail.d must be imported`); } bool collectExtraSources (in string input_dir, in string output_dir, in string[] extraSources, ref string[] sources, bool msc, in EnvData envData, in string compiler) { foreach (cur; extraSources) { auto curSrc = input_dir ~ envData.sep ~"extra-files" ~ envData.sep ~ cur; auto curObj = output_dir ~ envData.sep ~ cur ~ envData.obj; string command = compiler; if (envData.compiler == "dmd") { if (msc) { command ~= ` /c /nologo `~curSrc~` /Fo`~curObj; } else if (envData.os == "win32") { command ~= " -c "~curSrc~" -o"~curObj; } else { if (!envData.noArchVariant) command ~= " -m"~envData.model; command ~= " -c "~curSrc~" -o "~curObj; } } else { if (!envData.noArchVariant) command ~= " -m"~envData.model; command ~= " -c "~curSrc~" -o "~curObj; } auto rc = system(command); if(rc) { writeln("failed to execute '"~command~"'"); return false; } sources ~= curObj; } return true; } // compare output string to reference string, but ignore places // marked by $n$ that contain compiler generated unique numbers bool compareOutput(string output, string refoutput) { for ( ; ; ) { auto pos = refoutput.indexOf("$n$"); if (pos < 0) return refoutput == output; if (output.length < pos) return false; if (refoutput[0..pos] != output[0..pos]) return false; refoutput = refoutput[pos + 3 ..$]; output = output[pos..$]; munch(output, "0123456789"); } } int main(string[] args) { if (args.length != 4) { if (args.length == 2 && args[1] == "-unittest") return 0; usage(); return 1; } string input_dir = args[1]; string test_name = args[2]; string test_extension = args[3]; EnvData envData; envData.all_args = environment.get("ARGS"); envData.results_dir = environment.get("RESULTS_DIR"); envData.sep = environment.get("SEP"); envData.dsep = environment.get("DSEP"); envData.obj = environment.get("OBJ"); envData.exe = environment.get("EXE"); envData.os = environment.get("OS"); envData.dmd = replace(environment.get("DMD"), "/", envData.sep); envData.compiler = "dmd"; //should be replaced for other compilers envData.ccompiler = environment.get("CC"); envData.model = environment.get("MODEL"); envData.required_args = environment.get("REQUIRED_ARGS"); envData.dobjc = environment.get("D_OBJC") == "1"; envData.noArchVariant = environment.get("NO_ARCH_VARIANT") == "1"; string result_path = envData.results_dir ~ envData.sep; string input_file = input_dir ~ envData.sep ~ test_name ~ "." ~ test_extension; string output_dir = result_path ~ input_dir; string output_file = result_path ~ input_dir ~ envData.sep ~ test_name ~ "." ~ test_extension ~ ".out"; string test_app_dmd_base = output_dir ~ envData.sep ~ test_name ~ "_"; TestArgs testArgs; switch (input_dir) { case "compilable": testArgs.mode = TestMode.COMPILE; break; case "fail_compilation": testArgs.mode = TestMode.FAIL_COMPILE; break; case "runnable": testArgs.mode = TestMode.RUN; break; default: writeln("input_dir must be one of 'compilable', 'fail_compilation', or 'runnable'"); return 1; } if (envData.ccompiler.empty) { switch (envData.os) { case "win32": envData.ccompiler = "dmc"; break; case "win64": envData.ccompiler = `\"Program Files (x86)"\"Microsoft Visual Studio 10.0"\VC\bin\amd64\cl.exe`; break; default: envData.ccompiler = "g++"; break; } } bool msc = envData.ccompiler.toLower.endsWith("cl.exe"); if (!gatherTestParameters(testArgs, input_dir, input_file, envData)) return 0; //prepare cpp extra sources if (testArgs.cppSources.length) { switch (envData.compiler) { case "dmd": if(envData.os != "win32" && envData.os != "win64") testArgs.requiredArgs ~= " -L-lstdc++"; break; case "ldc": testArgs.requiredArgs ~= " -L-lstdc++"; break; case "gdc": testArgs.requiredArgs ~= "-Xlinker -lstdc++"; break; default: writeln("unknown compiler: "~envData.compiler); return 1; } if (!collectExtraSources(input_dir, output_dir, testArgs.cppSources, testArgs.sources, msc, envData, envData.ccompiler)) return 1; } //prepare objc extra sources if (!collectExtraSources(input_dir, output_dir, testArgs.objcSources, testArgs.sources, msc, envData, "clang")) return 1; writef(" ... %-30s %s%s(%s)", input_file, testArgs.requiredArgs, (!testArgs.requiredArgs.empty ? " " : ""), testArgs.permuteArgs); if (testArgs.disabled) writefln("!!! [DISABLED: %s]", testArgs.disabled_reason); else write("\n"); removeIfExists(output_file); auto f = File(output_file, "a"); foreach (i, c; combinations(testArgs.permuteArgs)) { string test_app_dmd = test_app_dmd_base ~ to!string(i) ~ envData.exe; try { string[] toCleanup; auto thisRunName = genTempFilename(result_path); auto fThisRun = File(thisRunName, "w"); scope(exit) { fThisRun.close(); f.write(readText(thisRunName)); f.writeln(); removeIfExists(thisRunName); } // can override -verrors by using REQUIRED_ARGS auto reqArgs = (testArgs.mode == TestMode.FAIL_COMPILE ? "-verrors=0 " : null) ~ testArgs.requiredArgs; string compile_output; if (!testArgs.compileSeparately) { string objfile = output_dir ~ envData.sep ~ test_name ~ "_" ~ to!string(i) ~ envData.obj; toCleanup ~= objfile; string command = format("%s -conf= -m%s -I%s %s %s -od%s -of%s %s%s", envData.dmd, envData.model, input_dir, reqArgs, c, output_dir, (testArgs.mode == TestMode.RUN ? test_app_dmd : objfile), (testArgs.mode == TestMode.RUN ? "" : "-c "), join(testArgs.sources, " ")); version (LDC) {} else version(Windows) command ~= " -map nul.map"; compile_output = execute(fThisRun, command, testArgs.mode != TestMode.FAIL_COMPILE, result_path); } else { foreach (filename; testArgs.sources) { string newo= result_path ~ replace(replace(filename, ".d", envData.obj), envData.sep~"imports"~envData.sep, envData.sep); toCleanup ~= newo; string command = format("%s -conf= -m%s -I%s %s %s -od%s -c %s", envData.dmd, envData.model, input_dir, reqArgs, c, output_dir, filename); compile_output ~= execute(fThisRun, command, testArgs.mode != TestMode.FAIL_COMPILE, result_path); } if (testArgs.mode == TestMode.RUN) { // link .o's into an executable string command = format("%s -conf= -m%s %s %s -od%s -of%s %s", envData.dmd, envData.model, envData.required_args, testArgs.requiredArgsForLink, output_dir, test_app_dmd, join(toCleanup, " ")); version (LDC) {} else version(Windows) command ~= " -map nul.map"; execute(fThisRun, command, true, result_path); } } compile_output = std.regex.replace(compile_output, regex(`^DMD v2\.[0-9]+.* DEBUG$`, "m"), ""); compile_output = std.string.strip(compile_output); compile_output = compile_output.unifyNewLine(); auto m = std.regex.match(compile_output, `Internal error: .*$`); enforce(!m, m.hit); if (testArgs.compileOutput !is null) { enforce(compareOutput(compile_output, testArgs.compileOutput), "\nexpected:\n----\n"~testArgs.compileOutput~"\n----\nactual:\n----\n"~compile_output~"\n----\n"); } if (testArgs.mode == TestMode.RUN) { toCleanup ~= test_app_dmd; version(Windows) if (msc) { toCleanup ~= test_app_dmd_base ~ to!string(i) ~ ".ilk"; toCleanup ~= test_app_dmd_base ~ to!string(i) ~ ".pdb"; } if (testArgs.gdbScript is null) { string command = test_app_dmd; if (testArgs.executeArgs) command ~= " " ~ testArgs.executeArgs; execute(fThisRun, command, true, result_path); } else version (linux) { auto script = test_app_dmd_base ~ to!string(i) ~ ".gdb"; toCleanup ~= script; with (File(script, "w")) write(testArgs.gdbScript); string command = "gdb "~test_app_dmd~" --batch -x "~script; auto gdb_output = execute(fThisRun, command, true, result_path); if (testArgs.gdbMatch !is null) { enforce(match(gdb_output, regex(testArgs.gdbMatch)), "\nGDB regex: '"~testArgs.gdbMatch~"' didn't match output:\n----\n"~gdb_output~"\n----\n"); } } } fThisRun.close(); if (testArgs.postScript) { f.write("Executing post-test script: "); string prefix = ""; version (Windows) prefix = "bash "; execute(f, prefix ~ testArgs.postScript ~ " " ~ thisRunName, true, result_path); } foreach (file; toCleanup) collectException(std.file.remove(file)); } catch(Exception e) { // it failed but it was disabled, exit as if it was successful if (testArgs.disabled) return 0; f.writeln(); f.writeln("=============================="); f.writeln("Test failed: ", e.msg); f.close(); writeln("Test failed. The logged output:"); writeln(cast(string)std.file.read(output_file)); std.file.remove(output_file); return 1; } } // it was disabled but it passed! print an informational message if (testArgs.disabled) writefln(" !!! %-30s DISABLED but PASSES!", input_file); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/README0000644000175000017500000000156613200164642020471 0ustar matthiasmatthiasDMD D2 test suite ================= This repository contains a mirror of the D2 test suite as found in the test/ directory of the official DMD repository [1]. It is intended for use as Git submodule in the development of LDC or other alternative compilers. The 'master' branch and all tags contain a pristine copy of the files in the DMD repository, the 'ldc' branch also has some LDC-specific adjustments and fixes. Updating the repository ----------------------- Updates from upstream are folded in using the update-dmd-testsuite script found in the ldc-scripts repository [2]. It performs a new history rewrite on the DMD repository each time, so please leave the master branch (or any tags, ...) alone, as this would change the SHA-1 commit ids and thus break the process. [1] https://github.com/D-Programming-Language/dmd [2] https://github.com/ldc-developers/ldc-scripts ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/0000755000175000017500000000000013200164642021407 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/sdtor.d0000644000175000017500000023555413200164642022725 0ustar matthiasmatthias import core.vararg; extern (C) int printf(const(char*) fmt, ...); template TypeTuple(T...) { alias TypeTuple = T; } /**********************************/ int sdtor; struct S1 { ~this() { printf("~S()\n"); sdtor++; } } void test1() { S1* s = new S1(); delete s; assert(sdtor == 1); } /**********************************/ int sdtor2; struct S2 { ~this() { printf("~S2()\n"); sdtor2++; } delete(void* p) { assert(sdtor2 == 1); printf("S2.delete()\n"); sdtor2++; } } void test2() { S2* s = new S2(); delete s; assert(sdtor2 == 2); } /**********************************/ int sdtor3; struct S3 { int a; ~this() { printf("~S3()\n"); sdtor3++; assert(a == 3); } } struct T3 { int i; S3 s; } void test3() { T3* s = new T3(); s.s.a = 3; delete s; assert(sdtor3 == 1); } /**********************************/ int sdtor4; struct S4 { int a = 3; ~this() { printf("~S4()\n"); if (a == 4) assert(sdtor4 == 2); else { assert(a == 3); assert(sdtor4 == 1); } sdtor4++; } } struct T4 { int i; S4 s; ~this() { printf("~T4()\n"); assert(sdtor4 == 0); sdtor4++; } S4 t; } void test4() { T4* s = new T4(); s.s.a = 4; delete s; assert(sdtor4 == 3); } /**********************************/ int sdtor5; template M5() { ~this() { printf("~M5()\n"); assert(sdtor5 == 1); sdtor5++; } } struct T5 { mixin M5 m; ~this() { printf("~T5()\n"); assert(sdtor5 == 0); sdtor5++; } } void test5() { T5* s = new T5(); delete s; assert(sdtor5 == 2); } /**********************************/ int sdtor6; struct S6 { int b = 7; ~this() { printf("~S6()\n"); assert(b == 7); assert(sdtor6 == 1); sdtor6++; } } class T6 { int a = 3; S6 s; ~this() { printf("~T6()\n"); assert(a == 3); assert(sdtor6 == 0); sdtor6++; } } void test6() { T6 s = new T6(); delete s; assert(sdtor6 == 2); } /**********************************/ int sdtor7; struct S7 { int b = 7; ~this() { printf("~S7()\n"); assert(b == 7); assert(sdtor7 >= 1 && sdtor7 <= 3); sdtor7++; } } struct T7 { int a = 3; S7[3] s; ~this() { printf("~T7() %d\n", sdtor7); assert(a == 3); assert(sdtor7 == 0); sdtor7++; } } void test7() { T7* s = new T7(); delete s; assert(sdtor7 == 4); } /**********************************/ int sdtor8; struct S8 { int b = 7; int c; ~this() { printf("~S8() %d\n", sdtor8); assert(b == 7); assert(sdtor8 == c); sdtor8++; } } void test8() { S8[] s = new S8[3]; s[0].c = 2; s[1].c = 1; s[2].c = 0; delete s; assert(sdtor8 == 3); } /**********************************/ int sdtor9; struct S9 { int b = 7; ~this() { printf("~S9() %d\n", sdtor9); assert(b == 7); sdtor9++; } } void test9() { { S9 s; } assert(sdtor9 == 1); } /**********************************/ int sdtor10; struct S10 { int b = 7; int c; ~this() { printf("~S10() %d\n", sdtor10); assert(b == 7); assert(sdtor10 == c); sdtor10++; } } void test10() { { S10[3] s; s[0].c = 2; s[1].c = 1; s[2].c = 0; } assert(sdtor10 == 3); } /**********************************/ int sdtor11; template M11() { ~this() { printf("~M11()\n"); assert(sdtor11 == 1); sdtor11++; } } class T11 { mixin M11 m; ~this() { printf("~T11()\n"); assert(sdtor11 == 0); sdtor11++; } } void test11() { T11 s = new T11(); delete s; assert(sdtor11 == 2); } /**********************************/ int sdtor12; struct S12 { int a = 3; ~this() { printf("~S12() %d\n", sdtor12); sdtor12++; } } void foo12(S12 s) { } void test12() { { S12 s; foo12(s); s.a = 4; } assert(sdtor12 == 2); } /**********************************/ struct S13 { int a = 3; int opAssign(S13 s) { printf("S13.opAssign(%p)\n", &this); a = 4; return s.a + 2; } } void test13() { S13 s; S13 t; assert((s = t) == 5); assert(s.a == 4); } /**********************************/ struct S14 { int a = 3; int opAssign(ref S14 s) { printf("S14.opAssign(%p)\n", &this); a = 4; return s.a + 2; } } void test14() { S14 s; S14 t; assert((s = t) == 5); assert(s.a == 4); } /**********************************/ struct S15 { int a = 3; int opAssign(ref const S15 s) { printf("S15.opAssign(%p)\n", &this); a = 4; return s.a + 2; } } void test15() { S15 s; S15 t; assert((s = t) == 5); assert(s.a == 4); } /**********************************/ struct S16 { int a = 3; int opAssign(S16 s, ...) { printf("S16.opAssign(%p)\n", &this); a = 4; return s.a + 2; } } void test16() { S16 s; S16 t; assert((s = t) == 5); assert(s.a == 4); } /**********************************/ struct S17 { int a = 3; int opAssign(...) { printf("S17.opAssign(%p)\n", &this); a = 4; return 5; } } void test17() { S17 s; S17 t; assert((s = t) == 5); assert(s.a == 4); } /**********************************/ struct S18 { int a = 3; int opAssign(S18 s, int x = 7) { printf("S18.opAssign(%p)\n", &this); a = 4; assert(x == 7); return s.a + 2; } } void test18() { S18 s; S18 t; assert((s = t) == 5); assert(s.a == 4); } /**********************************/ struct S19 { int a,b,c,d; this(this) { printf("this(this) %p\n", &this); } ~this() { printf("~this() %p\n", &this); } } S19 foo19() { S19 s; void bar() { s.a++; } bar(); return s; } void test19() { S19 t = foo19(); printf("-main()\n"); } /**********************************/ struct S20 { static char[] r; int a,b,c=2,d; this(this) { printf("this(this) %p\n", &this); r ~= '='; } ~this() { printf("~this() %p\n", &this); r ~= '~'; } } void foo20() { S20 s; S20[3] a; assert(S20.r == ""); a = s; assert(S20.r == "=~=~=~"); } void test20() { foo20(); assert(S20.r == "=~=~=~~~~~"); printf("-main()\n"); } /**********************************/ struct S21 { static char[] r; int a,b,c=2,d; this(this) { printf("this(this) %p\n", &this); r ~= '='; } ~this() { printf("~this() %p\n", &this); r ~= '~'; } } void foo21() { S21 s; S21[3] a = s; assert(S21.r == "==="); S21.r = null; S21[3][2] b = s; assert(S21.r == "======"); S21.r = null; } void test21() { foo21(); assert(S21.r == "~~~~~~~~~~"); printf("-main()\n"); } /**********************************/ struct S22 { static char[] r; int a,b,c=2,d; this(this) { printf("this(this) %p\n", &this); r ~= '='; } ~this() { printf("~this() %p\n", &this); r ~= '~'; } } void foo22() { S22[3] s; S22[3][2] a; assert(S22.r == ""); a = s; assert(S22.r == "===~~~===~~~"); S22.r = null; } void test22() { foo22(); assert(S22.r == "~~~~~~~~~"); printf("-main()\n"); } /************************************************/ struct S23 { int m = 4, n, o, p, q; this(int x) { printf("S23(%d)\n", x); assert(x == 3); assert(m == 4 && n == 0 && o == 0 && p == 0 && q == 0); q = 7; } } void test23() { { auto s = S23(3); printf("s.m = %d, s.n = %d, s.q = %d\n", s.m, s.n, s.q); assert(s.m == 4 && s.n == 0 && s.o == 0 && s.p == 0 && s.q == 7); } { auto s = new S23(3); printf("s.m = %d, s.n = %d, s.q = %d\n", s.m, s.n, s.q); assert(s.m == 4 && s.n == 0 && s.o == 0 && s.p == 0 && s.q == 7); } { S23 s; s = S23(3); printf("s.m = %d, s.n = %d, s.q = %d\n", s.m, s.n, s.q); assert(s.m == 4 && s.n == 0 && s.o == 0 && s.p == 0 && s.q == 7); } } /************************************************/ struct S24 { int m, n, o, p, q; this(int x) { printf("S24(%d)\n", x); assert(x == 3); assert(m == 0 && n == 0 && o == 0 && p == 0 && q == 0); q = 7; } } void test24() { { auto s = S24(3); printf("s.m = %d, s.n = %d, s.q = %d\n", s.m, s.n, s.q); assert(s.m == 0 && s.n == 0 && s.o == 0 && s.p == 0 && s.q == 7); } { auto s = new S24(3); printf("s.m = %d, s.n = %d, s.q = %d\n", s.m, s.n, s.q); assert(s.m == 0 && s.n == 0 && s.o == 0 && s.p == 0 && s.q == 7); } { S24 s; s = S24(3); printf("s.m = %d, s.n = %d, s.q = %d\n", s.m, s.n, s.q); assert(s.m == 0 && s.n == 0 && s.o == 0 && s.p == 0 && s.q == 7); } } /**********************************/ struct S25 { this(int s) {} } void test25() { auto a = S25(); } /**********************************/ int z26; struct A26 { int id; this(int x) { id = x; printf("Created A from scratch: %d\n", x); z26++; } this(this) { printf("Copying A: %d\n", id); z26 += 10; } ~this() { printf("Destroying A: %d\n", id); z26 += 100; } } struct B26 { A26 member; this(this) { printf("Copying B: %d\n", member.id); assert(0); } } B26 foo26() { A26 a = A26(45); printf("1\n"); assert(z26 == 1); return B26(a); } void test26() { { auto b = foo26(); assert(z26 == 111); printf("2\n"); } assert(z26 == 211); } /**********************************/ int z27; struct A27 { int id; this(int x) { id = x; printf("Ctor A27: %d\n", x); z27++; } this(this) { printf("Copying A27: %d\n", id); z27 += 10; } ~this() { printf("Destroying A27: %d\n", id); z27 += 100; } } struct B27 { A27[2][3] member; } void test27() { { A27[2][3] a; assert(z27 == 0); B27 b = B27(a); assert(z27 == 60); } assert(z27 == 1260); } /**********************************/ string s28; struct A28 { this(this) { printf("A's copy\n"); s28 ~= "A"; } } struct B28 { A28 member; this(this) { printf("B's copy\n"); s28 ~= "B"; } } void test28() { B28 b1; B28 b2 = b1; assert(s28 == "AB"); } /**********************************/ string s29; template Templ29 () { this(int i) { this(0.0); s29 ~= "i"; } this(double d) { s29 ~= "d"; } } class C29 { mixin Templ29; } struct S29 { mixin Templ29; } void test29() { auto r = S29(1); assert(s29 == "di"); r = S29(2.0); assert(s29 == "did"); auto c = new C29(2); assert(s29 == "diddi"); auto c2 = new C29(2.0); assert(s29 == "diddid"); } /**********************************/ struct S30 { int x; this(T)(T args) { x = args + 1; } } void test30() { auto s = S30(3); assert(s.x == 4); } /**********************************/ struct S31 { int x; this(T...)(T args) { x = args[0] + 1; } } void test31() { auto s = S31(3); assert(s.x == 4); } /**********************************/ struct S32 { static int x; this(int i) { printf("ctor %p(%d)\n", &this, i); x += 1; } this(this) { printf("postblit %p\n", &this); x += 0x10; } ~this() { printf("dtor %p\n", &this); x += 0x100; } } S32 foo32() { printf("test1\n"); return S32(1); } S32 bar32() { printf("test1\n"); S32 f = S32(1); printf("test2\n"); return f; } void test32() { { S32 s = foo32(); } assert(S32.x == 0x101); S32.x = 0; { S32 s = bar32(); } assert(S32.x == 0x101); } /**********************************/ struct S33 { static int x; this(int i) { printf("ctor %p(%d)\n", &this, i); x += 1; } this(this) { printf("postblit %p\n", &this); x += 0x10; } ~this() { printf("dtor %p\n", &this); x += 0x100; } } struct T33 { S33 foo() { return t; } S33 t; } void test33() { { T33 t; S33 s = t.foo(); } printf("S.x = %x\n", S33.x); assert(S33.x == 0x210); } /**********************************/ struct X34 { int i; this(this) { printf("postblit %p\n", &this); ++i; } ~this() { printf("dtor %p\n", &this); } } void test34() { X34[2] xs; // xs[0][0] = X34(); printf("foreach\n"); for (int j = 0; j < xs.length; j++) { auto x = (j++,j--,xs[j]); //foreach(x; xs) { //printf("foreach x.i = %d\n", x[0].i); //assert(x[0].i == 1); printf("foreach x.i = %d\n", x.i); assert(x.i == 1); } printf("loop done\n"); } /**********************************/ struct X35 { __gshared int k; int i; this(this) { printf("postblit %p\n", &this); ++i; } ~this() { printf("dtor %p\n", &this); k++; } } void test35() { { X35[2] xs; printf("foreach\n"); foreach(ref x; xs) { printf("foreach x.i = %d\n", x.i); assert(x.i == 0); } printf("loop done\n"); } assert(X35.k == 2); } /**********************************/ struct X36 { __gshared int k; int i; this(this) { printf("postblit %p\n", &this); ++i; } ~this() { printf("dtor %p\n", &this); k++; } } void test36() { { X36[2] xs; printf("foreach\n"); foreach(x; xs) { printf("foreach x.i = %d\n", x.i); assert(x.i == 1); } printf("loop done\n"); } assert(X36.k == 4); } /**********************************/ struct X37 { __gshared int k; int i; this(this) { printf("postblit %p\n", &this); ++i; } ~this() { printf("dtor %p\n", &this); k++; } } void test37() { { X37[2][3] xs; printf("foreach\n"); foreach(ref x; xs) { printf("foreach x.i = %d\n", x[0].i); assert(x[0].i == 0); } printf("loop done\n"); } assert(X37.k == 6); } /**********************************/ struct S38 { __gshared int count; __gshared int postblit; this(int x) { printf("this(%d)\n", x); assert(this.x == 0); this.x = x; count++; } this(this) { printf("this(this) with %d\n", x); assert(x == 1 || x == 2); count++; postblit++; } ~this() { printf("~this(%d)\n", x); assert(x == 1 || x == 2); x = 0; count--; } int x; } S38 foo38() { auto s = S38(1); return s; } S38 bar38() { return S38(2); } void test38() { { auto s1 = foo38(); assert(S38.count == 1); assert(S38.postblit == 0); } assert(S38.count == 0); S38.postblit = 0; { auto s2 = bar38(); assert(S38.count == 1); assert(S38.postblit == 0); } assert(S38.count == 0); } /**********************************/ struct Foo39 { int x; this(int v){ x = v + 1; } void opAssign(int v){ x = v + 3; } } void test39() { int y = 5; Foo39 f = y; assert(f.x == 6); f = y; assert(f.x == 8); // f = Foo39(y); } /**********************************/ bool approxEqual(float a, float b) { return a < b ? b-a < .001 : a-b < .001; } struct Point { float x = 0, y = 0; const bool opEquals(const ref Point rhs) { return approxEqual(x, rhs.x) && approxEqual(y, rhs.y); } } struct Rectangle { Point leftBottom, rightTop; } void test40() { Rectangle a, b; assert(a == b); a.leftBottom.x = 1e-8; assert(a == b); a.rightTop.y = 5; assert(a != b); } /**********************************/ struct S41 { this(int) immutable { } } void test41() { auto s = new immutable S41(3); //writeln(typeid(typeof(s))); static assert(is(typeof(s) == immutable(S41)*)); auto t = immutable S41(3); //writeln(typeid(typeof(t))); static assert(is(typeof(t) == immutable(S41))); } /**********************************/ class C42 { this(int) immutable { } } void test42() { static assert(!__traits(compiles, new C42(3))); //writeln(typeid(typeof(c))); //static assert(is(typeof(c) == immutable(C42))); auto d = new immutable(C42)(3); //writeln(typeid(typeof(d))); static assert(is(typeof(d) == immutable(C42))); } /**********************************/ struct S43 { int i; int* p; // this(int i, int* t) immutable { this.i = i; p = t; } } void test43() { int i; assert(!__traits(compiles, immutable(S43)(3, &i))); immutable int j = 4; auto s = immutable(S43)(3, &j); //writeln(typeid(typeof(s))); static assert(is(typeof(s) == immutable(S43))); } /**********************************/ struct S44 { int i; immutable(int)* p; this(int i, immutable(int)* t) immutable { this.i = i; this.p = t; } } void test44() { int i; assert(!__traits(compiles, immutable(S44)(3, &i))); immutable int j = 4; auto s = immutable(S44)(3, &j); //writeln(typeid(typeof(s))); static assert(is(typeof(s) == immutable(S44))); } /**********************************/ class C45 { C45 next; this(int[] data) immutable { next = new immutable(C45)(data[1 .. $]); } } void test45() { } /**********************************/ // 3986 struct SiberianHamster { int rat = 813; this(string z) { } } void test46() { SiberianHamster basil = "cybil"; assert(basil.rat == 813); } /**********************************/ // 8741 struct Vec8741 { this(float x) { m[0] = x; m[1] = 58; } float[2] m; static Vec8741 zzz = Vec8741(7); } void test8741() { assert(Vec8741.zzz.m[0] == 7); assert(Vec8741.zzz.m[1] == 58); } /**********************************/ struct Segfault3984 { int a; this(int x){ a = x; } } void test47() { //static assert(Segfault3984(3).a == 3); } /**********************************/ void test48() { struct B { void foo() { } } B x = B.init; } /**********************************/ struct Foo49 { int z; this(int a){z=a;} } void bar49(Foo49 a = Foo49(1)) { assert(a.z == 1); } void test49() { bar49(); bar49(); } /**********************************/ struct aStruct{ int m_Int; this(int a){ m_Int = a; } } class aClass{ void aFunc(aStruct a = aStruct(44)) { assert(a.m_Int == 44); } } void test50() { aClass a = new aClass(); a.aFunc(); a.aFunc(); } /**********************************/ int A51_a; struct A51 { ~this() { ++A51_a; } } void test51() { A51_a = 0; { while(0) A51 a; } assert(A51_a == 0); A51_a = 0; { if(0) A51 a; } assert(A51_a == 0); A51_a = 0; { if(1){} else A51 a; } assert(A51_a == 0); A51_a = 0; { for(;0;) A51 a; } assert(A51_a == 0); A51_a = 0; { if (1) { A51 a; } } assert(A51_a == 1); A51_a = 0; { if (1) A51 a; } assert(A51_a == 1); A51_a = 0; { if(0) {} else A51 a; } assert(A51_a == 1); A51_a = 0; { if (0) for(A51 a;;) {} } assert(A51_a == 0); A51_a = 0; { if (0) for(;;) A51 a; } assert(A51_a == 0); A51_a = 0; { do A51 a; while(0); } assert(A51_a == 1); A51_a = 0; { if (0) while(1) A51 a; } assert(A51_a == 0); A51_a = 0; { try A51 a; catch(Error e) {} } assert(A51_a == 1); A51_a = 0; { if (0) final switch(1) A51 a; } assert(A51_a == 0); // should fail to build A51_a = 0; { if (0) switch(1) { A51 a; default: } } assert(A51_a == 0); A51_a = 0; { if (0) switch(1) { default: A51 a; } } assert(A51_a == 0); A51_a = 0; { if (1) switch(1) { A51 a; default: } } assert(A51_a == 1); // should be 0, right? A51_a = 0; { if (1) switch(1) { default: A51 a; } } assert(A51_a == 1); // A51_a = 0; { final switch(0) A51 a; } assert(A51_a == 0); A51_a = 0; { A51 a; with(a) A51 b; } assert(A51_a == 2); } /**********************************/ string s52; struct A52 { int m; this(this) { printf("this(this) %p\n", &this); s52 ~= 'a'; } ~this() { printf("~this() %p\n", &this); s52 ~= 'b'; } A52 copy() { s52 ~= 'c'; A52 another = this; return another; } } void test52() { { A52 a; A52 b = a.copy(); printf("a: %p, b: %p\n", &a, &b); } printf("s = '%.*s'\n", s52.length, s52.ptr); assert(s52 == "cabb"); } /**********************************/ // 4339 struct A53 { invariant() { } ~this() { } void opAssign(A53 a) {} int blah(A53 a) { return 0; } } /**********************************/ struct S54 { int x = 1; int bar() { return x; } this(int i) { printf("ctor %p(%d)\n", &this, i); t ~= "a"; } this(this) { printf("postblit %p\n", &this); t ~= "b"; } ~this() { printf("dtor %p\n", &this); t ~= "c"; } static string t; } void bar54(S54 s) { } S54 abc54() { return S54(1); } void test54() { { S54.t = null; S54 s = S54(1); } assert(S54.t == "ac"); { S54.t = null; S54 s = S54(); } assert(S54.t == "c"); { S54.t = null; int b = 1 && (bar54(S54(1)), 1); } assert(S54.t == "ac"); { S54.t = null; int b = 0 && (bar54(S54(1)), 1); } assert(S54.t == ""); { S54.t = null; int b = 0 || (bar54(S54(1)), 1); } assert(S54.t == "ac"); { S54.t = null; int b = 1 || (bar54(S54(1)), 1); } assert(S54.t == ""); { S54.t = null; { const S54 s = S54(1); } assert(S54.t == "ac"); } { S54.t = null; abc54(); assert(S54.t == "ac"); } { S54.t = null; abc54().x += 1; assert(S54.t == "ac"); } } /**********************************/ void test55() { S55 s; auto t = s.copy(); assert(t.count == 1); // (5) } struct S55 { int count; this(this) { ++count; } S55 copy() { return this; } } /**********************************/ struct S56 { int x = 1; int bar() { return x; } this(int i) { printf("ctor %p(%d)\n", &this, i); t ~= "a"; } this(this) { printf("postblit %p\n", &this); t ~= "b"; } ~this() { printf("dtor %p\n", &this); t ~= "c"; } static string t; } int foo56() { throw new Throwable("hello"); return 5; } void test56() { int i; int j; try { j |= 1; i = S56(1).x + foo56() + 1; j |= 2; } catch (Throwable o) { printf("caught\n"); j |= 4; } printf("i = %d, j = %d\n", i, j); assert(i == 0); assert(j == 5); } /**********************************/ // 5859 int dtor_cnt = 0; struct S57 { int v; this(int n){ v = n; printf("S.ctor v=%d\n", v); } ~this(){ ++dtor_cnt; printf("S.dtor v=%d\n", v); } bool opCast(T:bool)(){ printf("S.cast v=%d\n", v); return true; } } S57 f(int n){ return S57(n); } void test57() { printf("----\n"); dtor_cnt = 0; if (auto s = S57(10)) { printf("ifbody\n"); } else assert(0); assert(dtor_cnt == 1); printf("----\n"); //+ dtor_cnt = 0; if (auto s = (S57(1), S57(2), S57(10))) { assert(dtor_cnt == 2); printf("ifbody\n"); } else assert(0); assert(dtor_cnt == 3); // +/ printf("----\n"); dtor_cnt = 0; try{ if (auto s = S57(10)) { printf("ifbody\n"); throw new Exception("test"); } else assert(0); }catch (Exception e){} assert(dtor_cnt == 1); printf("----\n"); dtor_cnt = 0; if (auto s = f(10)) { printf("ifbody\n"); } else assert(0); assert(dtor_cnt == 1); printf("----\n"); //+ dtor_cnt = 0; if (auto s = (f(1), f(2), f(10))) { assert(dtor_cnt == 2); printf("ifbody\n"); } else assert(0); assert(dtor_cnt == 3); // +/ printf("----\n"); dtor_cnt = 0; try{ if (auto s = f(10)) { printf("ifbody\n"); throw new Exception("test"); } else assert(0); }catch (Exception e){} assert(dtor_cnt == 1); printf("----\n"); dtor_cnt = 0; if (S57(10)) { assert(dtor_cnt == 1); printf("ifbody\n"); } else assert(0); printf("----\n"); dtor_cnt = 0; if ((S57(1), S57(2), S57(10))) { assert(dtor_cnt == 3); printf("ifbody\n"); } else assert(0); printf("----\n"); dtor_cnt = 0; try{ if (auto s = S57(10)) { printf("ifbody\n"); throw new Exception("test"); } else assert(0); }catch (Exception e){} assert(dtor_cnt == 1); printf("----\n"); dtor_cnt = 0; if (f(10)) { assert(dtor_cnt == 1); printf("ifbody\n"); } else assert(0); printf("----\n"); dtor_cnt = 0; if ((f(1), f(2), f(10))) { assert(dtor_cnt == 3); printf("ifbody\n"); } else assert(0); printf("----\n"); dtor_cnt = 0; try{ if (auto s = f(10)) { printf("ifbody\n"); throw new Exception("test"); } else assert(0); }catch (Exception e){} assert(dtor_cnt == 1); } /**********************************/ // 5574 struct foo5574a { ~this() {} } class bar5574a { foo5574a[1] frop; } struct foo5574b { this(this){} } struct bar5574b { foo5574b[1] frop; } /**********************************/ // 5777 int sdtor58 = 0; S58* ps58; struct S58 { @disable this(this); ~this(){ ++sdtor58; } } S58 makeS58() { S58 s; ps58 = &s; return s; } void test58() { auto s1 = makeS58(); assert(ps58 == &s1); assert(sdtor58 == 0); } /**********************************/ // 6308 struct C59 { void oops() { throw new Throwable("Oops!"); } ~this() { } } void foo59() { C59().oops(); // auto c = C(); c.oops(); } void test59() { int i = 0; try foo59(); catch (Throwable) { i = 1; } assert(i == 1); } /**********************************/ // 5737 void test5737() { static struct S { static int destroyed; static int copied; this(this) { copied++; } ~this() { destroyed++; } } static S s; ref S foo() { return s; } { auto s2 = foo(); } assert(S.copied == 1); // fail, s2 was not copied; assert(S.destroyed == 1); // ok, s2 was destroyed } /**********************************/ // 6119 void test6119() { int postblit = 0; int dtor = 0; struct Test { this(this) { ++postblit; } ~this() { ++dtor; } } void takesVal(Test x) {} ref Test returnsRef(ref Test x) { return x; } void f(ref Test x) { takesVal( x ); } Test x; postblit = dtor = 0; takesVal(returnsRef(x)); assert(postblit == 1); assert(dtor == 1); postblit = dtor = 0; f(x); assert(postblit == 1); assert(dtor == 1); } /**********************************/ // 6364 struct Foo6364 { int state = 1; ~this() { state = 0; } } void testfoo6364() { static Foo6364 foo; printf("%d\n", foo.state); assert(foo.state == 1); } void test6364() { testfoo6364(); testfoo6364(); } /**********************************/ // 6499 struct S6499 { string m = ""; this(string s) { m = s; printf("Constructor - %.*s\n", m.length, m.ptr); if (m == "foo") { ++sdtor; assert(sdtor == 1); } if (m == "bar") { ++sdtor; assert(sdtor == 2); } } this(this) { printf("Postblit - %.*s\n", m.length, m.ptr); assert(0); } ~this() { printf("Destructor - %.*s\n", m.length, m.ptr); if (m == "bar") { assert(sdtor == 2); --sdtor; } if (m == "foo") { assert(sdtor == 1); --sdtor; } } S6499 bar() { return S6499("bar"); } S6499 baz()() { return S6499("baz"); } } void test6499() { S6499 foo() { return S6499("foo"); } { sdtor = 0; scope(exit) assert(sdtor == 0); foo().bar(); } { sdtor = 0; scope(exit) assert(sdtor == 0); foo().baz(); } } /**********************************/ template isImplicitlyConvertible(From, To) { enum bool isImplicitlyConvertible = is(typeof({ void fun(ref From v) { void gun(To) {} gun(v); } }())); } void test60() { static struct X1 { void* ptr; this(this){} } static struct S1 { X1 x; } static struct X2 { int ptr; this(this){} } static struct S2 { X2 x; } { S1 ms; S1 ms2 = ms; // mutable to mutable const(S1) cs2 = ms; // mutable to const // NG -> OK } { const(S1) cs; static assert(!__traits(compiles,{ // NG -> OK S1 ms2 = cs; // field has reference, then const to mutable is invalid })); const(S1) cs2 = cs; // const to const // NG -> OK } static assert( isImplicitlyConvertible!( S1 , S1 ) ); static assert( isImplicitlyConvertible!( S1 , const(S1)) ); // NG -> OK static assert(!isImplicitlyConvertible!(const(S1), S1 ) ); static assert( isImplicitlyConvertible!(const(S1), const(S1)) ); // NG -> OK { S2 ms; S2 ms2 = ms; // mutable to mutable const(S2) cs2 = ms; // mutable to const // NG -> OK } { const(S2) cs; S2 ms2 = cs; // all fields are value, then const to mutable is OK const(S2) cs2 = cs; // const to const // NG -> OK } static assert( isImplicitlyConvertible!( S2 , S2 ) ); static assert( isImplicitlyConvertible!( S2 , const(S2)) ); // NG -> OK static assert( isImplicitlyConvertible!(const(S2), S2 ) ); static assert( isImplicitlyConvertible!(const(S2), const(S2)) ); // NG -> OK } /**********************************/ // 4316 struct A4316 { this(this) @safe { } } @safe void test4316() { A4316 a; auto b = a; // Error: safe function 'main' cannot call system function'__cpctor' } /**********************************/ struct F6177 { ~this() {} } struct G6177 { this(F6177[] p...) {} } void test6177() { F6177 c; auto g = G6177(c); } /**********************************/ // 6470 struct S6470 { static int spblit; this(this){ ++spblit; } } void test6470() { S6470[] a1; S6470[] a2; a1.length = 3; a2.length = 3; a1[] = a2[]; assert(S6470.spblit == 3); S6470 s; S6470[] a3; a3.length = 3; a3 = [s, s, s]; assert(S6470.spblit == 6); void func(S6470[] a){} func([s, s, s]); assert(S6470.spblit == 9); } /**********************************/ // 6636 struct S6636 { ~this() { ++sdtor; } } void func6636(S6636[3] sa) {} void test6636() { sdtor = 0; S6636[3] sa; func6636(sa); assert(sdtor == 3); } /**********************************/ // 6637 struct S6637 { static int spblit; this(this){ ++spblit; } } void test6637() { void func(S6637[3] sa){} S6637[3] sa; func(sa); assert(S6637.spblit == 3); } /**********************************/ // 7353 struct S7353 { static uint ci = 0; uint i; this(int x) { i = ci++; /*writeln("new: ", i);*/ } this(this) { i = ci++; /*writeln("copy ", i);*/ } ~this() { /*writeln("del ", i);*/ } S7353 save1() // produces 2 copies in total { S7353 s = this; return s; } auto save2() // produces 3 copies in total { S7353 s = this; return s; pragma(msg, typeof(return)); } } void test7353() { { auto s = S7353(1), t = S7353(1); t = s.save1(); assert(S7353.ci == 3); } S7353.ci = 0; //writeln("-"); { auto s = S7353(1), t = S7353(1); t = s.save2(); assert(S7353.ci == 3); } } /**********************************/ // 8036 struct S8036a { ~this() {} } struct S8036b // or class { S8036a[0] s; } /**********************************/ struct S61 { this(long length) { this.length = length; } long length; } const(S61) copy(const S61 s) { return s; } void test61() { S61 t = S61(42); const S61 u = t; assert(t == u); assert(copy(t) == u); assert(t == copy(u)); } /**********************************/ // 7506 void test7506() { static struct S { static uint ci = 0; static uint di = 0; uint i; this(int x) { i = ci++; /*writeln("new: ", i);*/ } this(this) { i = ci++; /*writeln("copy ", i);*/ } ~this() { ++di; /*writeln("del: ", i);*/ } S save3() { return this; } } { auto s = S(1), t = S(1); assert(S.ci == 2); t = s.save3(); assert(S.ci == 3); // line 23 } assert(S.di == 3); } /**********************************/ // 7530 void test7530() { static struct S { int val; this(int n) { val = n; } this(this) { val *= 3; } } S[] sa = new S[](1); sa[0].val = 1; S foo() { return sa[0]; } auto s = foo(); assert(s.val == 3); } /**********************************/ struct S62 { this(int length) { _length = length; } int opBinary(string op)(in S62 rhs) const if(op == "-") { return this.length - rhs.length; } @property int length() const { return _length; } invariant() { assert(_length == 1); } int _length = 1; } void test62() { immutable result = S62.init - S62.init; } /**********************************/ // 7579 void test7579a() { static struct S { // postblit can also have no body because isn't called @disable this(this) { assert(0); } } @property S fs() { return S(); } @property S[3] fsa() { return [S(), S(), S()]; } S s0; S s1 = S(); static assert(!__traits(compiles, { S s2 = s1; })); // OK S s2 = fs; static assert(!__traits(compiles, { s2 = s1; })); // OK // static array S[3] sa0; S[3] sa1 = [S(), S(), S()]; static assert(!__traits(compiles, { S[3] sa2 = sa1; })); // fixed S[3] sa2 = fsa; static assert(!__traits(compiles, { sa2 = sa1; })); // fixed sa2 = [S(), S(), S()]; sa2 = fsa; S[] da1 = new S[3]; S[] da2 = new S[3]; static assert(!__traits(compiles, { da2[] = da1[]; })); // fixed // concatenation and appending static assert(!__traits(compiles, { da1 ~= s1; })); // fixed static assert(!__traits(compiles, { da1 ~= S(); })); static assert(!__traits(compiles, { da1 ~= fsa; })); static assert(!__traits(compiles, { da1 ~= fsa[]; })); static assert(!__traits(compiles, { da1 = da1 ~ s1; })); // fixed static assert(!__traits(compiles, { da1 = s1 ~ da1; })); // fixed static assert(!__traits(compiles, { da1 = da1 ~ S(); })); static assert(!__traits(compiles, { da1 = da1 ~ fsa; })); static assert(!__traits(compiles, { da1 = da1 ~ da; })); } void test7579b() { static struct S { // postblit asserts in runtime this(this) { assert(0); } } @property S fs() { return S(); } @property S[3] fsa() { return [S(), S(), S()]; } S s0; S s1 = S(); S s2 = fs; // static array S[3] sa0; S[3] sa1 = [S(), S(), S()]; S[3] sa2 = fsa; sa2 = [S(), S(), S()]; sa2 = fsa; S[] da1 = new S[3]; S[] da2 = new S[3]; // concatenation and appending always run postblits } /**********************************/ // 8335 struct S8335 { static int postblit; int i; this(this) { ++postblit; } } void f8335(ref S8335[3] arr) { arr[0].i = 7; } void g8335(lazy S8335[3] arr) { assert(S8335.postblit == 0); auto x = arr; assert(S8335.postblit == 3); } void h8335(lazy S8335 s) { assert(S8335.postblit == 0); auto x = s; assert(S8335.postblit == 1); } void test8335() { S8335[3] arr; f8335(arr); assert(S8335.postblit == 0); assert(arr[0].i == 7); g8335(arr); assert(S8335.postblit == 3); S8335.postblit = 0; S8335 s; h8335(s); assert(S8335.postblit == 1); } /**********************************/ // 8356 void test8356() { static struct S { @disable this(this) { assert(0); } } S s; S[3] sa; static assert(!__traits(compiles, { S fs() { return s; } })); static assert(!__traits(compiles, { S[3] fsa() { return sa; } })); } /**********************************/ // 8475 T func8475(T)(T x) @safe pure { return T(); } template X8475(bool something) { struct XY { this(this) @safe pure {} void func(XY x) @safe pure { XY y = x; //Error: see below func8475(x); func8475(y); } } } alias X8475!(true).XY Xtrue; /**********************************/ struct Foo9320 { real x; this(real x) { this.x = x; } Foo9320 opBinary(string op)(Foo9320 other) { return Foo9320(mixin("x" ~ op ~ "other.x")); } } Foo9320 test9320(Foo9320 a, Foo9320 b, Foo9320 c) { return (a + b) / (a * b) - c; } /**********************************/ // 9386 struct Test9386 { string name; static char[25] op; static size_t i; static @property string sop() { return cast(string)op[0..i]; } this(string name) { this.name = name; printf("Created %.*s...\n", name.length, name.ptr); assert(i + 1 < op.length); op[i++] = 'a'; } this(this) { printf("Copied %.*s...\n", name.length, name.ptr); assert(i + 1 < op.length); op[i++] = 'b'; } ~this() { printf("Deleted %.*s\n", name.length, name.ptr); assert(i + 1 < op.length); op[i++] = 'c'; } const int opCmp(ref const Test9386 t) { return op[0] - t.op[0]; } } void test9386() { { Test9386.op[] = 0; Test9386.i = 0; Test9386[] tests = [ Test9386("one"), Test9386("two"), Test9386("three"), Test9386("four") ]; assert(Test9386.sop == "aaaa"); Test9386.op[] = 0; Test9386.i = 0; printf("----\n"); foreach (Test9386 test; tests) { printf("\tForeach %.*s\n", test.name.length, test.name.ptr); Test9386.op[Test9386.i++] = 'x'; } assert(Test9386.sop == "bxcbxcbxcbxc"); Test9386.op[] = 0; Test9386.i = 0; printf("----\n"); foreach (ref Test9386 test; tests) { printf("\tForeach %.*s\n", test.name.length, test.name.ptr); Test9386.op[Test9386.i++] = 'x'; } assert(Test9386.sop == "xxxx"); } printf("====\n"); { Test9386.op[] = 0; Test9386.i = 0; Test9386[Test9386] tests = [ Test9386("1") : Test9386("one"), Test9386("2") : Test9386("two"), Test9386("3") : Test9386("three"), Test9386("4") : Test9386("four") ]; Test9386.op[] = 0; Test9386.i = 0; printf("----\n"); foreach (Test9386 k, Test9386 v; tests) { printf("\tForeach %.*s : %.*s\n", k.name.length, k.name.ptr, v.name.length, v.name.ptr); Test9386.op[Test9386.i++] = 'x'; } assert(Test9386.sop == "bbxccbbxccbbxccbbxcc"); Test9386.op[] = 0; Test9386.i = 0; printf("----\n"); foreach (Test9386 k, ref Test9386 v; tests) { printf("\tForeach %.*s : %.*s\n", k.name.length, k.name.ptr, v.name.length, v.name.ptr); Test9386.op[Test9386.i++] = 'x'; } assert(Test9386.sop == "bxcbxcbxcbxc"); Test9386.op[] = 0; Test9386.i = 0; } } /**********************************/ // 9441 auto x9441 = X9441(0.123); struct X9441 { int a; this(double x) { a = cast(int)(x * 100); } } void test9441() { assert(x9441.a == 12); } /**********************************/ struct Payload { size_t _capacity; //Comment me int[] _pay; //Comment me size_t insertBack(Data d) { immutable newLen = _pay.length + 3; _pay.length = newLen; _pay = _pay[0 .. newLen]; //Comment me return 3; } } struct Impl { Payload _payload; size_t _count; } struct Data { Impl* _store; this(int i) { _store = new Impl; _store._payload = Payload.init; } ~this() { printf("%d\n", _store._count); --_store._count; } } void test9720() { auto a = Data(1); auto b = Data(1); a._store._payload.insertBack(b); //Fails } /**********************************/ // 9899 struct S9899 { @safe pure nothrow ~this() {} } struct MemberS9899 { S9899 s; } void test9899() @safe pure nothrow { MemberS9899 s; // 11 } /**********************************/ // 9907 void test9907() { static struct SX(bool hasCtor, bool hasDtor) { int i; static size_t assign; static size_t dtor; static if (hasCtor) { this(int i) { this.i = i; } } void opAssign(SX rhs) { printf("%08X(%d) from Rvalue %08X(%d)\n", &this.i, this.i, &rhs.i, rhs.i); ++assign; } void opAssign(ref SX rhs) { printf("%08X(%d) from Lvalue %08X(%d)\n", &this.i, this.i, &rhs.i, rhs.i); assert(0); } static if (hasDtor) { ~this() { printf("destroying %08X(%d)\n", &this.i, this.i); ++dtor; } } } S test(S)(int i) { return S(i); } foreach (hasCtor; TypeTuple!(false, true)) foreach (hasDtor; TypeTuple!(false, true)) { alias S = SX!(hasCtor, hasDtor); alias test!S foo; printf("----\n"); auto s = S(1); // Assignment from two kinds of rvalues assert(S.assign == 0); s = foo(2); static if (hasDtor) assert(S.dtor == 1); assert(S.assign == 1); s = S(3); assert(S.assign == 2); static if (hasDtor) assert(S.dtor == 2); } printf("----\n"); } /**********************************/ // 9985 struct S9985 { ubyte* b; ubyte buf[128]; this(this) { assert(0); } static void* ptr; } auto ref makeS9985() { S9985 s; s.b = s.buf.ptr; S9985.ptr = &s; return s; } void test9985() { S9985 s = makeS9985(); assert(S9985.ptr == &s); // NRVO static const int n = 1; static auto ref retN() { return n; } auto p = &(retN()); // OK assert(p == &n); alias pure nothrow @nogc @safe ref const(int) F1(); static assert(is(typeof(retN) == F1)); enum const(int) x = 1; static auto ref retX() { return x; } static assert(!__traits(compiles, { auto q = &(retX()); })); alias pure nothrow @nogc @safe const(int) F2(); static assert(is(typeof(retX) == F2)); } /**********************************/ // 9994 void test9994() { static struct S { static int dtor; ~this() { ++dtor; } } S s; static assert( __traits(compiles, s.opAssign(s))); static assert(!__traits(compiles, s.__postblit())); assert(S.dtor == 0); s = s; assert(S.dtor == 1); } /**********************************/ // 10053 struct S10053A { pure ~this() {} } struct S10053B { S10053A sa; ~this() {} } /**********************************/ // 10055 void test10055a() { static struct SX { pure nothrow @safe ~this() {} } static struct SY { pure nothrow @safe ~this() {} } static struct SZ { @disable ~this() {} } // function to check merge result of the dtor attributes static void check(S)() { S s; } static struct S1 { } static struct S2 { ~this() {} } static struct SA { SX sx; SY sy; } static struct SB { SX sx; SY sy; pure nothrow @safe ~this() {} } static struct SC { SX sx; SY sy; nothrow @safe ~this() {} } static struct SD { SX sx; SY sy; pure @safe ~this() {} } static struct SE { SX sx; SY sy; pure nothrow ~this() {} } static struct SF { SX sx; SY sy; @safe ~this() {} } static struct SG { SX sx; SY sy; nothrow ~this() {} } static struct SH { SX sx; SY sy; pure ~this() {} } static struct SI { SX sx; SY sy; ~this() {} } static assert(is( typeof(&check!S1) == void function() pure nothrow @nogc @safe )); static assert(is( typeof(&check!S2) == void function() )); static assert(is( typeof(&check!SA) == void function() pure nothrow @safe )); static assert(is( typeof(&check!SB) == void function() pure nothrow @safe )); static assert(is( typeof(&check!SC) == void function() nothrow @safe )); static assert(is( typeof(&check!SD) == void function() pure @safe )); static assert(is( typeof(&check!SE) == void function() pure nothrow )); static assert(is( typeof(&check!SF) == void function() @safe )); static assert(is( typeof(&check!SG) == void function() nothrow )); static assert(is( typeof(&check!SH) == void function() pure )); static assert(is( typeof(&check!SI) == void function() )); static struct S1x { SZ sz; } static struct S2x { ~this() {} SZ sz; } static struct SAx { SX sx; SY sy; SZ sz; } static struct SBx { SX sx; SY sy; pure nothrow @safe ~this() {} SZ sz; } static struct SCx { SX sx; SY sy; nothrow @safe ~this() {} SZ sz; } static struct SDx { SX sx; SY sy; pure @safe ~this() {} SZ sz; } static struct SEx { SX sx; SY sy; pure nothrow ~this() {} SZ sz; } static struct SFx { SX sx; SY sy; @safe ~this() {} SZ sz; } static struct SGx { SX sx; SY sy; nothrow ~this() {} SZ sz; } static struct SHx { SX sx; SY sy; pure ~this() {} SZ sz; } static struct SIx { SX sx; SY sy; ~this() {} SZ sz; } foreach (Sx; TypeTuple!(S1x, S2x, SAx, SBx, SCx, SDx, SEx, SFx, SGx, SHx, SIx)) { static assert(!__traits(compiles, &check!Sx)); } } void test10055b() { static struct SX { pure nothrow @safe this(this) {} } static struct SY { pure nothrow @safe this(this) {} } static struct SZ { @disable this(this) {} } // function to check merge result of the postblit attributes static void check(S)() { S s; S s2 = s; } static struct S1 { } static struct S2 { this(this) {} } static struct SA { SX sx; SY sy; } static struct SB { SX sx; SY sy; pure nothrow @safe this(this) {} } static struct SC { SX sx; SY sy; nothrow @safe this(this) {} } static struct SD { SX sx; SY sy; pure @safe this(this) {} } static struct SE { SX sx; SY sy; pure nothrow this(this) {} } static struct SF { SX sx; SY sy; @safe this(this) {} } static struct SG { SX sx; SY sy; nothrow this(this) {} } static struct SH { SX sx; SY sy; pure this(this) {} } static struct SI { SX sx; SY sy; this(this) {} } static assert(is( typeof(&check!S1) == void function() pure nothrow @nogc @safe )); static assert(is( typeof(&check!S2) == void function() )); static assert(is( typeof(&check!SA) == void function() pure nothrow @safe )); static assert(is( typeof(&check!SB) == void function() pure nothrow @safe )); static assert(is( typeof(&check!SC) == void function() nothrow @safe )); static assert(is( typeof(&check!SD) == void function() pure @safe )); static assert(is( typeof(&check!SE) == void function() pure nothrow )); static assert(is( typeof(&check!SF) == void function() @safe )); static assert(is( typeof(&check!SG) == void function() nothrow )); static assert(is( typeof(&check!SH) == void function() pure )); static assert(is( typeof(&check!SI) == void function() )); static struct S1x { SZ sz; } static struct S2x { this(this) {} SZ sz; } static struct SAx { SX sx; SY sy; SZ sz; } static struct SBx { SX sx; SY sy; pure nothrow @safe this(this) {} SZ sz; } static struct SCx { SX sx; SY sy; nothrow @safe this(this) {} SZ sz; } static struct SDx { SX sx; SY sy; pure @safe this(this) {} SZ sz; } static struct SEx { SX sx; SY sy; pure nothrow this(this) {} SZ sz; } static struct SFx { SX sx; SY sy; @safe this(this) {} SZ sz; } static struct SGx { SX sx; SY sy; nothrow this(this) {} SZ sz; } static struct SHx { SX sx; SY sy; pure this(this) {} SZ sz; } static struct SIx { SX sx; SY sy; this(this) {} SZ sz; } foreach (Sx; TypeTuple!(S1x, S2x, SAx, SBx, SCx, SDx, SEx, SFx, SGx, SHx, SIx)) { static assert(!__traits(compiles, &check!Sx)); } } /**********************************/ // 10160 struct S10160 { this(this) {} } struct X10160a { S10160 s; const int x; } struct X10160b { S10160 s; enum int x = 1; } void test10160() { X10160a xa; X10160b xb; } /**********************************/ // 10094 void test10094() { static void* p; const string[4] i2s = () { string[4] tmp; p = &tmp[0]; for (int i = 0; i < 4; ++i) { char[1] buf = [cast(char)('0' + i)]; string str = buf.idup; tmp[i] = str; } return tmp; // NRVO should work }(); assert(p == cast(void*)&i2s[0]); assert(i2s == ["0", "1", "2", "3"]); } /**********************************/ // 10079 // dtor || postblit struct S10079a { this(this) pure nothrow @safe {} } struct S10079b { ~this() pure nothrow @safe {} } struct S10079c { this(this) pure nothrow @safe {} ~this() pure nothrow @safe {} } struct S10079d { this(this) {} } struct S10079e { this(this) {} ~this() pure nothrow @safe {} } // memberwise struct S10079f { S10079a a; S10079b b; S10079c c; S10079d d; S10079e e; } void check10079(S)(ref S s) pure nothrow @safe { s = S(); } // Assignment is pure, nothrow, and @safe in all cases. static assert(__traits(compiles, &check10079!S10079a)); static assert(__traits(compiles, &check10079!S10079b)); static assert(__traits(compiles, &check10079!S10079c)); static assert(__traits(compiles, &check10079!S10079d)); static assert(__traits(compiles, &check10079!S10079e)); static assert(__traits(compiles, &check10079!S10079f)); /**********************************/ // 10244 void test10244() { static struct Foo { string _str; long _num; template DeclareConstructor(string fieldName) { enum code = `this(typeof(_` ~ fieldName ~ `) value)` ~ `{ this._` ~ fieldName ~ ` = value; }`; mixin(code); } mixin DeclareConstructor!"str"; mixin DeclareConstructor!"num"; } Foo value1 = Foo("D"); Foo value2 = Foo(128); assert(value1._str == "D"); assert(value2._num == 128); } /**********************************/ // 10694 struct Foo10694 { ~this() { } } void test10694() pure { static Foo10694 i1; __gshared Foo10694 i2; void foo() pure { static Foo10694 j1; __gshared Foo10694 j2; } } /**********************************/ // 10787 int global10787; static ~this() nothrow pure @safe { int* p; static assert(!__traits(compiles, ++p)); static assert(!__traits(compiles, ++global10787)); } shared static ~this() nothrow pure @safe { int* p; static assert(!__traits(compiles, ++p)); static assert(!__traits(compiles, ++global10787)); } /**********************************/ // 10789 struct S10789 { static int count; int value; this(int) { value = ++count; } ~this() { --count; } this(this) { value = ++count; assert(value == 3); } } S10789 fun10789a(bool isCondExp)(bool cond) { S10789 s1 = S10789(42), s2 = S10789(24); assert(S10789.count == 2); static if (isCondExp) { return cond ? s1 : s2; } else { if (cond) return s1; else return s2; } } auto fun10789b(bool isCondExp)(bool cond) { S10789 s1 = S10789(42), s2 = S10789(24); assert(S10789.count == 2); static if (isCondExp) { return cond ? s1 : s2; } else { if (cond) return s1; else return s2; } } void test10789() { foreach (fun; TypeTuple!(fun10789a, fun10789b)) foreach (isCondExp; TypeTuple!(false, true)) { { S10789 s = fun!isCondExp(true); assert(S10789.count == 1); assert(s.value == 3); } assert(S10789.count == 0); { S10789 s = fun!isCondExp(false); assert(S10789.count == 1); assert(s.value == 3); } assert(S10789.count == 0); } } /**********************************/ // 10972 int test10972() { string result; struct A { this(this) { result ~= "pA"; version(none) printf("copied A\n"); } ~this() { result ~= "dA"; version(none) printf("destroy A\n"); } } struct B { this(this) { result ~= "(pB)"; version(none) printf("B says what?\n"); throw new Exception("BOOM!"); } ~this() { result ~= "dB"; version(none) printf("destroy B\n"); } } struct S { A a; B b; } result = "{"; { S s1; result ~= "["; try { S s3 = s1; assert(0); } catch (Exception e) {} result ~= "]"; } result ~= "}"; assert(result == "{[pA(pB)dA]dBdA}", result); result = "{"; { S s1; S s2; result ~= "["; try { s2 = s1; assert(0); } catch (Exception e) {} result ~= "]"; } result ~= "}"; assert(result == "{[pA(pB)dA]dBdAdBdA}", result); return 1; } static assert(test10972()); // CTFE /**********************************/ // 11134 void test11134() { void test(S)() { S s; S[2] sa; S[2][] dsa = [[S(), S()]]; dsa.reserve(dsa.length + 2); // avoid postblit calls by GC S.count = 0; dsa ~= sa; assert(S.count == 2); S.count = 0; dsa ~= [s, s]; assert(S.count == 2); } static struct SS { static int count; this(this) { ++count; } } test!SS(); struct NS { static int count; this(this) { ++count; } } test!NS(); } /**********************************/ // 11197 struct S11197a { this(bool) {} this(this) {} } struct S11197b { //this(bool) {} this(this) {} } void test11197() { S11197a[][string] aa1; aa1["test"] ~= S11197a.init; S11197b[][string] aa2; aa2["test"] ~= S11197b.init; } /**********************************/ struct S7474 { float x; ~this() {} } void fun7474(T...)() { T x; } void test7474() { fun7474!S7474(); } /**********************************/ // 11286 struct A11286 { ~this() {} } A11286 getA11286() pure nothrow { return A11286(); } void test11286() { A11286 a = getA11286(); } /**********************************/ // 11505 struct Foo11505 { Bar11505 b; } struct Bar11505 { ~this() @safe { } void* p; } void test11505() { Foo11505 f; f = Foo11505(); } /**********************************/ // 12045 bool test12045() { string dtor; void* ptr; struct S12045 { string val; this(this) { assert(0); } ~this() { dtor ~= val; } } auto makeS12045(bool thrown) { auto s1 = S12045("1"); auto s2 = S12045("2"); ptr = &s1; if (thrown) throw new Exception(""); return s1; // NRVO } dtor = null, ptr = null; try { S12045 s = makeS12045(true); assert(0); } catch (Exception e) { assert(dtor == "21", dtor); } dtor = null, ptr = null; { S12045 s = makeS12045(false); assert(dtor == "2"); if (!__ctfe) assert(ptr is &s); // NRVO } assert(dtor == "21"); return true; } static assert(test12045()); /**********************************/ // 12591 struct S12591(T) { this(this) {} } struct Tuple12591(Types...) { Types expand; this(Types values) { expand[] = values[]; } } void test12591() { alias T1 = Tuple12591!(S12591!int); } /**********************************/ // 12660 struct X12660 { this(this) @nogc {} ~this() @nogc {} void opAssign(X12660) @nogc {} @nogc invariant() {} } struct Y12660 { X12660 x; this(this) @nogc {} ~this() @nogc {} @nogc invariant() {} } struct Z12660 { Y12660 y; } class C12660 { this() @nogc {} @nogc invariant() {} } void test12660() @nogc { X12660 x; x = x; Y12660 y = { x }; y = y; Z12660 z = { y }; z = z; } /**********************************/ // 12686 struct Foo12686 { static int count; invariant() { ++count; } @disable this(this); Foo12686 bar() { Foo12686 f; return f; } } void test12686() { Foo12686 f; Foo12686 f2 = f.bar(); version (unittest) { } else assert(Foo12686.count == 2); } /**********************************/ // 13089 struct S13089 { @disable this(this); // non nothrow } void* p13089; S13089[1000] foo13089() nothrow { typeof(return) data; p13089 = &data; return data; } void test13089() nothrow { immutable data = foo13089(); assert(p13089 == &data); } /**********************************/ struct NoDtortest11763 {} struct HasDtortest11763 { NoDtortest11763 func() { return NoDtortest11763(); } ~this() {} } void test11763() { HasDtortest11763().func(); } /**********************************/ struct Buf { } struct Variant { ~this() { } Buf get() { Buf b; return b; } } Variant value() { Variant v; return v; } void test13303() { value.get(); } /**********************************/ struct S13673 { string _name; ~this() {} } string name13673; void test13673() { S13673(name13673); S13673(name13673); } /**********************************/ void test13586() { static struct S { __gshared int count; ~this() { ++count; printf("~S\n"); } } static struct T { __gshared int count; ~this() { ++count; printf("~T\n"); } } static int foo(bool flag) { if (flag) throw new Exception("hello"); return 1; } static void func(S s, int f, T t) { printf("func()\n"); } static class C { this(S s, int f, T t) { printf("C()\n"); } } { bool threw = false; try { func(S(), foo(true), T()); printf("not reach\n"); } catch (Exception e) { threw = true; } printf("threw %d S %d T %d\n", threw, S.count, T.count); assert(threw && S.count == 1 && T.count == 0); S.count = 0; T.count = 0; } { bool threw = false; try { func(S(), foo(false), T()); printf("reached\n"); } catch (Exception e) { threw = true; } printf("threw %d S %d T %d\n", threw, S.count, T.count); assert(!threw && S.count == 1 && T.count == 1); S.count = 0; T.count = 0; } { bool threw = false; try { new C(S(), foo(true), T()); printf("not reach\n"); } catch (Exception e) { threw = true; } printf("threw %d S %d T %d\n", threw, S.count, T.count); assert(threw && S.count == 1 && T.count == 0); S.count = 0; T.count = 0; } } /**********************************/ // 14443 T enforce14443(E : Throwable = Exception, T)(T value) { if (!value) throw new E("Enforcement failed"); return value; } struct RefCounted14443(T) if (!is(T == class) && !(is(T == interface))) { struct RefCountedStore { private struct Impl { T _payload; size_t _count; } private Impl* _store; private void initialize(A...)(auto ref A args) { import core.stdc.stdlib : malloc; // enforce is necessary _store = cast(Impl*) enforce14443(malloc(Impl.sizeof)); // emulate 'emplace' static if (args.length > 0) _store._payload.tupleof = args; else _store._payload = T.init; _store._count = 1; } @property bool isInitialized() const nothrow @safe { return _store !is null; } void ensureInitialized() { if (!isInitialized) initialize(); } } RefCountedStore _refCounted; this(A...)(auto ref A args) if (A.length > 0) { _refCounted.initialize(args); } this(this) { if (!_refCounted.isInitialized) return; ++_refCounted._store._count; //printf("RefCounted count = %d (inc)\n", _refCounted._store._count); } ~this() { if (!_refCounted.isInitialized) return; assert(_refCounted._store._count > 0); if (--_refCounted._store._count) { //printf("RefCounted count = %u\n", _refCounted._store._count); return; } import core.stdc.stdlib : free; free(_refCounted._store); _refCounted._store = null; } void opAssign(typeof(this) rhs) { assert(0); } void opAssign(T rhs) { assert(0); } @property ref T refCountedPayload() { _refCounted.ensureInitialized(); return _refCounted._store._payload; } alias refCountedPayload this; } struct Path14443 { struct Payload { int p; } RefCounted14443!Payload data; } struct PathRange14443 { Path14443 path; size_t i; @property PathElement14443 front() { return PathElement14443(this, path.data.p); } } struct PathElement14443 { PathRange14443 range; this(PathRange14443 range, int) { this.range = range; } } void test14443() { auto path = Path14443(RefCounted14443!(Path14443.Payload)(12)); assert(path.data.p == 12); @property refCount() { return path.data._refCounted._store._count; } assert(refCount == 1); { auto _r = PathRange14443(path); assert(refCount == 2); // foreach { auto element = _r.front; assert(refCount == 3); // fail with 2.067 } assert(refCount == 2); } assert(refCount == 1); } /**********************************/ // 13661, 14022, 14023 - postblit/dtor call on static array assignment bool test13661() { string op; struct S { char x = 'x'; this(this) { op ~= x-0x20; } // upper case ~this() { op ~= x; } // lower case ref auto opAssign(T)(T arg) { assert(0); return this; } } { S[2] a; a[0].x = 'a'; a[1].x = 'b'; a = a.init; assert(op == "ab"); assert(a[0].x == 'x' && a[1].x == 'x'); a[0].x = 'c'; a[1].x = 'd'; a = [S(), S()]; // equivalent a = a.init assert(op == "abcd"); assert(a[0].x == 'x' && a[1].x == 'x'); } assert(op == "abcdxx"); return true; } bool test13661a() { string op; struct S { char x = 'x'; this(this) { op ~= x-0x20; } // upper case ~this() { op ~= x; } // lower case } { S[3] sa = [S('a'), S('b'), S('c')]; S[2] sb = sa[1..3]; assert(sa == [S('a'), S('b'), S('c')]); assert(sb == [S('b'), S('c')]); sb[0].x = 'x'; sb[1].x = 'y'; assert(sa != [S('a'), S('x'), S('y')]); // OK <- incorrectly fails assert(sa == [S('a'), S('b'), S('c')]); // OK <- incorrectly fails assert(sb == [S('x'), S('y')]); } return true; } static assert(test13661()); // CTFE static assert(test13661a()); bool test14022() { string op; struct S { char x = 'x'; this(this) { op ~= x-0x20; } // upper case ~this() { op ~= x; } // lower case } S[2] makeSA() { return [S('p'), S('q')]; } struct T { S[2] sb; this(ref S[2] sa) { assert(op == ""); this.sb = sa; // TOKconstruct assert(op == "BC", op); assert(sb == [S('b'), S('c')]); } void test(ref S[2] sa) { this.sb = sa; // dotvar: resolveSlice(newva) assert(op == "BxCy"); } } op = null; { S[2] sa = [S('a'), S('b')]; T t; t.sb[0].x = 'x'; t.sb[1].x = 'y'; assert(op == ""); t.sb = sa; assert(op == "AxBy"); t.sb = makeSA(); assert(op == "AxByab"); } assert(op == "AxByabqpba"); op = null; { S[3] sa = [S('a'), S('b'), S('c')]; T t = T(sa[1..3]); t.sb[0].x = 'x'; t.sb[1].x = 'y'; assert(sa == [S('a'), S('b'), S('c')]); assert(t.sb == [S('x'), S('y')]); assert(op == "BC"); } assert(op == "BCyxcba"); op = null; { S[3] sx = [S('a'), S('b'), S('c')]; T t; t.sb[0].x = 'x'; t.sb[1].x = 'y'; t.test(sx[1..3]); assert(op == "BxCy"); assert(t.sb == [S('b'), S('c')]); } assert(op == "BxCycbcba"); return true; } static assert(test14022()); bool test14023() { string op; struct S { char x = 'x'; this(this) { op ~= x-0x20; } // upper case ~this() { op ~= x; } // lower case } S[2] makeSA() { return [S('p'), S('q')]; } struct T { S[2][1] sb; this(ref S[2] sa) { assert(op == ""); this.sb[0] = sa; // TOKconstruct assert(sa == [S('b'), S('c')]); assert(sb[0] == [S('b'), S('c')]); } } void test(ref S[2] sa) { S[2][] a; //a.length = 1; // will cause runtine AccessViolation a ~= (S[2]).init; assert(op == ""); a[0] = sa; // index <-- resolveSlice(newva) assert(op == "BxCx"); assert(a[0] == [S('b'), S('c')]); } op = null; { S[3] sa = [S('a'), S('b'), S('c')]; T t = T(sa[1..3]); t.sb[0][0].x = 'x'; t.sb[0][1].x = 'y'; assert(sa != [S('a'), S('x'), S('y')]); // OK <- incorrectly fails assert(sa == [S('a'), S('b'), S('c')]); // OK <- incorrectly fails assert(t.sb[0] == [S('x'), S('y')]); } op = null; { S[2] sa = [S('a'), S('b')]; S[2][] a = [[S('x'), S('y')]]; assert(op == ""); a[0] = sa; assert(op == "AxBy"); a[0] = makeSA(); assert(op == "AxByab"); } assert(op == "AxByabba"); op = null; { S[3] sa = [S('a'), S('b'), S('c')]; test(sa[1..3]); assert(op == "BxCx"); } assert(op == "BxCxcba"); return true; } static assert(test14023()); /************************************************/ // 13669 - dtor call on static array variable bool test13669() { string dtor; struct S { char x = 'x'; ~this() { dtor ~= x; } } { S[2] a; } assert(dtor == "xx"); dtor = ""; { S[2] a = [S('a'), S('b')]; } assert(dtor == "ba"); // reverse order. See also: TypeInfo_StaticArray.destroy() return true; } static assert(test13669()); /**********************************/ __gshared bool b13095 = false; void bar13095() { throw new Exception(""); } struct S13095 { this(int) { printf("ctor %p\n", &this); bar13095(); } ~this() { b13095 = true; printf("dtor %p\n", &this); } } void test13095() { try { S13095(0); } catch(Exception) { printf("catch\n"); } assert(!b13095); } /**********************************/ // 14264 void test14264() { static int dtor; static struct Foo { ~this() { ++dtor; } T opCast(T:bool)() { return true; } } Foo makeFoo() { return Foo(); } assert(dtor == 0); makeFoo(); assert(dtor == 1); makeFoo; assert(dtor == 2); if (makeFoo()) {} assert(dtor == 3); if (makeFoo) {} assert(dtor == 4); } /**********************************/ // 14696 void test14696(int len = 2) { string result; struct S { int n; void* get(void* p = null) { result ~= "get(" ~ cast(char)(n+'0') ~ ")."; return null; } ~this() { result ~= "dtor(" ~ cast(char)(n+'0') ~ ")."; } } S makeS(int n) { result ~= "makeS(" ~ cast(char)(n+'0') ~ ")."; return S(n); } void foo(void* x, void* y = null) { result ~= "foo."; } void fooThrow(void* x, void* y = null) { result ~= "fooThrow."; throw new Exception("fail!"); } void check(void delegate() dg, string r, string file = __FILE__, size_t line = __LINE__) { import core.exception; result = null; try { dg(); } catch (Exception e) {} if (result != r) throw new AssertError(result, file, line); } // temporary in condition check({ foo(len == 2 ? makeS(1).get() : null); }, "makeS(1).get(1).foo.dtor(1)."); check({ foo(len == 2 ? null : makeS(1).get() ); }, "foo."); check({ foo(len != 2 ? makeS(1).get() : null); }, "foo."); check({ foo(len != 2 ? null : makeS(1).get() ); }, "makeS(1).get(1).foo.dtor(1)."); // temporary in nesting conditions check({ foo(len >= 2 ? (len == 2 ? makeS(1).get() : null) : null); }, "makeS(1).get(1).foo.dtor(1)."); check({ foo(len >= 2 ? (len == 2 ? null : makeS(1).get() ) : null); }, "foo."); check({ foo(len >= 2 ? (len != 2 ? makeS(1).get() : null) : null); }, "foo."); check({ foo(len >= 2 ? (len != 2 ? null : makeS(1).get() ) : null); }, "makeS(1).get(1).foo.dtor(1)."); check({ foo(len >= 2 ? null : (len == 2 ? makeS(1).get() : null) ); }, "foo."); check({ foo(len >= 2 ? null : (len == 2 ? null : makeS(1).get() ) ); }, "foo."); check({ foo(len >= 2 ? null : (len != 2 ? makeS(1).get() : null) ); }, "foo."); check({ foo(len >= 2 ? null : (len != 2 ? null : makeS(1).get() ) ); }, "foo."); check({ foo(len > 2 ? (len == 2 ? makeS(1).get() : null) : null); }, "foo."); check({ foo(len > 2 ? (len == 2 ? null : makeS(1).get() ) : null); }, "foo."); check({ foo(len > 2 ? (len != 2 ? makeS(1).get() : null) : null); }, "foo."); check({ foo(len > 2 ? (len != 2 ? null : makeS(1).get() ) : null); }, "foo."); check({ foo(len > 2 ? null : (len == 2 ? makeS(1).get() : null) ); }, "makeS(1).get(1).foo.dtor(1)."); check({ foo(len > 2 ? null : (len == 2 ? null : makeS(1).get() ) ); }, "foo."); check({ foo(len > 2 ? null : (len != 2 ? makeS(1).get() : null) ); }, "foo."); check({ foo(len > 2 ? null : (len != 2 ? null : makeS(1).get() ) ); }, "makeS(1).get(1).foo.dtor(1)."); // temporary in condition and throwing callee // check({ fooThrow(len == 2 ? makeS(1).get() : null); }, "makeS(1).get(1).fooThrow.dtor(1)."); // check({ fooThrow(len == 2 ? null : makeS(1).get() ); }, "fooThrow."); // check({ fooThrow(len != 2 ? makeS(1).get() : null); }, "fooThrow."); // check({ fooThrow(len != 2 ? null : makeS(1).get() ); }, "makeS(1).get(1).fooThrow.dtor(1)."); // temporary in nesting condititions and throwing callee // check({ fooThrow(len >= 2 ? (len == 2 ? makeS(1).get() : null) : null); }, "makeS(1).get(1).fooThrow.dtor(1)."); // check({ fooThrow(len >= 2 ? (len == 2 ? null : makeS(1).get() ) : null); }, "fooThrow."); // check({ fooThrow(len >= 2 ? (len != 2 ? makeS(1).get() : null) : null); }, "fooThrow."); // check({ fooThrow(len >= 2 ? (len != 2 ? null : makeS(1).get() ) : null); }, "makeS(1).get(1).fooThrow.dtor(1)."); // check({ fooThrow(len >= 2 ? null : (len == 2 ? makeS(1).get() : null) ); }, "fooThrow."); // check({ fooThrow(len >= 2 ? null : (len == 2 ? null : makeS(1).get() ) ); }, "fooThrow."); // check({ fooThrow(len >= 2 ? null : (len != 2 ? makeS(1).get() : null) ); }, "fooThrow."); // check({ fooThrow(len >= 2 ? null : (len != 2 ? null : makeS(1).get() ) ); }, "fooThrow."); // check({ fooThrow(len > 2 ? (len == 2 ? makeS(1).get() : null) : null); }, "fooThrow."); // check({ fooThrow(len > 2 ? (len == 2 ? null : makeS(1).get() ) : null); }, "fooThrow."); // check({ fooThrow(len > 2 ? (len != 2 ? makeS(1).get() : null) : null); }, "fooThrow."); // check({ fooThrow(len > 2 ? (len != 2 ? null : makeS(1).get() ) : null); }, "fooThrow."); // check({ fooThrow(len > 2 ? null : (len == 2 ? makeS(1).get() : null) ); }, "makeS(1).get(1).fooThrow.dtor(1)."); // check({ fooThrow(len > 2 ? null : (len == 2 ? null : makeS(1).get() ) ); }, "fooThrow."); // check({ fooThrow(len > 2 ? null : (len != 2 ? makeS(1).get() : null) ); }, "fooThrow."); // check({ fooThrow(len > 2 ? null : (len != 2 ? null : makeS(1).get() ) ); }, "makeS(1).get(1).fooThrow.dtor(1)."); // temporaries in each conditions check({ foo(len == 2 ? makeS(1).get() : null, len == 2 ? makeS(2).get() : null); }, "makeS(1).get(1).makeS(2).get(2).foo.dtor(2).dtor(1)."); check({ foo(len == 2 ? makeS(1).get() : null, len != 2 ? makeS(2).get() : null); }, "makeS(1).get(1).foo.dtor(1)."); check({ foo(len != 2 ? makeS(1).get() : null, len == 2 ? makeS(2).get() : null); }, "makeS(2).get(2).foo.dtor(2)."); check({ foo(len != 2 ? makeS(1).get() : null, len != 2 ? makeS(2).get() : null); }, "foo."); // nesting temporaries in conditions check({ foo(len == 2 ? makeS(1).get(len == 2 ? makeS(2).get() : null) : null); }, "makeS(1).makeS(2).get(2).get(1).foo.dtor(2).dtor(1)."); check({ foo(len == 2 ? makeS(1).get(len != 2 ? makeS(2).get() : null) : null); }, "makeS(1).get(1).foo.dtor(1)."); check({ foo(len != 2 ? makeS(1).get(len == 2 ? makeS(2).get() : null) : null); }, "foo."); check({ foo(len != 2 ? makeS(1).get(len != 2 ? makeS(2).get() : null) : null); }, "foo."); } // 14838 int test14838() pure nothrow @safe { int dtor; struct S14838(T) { ~this() { ++dtor; } } struct X14838 { S14838!int ms; const S14838!int cs; S14838!int[2] ma; const S14838!int[2] ca; S14838!int[2][2] ma2x2; const S14838!int[2][2] ca2x2; // number of S14838 = 1*2 + 2*2 + 4*2 = 14 } void test(Dg)(scope Dg code) { dtor = 0; code(); } test(delegate{ S14838!int a; }); assert(dtor == 1); test(delegate{ const S14838!int a; }); assert(dtor == 1); test(delegate{ S14838!int[2] a; }); assert(dtor == 2); test(delegate{ const S14838!int[2] a; }); assert(dtor == 2); test(delegate{ S14838!int[2][2] a; }); assert(dtor == 4); test(delegate{ const S14838!int[2][2] a; }); assert(dtor == 4); test(delegate{ X14838 a; }); assert(dtor == 1 * 14); test(delegate{ const X14838 a; }); assert(dtor == 1 * 14); test(delegate{ X14838[2] a; }); assert(dtor == 2 * 14); test(delegate{ const X14838[2] a; }); assert(dtor == 2 * 14); test(delegate{ X14838[2][2] a; }); assert(dtor == 4 * 14); test(delegate{ const X14838[2][2] a; }); assert(dtor == 4 * 14); return 1; } static assert(test14838()); /**********************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); test28(); test29(); test30(); test31(); test32(); test33(); test34(); test35(); test36(); test37(); test38(); test39(); test40(); test41(); test42(); test43(); test44(); test45(); test46(); test47(); test48(); test49(); test50(); test51(); test52(); test54(); test55(); test56(); test57(); test58(); test59(); test5737(); test6119(); test8741(); test6364(); test6499(); test60(); test4316(); test6177(); test6470(); test6636(); test6637(); test7353(); test61(); test7506(); test7530(); test62(); test7579a(); test7579b(); test8335(); test8356(); test9386(); test9441(); test9720(); test9899(); test9907(); test9985(); test9994(); test10094(); test10244(); test10694(); test10789(); test10972(); test11134(); test11197(); test7474(); test11505(); test12045(); test12591(); test12660(); test12686(); test13089(); test11763(); test13303(); test13673(); test13586(); test14443(); test13661(); test13661a(); test14022(); test14023(); test13669(); test13095(); test14264(); test14696(); test14838(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/integrate.d0000644000175000017500000001017213200164642023537 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: // NOTE: the shootout is under a BSD license // The Great Computer Language Shootout // http://shootout.alioth.debian.org/ // // contributed by Sebastien Loisel import std.math, std.stdio, std.string, std.conv; alias fl F; struct fl { double a; static fl opCall() { fl f; f.a = 0; return f; } static fl opCall(fl v) { fl f; f.a = v.a; return f; } void set(double x) { if(x==0) { a=0; return; } int k=cast(int)log(fabs(x)); a=round(x*exp(-k+6.0))*exp(k-6.0); } static fl opCall(int x) { fl f; f.set(x); return f; } static fl opCall(double x) { fl f; f.set(x); return f; } fl opAdd(fl y) { return fl(a+y.a); } fl opAddAssign(fl y) { this=(this)+y; return this; } fl opSub(fl y) { return fl(a-y.a); } fl opSubAssign(fl y) { this=(this)-y; return this; } fl opMul(fl y) { return fl(a*y.a); } fl opDiv(fl y) { return fl(a/y.a); } fl opAdd(int y) { return fl(a+y); } fl opSub(int y) { return fl(a-y); } fl opMul(int y) { return fl(a*y); } fl opDiv(int y) { return fl(a/y); } fl opAdd(double y) { return fl(a+y); } fl opSub(double y) { return fl(a-y); } fl opMul(double y) { return fl(a*y); } fl opDiv(double y) { return fl(a/y); } } struct ad { F x, dx; static ad opCall() { ad t; t.x = F(0); t.dx = F(0); return t; } static ad opCall(int y) { ad t; t.x = F(y); t.dx = F(0); return t; } static ad opCall(F y) { ad t; t.x = y; t.dx = F(0); return t; } static ad opCall(F X, F DX) { ad t; t.x = X; t.dx = DX; return t; } ad opAdd(ad y) { return ad(x+y.x,dx+y.dx); } ad opSub(ad y) { return ad(x-y.x,dx-y.dx); } ad opMul(ad y) { return ad(x*y.x,dx*y.x+x*y.dx); } ad opDiv(ad y) { return ad(x/y.x,(dx*y.x-x*y.dx)/(y.x*y.x)); } ad opMul(F v) { return ad(x*v,dx*v); } ad opAdd(F v) { return ad(x+v,dx); } } F sqr(F x) { return x * x; } ad sqr(ad x) { return x * x; } F pow(F x, int i) { if(i < 1) return F(1); if(i & 1) if(i == 1) return x; else return x * pow(x,i-1); return sqr(pow(x,i/2)); } ad pow(ad x, int i) { if(i < 1) return ad(1); if(i & 1) if(i == 1) return x; else return x * pow(x,i-1); return sqr(pow(x,i/2)); } F rat(F x) { F t = (x * F(2) + pow(x,2) * F(3) + pow(x,6) * F(7) + pow(x,11) * F(5) + F(1)) / (x * F(5) - pow(x,3) * F(6) - pow(x,7) * F(3) + F(2)); return t; } ad rat(ad x) { ad t = (x * ad(2) + pow(x,2) * ad(3) + pow(x,6) * ad(7) + pow(x,11) * ad(5) + ad(1)) / (x * ad(5) - pow(x,3) * ad(6) - pow(x,7) * ad(3) + ad(2)); return t; } F newton(F x0, int n, trapezoid_method_rooter g) { for(int i=0 ; i 1 ? to!int(args[1]) : 50; integrate_functions(F(0.02),N); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/gdb14313.d0000644000175000017500000000036513200164642022710 0ustar matthiasmatthias/* REQUIRED_ARGS: -g PERMUTE_ARGS: GDB_SCRIPT: --- b 21 r echo RESULT= p 'gdb.x' + 'gdb.y' --- GDB_MATCH: RESULT=.*4000065002 */ module gdb; __gshared uint x = 4_000_000_000; __gshared ushort y = 65000; void main() { ++x; ++y; // BP } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_1141.d0000644000175000017500000000030113200164642024320 0ustar matthiasmatthiasclass DClass { int a = 1; } extern (C++) class CppClass { int a = 1; } void main() { auto d = new DClass(); auto cpp = new CppClass(); assert(d.a == 1); assert(cpp.a == 1); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/variadic.d0000644000175000017500000004374213200164642023350 0ustar matthiasmatthiasalias TypeTuple(T...) = T; class A { } class B : A { } class C : B { } /***************************************/ template Foo(int a, int b, int c) { const int Foo = 1; } template Foo(A...) { const int Foo = 2; } void test1() { int y = Foo!(1,2,3); assert(y == 1); y = Foo!(1,2); assert(y == 2); y = Foo!(1,2,3,4); assert(y == 2); } /***************************************/ template Foo2(int a, int b, int c) { const int Foo2 = 1; } template Foo2(int a, int b, int c, A...) { const int Foo2 = 2; } void test2() { int y = Foo2!(1,2,3); assert(y == 1); y = Foo2!(1,2,3,4); assert(y == 2); } /***************************************/ void bar3(int x, int y) { assert(x == 2); assert(y == 3); } template Foo3(T, A...) { int Foo3(T t, A a) { assert(A.length == 2); assert(a.length == 2); bar3(a); assert([a] == [2, 3]); assert([cast(double)a] == [2.0, 3.0]); assert(a[0] == 2); assert(a[1] == 3); assert(a[$ - 2] == 2); assert(a[$ - 1] == 3); static if (1 || a[6]) assert(1); assert([a[]] == [2, 3]); assert([a[0 .. $]] == [2, 3]); assert([a[0 .. $ - 1]] == [2]); return 3; } } void test3() { int y = Foo3(1,2,3); assert(y == 3); } /***************************************/ void foo4(A...)() { int[] ai; int[] aa; aa = null; foreach (a; A) { aa ~= a; } assert(aa == [7,4,9]); aa = null; foreach (int a; A) { aa ~= a; } assert(aa == [7,4,9]); ai = null; aa = null; foreach (int i, a; A) { ai ~= i; aa ~= a; } assert(ai == [0,1,2]); assert(aa == [7,4,9]); ai = null; aa = null; foreach_reverse (uint i, a; A) { ai ~= i; aa ~= a; } assert(ai == [2,1,0]); assert(aa == [9,4,7]); ai = null; aa = null; foreach_reverse (i, a; A) { ai ~= i; aa ~= a; } assert(ai == [2,1,0]); assert(aa == [9,4,7]); ai = null; aa = null; foreach (int i, a; A) { ai ~= i; aa ~= a; if (i == 1) break; continue; } assert(ai == [0,1]); assert(aa == [7,4]); } void test4() { foo4!(7,4,9)(); } /***************************************/ int a12(TypeTuple!(int, int) t) { return t[0] + t[1]; } int b12(TypeTuple!(TypeTuple!(int), TypeTuple!(int)) t) { return t[0] + t[1]; } int c12(TypeTuple!(TypeTuple!(int), TypeTuple!(TypeTuple!(), int), TypeTuple!()) t) { return t[0] + t[1]; } void test12() { assert(a12(1, 2) == 3); assert(b12(1, 2) == 3); assert(c12(1, 2) == 3); } /***************************************/ int plus13(TypeTuple!(int, long, float)[0 .. 2] t) { typeof(t)[0] e; assert(typeid(typeof(e)) == typeid(int)); typeof(t)[1] f; assert(typeid(typeof(f)) == typeid(long)); return t[0] + cast(int)t[1]; } void test13() { assert(plus13(5, 6) == 11); } /***************************************/ int plus14(TypeTuple!(int, long, float)[0 .. $ - 1] t) { typeof(t)[$ - 2] e; assert(typeid(typeof(e)) == typeid(int)); typeof(t)[1] f; assert(typeid(typeof(f)) == typeid(long)); return t[0] + cast(int)t[1]; } void test14() { assert(plus14(5, 6) == 11); } /***************************************/ void returnAndArgs(T, U...) (T delegate(U) dg) { static if (U.length == 0) assert(dg() == 0); else static if (U.length == 1) assert(dg(false) == 1); else assert(dg(false, 63L) == 2); } void test24() { returnAndArgs(delegate int(){ return 0; }); returnAndArgs(delegate int(bool b){ return 1; }); returnAndArgs(delegate int(bool b, long c){ return 2; }); } /***************************************/ void test28() { alias TypeTuple!(int, long, double) TL; foreach (int i, T; TL) { switch (i) { case 0: assert(is(T == int)); break; case 1: assert(is(T == long)); break; case 2: assert(is(T == double)); break; default:assert(0); } } } /***************************************/ template g32(alias B) { int g32 = 2; } int f32(A...)(A a) { return g32!(a); } void test32() { assert(f32(4) == 2); } /***************************************/ struct S34 { int x; long y; double z; } void foo34(int x, long y, double z) { assert(x == 3); assert(y == 8); assert(z == 6.8); } void test34() { S34 s; s.x = 3; s.y = 8; s.z = 6.8; foo34(s.tupleof); } /***************************************/ alias TypeTuple!(int, long, double) TL35; struct S35 { TL35 tl; } void foo35(int x, long y, double z) { assert(x == 3); assert(y == 8); assert(z == 6.8); } void test35() { S35 s; s.tl[0] = 3; s.tl[1] = 8; s.tl[2] = 6.8; foo35(s.tupleof); foo35(s.tl); } /***************************************/ alias TypeTuple!(int, long, double) TL36; class C36 { TL36 tl; } void foo36(int x, long y, double z) { assert(x == 3); assert(y == 8); assert(z == 6.8); } void test36() { C36 s = new C36; s.tl[0] = 3; s.tl[1] = 8; s.tl[2] = 6.8; foo36(s.tupleof); foo36(s.tl); } /***************************************/ alias TypeTuple!(int, long, double) TL37; class C37 { TL37 tl; } void foo37(int x, long y, double z) { assert(x == 3); assert(y == 8); assert(z == 6.8); } void test37() { C37 s = new C37; s.tl[0] = 3; s.tl[1] = 8; s.tl[2] = 6.8; foo37(s.tupleof); TL37 x; assert(x[0] == 0); x[0] = 3; assert(x[0] == 3); assert(x[1] == 0); x[1] = 8; x[2] = 6.8; foo37(x); } /***************************************/ interface I38A { } interface I38B { } alias TypeTuple!(I38A, I38B) IL38; class C38 : IL38 { } void test38() { auto c = new C38; } /***************************************/ void test39() { static const string a = "\x01"; static const char b = a[0]; static const string c = "test"; static assert(c[a[0]] == 'e'); alias TypeTuple!(ulong,uint,ushort,ubyte) tuple; static assert(is(tuple[1] == uint)); static assert(is(tuple[a[0]] == uint)); } /***************************************/ struct Foo45 { static TypeTuple!(int) selements1; TypeTuple!(int) elements1; static TypeTuple!() selements0; TypeTuple!() elements0; } void test45() { Foo45 foo; static assert(Foo45.selements1.length == 1); static assert(Foo45.elements1.length == 1); static assert(Foo45.selements0.length == 0); static assert(Foo45.elements0.length == 0); static assert(foo.selements1.length == 1); static assert(foo.elements1.length == 1); static assert(foo.selements0.length == 0); static assert(foo.elements0.length == 0); } /***************************************/ template Tuple46(E ...) { alias E Tuple46; } alias Tuple46!(float, float, 3) TP46; alias TP46[1..$] TQ46; void test46() { TQ46[0] f = TQ46[1]; assert(is(typeof(f) == float)); assert(f == 3); } /***************************************/ template Foo47(T, Args...) { void bar(Args args, T t) { } } void test47() { alias Foo47!(int) aFoo; } /***************************************/ template Tuple48(E...) { alias E Tuple48; } void VarArg48(T...)(T args) { } void test48() { VarArg48( ); VarArg48( Tuple48!(1,2,3) ); VarArg48( Tuple48!() ); } /***************************************/ alias TypeTuple!(int, long) TX49; void foo49(TX49 t) { TX49 s; s = t; assert(s[0] == 1); assert(s[1] == 2); } void test49() { foo49(1, 2); } /***************************************/ void foo51(U...)(int t, U u) { assert(t == 1); assert(u[0] == 2); assert(u[1] == 3); } void bar51(U...)(U u, int t) { assert(u[0] == 1); assert(u[1] == 2); assert(t == 3); } void abc51(U...)(int s, U u, int t) { assert(s == 1); assert(u[0] == 2); assert(u[1] == 3); assert(t == 4); } void test51() { foo51(1, 2, 3); bar51(1, 2, 3); bar51!(int, int)(1, 2, 3); abc51(1,2,3,4); } /***************************************/ string to55(U, V)(V s) { return "he"; } private S wyda(S, T...)(T args) { S result; foreach (i, arg; args) { result ~= to55!(S)(args[i]); } return result; } string giba(U...)(U args) { return wyda!(string, U)(args); } void test55() { assert(giba(42, ' ', 1.5, ": xyz") == "hehehehe"); } /***************************************/ private template implicitlyConverts(U, V) { enum bool implicitlyConverts = V.sizeof >= U.sizeof && is(typeof({U s; V t = s;}())); } T to56(T, S)(S s) if (!implicitlyConverts!(S, T) /*&& isSomeString!(T) && isSomeString!(S)*/) { return T.init; } void test56() { auto x = to56!(int)("4"); assert(x == 0); assert(!implicitlyConverts!(const(char)[], string)); assert(implicitlyConverts!(string, const(char)[])); } /***************************************/ struct A57(B...) {} void test57() { alias A57!(int, float) X; static if (!is(X Y == A57!(Z), Z...)) { static assert(false); } } /***************************************/ struct A58(B...) {} void test58() { alias A58!(int, float) X; static if (!is(X Y == A58!(Z), Z...)) { static assert(false); } } /***************************************/ struct Tuple59(T...) { T field; } template reduce(fun...) { alias Reduce!(fun).reduce reduce; } template Reduce(fun...) { Tuple59!(double, double) reduce(Range)(Range r) { typeof(Tuple59!(double,double).field)[0] y; typeof(typeof(return).field)[0] x; Tuple59!(double, double) s; return s; } } void test59() { double[] a = [ 3.0, 4, 7, 11, 3, 2, 5 ]; static double sum(double a, double b) {return a + b;} auto r = reduce!((a, b) { return a + b; }, (a, b) { return a + b; })(a); } /***************************************/ template tuple60(T...) { alias T tuple60; } template Foo60(S : void delegate(tuple60!(int))) {} template Foo60(S : void delegate(tuple60!(int, int))) {} alias Foo60!(void delegate(int)) Bar60; void test60() { } /***************************************/ template TypeTuple61(TList...){ alias TList TypeTuple61; } template List61(lst...) { alias lst list; } alias TypeTuple61!(List61!(void)) A61; alias TypeTuple61!(A61[0].list) B61; void test61() { } /***************************************/ template Tuple63(T...){ alias T Tuple63; } // Bugzilla 3336 static assert(!is(int[ Tuple63!(int, int) ])); void test63() { } /***************************************/ template Tuple1411(T ...) { alias T Tuple1411; } void test1411() { int delegate(ref Tuple1411!(int, char[], real)) dg; // (*) int f(ref int a, ref char[] b, ref real c) { return 77; } dg = &f; } /***************************************/ // Bugzilla 4444 void test4444() { alias TypeTuple!(1) index; auto arr = new int[4]; auto x = arr[index]; // error } /***************************************/ // 13864 struct Tuple13864(T...) { T expand; alias expand this; } auto tuple13864(T...)(T args) { return Tuple13864!T(args); } void test13864() { int[] x = [2,3,4]; auto y = x[tuple13864(0).expand]; assert(y == 2); } /***************************************/ // 4884 struct A4884(T...) { void foo(T) {} void bar(bool, T) {} } void test4884() { auto a1 = A4884!(int)(); auto a2 = A4884!(int, long)(); } /***************************************/ // 4920 struct Test4920(parameters_...) { alias parameters_ parameters; } void test4920() { Test4920!(10, 20, 30) test; static assert(typeof(test).parameters[1] == 20); // okay static assert( test .parameters[1] == 20); // (7) } /***************************************/ // 4940 template Tuple4940(T...) { alias T Tuple4940; } struct S4940 { Tuple4940!(int, int) x; this(int) { } } void test4940() { auto w = S4940(0).x; } //---- struct S4940add { string s; long x; } ref S4940add get4940add(ref S4940add s){ return s; } void test4940add() { S4940add s; get4940add(s).tupleof[1] = 20; assert(s.x == 20); } /***************************************/ // 6530 struct S6530 { int a, b, c; } struct HasPostblit6530 { this(this) {} // Bug goes away without this. } auto toRandomAccessTuple6530(T...)(T input, HasPostblit6530 hasPostblit) { return S6530(1, 2, 3); } void doStuff6530(T...)(T args) { HasPostblit6530 hasPostblit; // Bug goes away without the .tupleof. auto foo = toRandomAccessTuple6530(args, hasPostblit).tupleof; } void test6530() { doStuff6530(1, 2, 3); } /***************************************/ import core.stdc.stdarg; extern(C) void func9495(int a, string format, ...) { va_list ap; va_start(ap, format); auto a1 = va_arg!int(ap); auto a2 = va_arg!int(ap); auto a3 = va_arg!int(ap); assert(a1 == 0x11111111); assert(a2 == 0x22222222); assert(a3 == 0x33333333); va_end(ap); } void test9495() { func9495(0, "", 0x11111111, 0x22222222, 0x33333333); } /***************************************/ void copya(int a, string format, ...) { va_list ap; va_start(ap, format); va_list ap2; va_copy(ap2, ap); auto a1 = va_arg!int(ap); auto a2 = va_arg!int(ap); auto a3 = va_arg!int(ap); assert(a1 == 0x11111111); assert(a2 == 0x22222222); assert(a3 == 0x33333333); auto b1 = va_arg!int(ap2); auto b2 = va_arg!int(ap2); auto b3 = va_arg!int(ap2); assert(b1 == 0x11111111); assert(b2 == 0x22222222); assert(b3 == 0x33333333); va_end(ap); va_end(ap2); } void testCopy() { copya(0, "", 0x11111111, 0x22222222, 0x33333333); } /***************************************/ // 6700 template bug6700(TList ...) { const int bug6700 = 2; } TypeTuple!(int, long) TT6700; static assert(bug6700!( (TT6700[1..$]) )==2); /***************************************/ // 6966 template X6966(T...) { alias const(T[0]) X6966; } static assert(is(X6966!(int) == const(int))); static assert(is(X6966!(int, 0) == const(int))); /***************************************/ // 7233 struct Foo7233 { int x, y; } Foo7233[] front7233(Foo7233[][] a) { return a[0]; } class Bar7233 { int x, y; } Bar7233[] front7233(Bar7233[][] a) { return a[0]; } void test7233() { Foo7233[][] b1 = [[Foo7233()]]; auto xy1 = b1.front7233[0].tupleof; Bar7233[][] b2 = [[new Bar7233()]]; auto xy2 = b2.front7233[0].tupleof; } /***************************************/ // 7263 template TypeTuple7263(T...){ alias T TypeTuple7263; } struct tuple7263 { TypeTuple7263!(int, int) field; alias field this; } auto front7263(T)(ref T arr){ return arr[0]; } void test7263() { auto bars = [tuple7263(0, 0), tuple7263(1, 1)]; auto spam1 = bars.front7263[1]; auto spam2 = bars.front7263[1..2]; } /***************************************/ // 8244 TypeTuple!(int,int)[] x8244; static assert(is(typeof(x8244) == TypeTuple!(int, int))); /***************************************/ // 9017 template X9017(Args...) { static if(__traits(compiles, { enum e = Args; })) enum e = Args; } alias X9017!0 x9017; static assert(x9017.e[0] == 0); void test9017() { enum tup1 = TypeTuple!(11, 22); enum tup2 = TypeTuple!("one", "two"); static assert(tup1 == TypeTuple!(11, 22)); static assert(tup2 == TypeTuple!("one", "two")); static assert(tup1[0] == 11 && tup1[1] == 22); static assert(tup2[0] == "one" && tup2[1] == "two"); shared const tup3 = TypeTuple!(10, 3.14); immutable tup4 = TypeTuple!("a", [1,2]); static assert(is(typeof(tup3[0]) == shared const int)); static assert(is(typeof(tup3[1]) == shared const double)); static assert(is(typeof(tup4[0]) == immutable string)); static assert(is(typeof(tup4[1]) == immutable int[])); } /***************************************/ // 10279 void foo10279(int[][] strs...) @trusted { } void bar10279() @safe { foo10279(); } /***************************************/ // 13508 struct S13508 { this(T)(T[] t...) {} } template make13508(T) { T make13508(Args...)(Args args) { return T(args); } } void test13508() @safe @nogc { S13508 s = make13508!S13508(5); } /***************************************/ // 14395 int v2u14395(uint[1] ar...) { return ar[0]; } void print14395(int size = v2u14395(7)) { assert(size == 7); } void test14395() { print14395(); } /***************************************/ // 10414 void foo10414(void delegate()[] ...) { } void bar10414() { } void test10414() { foo10414 ( { bar10414(); }, { bar10414(); }, ); } /***************************************/ import core.stdc.stdarg; struct S14179 { const(char)* filename; uint linnum; uint charnum; } extern(C++) const(char)* func14179(S14179 x, const(char)* string, ...) { return string; } void test14179() { const(char)* s = "hello"; assert(func14179(S14179(), s) == s); } /***************************************/ // 10722 struct S10722 { int x; } template GetSomething10722(S...) { alias GetSomething = int; } void test10722() { alias X10722 = GetSomething10722!(S10722.tupleof[0]); } /***************************************/ int main() { test1(); test2(); test3(); test4(); test12(); test13(); test14(); test24(); test28(); test32(); test34(); test35(); test36(); test37(); test38(); test39(); test45(); test46(); test47(); test48(); test49(); test51(); test55(); test56(); test57(); test58(); test59(); test60(); test61(); test63(); test1411(); test4444(); test13864(); test4884(); test4920(); test4940(); test4940add(); test6530(); test7233(); test7263(); test9017(); test14395(); test10414(); test9495(); testCopy(); test14179(); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/untag.d0000644000175000017500000001202213200164642022667 0ustar matthiasmatthias#!/home/aalexandre/dmd2/linux/bin/rdmd // PERMUTE_ARGS: import std.algorithm, std.ascii, std.conv, std.exception, std.file, std.getopt, std.path, std.range, std.stdio, std.string, std.traits; auto binaryFun(string pred, T, U)(T a, U b) { return(mixin(pred)); } /** If $(D startsWith(r1, r2)), consume the corresponding elements off $(D r1) and return $(D true). Otherwise, leave $(D r1) unchanged and return $(D false). */ bool startsWithConsume(alias pred = "a == b", R1, R2)(ref R1 r1, R2 r2) { auto r = r1; // .save(); while (!r2.empty && !r.empty && binaryFun!pred(r.front, r2.front)) { r.popFront(); r2.popFront(); } return r2.empty ? (r1 = r, true) : false; } uint bug = 1; int main(string args[]) { getopt(args, "bug", &bug); enforce(bug <= 2); auto txt = readText("runnable/extra-files/untag.html"); untag(txt, "runnable/extra-files/untag.html"); return 0; } void untag(string txt, string filename) { string currentParagraph; string origtxt = txt; string origtxtcopy = txt.idup; // Find beginning of content txt = std.algorithm.find(txt, "\n"); // Ancillary function that commits the current paragraph for // writing void commit() { writeParagraph(strip(currentParagraph)); } void writeChar(dchar c) { immutable lastWritten = currentParagraph.length ? currentParagraph.back : dchar.init; if (lastWritten == ' ' && c == ' ') { // Two consecutive spaces fused } else { // Normal case currentParagraph ~= c; } } void writeWords(string s) { if (bug == 0) { foreach (dchar c; s) { currentParagraph ~= c; } } else if (bug == 1) { reserve(currentParagraph, currentParagraph.length + s.length); currentParagraph ~= s; } else { currentParagraph = currentParagraph ~ s; } } // Parse the content while (!txt.empty) { size_t i = 0; while (i < txt.length && txt[i] != '<' && txt[i] != '&') { ++i; } writeWords(txt[0 .. i]); if (i == txt.length) { commit(); return; } txt = txt[i .. $]; auto c = txt[0]; txt = txt[1 .. $]; if (c == '<') { // This is a tag if (startsWithConsume(txt, `/p>`) || startsWithConsume(txt, `/li>`)) { // End of paragraph commit(); } else { // This is an uninteresting tag enforce(findConsume(txt, '>'), "Could not find closing tag: "~txt); } } else { auto app = appender!string(); findConsume(txt, ';', app); switch (app.data) { case "#160;": case "#32;": case "reg;": case "nbsp;": writeChar(' '); break; case "amp;": writeChar('&'); break; case "gt;": writeChar('>'); break; case "lt;": writeChar('<'); break; case "quot;": writeChar('"'); break; default: throw new Exception(text("Unknown code: &", app.data)); break; } } } } void writeParagraph(string sentence) { static bool isSeparator(dchar a) { return !(isAlpha(a) /*|| a == '.'*/); } foreach (string cand; std.algorithm.splitter(sentence, ' ')) { cand = toLower(cand); } } /** If $(D r2) can not be found in $(D r1), leave $(D r1) unchanged and return $(D false). Otherwise, consume elements in $(D r1) until $(D startsWithConsume(r1, r2)), and return $(D true). Effectively positions $(D r1) right after $(D r2). */ bool findConsume(R1, R2)(ref R1 r1, R2 r2) if (isForwardRange!R2) { auto r = r1; // .save(); while (!r.empty) { if (startsWithConsume(r, r2)) { r1 = r; return true; } r.popFront(); } return false; } /** If $(D r2) can not be found in $(D r1), leave $(D r1) unchanged and return $(D false). Otherwise, consume elements in $(D r1) until $(D startsWith(r1, r2)), and return $(D true). */ bool findConsume(R, E)(ref R r, E e) if (is(typeof(r.front == e))) { auto r1 = std.algorithm.find(r, e); if (r1.empty) return false; r = r1; r.popFront(); return true; } /** If $(D r2) can not be found in $(D r1), leave $(D r1) unchanged and return $(D false). Otherwise, consume elements in $(D r1) until $(D startsWith(r1, r2)), and return $(D true). */ bool findConsume(R1, E, R2)(ref R1 r1, E e, R2 r2) if (is(typeof(r1.front == e))) { auto r = r1; while (!r.empty) { r2.put(r.front); if (r.front == e) { r.popFront(); r1 = r; return true; } r.popFront(); } return false; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link14814.d0000644000175000017500000000024213200164642023111 0ustar matthiasmatthias// EXTRA_SOURCES: imports/link14814a.d // PERMUTE_ARGS: -inline -release -g -O -fPIC // COMPILE_SEPARATELY import imports.link14814a; void main() { fun4; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/externmangle.d0000644000175000017500000001136013200164642024246 0ustar matthiasmatthias// EXTRA_CPP_SOURCES: externmangle.cpp extern(C++): struct Foo(X) { X* v; } struct Boo(X) { X* v; } void test1(Foo!int arg1); void test2(int* arg2, Boo!(int*) arg1); struct Test3(int X, int Y) { } void test3(Test3!(3,3) arg1); void test4(Foo!(int*) arg1, Boo!(int*) arg2, Boo!(int*) arg3, int*, Foo!(double)); void test5(Foo!(int*) arg1, Boo!(int*) arg2, Boo!(int*) arg3); struct Goo { struct Foo(X) { X* v; } struct Boo(X) { struct Xoo(Y) { Y* v; }; X* v; } void test6(Foo!(Boo!(Foo!(void))) arg1); void test7(Boo!(void).Xoo!(int) arg1); } struct P1 { struct Mem(T) { } } struct P2 { struct Mem(T) { } } void test8(P1.Mem!int, P2.Mem!int); void test9(Foo!(int**), Foo!(int*), int**, int*); interface Test10 { private final void test10(); public final void test11(); protected final void test12(); public final void test13() const; private void test14(); public void test15(); protected void test16(); private static void test17(); public static void test18(); protected static void test19(); }; Test10 Test10Ctor(); void Test10Dtor(ref Test10 ptr); struct Test20 { __gshared: private extern int test20; protected extern int test21; public extern int test22; }; int test23(Test10*, Test10, Test10**, const(Test10)); int test23b(const Test10*, const Test10, Test10); void test24(int function(int,int)); void test25(int[291][6][5]* arr); int test26(int[291][6]* arr); void test27(int, ...); void test28(int); void test29(float); void test30(const float); struct Array(T) { int dim; } interface Module { public static void imports(Module); public static int dim(Array!Module*); }; ulong testlongmangle(int a, uint b, long c, ulong d); __gshared extern int[2][2][2] test31; __gshared extern int* test32; alias int function(Expression , void* ) apply_fp_t; interface Expression { public final int apply(apply_fp_t fp, apply_fp_t fp2, void* param); public final int getType(); public static Expression create(int); public static void dispose(ref Expression); } //int test34(int[0][0]*); version(CRuntime_Microsoft){} else { int test35(real arg); } const(char)* test36(const(char)*); final class Test37 { static Test37 create() { return new Test37; } bool test() { return true; } } bool test37(); interface Test38 { final int test(int, ...); public static Test38 create(); public static void dispose(ref Test38); } void main() { test1(Foo!int()); test2(null, Boo!(int*)()); test3(Test3!(3,3)()); test4(Foo!(int*)(), Boo!(int*)(), Boo!(int*)(), null, Foo!(double)()); test5(Foo!(int*)(), Boo!(int*)(), Boo!(int*)()); Goo goo; goo.test6(Goo.Foo!(Goo.Boo!(Goo.Foo!(void)))()); goo.test7(Goo.Boo!(void).Xoo!(int)()); test8(P1.Mem!int(), P2.Mem!int()); test9(Foo!(int**)(), Foo!(int*)(), null, null); auto t10 = Test10Ctor(); scope(exit) Test10Dtor(t10); t10.test10(); t10.test11(); t10.test12(); t10.test13(); t10.test14(); t10.test15(); t10.test16(); t10.test17(); t10.test18(); t10.test19(); assert(Test20.test20 == 20); assert(Test20.test21 == 21); assert(Test20.test22 == 22); assert(test23(null, null, null, null) == 1); assert(test23b(null, null, null) == 1); extern(C++) static int cb(int a, int b){return a+b;} test24(&cb); int[291][6][5] arr; arr[1][1][1] = 42; test25(&arr); assert(test26(&arr[0]) == 42); test27(3,4,5); test28(3); test29(3.14f); test30(3.14f); auto t32 = &Module.imports; Array!Module arr2; arr2.dim = 20; assert(Module.dim(&arr2) == 20); assert(testlongmangle(1, 2, 3, 4) == 10); assert(test31 == [[[1, 1], [1, 1]], [[1, 1], [1, 1]]]); assert(test32 == null); auto ee = Expression.create(42); extern(C++) static int efun(Expression e, void* p) { return cast(int)(cast(size_t)p ^ e.getType()); } extern(C++) static int efun2(Expression e, void* p) { return cast(int)(cast(size_t)p * e.getType()); } auto test33 = ee.apply(&efun, &efun2, cast(void*)&Expression.create); assert(test33 == cast(int)(cast(size_t)cast(void*)&Expression.create ^ 42) * cast(int)(cast(size_t)cast(void*)&Expression.create * 42)); Expression.dispose(ee); assert(ee is null); //assert(test34(null) == 0); version(CRuntime_Microsoft){} else { assert(test35(3.14L) == 3); } const char* hello = "hello"; assert(test36(hello) == hello); assert(test37()); auto t38 = Test38.create(); assert(t38.test(1, 2, 3) == 1); Test38.dispose(t38); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/a18.d0000644000175000017500000000034713200164642022151 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/a18a.d // PERMUTE_ARGS: import imports.a18a; extern(C) int printf(const char*, ...); alias IContainer!(int) icontainer_t; int main() { printf("Test enumerator\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/hello-profile.d0000644000175000017500000000131313200164642024313 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -profile // POST_SCRIPT: runnable/extra-files/hello-profile-postscript.sh // EXECUTE_ARGS: ${RESULTS_DIR}/runnable module hello; extern(C) { int printf(const char*, ...); int trace_setlogfilename(string name); int trace_setdeffilename(string name); } void showargs(string[] args) { printf("hello world\n"); printf("args.length = %d\n", args.length); for (int i = 0; i < args.length; i++) printf("args[%d] = '%.*s'\n", i, args[i].length, args[i].ptr); } int main(string[] args) { trace_setlogfilename(args[1] ~ "/hello-profile.d.trace.log"); trace_setdeffilename(args[1] ~ "/hello-profile.d.trace.def"); showargs(args); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test11745.d0000644000175000017500000000052013200164642023132 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test11745b.d // REQUIRED_ARGS: -unittest // PERMUTE_ARGS: import imports.test11745b; void main() { // Test that we can invoke all unittests, including private ones. assert(__traits(getUnitTests, imports.test11745b).length == 3); foreach(test; __traits(getUnitTests, imports.test11745b)) { test(); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/auto1.d0000644000175000017500000000256213200164642022612 0ustar matthiasmatthias import core.stdc.stdio; /******************************************/ scope class Foo { static int x; ~this() { printf("Foo.~this()\n"); x++; } } int test1x() { scope Foo f = new Foo(); return 6; } void test1() { { scope Foo f = new Foo(); } int c; assert(Foo.x == 1); c = test1x(); assert(c == 6); assert(Foo.x == 2); if (c != 6) scope Foo h = new Foo(); assert(Foo.x == 2); if (c == 6) scope Foo j = new Foo(); assert(Foo.x == 3); { scope Foo g = null, k = new Foo(); assert(Foo.x == 3); } assert(Foo.x == 4); } /******************************************/ int ax; scope class A2 { this() { printf("A2.this()\n"); ax += 1; } ~this() { printf("A2.~this()\n"); ax += 1000; } }; void test2() { { scope A2 a = new A2(); printf("Hello world.\n"); } assert(ax == 1001); } /******************************************/ int status3; scope class Parent3 { } scope class Child3 : Parent3 { this(){ assert(status3==0); status3=1; } ~this(){ assert(status3==1); status3=2; } } void foo3() { scope Parent3 o = new Child3(); assert(status3==1); } void test3() { foo3(); assert(status3==2); } /******************************************/ int main() { test1(); test2(); test3(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/uniformctor.d0000644000175000017500000001221713200164642024126 0ustar matthiasmatthiasextern(C) int printf(const char*, ...); template TypeTuple(TL...) { alias TypeTuple = TL; } import core.stdc.math : isnan; /********************************************/ // 9112 void test9112a() // T() and T(v) { void test(T)(T v) { foreach (string qual; TypeTuple!("", "const ", "immutable ")) { mixin("alias U = "~qual~T.stringof~";"); //pragma(msg, U); mixin("auto x1 = "~qual~T.stringof~"();"); // U() default construction syntax mixin("auto x2 = "~qual~T.stringof~"(v);"); // U(v) static assert(!__traits(compiles, mixin(qual~T.stringof~"(v, v)"))); // U(v, v) static assert(is(typeof(x1) == U)); static assert(is(typeof(x2) == U)); static if ( is(typeof(U.nan) : real)) assert( isnan(x1.re) && !isnan(x1.im), U.stringof); static if ( is(typeof(U.nan) : ireal)) assert(!isnan(x1.re) && isnan(x1.im), U.stringof); static if ( is(typeof(U.nan) : creal)) assert( isnan(x1.re) && isnan(x1.im), U.stringof); static if (!is(typeof(U.nan))) assert( x1 == U.init, U.stringof); assert(x2 == v, U.stringof); } } static assert(!__traits(compiles, { auto x1 = void(); })); static assert(!__traits(compiles, { auto x2 = void(1); })); test!( byte )(10); test!(ubyte )(10); test!( short )(10); test!(ushort )(10); test!( int )(10); test!(uint )(10); test!( long )(10); test!(ulong )(10); test!( float )(3.14); test!( double)(3.14); test!( real )(3.14); test!(ifloat )(1.4142i); test!(idouble)(1.4142i); test!(ireal )(1.4142i); test!(cfloat )(1.2+3.4i); test!(cdouble)(1.2+3.4i); test!(creal )(1.2+3.4i); test!( char )('A'); test!(wchar )('A'); test!(dchar )('A'); test!(bool )(true); static assert(!__traits(compiles, int(1.42))); // in curre,t this is disallowed static assert(!__traits(compiles, double(3.14i))); { int x; alias T = int*; //auto p = int*(&x); // Error: found '*' when expecting '.' following int //auto p = (int*)(&x); // Error: C style cast illegal, use cast(int*)&x auto p = T(&x); assert( p == &x); assert(*p == x); } } enum Enum : long { a = 10, b = 20 } void test9112b() // new T(v) { void test(T)(T v) { foreach (string qual; TypeTuple!("", "const ", "immutable ")) { mixin("alias U = "~qual~T.stringof~";"); //pragma(msg, U); mixin("auto p1 = new "~qual~T.stringof~"();"); // U() default construction syntax mixin("auto p2 = new "~qual~T.stringof~"(v);"); // U(v) static assert(!__traits(compiles, mixin("new "~qual~T.stringof~"(v, v)"))); // U(v, v) static assert(is(typeof(p1) == U*)); static assert(is(typeof(p2) == U*)); assert( p1 !is null); assert( p2 !is null); auto x1 = *p1; auto x2 = *p2; static if ( is(typeof(U.nan) : real)) assert( isnan(x1.re) && !isnan(x1.im), U.stringof); static if ( is(typeof(U.nan) : ireal)) assert(!isnan(x1.re) && isnan(x1.im), U.stringof); static if ( is(typeof(U.nan) : creal)) assert( isnan(x1.re) && isnan(x1.im), U.stringof); static if (!is(typeof(U.nan))) assert( x1 == U.init, U.stringof); assert(x2 == v, U.stringof); } } static assert(!__traits(compiles, { auto x1 = new void(); })); static assert(!__traits(compiles, { auto x2 = new void(1); })); static assert(!__traits(compiles, { auto x2 = new void(1, 2); })); test!( byte )(10); test!(ubyte )(10); test!( short )(10); test!(ushort )(10); test!( int )(10); test!(uint )(10); test!( long )(10); test!(ulong )(10); test!( float )(3.14); test!( double)(3.14); test!( real )(3.14); test!(ifloat )(1.4142i); test!(idouble)(1.4142i); test!(ireal )(1.4142i); test!(cfloat )(1.2+3.4i); test!(cdouble)(1.2+3.4i); test!(creal )(1.2+3.4i); test!( char )('A'); test!(wchar )('A'); test!(dchar )('A'); test!(bool )(true); test!(Enum )(Enum.a); void testPtr(T)(T v) { T* pv = &v; T** ppv = new T*(pv); assert( *ppv == pv); assert(**ppv == v); } foreach (T; TypeTuple!(int, const long, immutable double)) { testPtr!T(10); } foreach (T; TypeTuple!(Enum, const Enum, immutable Enum)) { testPtr!T(Enum.a); } static assert(!__traits(compiles, new const int(1, 2))); static assert(!__traits(compiles, new int(1.42))); // in curre,t this is disallowed static assert(!__traits(compiles, new double(3.14i))); // int(1) in directly on statement scope should be parsed as an expression, but // would fail to compile because of "has no effect" error. static assert(!__traits(compiles, { int(1); })); } /********************************************/ int main() { test9112a(); test9112b(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test4.d0000644000175000017500000005402213200164642022622 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: import core.exception; import core.stdc.math; import core.vararg; extern(C) { int atoi(const char*); int memcmp(const void*, const void*, size_t); int printf(const char*, ...); } int cmp(const(char)[] s1, const(char)[] s2) { assert(s1.length == s2.length); return memcmp(s1.ptr, s2.ptr, s1.length); } /* ================================ */ void test1() { int i; int[6] foo = 1; for (i = 0; i < foo.length; i++) assert(foo[i] == 1); int[10] bar; for (i = 0; i < bar.length; i++) assert(bar[i] == 0); foo[3] = 4; int[6] abc = foo; for (i = 0; i < abc.length; i++) assert(abc[i] == foo[i]); abc[2] = 27; foo[] = abc; for (i = 0; i < abc.length; i++) assert(abc[i] == foo[i]); } /* ================================ */ void test2() { byte foo1[5]; ubyte foo2[6]; short foo3[7]; ushort foo4[8]; int foo5[9]; uint foo6[10]; long foo7[11]; ulong foo8[12]; float foo9[13]; double foo10[14]; real foo11[15]; int i; printf("test2()\n"); for (i = 0; i < foo1.length; i++) assert(foo1[i] == 0); for (i = 0; i < foo2.length; i++) { printf("foo2[%d] = %d\n", i, foo2[i]); assert(foo2[i] == 0); } for (i = 0; i < foo3.length; i++) assert(foo3[i] == 0); for (i = 0; i < foo4.length; i++) assert(foo4[i] == 0); for (i = 0; i < foo5.length; i++) { printf("foo5[%d] = %d\n", i, foo5[i]); assert(foo5[i] == 0); } for (i = 0; i < foo6.length; i++) assert(foo6[i] == 0); for (i = 0; i < foo7.length; i++) assert(foo7[i] == 0); for (i = 0; i < foo8.length; i++) assert(foo8[i] == 0); for (i = 0; i < foo9.length; i++) assert(isnan(foo9[i])); for (i = 0; i < foo10.length; i++) assert(isnan(foo10[i])); for (i = 0; i < foo11.length; i++) assert(isnan(foo11[i])); } /* ================================ */ void test3() { byte foo1[5] = 20; ubyte foo2[6] = 21; short foo3[7] = 22; ushort foo4[8] = 23; int foo5[9] = 24; uint foo6[10] = 25; long foo7[11] = 26; ulong foo8[12] = 27; float foo9[13] = 28; double foo10[14] = 29; real foo11[15] = 30; int i; for (i = 0; i < foo1.length; i++) assert(foo1[i] == 20); for (i = 0; i < foo2.length; i++) assert(foo2[i] == 21); for (i = 0; i < foo3.length; i++) assert(foo3[i] == 22); for (i = 0; i < foo4.length; i++) assert(foo4[i] == 23); for (i = 0; i < foo5.length; i++) assert(foo5[i] == 24); for (i = 0; i < foo6.length; i++) assert(foo6[i] == 25); for (i = 0; i < foo7.length; i++) assert(foo7[i] == 26); for (i = 0; i < foo8.length; i++) assert(foo8[i] == 27); for (i = 0; i < foo9.length; i++) assert(foo9[i] == 28); for (i = 0; i < foo10.length; i++) assert(foo10[i] == 29); for (i = 0; i < foo11.length; i++) assert(foo11[i] == 30); } /* ================================ */ struct a4 { string b = "string"; int c; } void test4() { a4 a; int i; assert(a.b.length == 6); i = cmp(a.b, "string"); assert(i == 0); a4[3] c; int j; for (j = 0; j < 3; j++) { assert(c[j].b.length == 6); i = cmp(c[j].b, "string"); assert(i == 0); } } /* ================================ */ float f5; const char[4] x5 = "abcd"; struct a5 { string b = "string"; int c; } a5[5] foo5; void test5() { printf("test5()\n"); assert(isnan(f5)); assert(cmp(x5, "abcd") == 0); int i; for (i = 0; i < 5; i++) { assert(foo5[i].c == 0); assert(cmp(foo5[i].b, "string") == 0); } } /* ================================ */ struct TRECT6 { int foo1 = 2; union { struct { int Left = 3, Top = 4, Right = 5, Bottom = 6; } struct { long TopLeft, BottomRight; } } int foo2 = 7; } void test6() { TRECT6 t; assert(t.foo1 == 2); assert(t.Left == 3); assert(t.Top == 4); assert(t.Right == 5); assert(t.Bottom == 6); assert(t.foo2 == 7); assert(&t.foo1 < &t.Left); assert(&t.Bottom < &t.foo2); assert(TRECT6.foo1.offsetof == 0); version (Win32) { assert(TRECT6.Left.offsetof == 8); assert(TRECT6.Top.offsetof == 12); assert(TRECT6.Right.offsetof == 16); assert(TRECT6.Bottom.offsetof == 20); assert(TRECT6.TopLeft.offsetof == 8); assert(TRECT6.BottomRight.offsetof == 16); assert(TRECT6.foo2.offsetof == 24); } else version (X86_64) { assert(TRECT6.Left.offsetof == 8); assert(TRECT6.Top.offsetof == 12); assert(TRECT6.Right.offsetof == 16); assert(TRECT6.Bottom.offsetof == 20); assert(TRECT6.TopLeft.offsetof == 8); assert(TRECT6.BottomRight.offsetof == 16); assert(TRECT6.foo2.offsetof == 24); } else version(ARM) { assert(TRECT6.Left.offsetof == 8); assert(TRECT6.Top.offsetof == 12); assert(TRECT6.Right.offsetof == 16); assert(TRECT6.Bottom.offsetof == 20); assert(TRECT6.TopLeft.offsetof == 8); assert(TRECT6.BottomRight.offsetof == 16); assert(TRECT6.foo2.offsetof == 24); } else { assert(TRECT6.Left.offsetof == 4); assert(TRECT6.Top.offsetof == 8); assert(TRECT6.Right.offsetof == 12); assert(TRECT6.Bottom.offsetof == 16); assert(TRECT6.TopLeft.offsetof == 4); assert(TRECT6.BottomRight.offsetof == 12); assert(TRECT6.foo2.offsetof == 20); } } /* ================================ */ struct TestVectors { string pattern; string input; string result; string format; string replace; }; TestVectors tva[] = [ { pattern:"(a)\\1", input:"abaab", result:"y", format:"&", replace:"aa" }, { pattern:"abc", input:"abc", result:"y", format:"&", replace:"abc" }, ]; TestVectors tvs[2] = [ { pattern:"(a)\\1", input:"abaab", result:"y", format:"&", replace:"aa" }, { pattern:"abc", input:"abc", result:"y", format:"&", replace:"abc" }, ]; TestVectors* tvp = [ { pattern:"(a)\\1", input:"abaab", result:"y", format:"&", replace:"aa" }, { pattern:"abc", input:"abc", result:"y", format:"&", replace:"abc" }, ]; void test7() { int i; //printf("start\n"); //printf("%d\n", tva[0].pattern.length); //printf("%.*s\n", tva[0].pattern.length, tva[0].pattern.ptr); i = cmp(tva[0].pattern, "(a)\\1"); assert(i == 0); i = cmp(tva[1].replace, "abc"); assert(i == 0); i = cmp(tvs[0].pattern, "(a)\\1"); assert(i == 0); i = cmp(tvs[1].replace, "abc"); assert(i == 0); i = cmp(tvp[0].pattern, "(a)\\1"); assert(i == 0); i = cmp(tvp[1].replace, "abc"); assert(i == 0); //printf("finish\n"); } /* ================================ */ const uint WSABASEERR = 10000; const uint WSAENOTCONN = (WSABASEERR+57); void test8() { switch (10057) { case WSAENOTCONN: break; default: assert(0); } } /* ================================ */ alias T9* PPixel; align(1) struct TAG { int foo; } alias TAG T9; alias TAG Pixel; void func9(PPixel x) { } void test9() { Pixel p; func9(&p); } /* ================================ */ string[] colors10 = [ "red", "green", "blue" ]; void test10() { printf("test10()\n"); int i; i = cmp(colors10[0], "red"); assert(i == 0); } /* ================================ */ const uint MAX_PATH1 = 260; enum { MAX_PATH2 = 261 } struct WIN32_FIND_DATA { char cFileName1[MAX_PATH1]; char cFileName2[MAX_PATH2]; } void test11() { } /* ================================ */ interface IPersistent { int store(Object); int retrieve(Object); } class Persistent: IPersistent { int store(Object n) { return 1; } int retrieve(Object n) { return 2; } } void func12(IPersistent p) { Object o = new Object(); assert(p.store(o) == 1); assert(p.retrieve(o) == 2); } void test12() { Persistent p = new Persistent(); Object o = new Object(); assert(p.store(o) == 1); assert(p.retrieve(o) == 2); func12(p); } /* ================================ */ class X13 { } class A13 { X13 B(X13 x, out int i) { i = 666; return new X13; } X13 B(X13 x) { int j; return B(x, j); } } void test13() { A13 a; X13 x; int i; a = new A13(); x = a.B(x, i); assert(i == 666); } /* ================================ */ void foo14() { } int testx14(int x) { try { return 3; } finally { foo14(); } } class bar { int y; synchronized int sync(int x) { printf("in sync(%d) = %d\n", x, y + 3); return y + 3; } } void test14() { auto b = new shared(bar)(); int i; i = b.sync(4); printf("i = %d\n", i); assert(i == 3); assert(testx14(7) == 3); } /* ================================ */ /+ int foo15(int i) { switch (i) { case 7: case 8: return i; } return 0; } void test15() { int i = 0; try { foo15(3); } catch (SwitchError sw) { //printf("caught switch error\n"); i = 1; } assert(i == 1); } +/ /* ================================ */ struct GUID { // size is 16 align(1): uint Data1; ushort Data2; ushort Data3; ubyte Data4[8]; } GUID CLSID_Hello = { 0x30421140, 0, 0, [0xC0,0,0,0,0,0,0,0x46] }; GUID IID_IHello = { 0x00421140, 0, 0, [0xC0,0,0,0,0,0,0,0x46] }; int testa() { return CLSID_Hello == IID_IHello; } int testb() { return CLSID_Hello != IID_IHello; } int testc() { return CLSID_Hello == IID_IHello ? 5 : 3; } int testd() { return CLSID_Hello != IID_IHello ? 7 : 9; } void test16() { assert(testa() == 0); assert(testb() == 1); assert(testc() == 3); assert(testd() == 7); } /* ================================ */ void test17() { creal z = 1. + 2.0i; real r = z.re; assert(r == 1.0); real i = z.im; assert(i == 2.0); assert(r.im == 0.0); assert(r.re == 1.0); assert(i.re == 2.0); assert(i.im == 0.0i); } /* ================================ */ private const uint crc_table[256] = [ 0x00000000u, 0x77073096u, 0xee0e612cu, 0x990951bau, 0x076dc419u, 0x2d02ef8du ]; public const(uint)[] get_crc_table() { return crc_table; } void test18() { const(uint)[] c; c = get_crc_table(); assert(c[3] == 0x990951bau); } /* ================================ */ int[0xffff] foo19; void test19() { int i; for (i = 0; i < 0xffff; i++) assert(foo19[i] == 0); } /* ================================ */ extern (Windows) int cfw(int x, int y) { return x * 10 + y; } extern (C) int cfc(int x, int y) { return x * 10 + y; } extern (Pascal) int cfp(int x, int y) { return x * 10 + y; } int cfd(int x, int y) { return x * 10 + y; } extern (Windows) int function (int, int) fpw; extern (C) int function (int, int) fpc; extern (Pascal) int function (int, int) fpp; int function (int, int) fpd; void test20() { printf("test20()\n"); int i; fpw = &cfw; fpc = &cfc; fpp = &cfp; fpd = &cfd; //printf("test w\n"); i = (*fpw)(1, 2); assert(i == 12); //printf("test c\n"); i = (*fpc)(3, 4); assert(i == 34); //printf("test p\n"); i = (*fpp)(5, 6); assert(i == 56); //printf("test d\n"); i = (*fpd)(7, 8); assert(i == 78); } /* ================================ */ void test21() { ireal imag = 2.5i; printf ("test of imag*imag = %Lf\n",imag*imag); assert(imag * imag == -6.25); } /* ================================ */ void test22() { creal z1 = 1. - 2.0i; ireal imag_part = z1.im/1i; } /* ================================ */ int def23(int x, int y) { return x * y; } struct Foo23 { int a = 7; int b = 8; int c = 9; int abc() { def23(3, 4); a *= b; bar(); return a; } int bar() { a *= 2; return a; } invariant() { assert(c == 9); } } void test23() { Foo23 f; int i; assert(f.a == 7 && f.b == 8); i = f.abc(); assert(i == 112); } /* ================================ */ struct Foo24 { int x, y; int[] z; } void test24() { assert(Foo24.z.offsetof == 8); } /* ================================ */ void test25() { printf("test25()\n"); int a[10]; a[0] = 23; a[1] = 1; a[2] = 64; a[3] = 5; a[4] = 6; a[5] = 5; a[6] = 17; a[7] = 3; a[8] = 0; a[9] = -1; a.sort; for (int i = 0; i < a.length - 1; i++) { //printf("i = %d", i); //printf(" %d %d\n", a[i], a[i + 1]); assert(a[i] <= a[i + 1]); } } /* ================================ */ void test27() { static real[1] n = [ -1 ]; //printf("%Le\n", n[0]); assert(n[0] == -1.0); } /* ================================ */ int x29; class Foo29 { ~this() { x29 = bar(); } int bar() { return 3; } } void test29() { printf("test29()\n"); Foo29 f = new Foo29(); delete f; assert(x29 == 3); } /* ================================ */ struct GC30 { static ClassInfo gcLock; invariant() { } void *malloc() { void *p; synchronized (gcLock) { p = test(); if (!p) return null; } return p; } void *test() { return null; } } void test30() { printf("test30()\n"); GC30 gc; GC30.gcLock = Object.classinfo; assert(gc.malloc() == null); } /* ================================ */ void test31() { char[14] foo; char[] bar; int i = 3; while (i--) bar = foo; } /* ================================ */ real foo32() { return 4 % 1.0; } void test32() { assert(foo32() == 0); } /* ================================ */ void test33() { char[8] foo; foo[] = "12345678"; assert(foo[7] == '8'); } /* ================================ */ void foo34(int[] a) { //printf("a.length = %d\n", a.length); assert(a.length == 5); assert(a[0] == 11); assert(a[1] == 22); assert(a[2] == 33); assert(a[3] == 44); assert(a[4] == 55); } void test34() { printf("test34()\n"); static int[5] x = [11,22,33,44,55]; int[] y; int* z; foo34(x); y = x; foo34(y); z = x.ptr; foo34(z[0..5]); } /* ================================ */ class X35 { final synchronized void foo() { for(;;) { break; } } } void test35() { auto x = new shared(X35); x.foo(); } /* ================================ */ void test36() { synchronized { } } void test36b() @nogc nothrow { synchronized { } } /* ================================ */ int test37() { string one = "1"; debug printf("pre\n"); int N = atoi(one.ptr); assert(N == 1); return 0; } /* ================================ */ void test38() { version (D_Bits) { bit a[]; a.length=3; a[0]=false; a[1]=true; a[2]=false; bit[] b=a.sort; assert(a.length==3); assert(!a[0]); assert(!a[1]); assert(a[2]); assert(b.length==3); assert(!b[0]); assert(!b[1]); assert(b[2]); assert(&a != &b); } } /* ================================ */ void test39() { char[] array; array.length=4; char letter = 'a'; array[0..4]=letter; assert(array[0]=='a'); assert(array[1]=='a'); assert(array[2]=='a'); assert(array[3]=='a'); } /* ================================ */ int dummyJob; int dummy() { return ++dummyJob; } void bar40(){ return cast(void)dummy(); } int foo40() { bar40(); return dummyJob-1; } void test40() { assert(foo40() == 0); } /* ================================ */ int status; void check() { assert(status==1); void main(int dummy){ assert(status==3); status+=5; } status+=2; assert(status==3); main(2); assert(status==8); status+=7; } void test41() { status++; assert(status==1); check(); assert(status==15); } /* ================================ */ void test42() { real[10] array; real[] copy = array.dup; copy.sort; } /* ================================ */ void test43() { string s; s = __FILE__; printf("file = '%.*s'\n", s.length, s.ptr); printf("line = %d\n", __LINE__); s = __DATE__; printf("date = '%.*s'\n", s.length, s.ptr); s = __TIME__; printf("time = '%.*s'\n", s.length, s.ptr); s = __TIMESTAMP__; printf("timestamp = '%.*s'\n", s.length, s.ptr); } /* ================================ */ void test44() { int[] a; int i; a.length = 6; a = a[0 .. $ - 1]; assert(a.length == 5); } /* ================================ */ alias int MyInt; void test45() { MyInt test(string c="x"){ return 2; } assert(test("abc")==2); } /* ================================ */ int status46; class Check46 { void sum(byte[] b){ status46++; } void add(byte b){ assert(0); } alias sum write; alias add write; void test(){ byte[] buffer; write(buffer); } } void test46() { Check46 c = new Check46(); status46=0; assert(status46==0); c.test(); assert(status46==1); } /* ================================ */ int status47; int foo47(int arg) { loop: while(1) { try { try { if (arg == 1) { break loop; } } finally { assert(status47==0); status47+=2; } try { assert(0); } finally { assert(0); } } finally { assert(status47==2); status47+=3; } assert(0); return 0; } return -1; } void test47() { assert(status47 == 0); assert(foo47(1) == -1); assert(status47 == 5); } /* ================================ */ int status48; int foo48(int arg) { loop: while(1){ try{ try{ if(arg == 1) { break loop; } }finally{ assert(status48==0); status48+=2; } }finally{ assert(status48==2); status48+=3; } return 0; } return -1; } void test48() { assert(status48 == 0); assert(foo48(1) == -1); assert(status48 == 5); } /* ================================ */ int getch49() { return 0; } void writefln49(...) { } class Cout{ Cout set(int x){ return this; } alias set opShl; } void test49() { Cout cout = new Cout; cout << 5 << 4; writefln49,getch49; } /* ================================ */ struct S50{ int i; } class C50{ static S50 prop(){ S50 s; return s; } static void prop(S50 s){ } } void test50() { C50 c = new C50(); c.prop = true ? C50.prop : C50.prop; assert(c.prop.i == 0); c.prop.i = 7; assert(c.prop.i != 7); } /* ================================ */ void func1() { static class foo { public int a; } } void test51() { static class foo { public int b; } foo bar = new foo(); bar.b = 255; } /* ================================ */ struct S52 { int i; } const int a52 = 3; const S52 b52 = { a52 }; const S52 c52 = b52; void test52() { assert(c52.i == 3); } /* ================================ */ const int c53 = b53 + 1; const int a53 = 1; const int b53 = a53 + 1; void test53() { assert(a53==1); assert(b53==2); assert(c53==3); } /* ================================ */ void test54() { int status=0; try { try { status++; assert(status==1); throw new Exception("first"); } finally { printf("finally\n"); status++; assert(status==2); status++; throw new Exception("second"); } } catch(Exception e) { printf("catch %.*s\n", e.msg.length, e.msg.ptr); assert(e.msg == "first"); assert(e.next.msg == "second"); } printf("success54\n"); } /* ================================ */ void foo55() { try { Exception x = new Exception("second"); printf("inner throw %p\n", x); throw x; } catch (Exception e) { printf("inner catch %p\n", e); printf("e.msg == %.*s\n", e.msg.length, e.msg.ptr); assert(e.msg == "second"); //assert(e.msg == "first"); //assert(e.next.msg == "second"); } } void test55() { int status=0; try{ try{ status++; assert(status==1); Exception x = new Exception("first"); printf("outer throw %p\n", x); throw x; }finally{ printf("finally\n"); status++; assert(status==2); status++; foo55(); printf("finally2\n"); } }catch(Exception e){ printf("outer catch %p\n", e); assert(e.msg == "first"); assert(status==3); } printf("success55\n"); } /* ================================ */ void test56() { assert('\²'==178); assert('\³'==179); assert('\¹'==185); assert('\¼'==188); assert('\½'==189); assert('\¾'==190); assert('\∴'==8756); } /* ================================ */ void test57() { version (D_Bits) { void displayb(char[] name, bit[] x) { writef("%-5s: ", name); foreach(bit b; x) writef("%d",b); writefln(""); } bit[] a; bit[] b; a.length = 7; a[0] = 0; a[1] = 1; a[2] = 1; a[3] = 0; a[4] = 0; a[5] = 1; a[6] = 0; displayb("a", a); b ~= a; displayb("b1", b); b ~= a; displayb("b2", b); for (int i = 0; i < a.length; i++) { assert(b[i] == a[i]); assert(b[i+7] == a[i]); } b.length = 0; b ~= a; displayb("b3", b); b.length = b.length + 7; for(int i = 0; i < a.length; i++) b[i+7] = a[i]; displayb("b4", b); for (int i = 0; i < a.length; i++) { assert(b[i] == a[i]); assert(b[i+7] == a[i]); } } } /* ================================ */ interface Foo58 { } interface Bar58 : Foo58 { } class Baz58 : Bar58 { } Object test58() { Bar58 b = new Baz58; return cast(Object)b; } /* ================================ */ float x59; void test59() { return cast(void)(x59 = -x59); } /* ================================ */ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); //test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); // test26(); test27(); // test28(); test29(); test30(); test31(); test32(); test33(); test34(); test35(); test36(); test37(); test38(); test39(); test40(); test41(); test42(); test43(); test44(); test45(); test46(); test47(); test48(); test49(); test50(); test51(); test52(); test53(); test54(); test55(); test56(); test57(); test58(); test59(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link846.sh0000755000175000017500000000107013200164642023143 0ustar matthiasmatthias#!/usr/bin/env bash set -e src=runnable${SEP}extra-files dir=${RESULTS_DIR}${SEP}runnable output_file=${dir}/link846.sh.out if [ $OS == "win32" -o $OS == "win64" ]; then LIBEXT=.lib else LIBEXT=.a fi libname=${dir}${SEP}link846${LIBEXT} # build library with -release $DMD -m${MODEL} -I${src} -of${libname} -release -boundscheck=off -lib ${src}${SEP}lib846.d # use lib with -debug $DMD -m${MODEL} -I${src} -of${dir}${SEP}link846${EXE} -debug ${src}${SEP}main846.d ${libname} rm ${libname} rm ${dir}/{link846${OBJ},link846${EXE}} echo Success > ${output_file} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testbounds.d0000644000175000017500000001017513200164642023752 0ustar matthiasmatthias// REQUIRED_ARGS: // Test array bounds checking import core.exception; extern(C) int printf(const char*, ...); /******************************************/ const int foos[10] = [1,2,3,4,5,6,7,8,9,10]; const int food[] = [21,22,23,24,25,26,27,28,29,30]; const int *foop = cast(int*) foos; static int x = 2; int index() { return x++; } int tests(int i) { return foos[index()]; } int testd(int i) { return food[index()]; } int testp(int i) { return foop[i]; } const(int)[] slices(int lwr, int upr) { return foos[lwr .. upr]; } const(int)[] sliced(int lwr, int upr) { return food[lwr .. upr]; } const(int)[] slicep(int lwr, int upr) { return foop[lwr .. upr]; } void test1() { int i; i = tests(0); assert(i == 3); i = testd(0); assert(i == 24); i = testp(1); assert(i == 2); x = 10; try { i = tests(0); } catch (RangeError a) { i = 73; } assert(i == 73); x = -1; try { i = testd(0); } catch (RangeError a) { i = 37; } assert(i == 37); const(int)[] r; r = slices(3,5); assert(r[0] == foos[3]); assert(r[1] == foos[4]); r = sliced(3,5); assert(r[0] == food[3]); assert(r[1] == food[4]); r = slicep(3,5); assert(r[0] == foos[3]); assert(r[1] == foos[4]); try { i = 7; r = slices(5,3); } catch (RangeError a) { i = 53; } assert(i == 53); try { i = 7; r = slices(5,11); } catch (RangeError a) { i = 53; } assert(i == 53); try { i = 7; r = sliced(5,11); } catch (RangeError a) { i = 53; } assert(i == 53); try { i = 7; r = slicep(5,3); } catch (RangeError a) { i = 53; } assert(i == 53); // Take side effects into account x = 1; r = foos[index() .. 3]; assert(x == 2); assert(r[0] == foos[1]); assert(r[1] == foos[2]); r = foos[1 .. index()]; assert(r.length == 1); assert(x == 3); assert(r[0] == foos[1]); x = 1; r = food[index() .. 3]; assert(x == 2); assert(r[0] == food[1]); assert(r[1] == food[2]); r = food[1 .. index()]; assert(r.length == 1); assert(x == 3); assert(r[0] == food[1]); x = 1; r = foop[index() .. 3]; assert(x == 2); assert(r[0] == foop[1]); assert(r[1] == foop[2]); r = foop[1 .. index()]; assert(r.length == 1); assert(x == 3); assert(r[0] == foop[1]); } /******************************************/ // 13976 void test13976() { int[] da = new int[](10); int[10] sa; size_t l = 0; // upperInRange size_t u = 9; // | lowerLessThan // | | check code { auto s = da[l .. u]; } // 0 0 (u <= 10 && l <= u ) { auto s = da[1 .. u]; } // 0 0 (u <= 10 && l <= u ) { auto s = da[l .. 10]; } // 0 0 (u <= 10 && l <= u ) { auto s = da[1 .. u%5]; } // 0 0 (u <= 10 && l <= u%5) { auto s = da[l .. u]; } // 0 0 (u <= 10 && l <= u) { auto s = da[0 .. u]; } // 0 1 (u <= 10 ) { auto s = da[l .. 10]; } // 0 0 (u <= 10 && l <= u) { auto s = da[0 .. u%5]; } // 0 1 (u%5 <= 10 ) { auto s = sa[l .. u]; } // 0 0 (u <= 10 && l <= u ) { auto s = sa[1 .. u]; } // 0 0 (u <= 10 && l <= u ) { auto s = sa[l .. 10]; } // 1 0 ( l <= u ) { auto s = sa[1 .. u%5]; } // 1 0 ( l <= u%5) { auto s = sa[l .. u]; } // 0 0 (u <= 10 && l <= u ) { auto s = sa[0 .. u]; } // 0 1 (u <= 10 ) { auto s = sa[l .. 10]; } // 1 0 ( l <= 10) { auto s = sa[0 .. u%5]; } // 1 1 NULL int* p = new int[](10).ptr; { auto s = p[0 .. u]; } // 1 1 NULL { auto s = p[l .. u]; } // 1 0 (l <= u) { auto s = p[0 .. u%5]; } // 1 1 NULL { auto s = p[1 .. u%5]; } // 1 0 (l <= u%5) } /******************************************/ int main() { test1(); test13976(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link13350.d0000644000175000017500000000536713200164642023120 0ustar matthiasmatthiasextern (C) int printf(const(char*) fmt, ...); static int foo(); /**********************************/ auto red()() { return foo(); } void test13350() { int[] data; assert(is(typeof(red()))); } /**********************************/ struct A1(T) { void f1() {} } struct B1(T) { void f2() {} } A1!(B1!int) func1()() { return typeof(return).init; } void test1() { static if (is(typeof(func1()) R : X!(Y), alias X, Y)) { R.init.f1(); Y.init.f2(); } else static assert(0); } /**********************************/ struct A2(T) { void f1() { foo(); } } struct B2(T) { void f2() { foo(); } } A2!(B2!int) func2()() { return typeof(return).init; } void test2() { static if (is(typeof(func2()))) { } else static assert(0); } /**********************************/ template A3() { void foo() { B3!().bar(); } } template B3() { void bar() {} } void test3() { // A3!() and B3!() are marked as 'speculative' static assert(is(typeof(A3!().foo()))); // A3!() is unspeculative, but B3!() isn't. A3!().foo(); // in codegen phase, B3!() will generate its members, because // the tinst chain contains unspeculative instance A3!(). } /**********************************/ struct S4(T) { string toString() const { return "instantiated"; } } void test4() { // inside typeof is not speculative context alias X = typeof(S4!int()); assert(typeid(X).xtoString !is null); } /**********************************/ struct S5(T) { string toString() const { return "instantiated"; } } void test5() { enum x = S5!int(); assert(x.toString() == "instantiated"); } /**********************************/ int foo6()() { return 0; } template A6() { alias f = foo6!(); } void testa6()() if (is(typeof(A6!().f))) {} template B6() { alias f = foo6!(); } void testb6()() if (is(typeof(B6!().f))) {} template C6() { void f() { B6!().f(); } } void test6() { testa6(); // foo6!() is speculatively instantiated from A6!() [TemplateInstance a] // -> foo6!() is instantiated in A6!(), so it should be inserted to the members of this module. testb6(); // foo6!() is speculatively instantiated from B6!() [TemplateInstance b], // but the tinst of cached [TemplateInstance a] is not changed. // -> insert [b] to the tnext chain of [a] C6!().f(); // foo6!() is used through C6!(), so it should be linked to the final executable. // but its first instance does not link to any non-speculative instances. // -> look for tnext chain and determine its codegen is really necessary. } /**********************************/ int main() { test13350(); test1(); test2(); test3(); test4(); test5(); test6(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link15017.d0000644000175000017500000000170113200164642023106 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/std15017variant.d import imports.std15017variant; void test() { // OK <- in IndexExp::semantic Variant1[string] aa1; aa1["abc"] = Variant1(); // already ok in CatExp::semantic with checkPostblit Variant2[] a2; a2 = a2 ~ Variant2(); // already ok in CatAssignExp::semantic with checkPostblit Variant3[] a3; a3 ~= Variant3(); // OK <- in CmpExp::semantic Variant4[] a4; assert(a4 < a4); // already OK in needDirectEq from EqualExp::semantic Variant5[] a5; assert(a5 == a5); // already OK in EqualExp::semantic Variant6[Variant7] aa67; assert(aa67 == aa67); // OK <- in InExp::semantic string[Variant8] aa8; assert(Variant8() in aa8); // OK <- in resolveUFCS with RemoveExp string[Variant9] aa9; aa9.remove(Variant9()); // OK <- in DeleteExp::semantic Variant10* p10; delete p10; } void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/template9.d0000644000175000017500000032427513200164642023475 0ustar matthiasmatthias// PERMUTE_ARGS: module breaker; import core.stdc.stdio, core.vararg; /**********************************/ U foo(T, U)(U i) { return i + 1; } int foo(T)(int i) { return i + 2; } void test1() { auto i = foo!(int)(2L); // assert(i == 4); // now returns 3 } /**********************************/ U foo2(T, U)(U i) { return i + 1; } void test2() { auto i = foo2!(int)(2L); assert(i == 3); } /**********************************/ class Foo3 { T bar(T,U)(U u) { return cast(T)u; } } void test3() { Foo3 foo = new Foo3; int i = foo.bar!(int)(1.0); assert(i == 1); } /**********************************/ T* begin4(T)(T[] a) { return a.ptr; } void copy4(string pred = "", Ranges...)(Ranges rs) { alias rs[$ - 1] target; pragma(msg, typeof(target).stringof); auto tb = begin4(target);//, te = end(target); } void test4() { int[] a, b, c; copy4(a, b, c); // comment the following line to prevent compiler from crashing copy4!("a > 1")(a, b, c); } /**********************************/ import std.stdio:writefln; template foo5(T,S) { void foo5(T t, S s) { writefln("typeof(T)=",typeid(T)," typeof(S)=",typeid(S)); } } template bar5(T,S) { void bar5(S s) { writefln("typeof(T)=",typeid(T),"typeof(S)=",typeid(S)); } } void test5() { foo5(1.0,33); bar5!(double,int)(33); bar5!(float)(33); } /**********************************/ int foo6(T...)(auto ref T x) { int result; foreach (i, v; x) { if (v == 10) assert(__traits(isRef, x[i])); else assert(!__traits(isRef, x[i])); result += v; } return result; } void test6() { int y = 10; int r; r = foo6(8); assert(r == 8); r = foo6(y); assert(r == 10); r = foo6(3, 4, y); assert(r == 17); r = foo6(4, 5, y); assert(r == 19); r = foo6(y, 6, y); assert(r == 26); } /**********************************/ auto ref min(T, U)(auto ref T lhs, auto ref U rhs) { return lhs > rhs ? rhs : lhs; } void test7() { int x = 7, y = 8; int i; i = min(4, 3); assert(i == 3); i = min(x, y); assert(i == 7); min(x, y) = 10; assert(x == 10); static assert(!__traits(compiles, min(3, y) = 10)); static assert(!__traits(compiles, min(y, 3) = 10)); } /**********************************/ // 5946 template TTest8() { int call(){ return this.g(); } } class CTest8 { int f() { mixin TTest8!(); return call(); } int g() { return 10; } } void test8() { assert((new CTest8()).f() == 10); } /**********************************/ // 693 template TTest9(alias sym) { int call(){ return sym.g(); } } class CTest9 { int f1() { mixin TTest9!(this); return call(); } int f2() { mixin TTest9!this; return call(); } int g() { return 10; } } void test9() { assert((new CTest9()).f1() == 10); assert((new CTest9()).f2() == 10); } /**********************************/ // 1780 template Tuple1780(Ts ...) { alias Ts Tuple1780; } template Decode1780( T ) { alias Tuple1780!() Types; } template Decode1780( T : TT!(Us), alias TT, Us... ) { alias Us Types; } void test1780() { struct S1780(T1, T2) {} // should extract tuple (bool,short) but matches the first specialisation alias Decode1780!( S1780!(bool,short) ).Types SQ1780; // --> SQ2 is empty tuple! static assert(is(SQ1780 == Tuple1780!(bool, short))); } /**********************************/ // 1659 class Foo1659 { } class Bar1659 : Foo1659 { } void f1659(T : Foo1659)() { } void f1659(alias T)() { static assert(false); } void test1659() { f1659!Bar1659(); } /**********************************/ // 2025 struct S2025 {} void f2025() {} template Foo2025(int i) { enum Foo2025 = 1; } template Foo2025(TL...) { enum Foo2025 = 2; } static assert(Foo2025!1 == 1); static assert(Foo2025!int == 2); static assert(Foo2025!S2025 == 2); static assert(Foo2025!f2025 == 2); template Bar2025(T) { enum Bar2025 = 1; } template Bar2025(A...) { enum Bar2025 = 2; } static assert(Bar2025!1 == 2); static assert(Bar2025!int == 1); // 2 -> 1 static assert(Bar2025!S2025 == 1); // 2 -> 1 static assert(Bar2025!f2025 == 2); template Baz2025(T) { enum Baz2025 = 1; } template Baz2025(alias A) { enum Baz2025 = 2; } static assert(Baz2025!1 == 2); static assert(Baz2025!int == 1); static assert(Baz2025!S2025 == 1); // 2 -> 1 static assert(Baz2025!f2025 == 2); /**********************************/ // 3608 template foo3608(T, U){} template BaseTemplate3608(alias TTT : U!V, alias U, V...) { alias U BaseTemplate3608; } template TemplateParams3608(alias T : U!V, alias U, V...) { alias V TemplateParams3608; } template TyueTuple3608(T...) { alias T TyueTuple3608; } void test3608() { alias foo3608!(int, long) Foo3608; static assert(__traits(isSame, BaseTemplate3608!Foo3608, foo3608)); static assert(is(TemplateParams3608!Foo3608 == TyueTuple3608!(int, long))); } /**********************************/ // 5015 import breaker; static if (is(ElemType!(int))){} template ElemType(T) { alias _ElemType!(T).type ElemType; } template _ElemType(T) { alias r type; } /**********************************/ // 5185 class C5185(V) { void f() { C5185!(C5185!(int)) c; } } void test5185() { C5185!(C5185!(int)) c; } /**********************************/ // 5893 class C5893 { int concatAssign(C5893 other) { return 1; } int concatAssign(int other) { return 2; } // to demonstrate overloading template opOpAssign(string op) if (op == "~") { alias concatAssign opOpAssign; } int opOpAssign(string op)(int other) if (op == "+") { return 3; } } void test5893() { auto c = new C5893; assert(c.opOpAssign!"~"(c) == 1); // works assert(c.opOpAssign!"~"(1) == 2); // works assert((c ~= 1) == 2); assert((c += 1) == 3); // overload } /**********************************/ // 5988 template Templ5988(alias T) { alias T!int Templ5988; } class C5988a(T) { Templ5988!C5988a foo; } //Templ5988!C5988a foo5988a; // Commented version void test5988a() { C5988a!int a; } // Was error, now works class C5988b(T) { Templ5988!C5988b foo; } Templ5988!C5988b foo5988b; // Uncomment version void test5988b() { C5988b!int a; } // Works /**********************************/ // 6404 // receive only rvalue void rvalue(T)(auto ref T x) if (!__traits(isRef, x)) {} void rvalueVargs(T...)(auto ref T x) if (!__traits(isRef, x[0])) {} // receive only lvalue void lvalue(T)(auto ref T x) if ( __traits(isRef, x)) {} void lvalueVargs(T...)(auto ref T x) if ( __traits(isRef, x[0])) {} void test6404() { int n; static assert(!__traits(compiles, rvalue(n))); static assert( __traits(compiles, rvalue(0))); static assert( __traits(compiles, lvalue(n))); static assert(!__traits(compiles, lvalue(0))); static assert(!__traits(compiles, rvalueVargs(n))); static assert( __traits(compiles, rvalueVargs(0))); static assert( __traits(compiles, lvalueVargs(n))); static assert(!__traits(compiles, lvalueVargs(0))); } /**********************************/ // 2246 class A2246(T,d){ T p; } class B2246(int rk){ int[rk] p; } class C2246(T,int rk){ T[rk] p; } template f2246(T:A2246!(U,d),U,d){ void f2246(){ } } template f2246(T:B2246!(rank),int rank){ void f2246(){ } } template f2246(T:C2246!(U,rank),U,int rank){ void f2246(){ } } void test2246(){ A2246!(int,long) a; B2246!(2) b; C2246!(int,2) c; f2246!(A2246!(int,long))(); f2246!(B2246!(2))(); f2246!(C2246!(int,2))(); } /**********************************/ // 2296 void foo2296(size_t D)(int[D] i...){} void test2296() { foo2296(1, 2, 3); } /**********************************/ // 1684 template Test1684( uint memberOffset ){} class MyClass1684 { int flags2; mixin Test1684!(cast(uint)flags2.offsetof) t1; // compiles ok mixin Test1684!(cast(int)flags2.offsetof) t2; // compiles ok mixin Test1684!(flags2.offsetof) t3; // Error: no property 'offsetof' for type 'int' } /**********************************/ void bug4984a(int n)() if (n > 0 && is(typeof(bug4984a!(n-1) ()))) { } void bug4984a(int n : 0)() { } void bug4984b(U...)(U args) if ( is(typeof( bug4984b(args[1..$]) )) ) { } void bug4984b(U)(U u) { } void bug4984() { // Note: compiling this overflows the stack if dmd is build with DEBUG //bug4984a!400(); bug4984a!200(); bug4984b(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19); } /***************************************/ // 2579 void foo2579(T)(T delegate(in Object) dlg) { } void test2579() { foo2579( (in Object o) { return 15; } ); } /**********************************/ // 2803 auto foo2803(T)(T t = 0) { return t; } struct S2803 {} S2803 s2803; ref S2803 getS2803() { return s2803; } auto fun2803(T, U)(T t, ref U u = getS2803) { static assert(is(U == S2803)); return &u; } // from the past version of std.conv template to2803(T) { T to2803(S)(S src) { return T.init; } } auto toImpl2803a(T, S)(S s, in T left, in T sep = ", ", in T right = "]") {} auto toImpl2803b(T, S)(S s, in T left = to2803!T(S.stringof~"("), in T right = ")") {} auto toImpl2803c(T, S)(S s, in T left = S.stringof~"(" , in T right = ")") {} // combination with enh 13944 // from std.range.package in 2.067a. auto enumerate2803(En = size_t, R)(R r, En start = 0) { // The type of 'start' should be size_t, it's the defaultArg of En, // rather than the deduced type from its defualtArg '0'. static assert(is(typeof(start) == size_t)); return start; } // from std.numeric. alias ElementType2803(R) = typeof(R.init[0].init); void normalize2803(R)(R range, ElementType2803!R sum = 1) { // The type of 'sum' should be determined to ElementType!(double[]) == double // before the type deduction from its defaultArg '1'. static assert(is(typeof(sum) == double)); } auto foo14468(T)(T[]...) { return 1; } auto foo14468(bool flag, T)(T[]...) { return 2; } void test2803() { assert(foo2803() == 0); assert(foo2803(1) == 1); S2803 s; assert(fun2803(1) is &s2803); assert(fun2803(1, s) is &s); // regression cases toImpl2803a!string(1, "["); toImpl2803b! string(1); toImpl2803b!wstring(1); toImpl2803b!dstring(1); toImpl2803c! string(1); toImpl2803c!wstring(1); // requires enhancement 13944 toImpl2803c!dstring(1); // requires enhancement 13944 enumerate2803([1]); double[] a = []; normalize2803(a); assert(foo14468!int() == 1); } /**********************************/ // 6613 alias Tuple6613(T...) = T; void f6613(T...)(int x = 0, T xs = Tuple6613!()) { assert(x == 0); static assert(T.length == 0); } void test6613() { f6613(); } /**********************************/ // 4953 void bug4953(T = void)(short x) {} static assert(is(typeof(bug4953(3)))); /**********************************/ // 5886 & 5393 mixin template Foo5886(T) { void foo(U : T, this X)() const { static assert(is(X == const K5886)); } } struct K5886 { void get1(this T)() const { pragma(msg, T); } void get2(int N=4, this T)() const { pragma(msg, N, " ; ", T); } mixin Foo5886!double; mixin Foo5886!string; void test() const { get1; // OK get2; // OK get2!8; // NG foo!(int); foo!(typeof(null)); } } void test5886() { K5886 km; const(K5886) kc; immutable(K5886) ki; km.get1; // OK kc.get1; // OK ki.get1; // OK km.get2; // OK kc.get2; // OK ki.get2; // OK km.get2!(1, K5886); // Ugly kc.get2!(2, const(K5886)); // Ugly ki.get2!(3, immutable(K5886)); // Ugly km.get2!8; // Error kc.get2!9; // Error ki.get2!10; // Error } // -------- void test5393() { class A { void opDispatch (string name, this T) () { } } class B : A {} auto b = new B; b.foobar(); } /**********************************/ // 5896 struct X5896 { T opCast(T)(){ return 1; } const T opCast(T)(){ return 2; } immutable T opCast(T)(){ return 3; } shared T opCast(T)(){ return 4; } const shared T opCast(T)(){ return 5; } } void test5896() { auto xm = X5896 (); auto xc = const(X5896) (); auto xi = immutable(X5896) (); auto xs = shared(X5896) (); auto xcs= const(shared(X5896))(); assert(cast(int)xm == 1); assert(cast(int)xc == 2); assert(cast(int)xi == 3); assert(cast(int)xs == 4); assert(cast(int)xcs== 5); } /**********************************/ // 6312 void h6312() {} class Bla6312 { mixin wrap6312!h6312; } mixin template wrap6312(alias f) { void blub(alias g = f)() { g(); } } void test6312() { Bla6312 b = new Bla6312(); b.blub(); } /**********************************/ // 6825 void test6825() { struct File { void write(S...)(S args) {} } void dump(void delegate(string) d) {} auto o = File(); dump(&o.write!string); } /**********************************/ // 6789 template isStaticArray6789(T) { static if (is(T U : U[N], size_t N)) // doesn't match { pragma(msg, "> U = ", U, ", N:", typeof(N), " = ", N); enum isStaticArray6789 = true; } else enum isStaticArray6789 = false; } void test6789() { alias int[3] T; static assert(isStaticArray6789!T); } /**********************************/ // 2778 struct ArrayWrapper2778(T) { T[] data; alias data this; } void doStuffFunc2778(int[] data) {} void doStuffTempl2778(T)(T[] data) {} int doStuffTemplOver2778(T)(void* data) { return 1; } int doStuffTemplOver2778(T)(ArrayWrapper2778!T w) { return 2; } void test2778() { ArrayWrapper2778!(int) foo; doStuffFunc2778(foo); // Works. doStuffTempl2778!(int)(foo); // Works. doStuffTempl2778(foo); // Error assert(doStuffTemplOver2778(foo) == 2); } // ---- void test2778aa() { void foo(K, V)(V[K] aa){ pragma(msg, "K=", K, ", V=", V); } int[string] aa1; foo(aa1); // OK struct SubTypeOf(T) { T val; alias val this; } SubTypeOf!(string[char]) aa2; foo(aa2); // NG } // ---- void test2778get() { void foo(ubyte[]){} static struct S { ubyte[] val = [1,2,3]; @property ref ubyte[] get(){ return val; } alias get this; } S s; foo(s); } /**********************************/ // 6208 int getRefNonref(T)(ref T s){ return 1; } int getRefNonref(T)( T s){ return 2; } int getAutoRef(T)(auto ref T s){ return __traits(isRef, s) ? 1 : 2; } void getOut(T)(out T s){ ; } void getLazy1(T=int)(lazy void s){ s(), s(); } void getLazy2(T)(lazy T s){ s(), s(); } void test6208a() { int lvalue; int rvalue(){ int t; return t; } assert(getRefNonref(lvalue ) == 1); assert(getRefNonref(rvalue()) == 2); assert(getAutoRef(lvalue ) == 1); assert(getAutoRef(rvalue()) == 2); static assert( __traits(compiles, getOut(lvalue ))); static assert(!__traits(compiles, getOut(rvalue()))); int n1; getLazy1(++n1); assert(n1 == 2); int n2; getLazy2(++n2); assert(n2 == 2); struct X { int f(T)(auto ref T t){ return 1; } int f(T)(auto ref T t, ...){ return -1; } } auto xm = X (); auto xc = const(X)(); int n; assert(xm.f!int(n) == 1); // resolved 'auto ref' assert(xm.f!int(0) == 1); // ditto } void test6208b() { void foo(T)(const T value) if (!is(T == int)) {} int mn; const int cn; static assert(!__traits(compiles, foo(mn))); // OK -> OK static assert(!__traits(compiles, foo(cn))); // NG -> OK } void test6208c() { struct S { // Original test case. int foo(V)(in V v) { return 1; } int foo(Args...)(auto ref const Args args) { return 2; } // Reduced test cases int hoo(V)(const V v) { return 1; } // typeof(10) : const V -> MATCHconst int hoo(Args...)(const Args args) { return 2; } // typeof(10) : const Args[0] -> MATCHconst // If deduction matching level is same, tuple parameter is less specialized than others. int bar(V)(V v) { return 1; } // typeof(10) : V -> MATCHexact int bar(Args...)(const Args args) { return 2; } // typeof(10) : const Args[0] -> MATCHconst int baz(V)(const V v) { return 1; } // typeof(10) : const V -> MATCHconst int baz(Args...)(Args args) { return 2; } // typeof(10) : Args[0] -> MATCHexact inout(int) war(V)(inout V v) { return 1; } inout(int) war(Args...)(inout Args args){ return 2; } inout(int) waz(Args...)(inout Args args){ return 0; } // wild deduction test } S s; int nm = 10; assert(s.foo(nm) == 1); assert(s.hoo(nm) == 1); assert(s.bar(nm) == 1); assert(s.baz(nm) == 2); assert(s.war(nm) == 1); static assert(is(typeof(s.waz(nm)) == int)); const int nc = 10; assert(s.foo(nc) == 1); assert(s.hoo(nc) == 1); assert(s.bar(nc) == 1); assert(s.baz(nc) == 1); assert(s.war(nc) == 1); static assert(is(typeof(s.waz(nc)) == const(int))); immutable int ni = 10; assert(s.foo(ni) == 1); assert(s.hoo(ni) == 1); assert(s.bar(ni) == 1); assert(s.baz(ni) == 2); assert(s.war(ni) == 1); static assert(is(typeof(s.waz(ni)) == immutable(int))); static assert(is(typeof(s.waz(nm, nm)) == int)); static assert(is(typeof(s.waz(nm, nc)) == const(int))); static assert(is(typeof(s.waz(nm, ni)) == const(int))); static assert(is(typeof(s.waz(nc, nm)) == const(int))); static assert(is(typeof(s.waz(nc, nc)) == const(int))); static assert(is(typeof(s.waz(nc, ni)) == const(int))); static assert(is(typeof(s.waz(ni, nm)) == const(int))); static assert(is(typeof(s.waz(ni, nc)) == const(int))); static assert(is(typeof(s.waz(ni, ni)) == immutable(int))); } /**********************************/ // 6805 struct T6805 { template opDispatch(string name) { alias int Type; } } static assert(is(T6805.xxx.Type == int)); /**********************************/ // 6738 struct Foo6738 { int _val = 10; @property int val()() { return _val; } int get() { return val; } // fail } void test6738() { Foo6738 foo; auto x = foo.val; // ok assert(x == 10); assert(foo.get() == 10); } /**********************************/ // 7498 template IndexMixin(){ void insert(T)(T value){ } } class MultiIndexContainer{ mixin IndexMixin!() index0; class Index0{ void baburk(){ this.outer.index0.insert(1); } } } /**********************************/ // 6780 @property int foo6780()(){ return 10; } int g6780; @property void bar6780()(int n){ g6780 = n; } void test6780() { auto n = foo6780; assert(n == 10); bar6780 = 10; assert(g6780 == 10); } /**********************************/ // 6810 int f6810(int n)(int) { return 1;} int f6810(U...)(U) { assert(0); } int f6810(U...)(U a) { assert(0); } int f6810(U...)(U) if (true) { assert(0); } int f6810(U...)(U a) if (true) { assert(0); } void test6810() { assert(f6810!0(0) == 1); } /**********************************/ // 6891 struct S6891(int N, T) { void f(U)(S6891!(N, U) u) { } } void test6891() { alias S6891!(1, void) A; A().f(A()); } /**********************************/ // 6994 struct Foo6994 { T get(T)(){ return T.init; } T func1(T)() if (__traits(compiles, get!T())) { return get!T; } T func2(T)() if (__traits(compiles, this.get!T())) // add explicit 'this' { return get!T; } } void test6994() { Foo6994 foo; foo.get!int(); // OK foo.func1!int(); // OK foo.func2!int(); // NG } /**********************************/ // 6764 enum N6764 = 1; //use const for D1 alias size_t[N6764] T6764; //workaround void f6764()(T6764 arr...) { } void g6764()(size_t[1] arr...) { } void h6764()(size_t[N6764] arr...) { } void test6764() { f6764(0); //good g6764(0); //good h6764!()(0); //good h6764(0); //Error: template main.f() does not match any function template declaration } /**********************************/ // 3467 & 6806 struct Foo3467( uint n ) { Foo3467!( n ) bar( ) { typeof( return ) result; return result; } } struct Vec3467(size_t N) { void opBinary(string op:"~", size_t M)(Vec3467!M) {} } void test3467() { Foo3467!( 4 ) baz; baz = baz.bar;// FAIL Vec3467!2 a1; Vec3467!3 a2; a1 ~ a2; // line 7, Error } struct TS6806(size_t n) { pragma(msg, typeof(n)); } static assert(is(TS6806!(1u) == TS6806!(1))); /**********************************/ // 4413 struct Foo4413 { alias typeof(this) typeof_this; void bar1(typeof_this other) {} void bar2()(typeof_this other) {} void bar3(typeof(this) other) {} void bar4()(typeof(this) other) {} } void test4413() { Foo4413 f; f.bar1(f); // OK f.bar2(f); // OK f.bar3(f); // OK f.bar4(f); // ERR } /**********************************/ // 4675 template isNumeric(T) { enum bool test1 = is(T : long); // should be hidden enum bool test2 = is(T : real); // should be hidden enum bool isNumeric = test1 || test2; } void test4675() { static assert( isNumeric!int); static assert(!isNumeric!string); static assert(!__traits(compiles, isNumeric!int.test1)); // should be an error static assert(!__traits(compiles, isNumeric!int.test2)); // should be an error static assert(!__traits(compiles, isNumeric!int.isNumeric)); } /**********************************/ // 5525 template foo5525(T) { T foo5525(T t) { return t; } T foo5525(T t, T u) { return t + u; } } void test5525() { alias foo5525!int f; assert(f(1) == 1); assert(f(1, 2) == 3); } /**********************************/ // 5801 int a5801; void bar5801(T = double)(typeof(a5801) i) {} void baz5801(T)(typeof(a5801) i, T t) {} void test5801() { bar5801(2); // Does not compile. baz5801(3, "baz"); // Does not compile. } /**********************************/ // 5832 struct Bar5832(alias v) {} template isBar5832a(T) { static if (is(T _ : Bar5832!(v), alias v)) enum isBar5832a = true; else enum isBar5832a = false; } template isBar5832b(T) { static if (is(T _ : Bar5832!(v), alias int v)) enum isBar5832b = true; else enum isBar5832b = false; } template isBar5832c(T) { static if (is(T _ : Bar5832!(v), alias string v)) enum isBar5832c = true; else enum isBar5832c = false; } static assert( isBar5832a!(Bar5832!1234)); static assert( isBar5832b!(Bar5832!1234)); static assert(!isBar5832c!(Bar5832!1234)); /**********************************/ // 2550 template pow10_2550(long n) { const long pow10_2550 = 0; static if (n < 0) const long pow10_2550 = 0; else const long pow10_2550 = 10 * pow10_2550!(n - 1); } template pow10_2550(long n:0) { const long pow10_2550 = 1; } static assert(pow10_2550!(0) == 1); /**********************************/ // [2.057] Remove top const in IFTI, 9198 void foo10a(T )(T) { static assert(is(T == const(int)[])); } void foo10b(T...)(T) { static assert(is(T[0] == const(int)[])); } // ref paramter doesn't remove top const void boo10a(T )(ref T) { static assert(is(T == const(int[]))); } void boo10b(T...)(ref T) { static assert(is(T[0] == const(int[]))); } // auto ref with lvalue doesn't void goo10a(T )(auto ref T) { static assert(is(T == const(int[]))); } void goo10b(T...)(auto ref T) { static assert(is(T[0] == const(int[]))); } // auto ref with rvalue does void hoo10a(T )(auto ref T) { static assert(is(T == const(int)[])); } void hoo10b(T...)(auto ref T) { static assert(is(T[0] == const(int)[])); } void bar10a(T )(T) { static assert(is(T == const(int)*)); } void bar10b(T...)(T) { static assert(is(T[0] == const(int)*)); } void test10() { const a = [1,2,3]; static assert(is(typeof(a) == const(int[]))); foo10a(a); foo10b(a); boo10a(a); boo10b(a); goo10a(a); goo10b(a); hoo10a(cast(const)[1,2,3]); hoo10b(cast(const)[1,2,3]); int n; const p = &n; static assert(is(typeof(p) == const(int*))); bar10a(p); bar10b(p); } /**********************************/ // 3092 template Foo3092(A...) { alias A[0] Foo3092; } static assert(is(Foo3092!(int, "foo") == int)); /**********************************/ // 7037 struct Foo7037 {} struct Bar7037 { Foo7037 f; alias f this; } void works7037( T )( T value ) if ( is( T : Foo7037 ) ) {} void doesnotwork7037( T : Foo7037 )( T value ) {} void test7037() { Bar7037 b; works7037( b ); doesnotwork7037( b ); } /**********************************/ // 7110 struct S7110 { int opSlice(int, int) const { return 0; } int opSlice() const { return 0; } int opIndex(int, int) const { return 0; } int opIndex(int) const { return 0; } } enum e7110 = S7110(); template T7110(alias a) { } // or T7110(a...) alias T7110!( S7110 ) T71100; // passes alias T7110!((S7110)) T71101; // passes alias T7110!( S7110()[0..0] ) A0; // passes alias T7110!( (e7110[0..0]) ) A1; // passes alias T7110!( e7110[0..0] ) A2; // passes alias T7110!( S7110()[0, 0] ) B0; // passes alias T7110!( (e7110[0, 0]) ) B1; // passes alias T7110!( e7110[0, 0] ) B2; // passes alias T7110!( S7110()[] ) C0; // passes alias T7110!( (e7110[]) ) C1; // passes alias T7110!( e7110[] ) C2; // fails: e7110 is used as a type alias T7110!( S7110()[0] ) D0; // passes alias T7110!( (e7110[0]) ) D1; // passes alias T7110!( e7110[0] ) D2; // fails: e7110 must be an array or pointer type, not S7110 /**********************************/ // 7124 template StaticArrayOf(T : E[dim], E, size_t dim) { pragma(msg, "T = ", T, ", E = ", E, ", dim = ", dim); alias E[dim] StaticArrayOf; } template DynamicArrayOf(T : E[], E) { pragma(msg, "T = ", T, ", E = ", E); alias E[] DynamicArrayOf; } template AssocArrayOf(T : V[K], K, V) { pragma(msg, "T = ", T, ", K = ", K, ", V = ", V); alias V[K] AssocArrayOf; } void test7124() { struct SA { int[5] sa; alias sa this; } static assert(is(StaticArrayOf!SA == int[5])); struct DA { int[] da; alias da this; } static assert(is(DynamicArrayOf!DA == int[])); struct AA { int[string] aa; alias aa this; } static assert(is(AssocArrayOf!AA == int[string])); } /**********************************/ // 7359 bool foo7359(T)(T[] a ...) { return true; } void test7359() { assert(foo7359(1,1,1,1,1,1)); // OK assert(foo7359("abc","abc","abc","abc")); // NG } /**********************************/ // 7363 template t7363() { enum e = 0; static if (true) enum t7363 = 0; } static assert(!__traits(compiles, t7363!().t7363 == 0)); // Assertion fails static assert(t7363!() == 0); // Error: void has no value template u7363() { static if (true) { enum e = 0; enum u73631 = 0; } alias u73631 u7363; } static assert(!__traits(compiles, u7363!().u7363 == 0)); // Assertion fails static assert(u7363!() == 0); // Error: void has no value /**********************************/ struct S4371(T ...) { } alias S4371!("hi!") t; static if (is(t U == S4371!(U))) { } /**********************************/ // 7416 void t7416(alias a)() if(is(typeof(a()))) {} void test7416() { void f() {} alias t7416!f x; } /**********************************/ // 7563 class Test7563 { void test(T, bool a = true)(T t) { } } void test7563() { auto test = new Test7563; pragma(msg, typeof(test.test!(int, true)).stringof); pragma(msg, typeof(test.test!(int)).stringof); // Error: expression (test.test!(int)) has no type } /**********************************/ // 7572 class F7572 { Tr fn7572(Tr, T...)(T t) { return 1; } } Tr Fn7572(Tr, T...)(T t) { return 2; } void test7572() { F7572 f = new F7572(); int delegate() dg = &f.fn7572!int; assert(dg() == 1); int function() fn = &Fn7572!int; assert(fn() == 2); } /**********************************/ // 7580 struct S7580(T) { void opAssign()(T value) {} } struct X7580(T) { private T val; @property ref inout(T) get()() inout { return val; } // template alias get this; } struct Y7580(T) { private T val; @property ref auto get()() inout { return val; } // template + auto return alias get this; } void test7580() { S7580!(int) s; X7580!int x; Y7580!int y; s = x; s = y; shared(X7580!int) sx; static assert(!__traits(compiles, s = sx)); } /**********************************/ // 7585 extern(C) alias void function() Callback; template W7585a(alias dg) { //pragma(msg, typeof(dg)); extern(C) void W7585a() { dg(); } } void test7585() { static void f7585a(){} Callback cb1 = &W7585a!(f7585a); // OK static assert(!__traits(compiles, { void f7585b(){} Callback cb2 = &W7585a!(f7585b); // NG })); Callback cb3 = &W7585a!((){}); // NG -> OK Callback cb4 = &W7585a!(function(){}); // OK static assert(!__traits(compiles, { Callback cb5 = &W7585a!(delegate(){}); // NG })); static int global; // global data Callback cb6 = &W7585a!((){return global;}); // NG -> OK static assert(!__traits(compiles, { int n; Callback cb7 = &W7585a!((){return n;}); // NG })); } /**********************************/ // 7643 template T7643(A...){ alias A T7643; } alias T7643!(long, "x", string, "y") Specs7643; alias T7643!( Specs7643[] ) U7643; // Error: tuple A is used as a type /**********************************/ // 7671 inout(int)[3] id7671n1 ( inout(int)[3] ); inout( U )[n] id7671x1(U, size_t n)( inout( U )[n] ); shared(inout int)[3] id7671n2 ( shared(inout int)[3] ); shared(inout U )[n] id7671x2(U, size_t n)( shared(inout U )[n] ); void test7671() { static assert(is( typeof( id7671n1( (immutable(int)[3]).init ) ) == immutable(int[3]) )); static assert(is( typeof( id7671x1( (immutable(int)[3]).init ) ) == immutable(int[3]) )); static assert(is( typeof( id7671n2( (immutable(int)[3]).init ) ) == immutable(int[3]) )); static assert(is( typeof( id7671x2( (immutable(int)[3]).init ) ) == immutable(int[3]) )); } /************************************/ // 7672 T foo7672(T)(T a){ return a; } void test7672(inout(int[]) a = null, inout(int*) p = null) { static assert(is( typeof( a ) == inout(int[]) )); static assert(is( typeof(foo7672(a)) == inout(int)[] )); static assert(is( typeof( p ) == inout(int*) )); static assert(is( typeof(foo7672(p)) == inout(int)* )); } /**********************************/ // 7684 U[] id7684(U)( U[] ); shared(U[]) id7684(U)( shared(U[]) ); void test7684() { shared(int)[] x; static assert(is( typeof(id7684(x)) == shared(int)[] )); } /**********************************/ // 7694 void match7694(alias m)() { m.foo(); //removing this line supresses ice in both cases } struct T7694 { void foo(){} void bootstrap() { //next line causes ice match7694!(this)(); //while this works: alias this p; match7694!(p)(); } } /**********************************/ // 7755 template to7755(T) { T to7755(A...)(A args) { return toImpl7755!T(args); } } T toImpl7755(T, S)(S value) { return T.init; } template Foo7755(T){} struct Bar7755 { void qux() { if (is(typeof(to7755!string(Foo7755!int)))){}; } } /**********************************/ U[] id11a(U)( U[] ); inout(U)[] id11a(U)( inout(U)[] ); inout(U[]) id11a(U)( inout(U[]) ); inout(shared(U[])) id11a(U)( inout(shared(U[])) ); void test11a(inout int _ = 0) { shared(const(int))[] x; static assert(is( typeof(id11a(x)) == shared(const(int))[] )); shared(int)[] y; static assert(is( typeof(id11a(y)) == shared(int)[] )); inout(U)[n] idz(U, size_t n)( inout(U)[n] ); inout(shared(bool[1])) z; static assert(is( typeof(idz(z)) == inout(shared(bool[1])) )); } inout(U[]) id11b(U)( inout(U[]) ); void test11b() { alias const(shared(int)[]) T; static assert(is(typeof(id11b(T.init)) == const(shared(int)[]))); } /**********************************/ // 7769 void f7769(K)(inout(K) value){} void test7769() { f7769("abc"); } /**********************************/ // 7812 template A7812(T...) {} template B7812(alias C) if (C) {} template D7812() { alias B7812!(A7812!(NonExistent!())) D7812; } static assert(!__traits(compiles, D7812!())); /**********************************/ // 7873 inout(T)* foo(T)(inout(T)* t) { static assert(is(T == int*)); return t; } inout(T)* bar(T)(inout(T)* t) { return foo(t); } void test7873() { int *i; bar(&i); } /**********************************/ // 7933 struct Boo7933(size_t dim){int a;} struct Baa7933(size_t dim) { Boo7933!dim a; //Boo7933!1 a; //(1) This version causes no errors } auto foo7933()(Boo7933!1 b){return b;} //auto fuu7933(Boo7933!1 b){return b;} //(2) This line neutralizes the error void test7933() { Baa7933!1 a; //(3) This line causes the error message auto b = foo7933(Boo7933!1(1)); } /**********************************/ // 8094 struct Tuple8094(T...) {} template getParameters8094(T, alias P) { static if (is(T t == P!U, U...)) alias U getParameters8094; else static assert(false); } void test8094() { alias getParameters8094!(Tuple8094!(int, string), Tuple8094) args; } /**********************************/ struct Tuple12(T...) { void foo(alias P)() { alias Tuple12 X; static if (is(typeof(this) t == X!U, U...)) alias U getParameters; else static assert(false); } } void test12() { Tuple12!(int, string) t; t.foo!Tuple12(); } /**********************************/ // 14290 struct Foo14290(int i) {} alias Foo14290a = Foo14290!1; static assert(!is(Foo14290!2 == Foo14290a!T, T...)); /**********************************/ // 8125 void foo8125(){} struct X8125(alias a) {} template Y8125a(T : A!f, alias A, alias f) {} //OK template Y8125b(T : A!foo8125, alias A) {} //NG void test8125() { alias Y8125a!(X8125!foo8125) y1; alias Y8125b!(X8125!foo8125) y2; } /**********************************/ struct A13() {} struct B13(TT...) {} struct C13(T1) {} struct D13(T1, TT...) {} struct E13(T1, T2) {} struct F13(T1, T2, TT...) {} template Test13(alias X) { static if (is(X x : P!U, alias P, U...)) enum Test13 = true; else enum Test13 = false; } void test13() { static assert(Test13!( A13!() )); static assert(Test13!( B13!(int) )); static assert(Test13!( B13!(int, double) )); static assert(Test13!( B13!(int, double, string) )); static assert(Test13!( C13!(int) )); static assert(Test13!( D13!(int) )); static assert(Test13!( D13!(int, double) )); static assert(Test13!( D13!(int, double, string) )); static assert(Test13!( E13!(int, double) )); static assert(Test13!( F13!(int, double) )); static assert(Test13!( F13!(int, double, string) )); static assert(Test13!( F13!(int, double, string, bool) )); } /**********************************/ struct A14(T, U, int n = 1) { } template Test14(alias X) { static if (is(X x : P!U, alias P, U...)) alias U Test14; else static assert(0); } void test14() { alias A14!(int, double) Type; alias Test14!Type Params; static assert(Params.length == 3); static assert(is(Params[0] == int)); static assert(is(Params[1] == double)); static assert( Params[2] == 1); } /**********************************/ // test for evaluateConstraint assertion bool canSearchInCodeUnits15(C)(dchar c) if (is(C == char)) { return true; } void test15() { int needle = 0; auto b = canSearchInCodeUnits15!char(needle); } /**********************************/ // 8129 class X8129 {} class A8129 {} class B8129 : A8129 {} int foo8129(T : A8129)(X8129 x) { return 1; } int foo8129(T : A8129)(X8129 x, void function (T) block) { return 2; } int bar8129(T, R)(R range, T value) { return 1; } int baz8129(T, R)(R range, T value) { return 1; } int baz8129(T, R)(R range, Undefined value) { return 2; } void test8129() { auto x = new X8129; assert(x.foo8129!B8129() == 1); assert(x.foo8129!B8129((a){}) == 2); assert(foo8129!B8129(x) == 1); assert(foo8129!B8129(x, (a){}) == 2); assert(foo8129!B8129(x) == 1); assert(foo8129!B8129(x, (B8129 b){}) == 2); ubyte[] buffer = [0, 1, 2]; assert(bar8129!ushort(buffer, 915) == 1); // While deduction, parameter type 'Undefined' shows semantic error. static assert(!__traits(compiles, { baz8129!ushort(buffer, 915); })); } /**********************************/ // 8238 void test8238() { static struct S { template t(){ int t; } } S s1, s2; assert(cast(void*)&s1 != cast(void*)&s2 ); assert(cast(void*)&s1 != cast(void*)&s1.t!()); assert(cast(void*)&s2 != cast(void*)&s2.t!()); assert(cast(void*)&s1.t!() == cast(void*)&s2.t!()); s1.t!() = 256; assert(s2.t!() == 256); } /**********************************/ // 8669 struct X8669 { void mfoo(this T)() { static assert(is(typeof(this) == T)); } void cfoo(this T)() const { static assert(is(typeof(this) == const(T))); } void sfoo(this T)() shared { static assert(is(typeof(this) == shared(T))); } void scfoo(this T)() shared const { static assert(is(typeof(this) == shared(const(T)))); } void ifoo(this T)() immutable { static assert(is(typeof(this) == immutable(T))); } } void test8669() { X8669 mx; const X8669 cx; immutable X8669 ix; shared X8669 sx; shared const X8669 scx; mx.mfoo(); cx.mfoo(); ix.mfoo(); sx.mfoo(); scx.mfoo(); mx.cfoo(); cx.cfoo(); ix.cfoo(); sx.cfoo(); scx.cfoo(); static assert(!is(typeof( mx.sfoo() ))); static assert(!is(typeof( cx.sfoo() ))); ix.sfoo(); sx.sfoo(); scx.sfoo(); static assert(!is(typeof( mx.scfoo() ))); static assert(!is(typeof( cx.scfoo() ))); ix.scfoo(); sx.scfoo(); scx.scfoo(); static assert(!is(typeof( mx.ifoo() ))); static assert(!is(typeof( cx.ifoo() ))); ix.ifoo(); static assert(!is(typeof( sx.ifoo() ))); static assert(!is(typeof( scx.ifoo() ))); } /**********************************/ // 8833 template TypeTuple8833(T...) { alias TypeTuple = T; } void func8833(alias arg)() { } void test8833() { int x, y; alias TypeTuple8833!( func8833!(x), func8833!(y), ) Map; } /**********************************/ // 8976 void f8976(ref int) { } void g8976()() { f8976(0); // line 5 } void h8976()() { g8976!()(); } static assert(! __traits(compiles, h8976!()() ) ); // causes error static assert(!is(typeof( h8976!()() ))); void test8976() { static assert(! __traits(compiles, h8976!()() ) ); static assert(!is(typeof( h8976!()() ))); } /****************************************/ // 8940 const int n8940; // or `immutable` static this() { n8940 = 3; } void f8940(T)(ref int val) { assert(val == 3); ++val; } static assert(!__traits(compiles, f8940!void(n8940))); // fails void test8940() { assert(n8940 == 3); static assert(!__traits(compiles, f8940!void(n8940))); //assert(n8940 == 3); // may pass as compiler caches comparison result //assert(n8940 != 4); // may pass but likely will fail } /**********************************/ // 6969 + 8990 class A6969() { alias C6969!() C1; } class B6969 { alias A6969!() A1; } class C6969() : B6969 {} struct A8990(T) { T t; } struct B8990(T) { A8990!T* a; } struct C8990 { B8990!C8990* b; } /**********************************/ // 9018 template Inst9018(alias Template, T) { alias Template!T Inst; } template Template9018(T) { enum Template9018 = T; } static assert(!__traits(compiles, Inst9018!(Template9018, int))); // Assert passes static assert(!__traits(compiles, Inst9018!(Template9018, int))); // Assert fails /**********************************/ // 9022 class C9022 { struct X {} alias B = X; } class D9022 { struct X {} } void test9022() { auto c = new C9022(); auto d = new D9022(); auto cx = C9022.X(); auto dx = D9022.X(); void foo1(T)(T, T.X) { static assert(is(T == C9022)); } void foo2(T)(T.X, T) { static assert(is(T == C9022)); } foo1(c, cx); foo2(cx, c); void hoo1(T)(T, T.B) { static assert(is(T == C9022)); } void hoo2(T)(T.B, T) { static assert(is(T == C9022)); } hoo1(c, cx); hoo1(c, cx); void bar1(alias A)(A.C9022, A.D9022) { static assert(A.stringof == "module breaker"); } void bar2(alias A)(A.D9022, A.C9022) { static assert(A.stringof == "module breaker"); } bar1(c, d); bar2(d, c); void var1(alias A)(A.C9022, A.D9022.X) { static assert(A.stringof == "module breaker"); } void var2(alias A)(A.D9022.X, A.C9022) { static assert(A.stringof == "module breaker"); } var1(c, dx); var2(dx, c); void baz(T)(T.X t, T.X u) { } static assert(!__traits(compiles, baz(cx, dx))); } /**********************************/ // 9026 mixin template node9026() { static if (is(this == struct)) alias typeof(this)* E; else alias typeof(this) E; E prev, next; } struct list9026(alias N) { N.E head; N.E tail; } class A9026 { mixin node9026 L1; mixin node9026 L2; } list9026!(A9026.L1) g9026_l1; list9026!(A9026.L2) g9026_l2; void test9026() { list9026!(A9026.L1) l9026_l1; list9026!(A9026.L2) l9026_l2; } /**********************************/ // 9038 mixin template Foo9038() { string data = "default"; } class Bar9038 { string data; mixin Foo9038 f; } void check_data9038(alias M, T)(T obj) { //writeln(M.stringof); assert(obj.data == "Bar"); assert(obj.f.data == "F"); } void test9038() { auto bar = new Bar9038; bar.data = "Bar"; bar.f.data = "F"; assert(bar.data == "Bar"); assert(bar.f.data == "F"); check_data9038!(Bar9038)(bar); check_data9038!(Bar9038.f)(bar); check_data9038!(bar.f)(bar); } /**********************************/ // 9050 struct A9050(T) {} struct B9050(T) { void f() { foo9050(A9050!int()); } } auto foo9050()(A9050!int base) pure { return B9050!int(); } auto s9050 = foo9050(A9050!int()); /**********************************/ // 10936 (dup of 9050) struct Vec10936(string s) { auto foo(string v)() { return Vec10936!(v)(); } static void bar() { Vec10936!"" v; auto p = v.foo!"sup"; } } Vec10936!"" v; /**********************************/ // 9076 template forward9076(args...) { @property forward9076()(){ return args[0]; } } void test9076() { int a = 1; int b = 1; assert(a == forward9076!b); } /**********************************/ // 9083 template isFunction9083(X...) if (X.length == 1) { enum isFunction9083 = true; } struct S9083 { static string func(alias Class)() { foreach (m; __traits(allMembers, Class)) { pragma(msg, m); // prints "func" enum x1 = isFunction9083!(mixin(m)); //NG enum x2 = isFunction9083!(func); //OK } return ""; } } enum nothing9083 = S9083.func!S9083(); class C9083 { int x; // some class members void func() { void templateFunc(T)(const T obj) { enum x1 = isFunction9083!(mixin("x")); // NG enum x2 = isFunction9083!(x); // NG } templateFunc(this); } } /**********************************/ // 9100 template Id(alias A) { alias Id = A; } template ErrId(alias A) { static assert(0); } template TypeTuple9100(TL...) { alias TypeTuple9100 = TL; } class C9100 { int value; int fun() { return value; } int tfun(T)() { return value; } TypeTuple9100!(int, long) field; void test() { this.value = 1; auto c = new C9100(); c.value = 2; alias t1a = Id!(c.fun); // OK alias t1b = Id!(this.fun); // Prints weird error, bad // -> internally given TOKdotvar assert(t1a() == this.value); assert(t1b() == this.value); alias t2a = Id!(c.tfun); // OK static assert(!__traits(compiles, ErrId!(this.tfun))); alias t2b = Id!(this.tfun); // No error occurs, why? // -> internally given TOKdottd assert(t2a!int() == this.value); assert(t2b!int() == this.value); alias t3a = Id!(foo9100); // OK alias t3b = Id!(mixin("foo9100")); // Prints weird error, bad // -> internally given TOKtemplate assert(t3a() == 10); assert(t3b() == 10); assert(field[0] == 0); alias t4a = TypeTuple9100!(field); // NG alias t4b = TypeTuple9100!(GetField9100!()); // NG t4a[0] = 1; assert(field[0] == 1); t4b[0] = 2; assert(field[0] == 2); } } int foo9100()() { return 10; } template GetField9100() { alias GetField9100 = C9100.field[0]; } void test9100() { (new C9100()).test(); } /**********************************/ // 9101 class Node9101 { template ForwardCtorNoId() { this() {} // default constructor void foo() { 0 = 1; } // wrong code } } enum x9101 = __traits(compiles, Node9101.ForwardCtorNoId!()); /**********************************/ // 9124 struct Foo9124a(N...) { enum SIZE = N[0]; private int _val; public void opAssign (T) (T other) if (is(T unused == Foo9124a!(_N), _N...)) { _val = other._val; // compile error this._val = other._val; // explicit this make it work } public auto opUnary (string op) () if (op == "~") { Foo9124a!(SIZE) result = this; return result; } } void test9124a() { Foo9124a!(28) a; Foo9124a!(28) b = ~a; } // -------- template Foo9124b(T, U, string OP) { enum N = T.SIZE; alias Foo9124b = Foo9124b!(false, true, N); } struct Foo9124b(bool S, bool L, N...) { enum SIZE = 5; long[1] _a = 0; void someFunction() const { auto data1 = _a; // Does not compile auto data2 = this._a; // <--- Compiles } auto opBinary(string op, T)(T) { Foo9124b!(typeof(this), T, op) test; } } void test9124b() { auto p = Foo9124b!(false, false, 5)(); auto q = Foo9124b!(false, false, 5)(); p|q; p&q; } /**********************************/ // 9143 struct Foo9143a(bool S, bool L) { auto noCall() { Foo9143a!(S, false) x1; // compiles if this line commented static if(S) Foo9143a!(true, false) x2; else Foo9143a!(false, false) x2; } this(T)(T other) // constructor if (is(T unused == Foo9143a!(P, Q), bool P, bool Q)) { } } struct Foo9143b(bool L, size_t N) { void baaz0() { bar!(Foo9143b!(false, N))(); // line 7 // -> move to before the baaz semantic } void baaz() { bar!(Foo9143b!(false, 2LU))(); // line 3 bar!(Foo9143b!(true, 2LU))(); // line 4 bar!(Foo9143b!(L, N))(); // line 5 bar!(Foo9143b!(true, N))(); // line 6 bar!(Foo9143b!(false, N))(); // line 7 } void bar(T)() if (is(T unused == Foo9143b!(_L, _N), bool _L, size_t _N)) {} } void test9143() { Foo9143a!(false, true) k = Foo9143a!(false, false)(); auto p = Foo9143b!(true, 2LU)(); } /**********************************/ // 9266 template Foo9266(T...) { T Foo9266; } struct Bar9266() { alias Foo9266!int f; } void test9266() { Bar9266!() a, b; } /**********************************/ // 9361 struct Unit9361(A) { void butPleaseDontUseMe()() if (is(unitType9361!((this)))) // ! {} } template isUnit9361(alias T) if ( is(T)) {} template isUnit9361(alias T) if (!is(T)) {} template unitType9361(alias T) if (isUnit9361!T) {} void test9361() { Unit9361!int u; static assert(!__traits(compiles, u.butPleaseDontUseMe())); // crashes } /**********************************/ // 9536 struct S9536 { static A foo(A)(A a) { return a * 2; } int bar() const { return foo(42); } } void test9536() { S9536 s; assert(s.bar() == 84); } /**********************************/ // 9578 template t9578(alias f) { void tf()() { f(); } } void g9578a(alias f)() { f(); } // Error -> OK void g9578b(alias ti)() { ti.tf(); } // Error -> OK void test9578() { int i = 0; int m() { return i; } g9578a!(t9578!m.tf)(); g9578b!(t9578!m)(); } /**********************************/ // 9596 int foo9596a(K, V)(inout( V [K])) { return 1; } int foo9596a(K, V)(inout(shared(V) [K])) { return 2; } int foo9596b(K, V)(inout( V [K])) { return 1; } int foo9596b(K, V)(inout( const(V) [K])) { return 3; } int foo9596c(K, V)(inout(shared(V) [K])) { return 2; } int foo9596c(K, V)(inout( const(V) [K])) { return 3; } int foo9596d(K, V)(inout( V [K])) { return 1; } int foo9596d(K, V)(inout(shared(V) [K])) { return 2; } int foo9596d(K, V)(inout( const(V) [K])) { return 3; } int foo9596e(K, V)(inout(shared(V) [K])) { return 2; } int foo9596e(K, V)(inout( V [K])) { return 1; } int foo9596e(K, V)(inout( const(V) [K])) { return 3; } void test9596() { shared(int)[int] aa; static assert(!__traits(compiles, foo9596a(aa))); assert(foo9596b(aa) == 1); assert(foo9596c(aa) == 2); static assert(!__traits(compiles, foo9596d(aa))); static assert(!__traits(compiles, foo9596e(aa))); } /******************************************/ // 9806 struct S9806a(alias x) { alias S9806a!0 N; } enum expr9806a = 0 * 0; alias S9806a!expr9806a T9806a; // -------- struct S9806b(alias x) { template Next() { enum expr = x + 1; alias S9806b!expr Next; } } alias S9806b!1 One9806b; alias S9806b!0.Next!() OneAgain9806b; // -------- struct S9806c(x...) { template Next() { enum expr = x[0] + 1; alias S9806c!expr Next; } } alias S9806c!1 One9806c; alias S9806c!0.Next!() OneAgain9806c; /******************************************/ // 9837 void test9837() { enum DA : int[] { a = [1,2,3] } DA da; int[] bda = da; static assert(is(DA : int[])); void fda1(int[] a) {} void fda2(T)(T[] a) {} fda1(da); fda2(da); enum SA : int[3] { a = [1,2,3] } SA sa; int[3] bsa = sa; static assert(is(SA : int[3])); void fsa1(int[3] a) {} void fsa2(T)(T[3] a) {} void fsa3(size_t d)(int[d] a) {} void fsa4(T, size_t d)(T[d] a) {} fsa1(sa); fsa2(sa); fsa3(sa); fsa4(sa); enum AA : int[int] { a = null } AA aa; int[int] baa = aa; static assert(is(AA : int[int])); void faa1(int[int] a) {} void faa2(V)(V[int] a) {} void faa3(K)(int[K] a) {} void faa4(K, V)(V[K] a) {} faa1(aa); faa2(aa); faa3(aa); faa4(aa); } /******************************************/ // 9874 bool foo9874() { return true; } void bar9874(T)(T) if (foo9874()) {} // OK void baz9874(T)(T) if (foo9874) {} // error void test9874() { foo9874; // OK bar9874(0); baz9874(0); } /******************************************/ void test9885() { void foo(int[1][]) {} void boo()(int[1][]){} struct X(T...) { static void xoo(T){} } struct Y(T...) { static void yoo()(T){} } struct Z(T...) { static void zoo(U...)(T, U){} } struct V(T...) { static void voo()(T, ...){} } struct W(T...) { static void woo()(T...){} } struct R(T...) { static void roo(U...)(int, U, T){} } // OK foo([[10]]); boo([[10]]); // OK X!(int[1][]).xoo([[10]]); // NG! Y!().yoo(); Y!(int).yoo(1); Y!(int, int[]).yoo(1, [10]); static assert(!__traits(compiles, Y!().yoo(1))); static assert(!__traits(compiles, Y!(int).yoo("a"))); static assert(!__traits(compiles, Y!().yoo!(int)())); // NG! Z!().zoo(); Z!().zoo([1], [1:1]); Z!(int, string).zoo(1, "a"); Z!(int, string).zoo(1, "a", [1], [1:1]); Z!().zoo!()(); static assert(!__traits(compiles, Z!().zoo!()(1))); // (none) <- 1 static assert(!__traits(compiles, Z!(int).zoo!()())); // int <- (none) static assert(!__traits(compiles, Z!(int).zoo!()(""))); // int <- "" static assert(!__traits(compiles, Z!().zoo!(int)())); // int <- (none) static assert(!__traits(compiles, Z!().zoo!(int)(""))); // int <- "" V!().voo(1,2,3); V!(int).voo(1,2,3); V!(int, long).voo(1,2,3); static assert(!__traits(compiles, V!(int).voo())); // int <- (none) static assert(!__traits(compiles, V!(int, long).voo(1))); // long <- (none) static assert(!__traits(compiles, V!(int, string).voo(1,2,3))); // string <- 2 W!().woo(); //W!().woo(1, 2, 3); // Access Violation { // this behavior is consistent with: //alias TL = TypeTuple!(); //void foo(TL...) {} //foo(1, 2, 3); // Access Violation //pragma(msg, typeof(foo)); // void(...) -> D-style variadic function? } W!(int,int[]).woo(1,2,3); W!(int,int[2]).woo(1,2,3); static assert(!__traits(compiles, W!(int,int,int).woo(1,2,3))); // int... <- 2 static assert(!__traits(compiles, W!(int,int).woo(1,2))); // int... <- 2 static assert(!__traits(compiles, W!(int,int[2]).woo(1,2))); // int[2]... <- 2 R!().roo(1, "", []); R!(int).roo(1, "", [], 1); R!(int, string).roo(1, "", [], 1, ""); R!(int, string).roo(1, 2, ""); static assert(!__traits(compiles, R!(int).roo(1, "", []))); // int <- [] static assert(!__traits(compiles, R!(int, int).roo(1, "", []))); // int <- [] static assert(!__traits(compiles, R!(int, string).roo(1, 2, 3))); // string <- 3 // test case struct Tuple(T...) { this()(T values) {} } alias T = Tuple!(int[1][]); auto t = T([[10]]); } /******************************************/ // 9971 void goo9971()() { auto g = &goo9971; } struct S9971 { void goo()() { auto g = &goo; static assert(is(typeof(g) == delegate)); } } void test9971() { goo9971!()(); S9971.init.goo!()(); } /******************************************/ // 9977 void test9977() { struct S1(T) { T value; } auto func1(T)(T value) { return value; } static assert(is(S1!int == struct)); assert(func1(10) == 10); template S2(T) { struct S2 { T value; } } template func2(T) { auto func2(T value) { return value; } } static assert(is(S2!int == struct)); assert(func2(10) == 10); template X(T) { alias X = T[3]; } static assert(is(X!int == int[3])); int a; template Y(T) { alias Y = T[typeof(a)]; } static assert(is(Y!double == double[int])); int v = 10; template Z() { alias Z = v; } assert(v == 10); Z!() = 20; assert(v == 20); } /******************************************/ enum T8848a(int[] a) = a; enum T8848b(int[int] b) = b; enum T8848c(void* c) = c; static assert(T8848a!([1,2,3]) == [1,2,3]); static assert(T8848b!([1:2,3:4]) == [1:2,3:4]); static assert(T8848c!(null) == null); /******************************************/ // 9990 auto initS9990() { return "hi"; } class C9990(alias init) {} alias SC9990 = C9990!(initS9990); /******************************************/ // 10067 struct assumeSize10067(alias F) {} template useItemAt10067(size_t idx, T) { void impl(){ } alias useItemAt10067 = assumeSize10067!(impl); } useItemAt10067!(0, char) mapS10067; /******************************************/ // 4072 void bug4072(T)(T x) if (is(typeof(bug4072(x)))) {} static assert(!is(typeof(bug4072(7)))); /******************************************/ // 10074 template foo10074(F) { enum foo10074 = false; } bool foo10074(F)(F f) if (foo10074!F) { return false; } static assert(!is(typeof(foo10074(1)))); /******************************************/ // 10083 // [a-c] IFTI can find syntactic eponymous member template foo10083a(T) { int foo10083a(double) { return 1; } int foo10083a(T) { return 2; } } template foo10083b(T) { int foo10083b(T) { return 1; } int foo10083b(T, T) { return 2; } } template foo10083c1(T) { int foo10083c1(T) { return 1; } static if (true) { int x; } } template foo10083c2(T) { int foo10083c2(T) { return 1; } static if (true) { int x; } else { int y; } } // [d-f] IFTI cannot find syntactic eponymous member template foo10083d1(T) { static if (true) { int foo10083d1(T) { return 1; } } else { } } template foo10083d2(T) { static if (true) { } else { int foo10083d2(T) { return 1; } } } template foo10083e(T) { static if (true) { int foo10083e(double arg) { return 1; } } int foo10083e(T arg) { return 2; } } template foo10083f(T) { static if (true) { int foo10083f(T) { return 1; } } else { int foo10083f(T) { return 2; } } } void test10083() { assert(foo10083a(1) == 2); assert(foo10083a!int(1) == 2); assert(foo10083a!int(1.0) == 1); static assert(!__traits(compiles, foo10083a!double(1))); static assert(!__traits(compiles, foo10083a!double(1.0))); static assert(!__traits(compiles, foo10083a!real(1))); assert(foo10083a!real(1.0) == 1); assert(foo10083a!real(1.0L) == 2); assert(foo10083b(2) == 1); assert(foo10083b(3, 4) == 2); static assert(!__traits(compiles, foo10083b(2, ""))); assert(foo10083c1(1) == 1); assert(foo10083c2(1) == 1); static assert(!__traits(compiles, foo10083d1(2))); static assert(!__traits(compiles, foo10083d2(2))); static assert(!__traits(compiles, foo10083e(3))); static assert(!__traits(compiles, foo10083f(3))); } /******************************************/ // 10134 template ReturnType10134(alias func) { static if (is(typeof(func) R == return)) alias R ReturnType10134; else static assert(0); } struct Result10134(T) {} template getResultType10134(alias func) { static if(is(ReturnType10134!(func.exec) _ == Result10134!(T), T)) { alias getResultType10134 = T; } } template f10134(alias func) { Result10134!(getResultType10134!(func)) exec(int i) { return typeof(return)(); } } template a10134() { Result10134!(double) exec(int i) { return b10134!().exec(i); } } template b10134() { Result10134!(double) exec(int i) { return f10134!(a10134!()).exec(i); } } pragma(msg, getResultType10134!(a10134!())); /******************************************/ // 10313 void test10313() { struct Nullable(T) { this()(inout T value) inout {} } struct S { S[] array; } S s; auto ns = Nullable!S(s); class C { C[] array; } C c; auto nc = Nullable!C(c); } /******************************************/ // 10498 template triggerIssue10498a() { enum triggerIssue10498a = __traits(compiles, { T10498a; }); } template PackedGenericTuple10498a(Args...) { alias Args Tuple; enum e = triggerIssue10498a!(); } struct S10498a { } template T10498a() { alias PackedGenericTuple10498a!S10498a T10498a; } void test10498a() { alias T10498a!() t; static assert(is(t.Tuple[0])); // Fails -> OK } // -------- template triggerIssue10498b(A...) { enum triggerIssue10498b = __traits(compiles, { auto a = A[0]; }); } template PackedGenericTuple10498b(Args...) { alias Args Tuple; enum e = triggerIssue10498b!Args; } template T10498b() { struct S {} // The fact `S` is in `T` causes the problem alias PackedGenericTuple10498b!S T10498b; } void test10498b() { alias T10498b!() t; static assert(is(t.Tuple[0])); } /******************************************/ // 10537 struct Iota10537 { int s,e,i; mixin Yield10537!q{ ; }; } auto skipStrings10537(T)(T source) { return ""; } mixin template Yield10537(dstring code) { alias X = typeof({ enum x = rewriteCode10537(code); }()); } dstring rewriteCode10537(dstring code) { skipStrings10537(code); // IFTI causes forward reference return ""; } /******************************************/ // 10558 template Template10558() {} struct Struct10558(alias T){} alias bar10558 = foo10558!(Template10558!()); template foo10558(alias T) { alias foobar = Struct10558!T; void fun() { alias a = foo10558!T; } } /******************************************/ // 10592 void test10592() { struct A(E) { int put()(const(E)[] data) { return 1; } int put()(const(dchar)[] data) if (!is(E == dchar)) { return 2; } int put(C)(const(C)[] data) if (!is(C == dchar) && !is(E == C)) { return 3; } } A!char x; assert(x.put("abcde"c) == 1); // OK: hit 1 assert(x.put("abcde"w) == 3); // NG: this should hit 3 assert(x.put("abcde"d) == 2); // OK: hit 2 } /******************************************/ // 11242 inout(T[]) fromString11242(T)(inout(char[]) s, T[] dst) { return s; } void test11242() { char[] a; fromString11242(a, a); } /******************************************/ // 10811 void foo10811a(R1, R2)(R1, R2) {} template foo10811a(alias pred) { void foo10811a(R1, R2)(R1, R2) {} } template foo10811b(alias pred) { void foo10811b(R1, R2)(R1, R2) {} } void foo10811b(R1, R2)(R1, R2) {} void test10811() { foo10811a(1, 2); foo10811a!(a => a)(1, 2); foo10811b(1, 2); foo10811b!(a => a)(1, 2); } /******************************************/ // 10969 template A10969(T, U...) { alias A10969 = T; } void foo10969(T, U...)(A10969!(T, U) a) {} template B10969(T, U) { alias B10969 = T; } void bar10969(T, U...)(B10969!(T, U[0]) a) {} void test10969() { foo10969!(int, float)(3); bar10969!(int, float)(3); } /******************************************/ // 11271 struct SmartPtr11271(T) { ~this() {} void opAssign(U)(auto ref U rh) {} } void test11271() { SmartPtr11271!Object a; a = SmartPtr11271!Object(); } /******************************************/ // 11533 version (none) { struct S11533 { void put(alias fun)() { fun!int(); } } void test11533a() { static void foo(T)() {} S11533 s; s.put!foo(); } void test11533b() { static void bar(alias fun)() { fun(); } void nested() {} bar!nested(); } void test11533c() { static struct Foo(alias fun) { auto call() { return fun(); } } int var = 1; auto getVar() { return var; } Foo!getVar foo; assert(foo.call() == var); var += 1; assert(foo.call() == var); } void test11533() { test11533a(); test11533b(); test11533c(); } } else { void test11533() { } } /******************************************/ // 11553 struct Pack11553(T ...) { alias Unpack = T; enum length = T.length; } template isPack11553(TList ...) { static if (TList.length == 1 && is(Pack11553!(TList[0].Unpack) == TList[0])) { enum isPack11553 = true; } else { enum isPack11553 = false; } } template PartialApply11553(alias T, uint argLoc, Arg ...) if (Arg.length == 1) { template PartialApply11553(L ...) { alias PartialApply11553 = T!(L[0 .. argLoc], Arg, L[argLoc .. $]); } } template _hasLength11553(size_t len, T) { static if (T.length == len) { enum _hasLength11553 = true; } else { enum _hasLength11553 = false; } } alias _hasLength11553(size_t len) = PartialApply11553!(._hasLength11553, 0, len); alias hl11553 = _hasLength11553!1; // this segfaults static if (!isPack11553!hl11553) { pragma(msg, "All good 1"); } // these are fine static if ( hl11553!(Pack11553!(5))) { pragma(msg, "All good 2"); } static if (!hl11553!(Pack11553!( ))) { pragma(msg, "All good 3"); } /******************************************/ // 11818 enum E11818 { e0, e1 } struct SortedRange11818 { void fun(E11818 e = true ? E11818.e0 : E11818.e1)() { } } void test11818() { SortedRange11818 s; s.fun(); } /******************************************/ // 11843 void test11843() { struct Foo { int x[string]; } struct Bar(alias foo) {} enum bar1 = Bar!(Foo(["a": 1]))(); enum bar2 = Bar!(Foo(["a": 1]))(); static assert(is(typeof(bar1) == typeof(bar2))); enum foo1 = Foo(["a": 1]); enum foo2 = Foo(["b": -1]); static assert(!__traits(isSame, foo1, foo2)); enum bar3 = Bar!foo1(); enum bar4 = Bar!foo2(); static assert(!is(typeof(bar3) == typeof(bar4))); } /******************************************/ // 11872 class Foo11872 { auto test(int v)() {} auto test(int v)(string) {} template Bar(T) { void test(T) {} } } void test11872() { auto foo = new Foo11872(); with (foo) { // ScopeExp(ti) -> DotTemplateInstanceExp(wthis, ti) foo.test!2(); // works test!2(); // works <- fails test!2; // works <- fails // ScopeExp(ti) -> DotTemplateInstanceExp(wthis, ti) -> DotExp(wthis, ScopeExp) foo.Bar!int.test(1); // works Bar!int.test(1); // works <- fails } } /******************************************/ // 12042 struct S12042 { int[] t; void m()() { t = null; // CTFE error -> OK } } int test12042() { S12042 s; with (s) m!()(); return 1; } static assert(test12042()); /******************************************/ // 12077 struct S12077(A) {} alias T12077(alias T : Base!Args, alias Base, Args...) = Base; static assert(__traits(isSame, T12077!(S12077!int), S12077)); alias U12077(alias T : Base!Args, alias Base, Args...) = Base; alias U12077( T : Base!Args, alias Base, Args...) = Base; static assert(__traits(isSame, U12077!(S12077!int), S12077)); /******************************************/ // 12262 template Inst12262(T) { int x; } enum fqnSym12262(alias a) = 1; enum fqnSym12262(alias a : B!A, alias B, A...) = 2; static assert(fqnSym12262!(Inst12262!(Object)) == 2); static assert(fqnSym12262!(Inst12262!(Object).x) == 1); /******************************************/ // 12264 struct S12264(A) {} template AX12264(alias A1) { enum AX12264 = 1; } template AX12264(alias A2 : B!A, alias B, A...) { enum AX12264 = 2; } template AY12264(alias A1) { enum AY12264 = 1; } template AY12264(alias A2 : B!int, alias B) { enum AY12264 = 2; } template AZ12264(alias A1) { enum AZ12264 = 1; } template AZ12264(alias A2 : S12264!T, T) { enum AZ12264 = 2; } static assert(AX12264!(S12264!int) == 2); static assert(AY12264!(S12264!int) == 2); static assert(AZ12264!(S12264!int) == 2); template TX12264(T1) { enum TX12264 = 1; } template TX12264(T2 : B!A, alias B, A...) { enum TX12264 = 2; } template TY12264(T1) { enum TY12264 = 1; } template TY12264(T2 : B!int, alias B) { enum TY12264 = 2; } template TZ12264(T1) { enum TZ12264 = 1; } template TZ12264(T2 : S12264!T, T) { enum TZ12264 = 2; } static assert(TX12264!(S12264!int) == 2); static assert(TY12264!(S12264!int) == 2); static assert(TZ12264!(S12264!int) == 2); /******************************************/ // 12122 enum N12122 = 1; void foo12122(T)(T[N12122]) if(is(T == int)) {} void test12122() { int[N12122] data; foo12122(data); } /******************************************/ // 12186 template map_front12186(fun...) { auto map_front12186(Range)(Range r) { return fun[0](r[0]); } } void test12186() { immutable int[][] mat; mat.map_front12186!((in r) => 0); // OK mat.map_front12186!((const r) => 0); // OK mat.map_front12186!((immutable int[] r) => 0); // OK mat.map_front12186!((immutable r) => 0); // OK <- Error } /******************************************/ // 12207 void test12207() { static struct S { static void f(T)(T) {} } immutable S s; s.f(1); } /******************************************/ // 12263 template A12263(alias a) { int x; } template B12263(alias a) { int x; } template fqnSym12263(alias T : B12263!A, alias B12263, A...) { enum fqnSym12263 = true; } static assert(fqnSym12263!(A12263!(Object))); static assert(fqnSym12263!(B12263!(Object))); /******************************************/ // 12290 void test12290() { short[] arrS; float[] arrF; double[] arrD; real[] arrR; string cstr; wstring wstr; dstring dstr; short[short] aa; auto func1a(E)(E[], E) { return E.init; } auto func1b(E)(E, E[]) { return E.init; } static assert(is(typeof(func1a(arrS, 1)) == short)); static assert(is(typeof(func1b(1, arrS)) == short)); static assert(is(typeof(func1a(arrF, 1.0)) == float)); static assert(is(typeof(func1b(1.0, arrF)) == float)); static assert(is(typeof(func1a(arrD, 1.0L)) == double)); static assert(is(typeof(func1b(1.0L, arrD)) == double)); static assert(is(typeof(func1a(arrR, 1)) == real)); static assert(is(typeof(func1b(1, arrR)) == real)); static assert(is(typeof(func1a("str" , 'a')) == immutable char)); static assert(is(typeof(func1b('a', "str" )) == immutable char)); static assert(is(typeof(func1a("str"c, 'a')) == immutable char)); static assert(is(typeof(func1b('a', "str"c)) == immutable char)); static assert(is(typeof(func1a("str"w, 'a')) == immutable wchar)); static assert(is(typeof(func1b('a', "str"w)) == immutable wchar)); static assert(is(typeof(func1a("str"d, 'a')) == immutable dchar)); static assert(is(typeof(func1b('a', "str"d)) == immutable dchar)); static assert(is(typeof(func1a([1,2,3], 1L)) == long)); static assert(is(typeof(func1b(1L, [1,2,3])) == long)); static assert(is(typeof(func1a([1,2,3], 1.5)) == double)); static assert(is(typeof(func1b(1.5, [1,2,3])) == double)); static assert(is(typeof(func1a(["a","b"], "s"c)) == string)); static assert(is(typeof(func1b("s"c, ["a","b"])) == string)); static assert(is(typeof(func1a(["a","b"], "s"w)) == wstring)); static assert(is(typeof(func1b("s"w, ["a","b"])) == wstring)); static assert(is(typeof(func1a(["a","b"], "s"d)) == dstring)); static assert(is(typeof(func1b("s"d, ["a","b"])) == dstring)); auto func2a(K, V)(V[K], K, V) { return V[K].init; } auto func2b(K, V)(V, K, V[K]) { return V[K].init; } static assert(is(typeof(func2a(aa, 1, 1)) == short[short])); static assert(is(typeof(func2b(1, 1, aa)) == short[short])); static assert(is(typeof(func2a([1:10,2:20,3:30], 1L, 10L)) == long[long])); static assert(is(typeof(func2b(1L, 10L, [1:20,2:20,3:30])) == long[long])); auto func3a(T)(T, T) { return T.init; } auto func3b(T)(T, T) { return T.init; } static assert(is(typeof(func3a(arrS, null)) == short[])); static assert(is(typeof(func3b(null, arrS)) == short[])); static assert(is(typeof(func3a(arrR, null)) == real[])); static assert(is(typeof(func3b(null, arrR)) == real[])); static assert(is(typeof(func3a(cstr, "str")) == string)); static assert(is(typeof(func3b("str", cstr)) == string)); static assert(is(typeof(func3a(wstr, "str")) == wstring)); static assert(is(typeof(func3b("str", wstr)) == wstring)); static assert(is(typeof(func3a(dstr, "str")) == dstring)); static assert(is(typeof(func3b("str", dstr)) == dstring)); static assert(is(typeof(func3a("str1" , "str2"c)) == string)); static assert(is(typeof(func3b("str1"c, "str2" )) == string)); static assert(is(typeof(func3a("str1" , "str2"w)) == wstring)); static assert(is(typeof(func3b("str1"w, "str2" )) == wstring)); static assert(is(typeof(func3a("str1" , "str2"d)) == dstring)); static assert(is(typeof(func3b("str1"d, "str2" )) == dstring)); inout(V) get(K, V)(inout(V[K]) aa, K key, lazy V defaultValue) { return V.init; } short[short] hash12220; short res12220 = get(hash12220, 1, 1); short[short] hash12221; enum Key12221 : short { a } get(hash12221, Key12221.a, Key12221.a); int[][string] mapping13026; int[] v = get(mapping13026, "test", []); } /******************************************/ // 12292 void test12292() { void fun(T : string)(T data) {} ubyte[3] sa; static assert(!__traits(compiles, fun(sa))); static assert(!__traits(compiles, { alias f = fun!(ubyte[3]); })); } /******************************************/ // 12376 static auto encode12376(size_t sz)(dchar ch) if (sz > 1) { undefined; } void test12376() { enum x = __traits(compiles, encode12376!2(x)); } /******************************************/ // 12447 enum test12447(string str) = str; // [1] string test12447(T...)(T args) if (T.length) { return args[0]; } // [2] // With [1]: The template parameter str cannot be be deduced -> no match // With [2]: T is deduced to a type tuple (string), then match to the function call. static assert(test12447("foo") == "foo"); // With [1]: template parameter str is deduced to "bar", then match. // With [2]: T is deduced to an expression tuple ("bar"), but it will make invalid the function signature (T args). // The failure should be masked silently and prefer the 1st version. static assert(test12447!("bar") == "bar"); /******************************************/ // 12651 alias TemplateArgsOf12651(alias T : Base!Args, alias Base, Args...) = Args; struct S12651(T) { } static assert(!__traits(compiles, TemplateArgsOf12651!(S12651!int, S, float))); /******************************************/ // 12719 struct A12719 { B12719!int b(); } struct B12719(T) { A12719 a; void m() { auto v = B12719!T.init; } } // -------- enum canDoIt12719(R) = is(typeof(W12719!R)); struct W12719(R) { R r; static if (canDoIt12719!R) {} } W12719!int a12719; /******************************************/ // 12746 template foo12746() { void bar() { static assert(!__traits(compiles, bar(1))); } alias foo12746 = bar; } void foo12746(int) { assert(0); } void test12746() { foo12746(); // instantiate } /******************************************/ // 9708 struct S9708 { void f()(inout(Object)) inout {} } void test9708() { S9708 s; s.f(new Object); } /******************************************/ // 12880 void f12880(T)(in T value) { static assert(is(T == string)); } void test12880() { f12880(string.init); } /******************************************/ // 13087 struct Vec13087 { int x; void m() { auto n = component13087!(this, 'x'); } void c() const { auto n = component13087!(this, 'x'); } void w() inout { auto n = component13087!(this, 'x'); } void wc() inout const { auto n = component13087!(this, 'x'); } void s() shared { auto n = component13087!(this, 'x'); } void sc() shared const { auto n = component13087!(this, 'x'); } void sw() shared inout { auto n = component13087!(this, 'x'); } void swc() shared inout const { auto n = component13087!(this, 'x'); } void i() immutable { auto n = component13087!(this, 'x'); } } template component13087(alias vec, char c) { alias component13087 = vec.x; } /******************************************/ // 13127 /+void test13127(inout int = 0) { int [] ma1; const(int)[] ca1; const(int[]) ca2; inout( int)[] wma1; inout( int[]) wma2; inout(const int)[] wca1; inout(const int[]) wca2; immutable(int)[] ia1; immutable(int[]) ia2; shared( int)[] sma1; shared( int[]) sma2; shared( const int)[] sca1; shared( const int[]) sca2; shared(inout int)[] swma1; shared(inout int[]) swma2; shared(inout const int)[] swca1; shared(inout const int[]) swca2; /* In all cases, U should be deduced to top-unqualified type. */ /* Parameter is (shared) mutable */ U f_m(U)( U) { return null; } U fsm(U)(shared U) { return null; } // 9 * 2 - 1 static assert(is(typeof(f_m( ma1)) == int [])); static assert(is(typeof(f_m( ca1)) == const(int)[])); static assert(is(typeof(f_m( ca2)) == const(int)[])); static assert(is(typeof(f_m( wma1)) == inout( int)[])); static assert(is(typeof(f_m( wma2)) == inout( int)[])); static assert(is(typeof(f_m( wca1)) == inout(const int)[])); static assert(is(typeof(f_m( wca2)) == inout(const int)[])); static assert(is(typeof(f_m( ia1)) == immutable(int)[])); static assert(is(typeof(f_m( ia2)) == immutable(int)[])); static assert(is(typeof(f_m( sma1)) == shared( int)[])); static assert(is(typeof(f_m( sma2)) == shared( int)[])); // <- shared(int[]) static assert(is(typeof(f_m( sca1)) == shared( const int)[])); static assert(is(typeof(f_m( sca2)) == shared( const int)[])); // <- shared(const(int)[]) static assert(is(typeof(f_m(swma1)) == shared(inout int)[])); static assert(is(typeof(f_m(swma2)) == shared(inout int)[])); // <- shared(inout(int[]) static assert(is(typeof(f_m(swca1)) == shared(inout const int)[])); static assert(is(typeof(f_m(swca2)) == shared(inout const int)[])); // <- shared(inout(const(int))[]) // 9 * 2 - 1 static assert(is(typeof(fsm( ma1))) == false); static assert(is(typeof(fsm( ca1))) == false); static assert(is(typeof(fsm( ca2))) == false); static assert(is(typeof(fsm( wma1))) == false); static assert(is(typeof(fsm( wma2))) == false); static assert(is(typeof(fsm( wca1))) == false); static assert(is(typeof(fsm( wca2))) == false); static assert(is(typeof(fsm( ia1))) == false); static assert(is(typeof(fsm( ia2))) == false); static assert(is(typeof(fsm( sma1)) == shared( int)[])); // <- NG static assert(is(typeof(fsm( sma2)) == shared( int)[])); static assert(is(typeof(fsm( sca1)) == shared( const int)[])); // <- NG static assert(is(typeof(fsm( sca2)) == shared( const int)[])); static assert(is(typeof(fsm(swma1)) == shared(inout int)[])); // <- NG static assert(is(typeof(fsm(swma2)) == shared(inout int)[])); static assert(is(typeof(fsm(swca1)) == shared(inout const int)[])); // <- NG static assert(is(typeof(fsm(swca2)) == shared(inout const int)[])); /* Parameter is (shared) const */ U f_c(U)( const U) { return null; } U fsc(U)(shared const U) { return null; } // 9 * 2 - 1 static assert(is(typeof(f_c( ma1)) == int [])); static assert(is(typeof(f_c( ca1)) == const(int)[])); static assert(is(typeof(f_c( ca2)) == const(int)[])); static assert(is(typeof(f_c( wma1)) == inout( int)[])); static assert(is(typeof(f_c( wma2)) == inout( int)[])); static assert(is(typeof(f_c( wca1)) == inout(const int)[])); static assert(is(typeof(f_c( wca2)) == inout(const int)[])); static assert(is(typeof(f_c( ia1)) == immutable(int)[])); static assert(is(typeof(f_c( ia2)) == immutable(int)[])); static assert(is(typeof(f_c( sma1)) == shared( int)[])); static assert(is(typeof(f_c( sma2)) == shared( int)[])); // <- shared(int[]) static assert(is(typeof(f_c( sca1)) == shared( const int)[])); static assert(is(typeof(f_c( sca2)) == shared( const int)[])); // <- shared(const(int)[]) static assert(is(typeof(f_c(swma1)) == shared(inout int)[])); static assert(is(typeof(f_c(swma2)) == shared(inout int)[])); // shared(inout(int)[]) static assert(is(typeof(f_c(swca1)) == shared(inout const int)[])); static assert(is(typeof(f_c(swca2)) == shared(inout const int)[])); // shared(inout(const(int))[]) // 9 * 2 - 1 static assert(is(typeof(fsc( ma1))) == false); static assert(is(typeof(fsc( ca1))) == false); static assert(is(typeof(fsc( ca2))) == false); static assert(is(typeof(fsc( wma1))) == false); static assert(is(typeof(fsc( wma2))) == false); static assert(is(typeof(fsc( wca1))) == false); static assert(is(typeof(fsc( wca2))) == false); static assert(is(typeof(fsc( ia1)) == immutable(int)[])); // <- NG static assert(is(typeof(fsc( ia2)) == immutable(int)[])); // <- NG static assert(is(typeof(fsc( sma1)) == shared( int)[])); // <- NG static assert(is(typeof(fsc( sma2)) == shared( int)[])); static assert(is(typeof(fsc( sca1)) == shared( const int)[])); // <- NG static assert(is(typeof(fsc( sca2)) == shared( const int)[])); static assert(is(typeof(fsc(swma1)) == shared(inout int)[])); // <- NG static assert(is(typeof(fsc(swma2)) == shared(inout int)[])); static assert(is(typeof(fsc(swca1)) == shared(inout const int)[])); // <- NG static assert(is(typeof(fsc(swca2)) == shared(inout const int)[])); /* Parameter is immutable */ U fi(U)(immutable U) { return null; } // 9 * 2 - 1 static assert(is(typeof(fi( ma1))) == false); static assert(is(typeof(fi( ca1))) == false); static assert(is(typeof(fi( ca2))) == false); static assert(is(typeof(fi( wma1))) == false); static assert(is(typeof(fi( wma2))) == false); static assert(is(typeof(fi( wca1))) == false); static assert(is(typeof(fi( wca2))) == false); static assert(is(typeof(fi( ia1)) == immutable(int)[])); // <- NG static assert(is(typeof(fi( ia2)) == immutable(int)[])); // <- NG static assert(is(typeof(fi( sma1))) == false); static assert(is(typeof(fi( sma2))) == false); static assert(is(typeof(fi( sca1))) == false); static assert(is(typeof(fi( sca2))) == false); static assert(is(typeof(fi(swma1))) == false); static assert(is(typeof(fi(swma2))) == false); static assert(is(typeof(fi(swca1))) == false); static assert(is(typeof(fi(swca2))) == false); /* Parameter is (shared) inout */ U f_w(U)( inout U) { return null; } U fsw(U)(shared inout U) { return null; } // 9 * 2 - 1 static assert(is(typeof(f_w( ma1)) == int [])); static assert(is(typeof(f_w( ca1)) == int [])); // <- const(int)[] static assert(is(typeof(f_w( ca2)) == int [])); // <- const(int)[] static assert(is(typeof(f_w( wma1)) == int [])); // <- inout(int)[] static assert(is(typeof(f_w( wma2)) == int [])); // <- inout(int)[] static assert(is(typeof(f_w( wca1)) == const(int)[])); // <- inout(const(int))[] static assert(is(typeof(f_w( wca2)) == const(int)[])); // <- inout(const(int))[] static assert(is(typeof(f_w( ia1)) == int [])); // <- immutable(int)[] static assert(is(typeof(f_w( ia2)) == int [])); // <- immutable(int)[] static assert(is(typeof(f_w( sma1)) == shared( int)[])); static assert(is(typeof(f_w( sma2)) == shared( int)[])); // <- shared(int[]) static assert(is(typeof(f_w( sca1)) == shared( int)[])); // <- shared(const(int))[] static assert(is(typeof(f_w( sca2)) == shared( int)[])); // <- shared(const(int)[]) static assert(is(typeof(f_w(swma1)) == shared( int)[])); // <- shared(inout(int))[] static assert(is(typeof(f_w(swma2)) == shared( int)[])); // <- shared(inout(int)[]) static assert(is(typeof(f_w(swca1)) == shared(const int)[])); // <- shared(inout(const(int)))[] static assert(is(typeof(f_w(swca2)) == shared(const int)[])); // <- shared(inout(const(int))[]) // 9 * 2 - 1 static assert(is(typeof(fsw( ma1))) == false); static assert(is(typeof(fsw( ca1))) == false); static assert(is(typeof(fsw( ca2))) == false); static assert(is(typeof(fsw( wma1))) == false); static assert(is(typeof(fsw( wma2))) == false); static assert(is(typeof(fsw( wca1))) == false); static assert(is(typeof(fsw( wca2))) == false); static assert(is(typeof(fsw( ia1)) == int [])); // <- NG static assert(is(typeof(fsw( ia2)) == int [])); // <- NG static assert(is(typeof(fsw( sma1)) == int [])); // <- NG static assert(is(typeof(fsw( sma2)) == int [])); static assert(is(typeof(fsw( sca1)) == int [])); // <- NG static assert(is(typeof(fsw( sca2)) == int [])); // const(int)[] static assert(is(typeof(fsw(swma1)) == int [])); // <- NG static assert(is(typeof(fsw(swma2)) == int [])); // inout(int)[] static assert(is(typeof(fsw(swca1)) == const(int)[])); // <- NG static assert(is(typeof(fsw(swca2)) == const(int)[])); // <- inout(const(int))[] /* Parameter is (shared) inout const */ U f_wc(U)( inout const U) { return null; } U fswc(U)(shared inout const U) { return null; } // 9 * 2 - 1 static assert(is(typeof(f_wc( ma1)) == int [])); static assert(is(typeof(f_wc( ca1)) == int [])); // <- const(int)[] static assert(is(typeof(f_wc( ca2)) == int [])); // <- const(int)[] static assert(is(typeof(f_wc( wma1)) == int [])); // <- inout(int)[] static assert(is(typeof(f_wc( wma2)) == int [])); // <- inout(int)[] static assert(is(typeof(f_wc( wca1)) == int [])); // <- inout(const(int))[] static assert(is(typeof(f_wc( wca2)) == int [])); // <- inout(const(int))[] static assert(is(typeof(f_wc( ia1)) == int [])); // <- immutable(int)[] static assert(is(typeof(f_wc( ia2)) == int [])); // <- immutable(int)[] static assert(is(typeof(f_wc( sma1)) == shared(int)[])); static assert(is(typeof(f_wc( sma2)) == shared(int)[])); // <- shared(int[]) static assert(is(typeof(f_wc( sca1)) == shared(int)[])); // <- shared(const(int))[] static assert(is(typeof(f_wc( sca2)) == shared(int)[])); // <- shared(const(int)[]) static assert(is(typeof(f_wc(swma1)) == shared(int)[])); // <- shared(inout(int))[] static assert(is(typeof(f_wc(swma2)) == shared(int)[])); // <- shared(inout(int)[]) static assert(is(typeof(f_wc(swca1)) == shared(int)[])); // <- shared(inout(const(int)))[] static assert(is(typeof(f_wc(swca2)) == shared(int)[])); // <- shared(inout(const(int))[]) // 9 * 2 - 1 static assert(is(typeof(fswc( ma1))) == false); static assert(is(typeof(fswc( ca1))) == false); static assert(is(typeof(fswc( ca2))) == false); static assert(is(typeof(fswc( wma1))) == false); static assert(is(typeof(fswc( wma2))) == false); static assert(is(typeof(fswc( wca1))) == false); static assert(is(typeof(fswc( wca2))) == false); static assert(is(typeof(fswc( ia1)) == int [])); // <- NG static assert(is(typeof(fswc( ia2)) == int [])); // <- NG static assert(is(typeof(fswc( sma1)) == int [])); // <- NG static assert(is(typeof(fswc( sma2)) == int [])); static assert(is(typeof(fswc( sca1)) == int [])); // <- NG static assert(is(typeof(fswc( sca2)) == int [])); // <- const(int)[] static assert(is(typeof(fswc(swma1)) == int [])); // <- NG static assert(is(typeof(fswc(swma2)) == int [])); // <- inout(int)[] static assert(is(typeof(fswc(swca1)) == int [])); // <- NG static assert(is(typeof(fswc(swca2)) == int [])); // <- inout(const(int))[] }+/ void test13127a() { void foo(T)(in T[] src, T[] dst) { static assert(is(T == int[])); } int[][] a; foo(a, a); } /******************************************/ // 13159 template maxSize13159(T...) { static if (T.length == 1) { enum size_t maxSize13159 = T[0].sizeof; } else { enum size_t maxSize13159 = T[0].sizeof >= maxSize13159!(T[1 .. $]) ? T[0].sizeof : maxSize13159!(T[1 .. $]); } } struct Node13159 { struct Pair { Node13159 value; } //alias Algebraic!(Node[], int) Value; enum n = maxSize13159!(Node13159[], int); } /******************************************/ // 13180 void test13180() { inout(V) get1a(K, V)(inout(V[K]) aa, lazy inout(V) defaultValue) { static assert(is(V == string)); static assert(is(K == string)); return defaultValue; } inout(V) get1b(K, V)(lazy inout(V) defaultValue, inout(V[K]) aa) { static assert(is(V == string)); static assert(is(K == string)); return defaultValue; } inout(V) get2a(K, V)(inout(V)[K] aa, lazy inout(V) defaultValue) { static assert(is(V == string)); static assert(is(K == string)); return defaultValue; } inout(V) get2b(K, V)(lazy inout(V) defaultValue, inout(V)[K] aa) { static assert(is(V == string)); static assert(is(K == string)); return defaultValue; } string def; string[string] aa; string s1a = get1a(aa, def); string s1b = get1b(def, aa); string s2a = get2a(aa, def); string s2b = get2b(def, aa); } /******************************************/ // 13204 struct A13204(uint v) { alias whatever = A13204y; static assert(is(whatever == A13204)); } alias A13204x = A13204!1; alias A13204y = A13204x; struct B13204(uint v) { alias whatever = B13204z; static assert(is(whatever == B13204)); } alias B13204x = B13204!1; alias B13204y = B13204x; alias B13204z = B13204y; void test13204() { static assert(is(A13204x == A13204!1)); static assert(is(A13204x == A13204!1.whatever)); static assert(is(A13204x == A13204y)); static assert(is(B13204x == B13204!1)); static assert(is(B13204x == B13204!1.whatever)); static assert(is(B13204x == B13204y)); static assert(is(B13204x == B13204z)); } /******************************************/ // 8462 (dup of 13204) alias FP8462 = void function(C8462.Type arg); class C8462 { enum Type { Foo } alias funcPtrPtr = FP8462*; } /******************************************/ // 13218 template isCallable13218(T...) if (T.length == 1) { static assert(0); } template ParameterTypeTuple13218(func...) if (func.length == 1 && isCallable13218!func) { static assert(0); } struct R13218 { private static string mangleFuncPtr(ArgTypes...)() { string result = "fnp_"; foreach (T; ArgTypes) result ~= T.mangleof; return result; } void function(int) fnp_i; double delegate(double) fnp_d; void opAssign(FnT)(FnT func) { mixin(mangleFuncPtr!( ParameterTypeTuple13218!FnT) ~ " = func;"); // parsed as TypeInstance //mixin(mangleFuncPtr!(.ParameterTypeTuple13218!FnT) ~ " = func;"); // parsed as DotTemplateInstanceExp -> works } } /******************************************/ // 13219 struct Map13219(V) {} void test13219a(alias F, VA, VB)(Map13219!VA a, Map13219!VB b) if (is(VA : typeof(F(VA.init, VB.init)))) {} void test13219b(alias F)() { test13219a!((a, b) => b)(Map13219!int.init, Map13219!int.init); } void test13219() { int x; test13219b!x(); } /******************************************/ // 13223 void test13223() { T[] f1(T)(T[] a1, T[] a2) { static assert(is(T == int)); return a1 ~ a2; } T[] f2(T)(T[] a1, T[] a2) { static assert(is(T == int)); return a1 ~ a2; } int[] a = [1, 2]; static assert(is(typeof(f1(a, [])) == int[])); static assert(is(typeof(f2([], a)) == int[])); static assert(is(typeof(f1(a, null)) == int[])); static assert(is(typeof(f2(null, a)) == int[])); T[] f3(T)(T[] a) { return a; } static assert(is(typeof(f3([])) == void[])); static assert(is(typeof(f3(null)) == void[])); T f4(T)(T a) { return a; } static assert(is(typeof(f4([])) == void[])); static assert(is(typeof(f4(null)) == typeof(null))); T[][] f5(T)(T[][] a) { return a; } static assert(is(typeof(f5([])) == void[][])); static assert(is(typeof(f5(null)) == void[][])); void translate(C = immutable char)(const(C)[] toRemove) { static assert(is(C == char)); } translate(null); } void test13223a() { T f(T)(T, T) { return T.init; } immutable i = 0; const c = 0; auto m = 0; shared s = 0; static assert(is(typeof(f(i, i)) == immutable int)); static assert(is(typeof(f(i, c)) == const int)); static assert(is(typeof(f(c, i)) == const int)); static assert(is(typeof(f(i, m)) == int)); static assert(is(typeof(f(m, i)) == int)); static assert(is(typeof(f(c, m)) == int)); static assert(is(typeof(f(m, c)) == int)); static assert(is(typeof(f(m, m)) == int)); static assert(is(typeof(f(i, s)) == shared int)); static assert(is(typeof(f(s, i)) == shared int)); static assert(is(typeof(f(c, s)) == shared int)); static assert(is(typeof(f(s, c)) == shared int)); static assert(is(typeof(f(s, s)) == shared int)); static assert(is(typeof(f(s, m)) == int)); static assert(is(typeof(f(m, s)) == int)); } /******************************************/ // 13235 struct Tuple13235(T...) { T expand; alias expand field; this(T values) { field = values; } } struct Foo13235 { Tuple13235!(int, Foo13235)* foo; } template Inst13235(T...) { struct Tuple { T expand; alias expand field; this(T values) { field = values; } } alias Inst13235 = Tuple*; } struct Bar13235 { Inst13235!(int, Bar13235) bar; } void test13235() { alias Tup1 = Tuple13235!(int, Foo13235); assert(Tup1(1, Foo13235()).expand[0] == 1); alias Tup2 = typeof(*Inst13235!(int, Bar13235).init); assert(Tup2(1, Bar13235()).expand[0] == 1); } /******************************************/ // 13252 alias TypeTuple13252(T...) = T; static assert(is(typeof(TypeTuple13252!(cast(int )1)[0]) == int )); static assert(is(typeof(TypeTuple13252!(cast(long)1)[0]) == long)); static assert(is(typeof(TypeTuple13252!(cast(float )3.14)[0]) == float )); static assert(is(typeof(TypeTuple13252!(cast(double)3.14)[0]) == double)); static assert(is(typeof(TypeTuple13252!(cast(cfloat )(1 + 2i))[0]) == cfloat )); static assert(is(typeof(TypeTuple13252!(cast(cdouble)(1 + 2i))[0]) == cdouble)); static assert(is(typeof(TypeTuple13252!(cast(string )null)[0]) == string )); static assert(is(typeof(TypeTuple13252!(cast(string[])null)[0]) == string[])); // OK <- NG static assert(is(typeof(TypeTuple13252!(cast(wstring)"abc")[0]) == wstring)); static assert(is(typeof(TypeTuple13252!(cast(dstring)"abc")[0]) == dstring)); static assert(is(typeof(TypeTuple13252!(cast(int[] )[])[0]) == int[] )); static assert(is(typeof(TypeTuple13252!(cast(long[])[])[0]) == long[])); // OK <- NG struct S13252 { } static assert(is(typeof(TypeTuple13252!(const S13252())[0]) == const(S13252))); static assert(is(typeof(TypeTuple13252!(immutable S13252())[0]) == immutable(S13252))); // OK <- NG /******************************************/ // 13294 void test13294() { void f(T)(const ref T src, ref T dst) { pragma(msg, "T = ", T); static assert(!is(T == const)); } { const byte src; byte dst; f(src, dst); } { const char src; char dst; f(src, dst); } // 13351 T add(T)(in T x, in T y) { T z; z = x + y; return z; } const double a = 1.0; const double b = 2.0; double c; c = add(a,b); } /******************************************/ // 13299 struct Foo13299 { Foo13299 opDispatch(string name)(int a, int[] b...) if (name == "bar") { return Foo13299(); } Foo13299 opDispatch(string name)() if (name != "bar") { return Foo13299(); } } void test13299() { Foo13299() .bar(0) .bar(1) .bar(2); Foo13299() .opDispatch!"bar"(0) .opDispatch!"bar"(1) .opDispatch!"bar"(2); } /******************************************/ // 13333 template AliasThisTypeOf13333(T) { static assert(0, T.stringof); // T.stringof is important } template StaticArrayTypeOf13333(T) { static if (is(AliasThisTypeOf13333!T AT)) alias X = StaticArrayTypeOf13333!AT; else alias X = T; static if (is(X : E[n], E, size_t n)) alias StaticArrayTypeOf13333 = X; else static assert(0, T.stringof~" is not a static array type"); } enum bool isStaticArray13333(T) = is(StaticArrayTypeOf13333!T); struct VaraiantN13333(T) { static if (isStaticArray13333!T) ~this() { static assert(0); } } struct DummyScope13333 { alias A = VaraiantN13333!C; static class C { A entity; } } void test13333() { struct DummyScope { alias A = VaraiantN13333!C; static class C { A entity; } } } /******************************************/ // 13374 int f13374(alias a)() { return 1; } int f13374(string s)() { return 2; } void x13374(int i) {} void test13374() { assert(f13374!x13374() == 1); } /******************************************/ // 14109 string f14109() { return "a"; } string g14109()() { return "a"; } struct S14109(string s) { static assert(s == "a"); } alias X14109 = S14109!(f14109); alias Y14109 = S14109!(g14109!()); static assert(is(X14109 == Y14109)); /******************************************/ // 13378 struct Vec13378(size_t n, T, string as) { T[n] data; } void doSome13378(size_t n, T, string as)(Vec13378!(n,T,as) v) {} void test13378() { auto v = Vec13378!(3, float, "xyz")([1,2,3]); doSome13378(v); } /******************************************/ // 13379 void test13379() { match13379(""); } auto match13379(RegEx )(RegEx re) if (is(RegEx == Regex13379!char)) // #1 Regex!char (speculative && tinst == NULL) {} auto match13379(String)(String re) {} struct Regex13379(Char) { ShiftOr13379!Char kickstart; // #2 ShiftOr!char (speculative && tinst == Regex!char) } struct ShiftOr13379(Char) { this(ref Regex13379!Char re) // #3 Regex!Char (speculative && tinst == ShiftOr!char) { uint n_length; uint idx; n_length = min13379(idx, n_length); } } template MinType13379(T...) { alias MinType13379 = T[0]; } MinType13379!T min13379(T...)(T args) // #4 MinType!uint (speculative && thist == ShiftOr!char) { alias a = args[0]; alias b = args[$-1]; return cast(typeof(return)) (a < b ? a : b); } /******************************************/ // 13417 struct V13417(size_t N, E, alias string AS) { } auto f13417(E)(in V13417!(4, E, "ijka")) { return V13417!(3, E, "xyz")(); } void test13417() { f13417(V13417!(4, float, "ijka")()); } /******************************************/ // 13484 int foo13484()(void delegate() hi) { return 1; } int foo13484(T)(void delegate(T) hi) { return 2; } void test13484() { assert(foo13484({}) == 1); // works assert(foo13484((float v){}) == 2); // works <- throws error } /******************************************/ // 13675 enum E13675; bool foo13675(T : E13675)() { return false; } void test13675() { if (foo13675!E13675) {} } /******************************************/ // 13694 auto foo13694(T)(string A, T[] G ...) { return 1; } auto foo13694(T)(string A, long E, T[] G ...) { return 2; } void test13694() { struct S {} S v; assert(foo13694("A", v) == 1); // <- OK assert(foo13694("A", 0, v) == 2); // <- used to be OK but now fails assert(foo13694!S("A", 0, v) == 2); // <- workaround solution } /******************************************/ // 13760 void test13760() { void func(K, V)(inout(V[K]) aa, inout(V) val) {} class C {} C[int] aa; func(aa, new C); } /******************************************/ // 13714 struct JSONValue13714 { this(T)(T arg) { } this(T : JSONValue13714)(inout T arg) inout { //store = arg.store; } void opAssign(T)(T arg) { } } void test13714() { enum DummyStringEnum { foo = "bar" } JSONValue13714[string] aa; aa["A"] = DummyStringEnum.foo; } /******************************************/ // 13807 T f13807(T)(inout(T)[] arr) { return T.init; } void test13807() { static assert(is(typeof(f13807([1, 2, 3])) == int)); // OK static assert(is(typeof(f13807(["a", "b"])) == string)); // OK <- Error static assert(is(typeof(f13807!string(["a", "b"])) == string)); // OK } /******************************************/ // 14174 struct Config14174(a, b) {} struct N14174 {} alias defConfig14174 = Config14174!(N14174, N14174); void accepter14174a(Config : Config14174!(T) = defConfig14174, T...)() { static assert(accepter14174a.mangleof == "_D7breaker131__T14"~ "accepter14174a"~ "HTS7breaker51__T11Config14174TS7breaker6N14174TS7breaker6N14174Z11Config14174TS7breaker6N14174TS7breaker6N14174Z14"~ "accepter14174a"~ "FZv"); } void accepter14174b(Config : Config14174!(T) = defConfig14174, T...)() { static assert(accepter14174b.mangleof == "_D7breaker131__T14"~ "accepter14174b"~ "HTS7breaker51__T11Config14174TS7breaker6N14174TS7breaker6N14174Z11Config14174TS7breaker6N14174TS7breaker6N14174Z14"~ "accepter14174b"~ "FZv"); } void test14174() { accepter14174a!()(); // ok accepter14174b(); // error } /******************************************/ // 14836 template a14836x(alias B, C...) { int a14836x(D...)() if (D.length == 0) { return 1; } int a14836x(D...)(D d) if (D.length > 0) { return 2; } } template a14836y(alias B, C...) { int a14836y(T, D...)(T t) if (D.length == 0) { return 1; } int a14836y(T, D...)(T t, D d) if (D.length > 0) { return 2; } } void test14836() { int v; assert(a14836x!(v)() == 1); assert(a14836x!(v)(1) == 2); assert(a14836y!(v)(1) == 1); assert(a14836y!(v)(1, 2) == 2); } /******************************************/ // 14357 template Qux14357(T : U*, U : V*, V) { pragma(msg, T); // no match <- float** pragma(msg, U); // no match <- float* pragma(msg, V); // no match <- int enum Qux14357 = T.sizeof + V.sizeof; } static assert(!__traits(compiles, Qux14357!(float**, int*))); /******************************************/ // 14481 template someT14481(alias e) { alias someT14481 = e; } mixin template Mix14481(alias e) { alias SomeAlias = someT14481!e; } struct Hoge14481 { mixin Mix14481!e; enum e = 10; } /******************************************/ // 14520 template M14520(alias a) { enum M14520 = 1; } template M14520(string s) { enum M14520 = 2; } int f14520a(); string f14520b() { assert(0); } string f14520c() { return "a"; } static assert(M14520!f14520a == 1); static assert(M14520!f14520b == 1); static assert(M14520!f14520c == 1); /******************************************/ // 14568 struct Interval14568() { auto left = INVALID; auto opAssign()(Interval14568) { left; } } auto interval14568(T)(T point) { Interval14568!(); } alias Instantiate14568(alias symbol, Args...) = symbol!Args; template Match14568(patterns...) { static if (__traits(compiles, Instantiate14568!(patterns[0]))) { alias Match14568 = patterns[0]; } else static if (patterns.length == 1) {} } template SubOps14568(Args...) { auto opIndex() { template IntervalType(T...) { alias Point() = typeof(T.interval14568); alias IntervalType = Match14568!(Point); } alias Subspace = IntervalType!(Args); } } struct Nat14568 { mixin SubOps14568!(null); } /******************************************/ // 14735 enum CS14735 { yes, no } int indexOf14735a(Range )(Range s, in dchar c) { return 1; } int indexOf14735a(T, size_t n)(ref T[n] s, in dchar c) { return 2; } int indexOf14735b(Range )(Range s, in dchar c, in CS14735 cs = CS14735.yes) { return 1; } int indexOf14735b(T, size_t n)(ref T[n] s, in dchar c, in CS14735 cs = CS14735.yes) { return 2; } void test14735() { char[64] buf; // Supported from 2.063: (http://dlang.org/changelog#implicitarraycast) assert(indexOf14735a(buf[0..32], '\0') == 2); assert(indexOf14735b(buf[0..32], '\0') == 2); // Have to work as same as above. assert(indexOf14735a(buf[], '\0') == 2); assert(indexOf14735b(buf[], '\0') == 2); } /******************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test1780(); test3608(); test5893(); test6404(); test2246(); test2296(); bug4984(); test2579(); test2803(); test6613(); test5886(); test5393(); test5896(); test6825(); test6789(); test2778(); test2778aa(); test2778get(); test6208a(); test6208b(); test6208c(); test6738(); test6780(); test6810(); test6891(); test6994(); test6764(); test3467(); test4413(); test5525(); test5801(); test10(); test7037(); test7124(); test7359(); test7416(); test7563(); test7572(); test7580(); test7585(); test7671(); test7672(); test7684(); test11a(); test11b(); test7769(); test7873(); test7933(); test8094(); test12(); test8125(); test13(); test14(); test8129(); test8238(); test8669(); test8833(); test8976(); test8940(); test9022(); test9026(); test9038(); test9076(); test9100(); test9124a(); test9124b(); test9143(); test9266(); test9536(); test9578(); test9596(); test9837(); test9874(); test9885(); test9971(); test9977(); test10083(); test10592(); test11242(); test10811(); test10969(); test11271(); test11533(); test11818(); test11843(); test11872(); test12122(); test12207(); test12376(); test13235(); test13294(); test13299(); test13374(); test13378(); test13379(); test13484(); test13694(); test14836(); test14735(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/a19.d0000644000175000017500000000026113200164642022145 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/a19a.d // PERMUTE_ARGS: import imports.a19a; int main(char[][] args) { TemplatedStruct!(Dummy) e; return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ice15030.d0000644000175000017500000001047613200164642022715 0ustar matthiasmatthias// REQUIRED_ARGS: -unittest -boundscheck=off // PERMUTE_ARGS: // EXTRA_SOURCES: imports/a15030.d imports/b15030.d void main() {} /+ Compiler output with -v switch. With 2.068.0: -------- code a code b function b.__unittestL5_2 function b.__unittestL5_2.__lambda1 function b.__unittestL5_2.__lambda1.__lambda2 function b.__unittestL5_2.__lambda1.__lambda2.filter!((a) => a).filter!(int[]).filter function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.this function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.empty function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.front function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.popFront function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.__xopEquals function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.__xtoHash function b.__unittestL5_2.__lambda1.__lambda2.__lambda2 The nested functions '__lambda1', '__lambda2', and 'filter' are (fortunately) generated from outer to inner. With 2.068.1: -------- code a function b.__unittestL5_2.__lambda1.__lambda2.filter!((a) => a).filter!(int[]).filter function b.__unittestL5_2.__lambda1.__lambda2 function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.this function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.empty function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.front function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.popFront function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.__xopEquals function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.__xtoHash code b function b.__unittestL5_2 function b.__unittestL5_2.__lambda1 Assertion failure: '!v->csym' on line 1060 in file 'glue.c' abnormal program termination 'filer' is generated before its ancestor functions '__lambda1' and '__lambda2' - it's a bug. Fixed (contains debug prints): -------- code a b.__unittestL5_2.__lambda1.__lambda2.filter!((a) => a).filter!(int[]).filter @[algorithm.d(5)] --> pushed to unittest @[b.d(5)] function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.this function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.empty function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.front function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.popFront function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.__xopEquals function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.__xtoHash code b function b.__unittestL5_2 function b.__unittestL5_2.__lambda1 function b.__unittestL5_2.__lambda1.__lambda2 function b.__unittestL5_2.__lambda1.__lambda2.filter!((a) => a).filter!(int[]).filter function b.__unittestL5_2.__lambda1.__lambda2.__lambda2 By using `deferredNested` correctly, those nested function generations are ordered again. Fixed more: -------- function D main code a code b function b.__unittestL5_2 function b.__unittestL5_2.__lambda1 function b.__unittestL5_2.__lambda1.__lambda2 function b.__unittestL5_2.__lambda1.__lambda2.filter!(int[]).filter function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.this function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.empty function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.front function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.popFront function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.__xopEquals function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.__xtoHash function b.__unittestL5_2.__lambda1.__lambda2.__lambda2 By the tweak in TemplateInstance::appendToModuleMember(), all the code of (implicitly) nested instances are stored into corresponding module object file. +/ ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testUTF32.d0000644000175000017500000000150413156012230023252 0ustar matthiasmatthiasÿþ// encoding :utf-32le-bom int main(){ assert('y'== 0x79); assert('€'== 0x80); assert('™'== 0x799); assert(''== 0x800); assert('úÿ'== 0xFFFA); assert(''== 0x10000); assert('ý'== 0x10FFD); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/s2ir.d0000644000175000017500000000305113200164642022432 0ustar matthiasmatthias import std.stdio; /***********************************/ void test1() { int i; __gshared int j; version (LDC) { // Local variables in nested functions (which by definition have no // stack frame the compiler can know about) are ill-defined and will not // be supported by LDC in the forseeable future. } else version (D_InlineAsm_X86) { asm { naked ; mov EAX, i ; } version(D_PIC) {} else { asm { mov EAX, j ; } } } } /***********************************/ int main() { for (int i = 0; ; i++) { if (i == 10) break; } string[] a = new string[3]; a[0] = "hello"; a[1] = "world"; a[2] = "foo"; foreach (string s; a) writefln(s); switch (1) { default: break; } switch ("foo"w) { case "foo": break; default: assert(0); } switch (1) { case 1: try { goto default; } catch (Throwable o) { } break; default: break; } switch (1) { case 1: try { goto case 2; } catch (Throwable o) { } break; case 2: break; default: assert(0); } writefln("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/gdb4181.d0000644000175000017500000000035313200164642022627 0ustar matthiasmatthias/* REQUIRED_ARGS: -g PERMUTE_ARGS: GDB_SCRIPT: --- b 22 r echo RESULT= p 'gdb.x' + 'gdb.STest.y' --- GDB_MATCH: RESULT=.*33 */ module gdb; int x; struct STest { static int y; } void main() { x = 11; STest.y = 22; // BP } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/entity1.d0000644000175000017500000000737113200164642023161 0ustar matthiasmatthias// $HeadURL$ // $Date$ // $Author$ module dstress.run.named_entity_02; // "-//W3C//ENTITIES Symbolic//EN//HTML" int main(){ assert('\ƒ'==402); assert('\Α'==913); assert('\Β'==914); assert('\Γ'==915); assert('\Δ'==916); assert('\Ε'==917); assert('\Ζ'==918); assert('\Η'==919); assert('\Θ'==920); assert('\Ι'==921); assert('\Κ'==922); assert('\Λ'==923); assert('\Μ'==924); assert('\Ν'==925); assert('\Ξ'==926); assert('\Ο'==927); assert('\Π'==928); assert('\Ρ'==929); assert('\Σ'==931); assert('\Τ'==932); assert('\Υ'==933); assert('\Φ'==934); assert('\Χ'==935); assert('\Ψ'==936); assert('\Ω'==937); assert('\α'==945); assert('\β'==946); assert('\γ'==947); assert('\δ'==948); assert('\ε'==949); assert('\ζ'==950); assert('\η'==951); assert('\θ'==952); assert('\ι'==953); assert('\κ'==954); assert('\λ'==955); assert('\μ'==956); assert('\ν'==957); assert('\ξ'==958); assert('\ο'==959); assert('\π'==960); assert('\ρ'==961); assert('\ς'==962); assert('\σ'==963); assert('\τ'==964); assert('\υ'==965); assert('\φ'==966); assert('\χ'==967); assert('\ψ'==968); assert('\ω'==969); assert('\ϑ'==977); assert('\ϒ'==978); assert('\ϖ'==982); assert('\•'==8226); assert('\…'==8230); assert('\′'==8242); assert('\″'==8243); assert('\‾'==8254); assert('\⁄'==8260); assert('\℘'==8472); assert('\ℑ'==8465); assert('\ℜ'==8476); assert('\™'==8482); assert('\ℵ'==8501); assert('\←'==8592); assert('\↑'==8593); assert('\→'==8594); assert('\↓'==8595); assert('\↔'==8596); assert('\↵'==8629); assert('\⇐'==8656); assert('\⇑'==8657); assert('\⇒'==8658); assert('\⇓'==8659); assert('\⇔'==8660); assert('\∀'==8704); assert('\∂'==8706); assert('\∃'==8707); assert('\∅'==8709); assert('\∇'==8711); assert('\∈'==8712); assert('\∉'==8713); assert('\∋'==8715); assert('\∏'==8719); assert('\∑'==8721); assert('\−'==8722); assert('\∗'==8727); assert('\√'==8730); assert('\∝'==8733); assert('\∞'==8734); assert('\∠'==8736); assert('\∧'==8743); assert('\∨'==8744); assert('\∩'==8745); assert('\∪'==8746); assert('\∫'==8747); assert('\∴'==8756); assert('\∼'==8764); assert('\≅'==8773); assert('\≈'==8776); assert('\≠'==8800); assert('\≡'==8801); assert('\≤'==8804); assert('\≥'==8805); assert('\⊂'==8834); assert('\⊃'==8835); assert('\⊄'==8836); assert('\⊆'==8838); assert('\⊇'==8839); assert('\⊕'==8853); assert('\⊗'==8855); assert('\⊥'==8869); assert('\⋅'==8901); assert('\⌈'==8968); assert('\⌉'==8969); assert('\⌊'==8970); assert('\⌋'==8971); //assert('\⟨'==9001); // U+2329 valid for HTML 4.01; changed in HTML5 //assert('\⟩'==9002); // U+232A valid for HTML 4.01; changed in HTML5 assert('\⟨'==0x27E8); // valid for HTML 5 and later. The character was introduced in HTML 3.2 assert('\⟩'==0x27E9); // valid for HTML 5 and later. The character was introduced in HTML 3.2 assert('\◊'==9674); assert('\♠'==9824); assert('\♣'==9827); assert('\♥'==9829); assert('\♦'==9830); return 0; } // Bug 5221 static assert('\✓'==10003); static assert('\≲'==8818); static assert('\№'==8470); static assert('\⌝'==8989); static assert('\Ż'==379); ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/wc2.d0000644000175000017500000000261013200164642022246 0ustar matthiasmatthias// PERMUTE_ARGS: // EXECUTE_ARGS: runnable/wc2.d import std.file; extern(C) int printf(const char*, ...); int main (string[] args) { int w_total; int l_total; int c_total; int[string] dictionary; printf(" lines words bytes file\n"); foreach (string arg; args[1 .. args.length]) { string input; int w_cnt, l_cnt, c_cnt; int inword; int wstart; input = cast(string)std.file.read(arg); for (int j = 0; j < input.length; j++) { char c; c = input[j]; if (c == '\n') ++l_cnt; if (c >= '0' && c <= '9') { } else if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') { if (!inword) { wstart = j; inword = 1; ++w_cnt; } } else if (inword) { string word = input[wstart .. j]; dictionary[word]++; inword = 0; } ++c_cnt; } if (inword) { string w = input[wstart .. input.length]; dictionary[w]++; } printf("%8lu%8lu%8lu %.*s\n", l_cnt, w_cnt, c_cnt, arg.length, arg.ptr); l_total += l_cnt; w_total += w_cnt; c_total += c_cnt; } if (args.length > 2) { printf("--------------------------------------\n%8lu%8lu%8lu total", l_total, w_total, c_total); } printf("--------------------------------------\n"); foreach (string word1; dictionary.keys.sort) { printf("%3d %.*s\n", dictionary[word1], word1.length, word1.ptr); } return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/nogc.d0000644000175000017500000000133213200164642022501 0ustar matthiasmatthias extern(C) int printf(const char*, ...); /***********************/ @nogc int test1() { return 3; } /***********************/ // 3032 void test3032() @nogc { scope o1 = new Object(); // on stack scope o2 = new class Object {}; // on stack int n = 1; scope fp = (){ n = 10; }; // no closure fp(); assert(n == 10); } /***********************/ // 12642 __gshared int[1] data12642; int[1] foo12642() @nogc { int x; return [x]; } void test12642() @nogc { int x; data12642 = [x]; int[1] data2; data2 = [x]; data2 = foo12642(); } /***********************/ int main() { test1(); test3032(); test12642(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/version.d0000644000175000017500000000133013200164642023236 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -version=3 -version=foo extern(C) int printf(const char*, ...); /*******************************************/ void test1() { int i = 3; version(2) { i = 2; } else { i = 0; } printf("i = %d\n", i); assert(i == 2); i = 3; version(foo) { i = 2; } else { i = 0; } printf("i = %d\n", i); assert(i == 2); } /*******************************************/ version(foo) { version = bar; } else { version = 4; } void test2() { version(bar) { } else assert(0); version(4) assert(0); } /*******************************************/ int main() { test1(); test2(); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_809.d0000644000175000017500000000055213200164642024262 0ustar matthiasmatthiasstruct Foo(E1, E2) { Spam tm; static struct Bar { this(in E2, in E1) {} } static struct Spam { Bar[E2][E1] bars; } } void main() { import std.stdio: writeln; writeln("hello world"); enum E3 { A, B } enum E4 { C, D } alias M1 = Foo!(E3, E4); M1.Spam s; s.bars = [E3.A: [E4.C: M1.Bar(E4.D, E3.B)]]; }ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testcontracts.d0000644000175000017500000002231113200164642024453 0ustar matthiasmatthias// PERMUTE_ARGS: -inline -g -O extern(C) int printf(const char*, ...); /*******************************************/ class A { int x = 7; int foo(int i) in { printf("A.foo.in %d\n", i); assert(i == 2); assert(x == 7); printf("A.foo.in pass\n"); } out (result) { assert(result & 1); assert(x == 7); } body { return i; } } class B : A { override int foo(int i) in { float f; printf("B.foo.in %d\n", i); assert(i == 4); assert(x == 7); f = f + i; } out (result) { assert(result < 8); assert(x == 7); } body { return i - 1; } } void test1() { auto b = new B(); b.foo(2); b.foo(4); } /*******************************************/ class A2 { int x = 7; int foo(int i) in { printf("A2.foo.in %d\n", i); assert(i == 2); assert(x == 7); printf("A2.foo.in pass\n"); } out (result) { assert(result & 1); assert(x == 7); } body { return i; } } class B2 : A2 { override int foo(int i) in { float f; printf("B2.foo.in %d\n", i); assert(i == 4); assert(x == 7); f = f + i; } out (result) { assert(result < 8); assert(x == 7); } body { return i - 1; } } class C : B2 { override int foo(int i) in { float f; printf("C.foo.in %d\n", i); assert(i == 6); assert(x == 7); f = f + i; } out (result) { assert(result == 1 || result == 3 || result == 5); assert(x == 7); } body { return i - 1; } } void test2() { auto c = new C(); c.foo(2); c.foo(4); c.foo(6); } /*******************************************/ void fun(int x) in { if (x < 0) throw new Exception("a"); } body { } void test3() { fun(1); } /*******************************************/ interface Stack { int pop() // in { printf("pop.in\n"); } out(result) { printf("pop.out\n"); assert(result == 3); } } class CC : Stack { int pop() //out (result) { printf("CC.pop.out\n"); } body { printf("CC.pop.in\n"); return 3; } } void test4() { auto cc = new CC(); cc.pop(); } /*******************************************/ int mul100(int n) out(result) { assert(result == 500); } body { return n * 100; } void test5() { mul100(5); } /*******************************************/ // 3273 // original case struct Bug3273 { ~this() {} invariant() {} } // simplest case ref int func3273() out(r) { // Regression check of issue 3390 static assert(!__traits(compiles, r = 1)); } body { static int dummy; return dummy; } void test6() { func3273() = 1; assert(func3273() == 1); } /*******************************************/ /+ // http://d.puremagic.com/issues/show_bug.cgi?id=3722 class Bug3722A { void fun() {} } class Bug3722B : Bug3722A { override void fun() in { assert(false); } body {} } void test6() { auto x = new Bug3722B(); x.fun(); } +/ /*******************************************/ auto test7foo() in{ ++cnt; }body{ ++cnt; return "str"; } void test7() { cnt = 0; assert(test7foo() == "str"); assert(cnt == 2); } /*******************************************/ auto foo8() out(r){ ++cnt; assert(r == 10); }body{ ++cnt; return 10; } auto bar8() out{ ++cnt; }body{ ++cnt; } void test8() { cnt = 0; assert(foo8() == 10); assert(cnt == 2); cnt = 0; bar8(); assert(cnt == 2); } /*******************************************/ // from fail317 void test9() { auto f1 = function() body { }; // fine auto f2 = function() in { } body { }; // fine auto f3 = function() out { } body { }; // error auto f4 = function() in { } out { } body { }; // error auto d1 = delegate() body { }; // fine auto d2 = delegate() in { } body { }; // fine auto d3 = delegate() out { } body { }; // error auto d4 = delegate() in { } out { } body { }; // error } /*******************************************/ // 4785 int cnt; auto foo4785() in{ int r; ++cnt; } out(r){ assert(r == 10); ++cnt; }body{ ++cnt; int r = 10; return r; } void test4785() { cnt = 0; assert(foo4785() == 10); assert(cnt == 3); } /*******************************************/ // 5039 class C5039 { int x; invariant() { assert( x < int.max ); } auto foo() { return x; } } /*******************************************/ // 5204 interface IFoo5204 { IFoo5204 bar() out {} } class Foo5204 : IFoo5204 { Foo5204 bar() { return null; } } /*******************************************/ // 7218 void test7218() { size_t foo() in{} out{} body{ return 0; } // OK size_t bar() in{}/*out{}*/body{ return 0; } // OK size_t hoo()/*in{}*/out{} body{ return 0; } // NG1 size_t baz()/*in{} out{}*/body{ return 0; } // NG2 } /*******************************************/ // 7699 class P7699 { void f(int n) in { assert (n); } body { } } class D7699 : P7699 { override void f(int n) in { } body { } } /*******************************************/ // 7883 // Segmentation fault class AA7883 { int foo() out (r1) { } body { return 1; } } class BA7883 : AA7883 { override int foo() out (r2) { } body { return 1; } } class CA7883 : BA7883 { override int foo() body { return 1; } } // Error: undefined identifier r2, did you mean variable r3? class AB7883 { int foo() out (r1) { } body { return 1; } } class BB7883 : AB7883 { override int foo() out (r2) { } body { return 1; } } class CB7883 : BB7883 { override int foo() out (r3) { } body { return 1; } } // Error: undefined identifier r3, did you mean variable r4? class AC7883 { int foo() out (r1) { } body { return 1; } } class BC7883 : AC7883 { override int foo() out (r2) { } body { return 1; } } class CC7883 : BC7883 { override int foo() out (r3) { } body { return 1; } } class DC7883 : CC7883 { override int foo() out (r4) { } body { return 1; } } /*******************************************/ // 7892 struct S7892 { @disable this(); this(int x) {} } S7892 f7892() out (result) {} // case 1 body { return S7892(1); } interface I7892 { S7892 f(); } class C7892 { invariant() {} // case 2 S7892 f() { return S7892(1); } } /*******************************************/ // 8066 struct CLCommandQueue { invariant() {} //private: int enqueueNativeKernel() { assert(0, "implement me"); } } /*******************************************/ // 8073 struct Container8073 { int opApply (int delegate(ref int) dg) { return 0; } } class Bug8073 { static int test; int foo() out(r) { test = 7; } body { Container8073 ww; foreach( xxx ; ww ) { } return 7; } ref int bar() out { } body { Container8073 ww; foreach( xxx ; ww ) { } test = 7; return test; } } void test8073() { auto c = new Bug8073(); assert(c.foo() == 7); assert(c.test == 7); auto p = &c.bar(); assert(p == &c.test); assert(*p == 7); } /*******************************************/ // 8093 void test8093() { static int g = 10; static int* p; enum fbody = q{ static struct S { int opApply(scope int delegate(ref int) dg) { return dg(g); } } S s; foreach (ref e; s) return g; assert(0); }; ref int foo_ref1() out(r) { assert(&r is &g && r == 10); } body { mixin(fbody); } ref int foo_ref2() body { mixin(fbody); } { auto q = &foo_ref1(); assert(q is &g && *q == 10); } { auto q = &foo_ref2(); assert(q is &g && *q == 10); } int foo_val1() out(r) { assert(&r !is &g && r == 10); } body { mixin(fbody); } int foo_val2() body { mixin(fbody); } { auto n = foo_val1(); assert(&n !is &g && n == 10); } { auto n = foo_val2(); assert(&n !is &g && n == 10); } } /*******************************************/ // 10479 class B10479 { B10479 foo() out { } body { return null; } } class D10479 : B10479 { override D10479 foo() { return null; } } /*******************************************/ // 10596 class Foo10596 { auto bar() out (result) { } body { return 0; } } /*******************************************/ // 10721 class Foo10721 { this() out { } body { } ~this() out { } body { } } struct Bar10721 { this(this) out { } body { } } /*******************************************/ // 10981 class C10981 { void foo(int i) pure in { assert(i); } out { assert(i); } body {} } /*******************************************/ int main() { test1(); test2(); test3(); test4(); test5(); // test6(); test7(); test8(); test9(); test4785(); test7218(); test8073(); test8093(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testbounds2.d0000644000175000017500000002605013200164642024033 0ustar matthiasmatthias// REQUIRED_ARGS: // Test compile time boundaries checking extern(C) int printf(const char*, ...); template TypeTuple(T...) { alias T TypeTuple; } /******************************************/ // 3652 void test3652() { int foo(int[4] x) { return x[0] + x[1] * x[2] - x[3]; } int[] xs = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]; // simple case foo(xs[0 .. 4]); version(none) { // Need deformation of formula and detection of base point int x = 0; int y = 0; foreach (i; 0 .. 4) { x += foo(xs[i .. i + 4]); y += foo(xs[(i*4+10)/2 .. (i*8>>1)/2+9]); // lwr = (i*4 + 10)/2 = i*4/2 + 10/2 = (i*2+5) // upr = (i*8>>1)/2 + 5 = (i*4/2) + 5 = i*2 + 9 = (i*2+5) + 4 } assert(x == (0,1,2,3) + (1,2,3, 4) + (2, 3, 4, 5) + ( 3, 4, 5, 6)); assert(y == (5,6,7,8) + (7,8,9,10) + (9,10,11,12) + (11,12,13,14)); } } void test3652a() @safe { string str = "aaaabbbbccccdddd"; //printf("str.ptr = %p\n", str.ptr); void foo(ref const(char)[16] buf) { //printf("buf.ptr = %p\n", buf.ptr); assert(buf.ptr is str.ptr); } // can check length at runtime assert(str.length == 16); // compiler can check the length of string literal, so // conversion from immutable(char)[] to ref const(char)[16] is allowed; static assert(__traits(compiles, foo("aaaabbbbccccdddd"))); // OK, correctly rejected by the compiler. static assert(!__traits(compiles, foo(str[]))); // Ugly, furthermore does not work in safe code! //foo(*cast(const(char)[16]*)(str[0..16].ptr)); // New: compiler can check the length of slice, but currently it is not allowed. enum size_t m = 0; size_t calc(){ return 0; } foo(str[0 .. 16]); foo(str[m .. 16]); //foo(str[calc() .. 16]); // with CTFE // If boundaries cannot be calculated in compile time, it's rejected. size_t n; size_t calc2(){ return n; } static assert(!__traits(compiles, foo(str[n .. 16]))); static assert(!__traits(compiles, foo(str[calc2() .. 16]))); void hoo1(size_t dim)(char[dim]) { static assert(dim == 2); } void hoo2(char[2]) {} void hoo3(size_t dim)(ref char[dim]) {} void hoo4(ref char[2]) {} hoo1(str[0 .. 2]); hoo2(str[0 .. 2]); static assert(!__traits(compiles, hoo3(str[0 .. 2]))); static assert(!__traits(compiles, hoo4(str[0 .. 2]))); } void test3652b() @safe { int[] da = [1,2,3,4,5]; void bar(int[3] sa1, ref int[3] sa2) { assert(sa1 == [1,2,3] && sa1.ptr !is da.ptr); assert(sa2 == [1,2,3] && sa2.ptr is da.ptr); } bar(da[0..3], da[0..3]); static assert(!__traits(compiles, bar(da[0..4], da[0..4]))); void baz1(T)(T[3] sa1, ref T[3] sa2) { assert(sa1 == [1,2,3] && sa1.ptr !is da.ptr); assert(sa2 == [1,2,3] && sa2.ptr is da.ptr); } void baz2(T, size_t dim)(T[dim] sa1, ref T[dim] sa2, size_t result) { assert(dim == result); static if (dim == 3) { assert(sa1 == [1,2,3] && sa1.ptr !is da.ptr); assert(sa2 == [1,2,3] && sa2.ptr is da.ptr); } else { assert(sa1 == [1,2,3,4] && sa1.ptr !is da.ptr); assert(sa2 == [1,2,3,4] && sa2.ptr is da.ptr); } } baz1(da[0..3], da[0..3]); static assert(!__traits(compiles, baz1(da[0..4], da[0..4]))); baz2(da[0..3], da[0..3], 3); baz2(da[0..4], da[0..4], 4); void hoo1(size_t dim)(int[dim]) { static assert(dim == 2); } void hoo2(int[2]) {} void hoo3(size_t dim)(ref int[dim]) {} void hoo4(ref int[2]) {} hoo1(da.idup[0 .. 2]); hoo2(da.idup[0 .. 2]); static assert(!__traits(compiles, hoo3(da.idup[0 .. 2]))); static assert(!__traits(compiles, hoo4(da.idup[0 .. 2]))); } /**********************************/ // 9654 auto foo9654a(ref char[8] str) { return str; } auto foo9654b(ref const char[8] str) { return str; } auto foo9654c(ref immutable char[8] str) { return str; } static assert(!is(typeof(foo9654a("testinfo")))); static assert( is(typeof(foo9654b("testinfo")) == const char[8])); static assert( is(typeof(foo9654c("testinfo")) == immutable char[8])); auto bar9654a(T)(ref T[8] str) { return str; static assert(is(T == immutable char)); } auto bar9654b(T)(ref const T[8] str) { return str; static assert(is(T == char)); } auto bar9654c(T)(ref immutable T[8] str) { return str; static assert(is(T == char)); } static assert( is(typeof(bar9654a("testinfo")) == immutable char[8])); static assert( is(typeof(bar9654b("testinfo")) == const char[8])); static assert( is(typeof(bar9654c("testinfo")) == immutable char[8])); auto baz9654a(T, size_t dim)(ref T[dim] str) { return str; static assert(is(T == immutable char)); } auto baz9654b(T, size_t dim)(ref const T[dim] str) { return str; static assert(is(T == char)); } auto baz9654c(T, size_t dim)(ref immutable T[dim] str) { return str; static assert(is(T == char)); } static assert( is(typeof(baz9654a("testinfo")) == immutable char[8])); static assert( is(typeof(baz9654b("testinfo")) == const char[8])); static assert( is(typeof(baz9654c("testinfo")) == immutable char[8])); /******************************************/ // 9712 auto func9712(T)(T[2] arg) { return arg; } static assert(is(typeof(func9712([1,2])) == int[2])); auto deduceLength9712(T,size_t n)(T[n] a) { return a; } static assert(is(typeof(deduceLength9712([1,2,3])) == int[3])); /******************************************/ // 9743 void test9743() { // +-Char // |+-Immutable or Const or Mutable // ||+-Value or Ref // |||+-Function or +-Template void fCIVF( immutable char[4]) {} void fCIVT()( immutable char[4]) {} void fCCVF( const char[4]) {} void fCCVT()( const char[4]) {} void fCMVF( char[4]) {} void fCMVT()( char[4]) {} void fCIRF(ref immutable char[4]) {} void fCIRT()(ref immutable char[4]) {} void fCCRF(ref const char[4]) {} void fCCRT()(ref const char[4]) {} void fCMRF(ref char[4]) {} void fCMRT()(ref char[4]) {} alias fcOK = TypeTuple!(fCIVF, fCIVT, fCCVF, fCCVT, fCMVF, fCMVT, fCIRF, fCIRT, fCCRF, fCCRT); foreach (f; fcOK) f("1234" ) ; foreach (f; fcOK) f("1234"c) ; foreach (f; fcOK) static assert(!__traits(compiles, f("1234"w) )); foreach (f; fcOK) static assert(!__traits(compiles, f("1234"d) )); alias fcNG = TypeTuple!(fCMRF, fCMRT); // cannot hold immutable data by mutable ref foreach (f; fcNG) static assert(!__traits(compiles, f("1234" ) )); foreach (f; fcNG) static assert(!__traits(compiles, f("1234"c) )); foreach (f; fcNG) static assert(!__traits(compiles, f("1234"w) )); foreach (f; fcNG) static assert(!__traits(compiles, f("1234"d) )); // +-Wchar void fWIVF( immutable wchar[4]) {} void fWIVT()( immutable wchar[4]) {} void fWCVF( const wchar[4]) {} void fWCVT()( const wchar[4]) {} void fWMVF( wchar[4]) {} void fWMVT()( wchar[4]) {} void fWIRF(ref immutable wchar[4]) {} void fWIRT()(ref immutable wchar[4]) {} void fWCRF(ref const wchar[4]) {} void fWCRT()(ref const wchar[4]) {} void fWMRF(ref wchar[4]) {} void fWMRT()(ref wchar[4]) {} alias fwOK = TypeTuple!(fWIVF, fWIVT, fWCVF, fWCVT, fWMVF, fWMVT, fWIRF, fWIRT, fWCRF, fWCRT); foreach (f; fwOK) f("1234" ) ; foreach (f; fwOK) static assert(!__traits(compiles, f("1234"c) )); foreach (f; fwOK) f("1234"w) ; foreach (f; fwOK) static assert(!__traits(compiles, f("1234"d) )); alias fwNG = TypeTuple!(fWMRF, fWMRT); // cannot hold immutable data by mutable ref foreach (f; fwNG) static assert(!__traits(compiles, f("1234" ) )); foreach (f; fwNG) static assert(!__traits(compiles, f("1234"c) )); foreach (f; fwNG) static assert(!__traits(compiles, f("1234"w) )); foreach (f; fwNG) static assert(!__traits(compiles, f("1234"d) )); // +-Dchar void fDIVF( immutable dchar[4]) {} void fDIVT()( immutable dchar[4]) {} void fDCVF( const dchar[4]) {} void fDCVT()( const dchar[4]) {} void fDMVF( dchar[4]) {} void fDMVT()( dchar[4]) {} void fDIRF(ref immutable dchar[4]) {} void fDIRT()(ref immutable dchar[4]) {} void fDCRF(ref const dchar[4]) {} void fDCRT()(ref const dchar[4]) {} void fDMRF(ref dchar[4]) {} void fDMRT()(ref dchar[4]) {} alias fdOK = TypeTuple!(fDIVF, fDIVT, fDCVF, fDCVT, fDMVF, fDMVT, fDIRF, fDIRT, fDCRF, fDCRT); foreach (f; fdOK) f("1234" ) ; foreach (f; fdOK) static assert(!__traits(compiles, f("1234"c) )); foreach (f; fdOK) static assert(!__traits(compiles, f("1234"w) )); foreach (f; fdOK) f("1234"d) ; alias fdNG = TypeTuple!(fDMRF, fDMRT); // cannot hold immutable data by mutable ref foreach (f; fdNG) static assert(!__traits(compiles, f("1234" ) )); foreach (f; fdNG) static assert(!__traits(compiles, f("1234"c) )); foreach (f; fdNG) static assert(!__traits(compiles, f("1234"w) )); foreach (f; fdNG) static assert(!__traits(compiles, f("1234"d) )); } /******************************************/ // 9747 void foo9747A(T)(T[4]) {} void foo9747C(size_t dim)(char[dim]) {} void foo9747W(size_t dim)(wchar[dim]) {} void foo9747D(size_t dim)(dchar[dim]) {} void test9747() { foo9747A("abcd"c); foo9747A("abcd"w); foo9747A("abcd"d); foo9747C("abcd"c); foo9747W("abcd"w); foo9747D("abcd"d); } /******************************************/ // 12876 void test12876() { void foo(int[4] b) {} void bar(size_t n)(int[n] c) { static assert(n == 4); } int[5] a; foo(a[1 .. $]); // OK bar(a[1 .. $]); // OK <- Error } /******************************************/ // 13775 void test13775() { ubyte[4] ubytes = [1,2,3,4]; // CT-known slicing (issue 3652) auto ok1 = cast(ubyte[2]) ubytes[0 .. 2]; assert(ok1 == [1, 2]); // CT-known slicing with implicit conversion of SliceExp::e1 (issue 13154) enum double[] arr = [1.0, 2.0, 3.0]; auto ok2 = cast(float[2]) [1.0, 2.0, 3.0][0..2]; auto ok3 = cast(float[2]) arr[1..3]; // currently this is accepted assert(ok2 == [1f, 2f]); assert(ok3 == [2f, 3f]); // CT-known slicing with type coercing (issue 13775) auto ok4 = cast( byte[2]) ubytes[0 .. 2]; // CT-known slicing + type coercing auto ok5 = cast(short[1]) ubytes[0 .. 2]; // CT-known slicing + type coercing assert(ok4 == [1, 2]); version(LittleEndian) assert(ok5 == [0x0201]); version( BigEndian) assert(ok5 == [0x0102]); } /******************************************/ int main() { test3652(); test3652a(); test3652b(); test9743(); test9747(); test13775(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/newdel.d0000644000175000017500000000267113200164642023040 0ustar matthiasmatthias// PERMUTE_ARGS: import core.stdc.stdio; import core.stdc.stdlib; /*********************************************/ class Foo { static uint flags; new(size_t sz, int x) { void* p; printf("Foo.new(sz = %d, x = %d)\n", sz, x); assert(sz == Foo.classinfo.init.length); assert(x == 5); p = core.stdc.stdlib.malloc(sz); flags |= 4; return p; } this() { printf("this() %p\n", this); a = 36; } ~this() { printf("~this() %p\n", this); a = -5; flags |= 1; } delete(void* p) { printf("delete %p\n", p); free(p); flags |= 2; } int a = 3; int b = 4; int d = 56; } void test1() { Foo f; f = new(5) Foo; assert(f.a == 36); assert(f.b == 4); assert(f.d == 56); assert(Foo.flags == 4); delete f; assert(Foo.flags == 7); } /*********************************************/ struct Foo2 { static uint flags; new(size_t sz, int x) { void* p; printf("Foo2.new(sz = %d, x = %d)\n", sz, x); assert(sz == Foo2.sizeof); assert(x == 5); p = core.stdc.stdlib.malloc(sz); flags |= 4; return p; } delete(void *p) { printf("p = %p\n", p); flags |= 2; core.stdc.stdlib.free(p); } } void test2() { Foo2 *f = new(5) Foo2(); printf("f = %p\n", f); delete f; assert(Foo2.flags == 6); } /*********************************************/ int main() { test1(); test2(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/hello.d0000644000175000017500000000043413200164642022660 0ustar matthiasmatthias// PERMUTE_ARGS: extern(C) int printf(const char*, ...); int main(char[][] args) { printf("hello world\n"); printf("args.length = %d\n", args.length); for (int i = 0; i < args.length; i++) printf("args[%d] = '%.*s'\n", i, args[i].length, args[i].ptr); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test39.sh0000755000175000017500000000230013200164642023074 0ustar matthiasmatthias#!/usr/bin/env bash dir=${RESULTS_DIR}/runnable dmddir=${RESULTS_DIR}${SEP}runnable output_file=${dir}/test39.sh.out rm -f ${output_file} $DMD -m${MODEL} -Irunnable -od${dmddir} -c runnable/extra-files/test39.d >> ${output_file} if [ $? -ne 0 ]; then cat ${output_file} rm -f ${output_file} exit 1 fi $DMD -m${MODEL} -Irunnable -od${dmddir} -c runnable/imports/test39a.d >> ${output_file} if [ $? -ne 0 ]; then cat ${output_file} rm -f ${output_file} exit 1 fi if [ ${OS} == "win32" -o ${OS} == "win64" ]; then $DMD -m${MODEL} -lib -of${dmddir}${SEP}test39a.lib ${dmddir}${SEP}test39a.obj >> ${output_file} 2>&1 LIBEXT=.lib else ar -r ${dir}/test39a.a ${dir}/test39a.o >> ${output_file} 2>&1 LIBEXT=.a fi if [ $? -ne 0 ]; then cat ${output_file} rm -f ${output_file} exit 1 fi $DMD -m${MODEL} -of${dmddir}${SEP}test39${EXE} ${dir}/test39${OBJ} ${dir}/test39a${LIBEXT} >> ${output_file} if [ $? -ne 0 ]; then cat ${output_file} rm -f ${output_file} exit 1 fi ${dir}/test39 >> ${output_file} if [ $? -ne 0 ]; then cat ${output_file} rm -f ${output_file} exit 1 fi rm ${dir}/{test39${OBJ},test39a${OBJ},test39a${LIBEXT},test39${EXE}} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testassign.d0000644000175000017500000006446313200164642023755 0ustar matthiasmatthiasimport core.stdc.stdio; template TypeTuple(T...){ alias T TypeTuple; } /***************************************************/ // 2625 struct Pair { immutable uint g1; uint g2; } void test1() { Pair[1] stuff; static assert(!__traits(compiles, (stuff[0] = Pair(1, 2)))); } /***************************************************/ // 5327 struct ID { immutable int value; } struct Data { ID id; } void test2() { Data data = Data(ID(1)); immutable int* val = &data.id.value; static assert(!__traits(compiles, data = Data(ID(2)))); } /***************************************************/ struct S31A { union { immutable int field1; immutable int field2; } enum result = false; } struct S31B { union { immutable int field1; int field2; } enum result = true; } struct S31C { union { int field1; immutable int field2; } enum result = true; } struct S31D { union { int field1; int field2; } enum result = true; } struct S32A { int dummy0; union { immutable int field1; int field2; } enum result = true; } struct S32B { immutable int dummy0; union { immutable int field1; int field2; } enum result = false; } struct S32C { union { immutable int field1; int field2; } int dummy1; enum result = true; } struct S32D { union { immutable int field1; int field2; } immutable int dummy1; enum result = false; } void test3() { foreach (S; TypeTuple!(S31A,S31B,S31C,S31D, S32A,S32B,S32C,S32D)) { S s; static assert(__traits(compiles, s = s) == S.result); } } /***************************************************/ // 3511 struct S4 { private int _prop = 42; ref int property() { return _prop; } } void test4() { S4 s; assert(s.property == 42); s.property = 23; // Rewrite to s.property() = 23 assert(s.property == 23); } /***************************************************/ struct S5 { int mX; string mY; ref int x() { return mX; } ref string y() { return mY; } ref int err(Object) { static int v; return v; } } void test5() { S5 s; s.x += 4; assert(s.mX == 4); s.x -= 2; assert(s.mX == 2); s.x *= 4; assert(s.mX == 8); s.x /= 2; assert(s.mX == 4); s.x %= 3; assert(s.mX == 1); s.x <<= 3; assert(s.mX == 8); s.x >>= 1; assert(s.mX == 4); s.x >>>= 1; assert(s.mX == 2); s.x &= 0xF; assert(s.mX == 0x2); s.x |= 0x8; assert(s.mX == 0xA); s.x ^= 0xF; assert(s.mX == 0x5); s.x ^^= 2; assert(s.mX == 25); s.mY = "ABC"; s.y ~= "def"; assert(s.mY == "ABCdef"); static assert(!__traits(compiles, s.err += 1)); } /***************************************************/ // 4424 void test4424() { static struct S { this(this) {} void opAssign(T)(T rhs) if (!is(T == S)) {} } } /***************************************************/ // 6174 struct CtorTest6174(Data) { const Data data; const Data[2] sa1; const Data[2][1] sa2; const Data[][2] sa3; const Data[] da1; const Data[2][] da2; this(Data a) { auto pdata = &data; // If compiler can determine that an assignment really sets the fields // which belongs to `this` object, it can bypass const qualifier. // For example, sa3, da1, da2, and pdata have indirections. // As long as you don't try to rewrite values beyond the indirections, // an assignment will always be succeeded inside constructor. static assert( is(typeof( data = a ))); // OK static if (is(Data == struct)) { static assert( is(typeof( data.x = 1 ))); // OK static assert( is(typeof( data.y = 2 ))); // OK } static assert(!is(typeof( *pdata = a ))); // NG static assert( is(typeof( *&data = a ))); // OK static assert( is(typeof( sa1 = [a,a] ))); // OK static assert( is(typeof( sa1[0] = a ))); // OK static assert( is(typeof( sa1[] = a ))); // OK static assert( is(typeof( sa1[][] = a ))); // OK static assert( is(typeof( sa2 = [[a,a]] ))); // OK static assert( is(typeof( sa2[0][0] = a ))); // OK static assert( is(typeof( sa2[][0][] = a ))); // OK static assert( is(typeof( sa2[0][][0] = a ))); // OK static assert( is(typeof( sa3 = [[a],[]] ))); // OK static assert( is(typeof( sa3[0] = [a,a] ))); // OK static assert(!is(typeof( sa3[0][0] = a ))); // NG static assert( is(typeof( sa3[] = [a] ))); // OK static assert( is(typeof( sa3[][0] = [a] ))); // OK static assert(!is(typeof( sa3[][0][0] = a ))); // NG static assert( is(typeof( da1 = [a,a] ))); // OK static assert(!is(typeof( da1[0] = a ))); // NG static assert(!is(typeof( da1[] = a ))); // NG static assert( is(typeof( da2 = [[a,a]] ))); // OK static assert(!is(typeof( da2[0][0] = a ))); // NG static assert(!is(typeof( da2[] = [a,a] ))); // NG static assert(!is(typeof( da2[][0] = a ))); // NG static assert(!is(typeof( da2[0][] = a ))); // NG } void func(Data a) { auto pdata = &data; static assert(!is(typeof( data = a ))); // NG static if (is(Data == struct)) { static assert(!is(typeof( data.x = 1 ))); // NG static assert(!is(typeof( data.y = 2 ))); // NG } static assert(!is(typeof( *pdata = a ))); // NG static assert(!is(typeof( *&data = a ))); // NG static assert(!is(typeof( sa1 = [a,a] ))); // NG static assert(!is(typeof( sa1[0] = a ))); // NG static assert(!is(typeof( sa1[] = a ))); // NG static assert(!is(typeof( sa1[][] = a ))); // NG static assert(!is(typeof( sa2 = [[a,a]] ))); // NG static assert(!is(typeof( sa2[0][0] = a ))); // NG static assert(!is(typeof( sa2[][0][] = a ))); // NG static assert(!is(typeof( sa2[0][][0] = a ))); // NG static assert(!is(typeof( sa3 = [[a],[]] ))); // NG static assert(!is(typeof( sa3[0] = [a,a] ))); // NG static assert(!is(typeof( sa3[0][0] = a ))); // NG static assert(!is(typeof( sa3[] = [a] ))); // NG static assert(!is(typeof( sa3[][0] = [a] ))); // NG static assert(!is(typeof( sa3[][0][0] = a ))); // NG static assert(!is(typeof( da1 = [a,a] ))); // NG static assert(!is(typeof( da1[0] = a ))); // NG static assert(!is(typeof( da1[] = a ))); // NG static assert(!is(typeof( da2 = [[a,a]] ))); // NG static assert(!is(typeof( da2[0][0] = a ))); // NG static assert(!is(typeof( da2[] = [a,a] ))); // NG static assert(!is(typeof( da2[][0] = a ))); // NG static assert(!is(typeof( da2[0][] = a ))); // NG } } const char gc6174; const char[1] ga6174; static this() { gc6174 = 'a'; // OK ga6174[0] = 'a'; // line 5, Err } struct Foo6174 { const char cc; const char[1] array; const char[1] arr; this(char c) { cc = c; // OK array = [c]; // line 12, Err arr[0] = c; // line 12, Err } } void test6174a() { static struct Pair { const int x; int y; } alias CtorTest6174!long CtorTest1; alias CtorTest6174!Pair CtorTest2; auto foo = Foo6174('c'); } /***************************************************/ template Select(bool cond, T, F) { static if (cond) alias Select = T; else alias Select = F; } void test6174b() { enum { none, unrelated, mutable, constant } static struct FieldStruct(bool c, int k) { enum fieldConst = c; enum assignKind = k; Select!(fieldConst, const int, int) x; int y; static if (assignKind == none) {} static if (assignKind == unrelated) void opAssign(int) {} static if (assignKind == mutable) void opAssign(FieldStruct) {} static if (assignKind == constant) void opAssign(FieldStruct) const {} } static struct TestStruct(F, bool fieldConst) { int w; Select!(fieldConst, const F, F) f; Select!(fieldConst, const int, int) z; this(int) { // If F has an identity `opAssign`,it is used even for initializing. // Otherwise, initializing will always succeed, by bypassing const qualifier. static assert(is(typeof( f = F() )) == ( F.assignKind == none || F.assignKind == unrelated || F.assignKind == mutable || F.assignKind == constant)); static assert(is(typeof( w = 1000 )) == true); static assert(is(typeof( f.x = 1000 )) == true); static assert(is(typeof( f.y = 1000 )) == true); static assert(is(typeof( z = 1000 )) == true); } void func() { // In mutable member functions, identity assignment is allowed // when all of the fields are identity assignable, // or identity `opAssign`, which callable from mutable object, is defined. static assert(__traits(compiles, f = F()) == ( F.assignKind == none && !fieldConst && !F.fieldConst || F.assignKind == unrelated && !fieldConst && !F.fieldConst || F.assignKind == constant || F.assignKind == mutable && !fieldConst)); static assert(__traits(compiles, w = 1000) == true); static assert(__traits(compiles, f.x = 1000) == (!fieldConst && !F.fieldConst)); static assert(__traits(compiles, f.y = 1000) == (!fieldConst && true )); static assert(__traits(compiles, z = 1000) == !fieldConst); } void func() const { // In non-mutable member functions, identity assignment is allowed // just only user-defined identity `opAssign` is qualified. static assert(__traits(compiles, f = F()) == (F.assignKind == constant)); static assert(__traits(compiles, w = 1000) == false); static assert(__traits(compiles, f.x = 1000) == false); static assert(__traits(compiles, f.y = 1000) == false); static assert(__traits(compiles, z = 1000) == false); } } foreach (fieldConst; TypeTuple!(false, true)) foreach ( hasConst; TypeTuple!(false, true)) foreach (assignKind; TypeTuple!(none, unrelated, mutable, constant)) { alias TestStruct!(FieldStruct!(hasConst, assignKind), fieldConst) TestX; } } void test6174c() { static assert(!is(typeof({ int func1a(int n) in{ n = 10; } body { return n; } }))); static assert(!is(typeof({ int func1b(int n) out(r){ r = 20; } body{ return n; } }))); struct DataX { int x; } static assert(!is(typeof({ DataX func2a(DataX n) in{ n.x = 10; } body { return n; } }))); static assert(!is(typeof({ DataX func2b(DataX n) in{} out(r){ r.x = 20; } body{ return n; } }))); } /***************************************************/ // 6216 void test6216a() { static class C{} static struct Xa{ int n; } static struct Xb{ int[] a; } static struct Xc{ C c; } static struct Xd{ void opAssign(typeof(this) rhs){} } static struct Xe{ void opAssign(T)(T rhs){} } static struct Xf{ void opAssign(int rhs){} } static struct Xg{ void opAssign(T)(T rhs)if(!is(T==typeof(this))){} } // has value type as member static struct S1 (X){ static if (!is(X==void)) X x; int n; } // has reference type as member static struct S2a(X){ static if (!is(X==void)) X x; int[] a; } static struct S2b(X){ static if (!is(X==void)) X x; C c; } // has identity opAssign static struct S3a(X){ static if (!is(X==void)) X x; void opAssign(typeof(this) rhs){} } static struct S3b(X){ static if (!is(X==void)) X x; void opAssign(T)(T rhs){} } // has non identity opAssign static struct S4a(X){ static if (!is(X==void)) X x; void opAssign(int rhs){} } static struct S4b(X){ static if (!is(X==void)) X x; void opAssign(T)(T rhs)if(!is(T==typeof(this))){} } enum result = [ /*S1, S2a, S2b, S3a, S3b, S4a, S4b*/ /*- */ [true, true, true, true, true, true, true], /*Xa*/ [true, true, true, true, true, true, true], /*Xb*/ [true, true, true, true, true, true, true], /*Xc*/ [true, true, true, true, true, true, true], /*Xd*/ [true, true, true, true, true, true, true], /*Xe*/ [true, true, true, true, true, true, true], /*Xf*/ [true, true, true, true, true, true, true], /*Xg*/ [true, true, true, true, true, true, true], ]; pragma(msg, "\\\tS1\tS2a\tS2b\tS3a\tS3b\tS4a\tS4b"); foreach (i, X; TypeTuple!(void,Xa,Xb,Xc,Xd,Xe,Xf,Xg)) { S1!X s1; S2a!X s2a; S2b!X s2b; S3a!X s3a; S3b!X s3b; S4a!X s4a; S4b!X s4b; pragma(msg, is(X==void) ? "-" : X.stringof, "\t", __traits(compiles, (s1 = s1)), "\t", __traits(compiles, (s2a = s2a)), "\t", __traits(compiles, (s2b = s2b)), "\t", __traits(compiles, (s3a = s3a)), "\t", __traits(compiles, (s3b = s3b)), "\t", __traits(compiles, (s4a = s4a)), "\t", __traits(compiles, (s4b = s4b)) ); static assert(result[i] == [ __traits(compiles, (s1 = s1)), __traits(compiles, (s2a = s2a)), __traits(compiles, (s2b = s2b)), __traits(compiles, (s3a = s3a)), __traits(compiles, (s3b = s3b)), __traits(compiles, (s4a = s4a)), __traits(compiles, (s4b = s4b)) ]); } } void test6216b() { static int cnt = 0; static struct X { int n; void opAssign(X rhs){ cnt = 1; } } static struct S { int n; X x; } S s; s = s; assert(cnt == 1); // Built-in opAssign runs member's opAssign } void test6216c() { static int cnt = 0; static struct X { int n; void opAssign(const X rhs) const { cnt = 2; } } static struct S { int n; const(X) x; } S s; const(S) cs; s = s; s = cs; // cs is copied as mutable and assigned into s assert(cnt == 2); static assert(!__traits(compiles, cs = cs)); // built-in opAssin is only allowed with mutable object } void test6216d() { static int cnt = 0; static struct X { int[] arr; // X has mutable indirection void opAssign(const X rhs) const { ++cnt; } } static struct S { int n; const(X) x; } X mx; const X cx; mx = mx; // copying mx to const X is possible assert(cnt == 1); mx = cx; assert(cnt == 2); cx = mx; // copying mx to const X is possible assert(cnt == 3); S s; const(S) cs; s = s; s = cs; //assert(cnt == 4); static assert(!__traits(compiles, cs = cs)); // built-in opAssin is only allowed with mutable object } void test6216e() { static struct X { int x; @disable void opAssign(X); } static struct S { X x; } S s; static assert(!__traits(compiles, s = s)); // built-in generated opAssin is marked as @disable. } /***************************************************/ // 6286 void test6286() { const(int)[4] src = [1, 2, 3, 4]; int[4] dst; dst = src; dst[] = src[]; dst = 4; int[4][4] x; x = dst; } /***************************************************/ // 6336 void test6336() { // structs aren't identity assignable static struct S1 { immutable int n; } static struct S2 { void opAssign(int n){ assert(0); } } S1 s1; S2 s2; void f(S)(out S s){} static assert(!__traits(compiles, f(s1))); f(s2); // Out parameters refuse only S1 because it isn't blit assignable ref S g(S)(ref S s){ return s; } g(s1); g(s2); // Allow return by ref both S1 and S2 } /***************************************************/ // 8783 struct Foo8783 { int[1] bar; } const Foo8783[1] foos8783; static this() { foreach (i; 0 .. foos8783.length) foos8783[i].bar[i] = 1; // OK foreach (i, ref f; foos8783) f.bar[i] = 1; // line 9, Error } /***************************************************/ // 9077 struct S9077a { void opAssign(int n) {} void test() { typeof(this) s; s = this; } this(this) {} } struct S9077b { void opAssign()(int n) {} void test() { typeof(this) s; s = this; } this(this) {} } /***************************************************/ // 9140 immutable(int)[] bar9140() out(result) { foreach (ref r; result) {} } body { return null; } /***************************************************/ // 9154 struct S9154a { int x; void opAssign(ref S9154a s) { } } struct S9154b { int x; void opAssign(X)(ref X s) { } } struct T9154 { S9154a member1; S9154b member2; } void test9154() { T9154 t1, t2; t1 = t2; } /***************************************************/ // 9258 class A9258 {} class B9258 : A9258 // Error: class test.B9258 identity assignment operator overload is illegal { void opAssign(A9258 b) {} } class C9258 { int n; alias n this; void opAssign(int n) {} } class D9258 { int n; alias n this; void opAssign(int n, int y = 0) {} } class E9258 : A9258 { void set(A9258 a) {} alias set opAssign; } /***************************************************/ // 9416 struct S9416 { void opAssign()(S9416) { static assert(0); } } struct U9416 { S9416 s; } void test9416() { U9416 u; static assert(__traits(allMembers, U9416)[$-1] == "opAssign"); static assert(!__traits(compiles, u = u)); } /***************************************************/ // 9658 struct S9658 { private bool _isNull = true; this(int v) const { _isNull = false; // cannot modify const expression this._isNull } } /***************************************************/ // 11187 void test11187() { static struct X { int[] arr; } static struct S { const(X) cx; } static assert(is(typeof((const S).init.cx.arr) == const(int[]))); static assert(is(typeof(( S).init.cx.arr) == const(int[]))); const S sc; S sm = sc; static assert(is(const S : S)); } /***************************************************/ // 12131 struct X12131 { void opAssign()(X12131 y) pure {} } struct Y12131 { X12131 a; } void test12131() pure { X12131 x; x = X12131(); // OK Y12131 y; y = Y12131(); // OK <- Error } /***************************************************/ // 12211 void test12211() { int a = 0; void foo(ref int x) { assert(x == 10); assert(&x == &a); x = 3; } foo(a = 10); assert(a == 3); foo(a += 7); assert(a == 3); // array ops should make rvalue int[3] sa, sb; void bar(ref int[]) {} static assert(!__traits(compiles, bar(sa[] = sb[]))); static assert(!__traits(compiles, bar(sa[] += sb[]))); } /***************************************************/ // 4791 (dup of 12212) void test4791() { int[2] na; na = na; static struct S { static string res; int n; this(this) { ++n; res ~= "p" ~ cast(char)('0' + n); } ~this() { res ~= "d" ~ cast(char)('0' + n); } } { S[3] sa; sa[0].n = 1, sa[1].n = 2, sa[2].n = 3; S.res = null; sa = sa; assert(S.res == "p2d1p3d2p4d3"); assert(sa[0].n == 2 && sa[1].n == 3 && sa[2].n == 4); S.res = null; } assert(S.res == "d4d3d2"); } /***************************************************/ // 12212 void test12212() { struct S { int x, y; static int cpctor; this(this) { cpctor++; } } void funcVal(E)(E[3] x) {} auto funcRef(E)(ref E[3] x) { return &x; } ref get(E)(ref E[3] a){ return a; } { int[3] a, b; funcVal(a = b); auto p = funcRef(a = b); assert(p == &a); } { S.cpctor = 0; S[3] a, b; assert(S.cpctor == 0); S[3] c = a; //printf("cpctpr = %d\n", S.cpctor); assert(S.cpctor == 3); S.cpctor = 0; c = a; //printf("cpctpr = %d\n", S.cpctor); assert(S.cpctor == 3); S.cpctor = 0; c = (a = b); //printf("cpctpr = %d\n", S.cpctor); assert(S.cpctor == 6); S.cpctor = 0; c = (get(a) = b); //printf("cpctpr = %d\n", S.cpctor); assert(S.cpctor == 6); S.cpctor = 0; } { S.cpctor = 0; S[3] a, b; assert(S.cpctor == 0); funcVal(a = b); //printf("cpctpr = %d\n", S.cpctor); assert(S.cpctor == 6); S.cpctor = 0; funcVal(get(a) = b); //printf("cpctpr = %d\n", S.cpctor); assert(S.cpctor == 6); S.cpctor = 0; } { S.cpctor = 0; S[3] a, b; assert(S.cpctor == 0); S[3]* p; p = funcRef(a = b); //printf("cpctpr = %d\n", S.cpctor); assert(p == &a); assert(S.cpctor == 3); S.cpctor = 0; p = funcRef(get(a) = b); assert(p == &a); //printf("cpctpr = %d\n", S.cpctor); assert(S.cpctor == 3); S.cpctor = 0; } } /***************************************************/ // 12650 void test12650() { // AssignExp::toElem should make an lvalue of e1. static class A1 { struct S { int a; } static foo(ref const(S) s) { assert(s.a == 2); return &s; } S s; this() { const v = S(2); // (this.s = v) will become ConstructExp auto p = foo(s = v); assert(p == &s); } } assert(new A1().s.a == 2); static class A2 { static foo(ref int[2] sa) { assert(sa[1] == 2); return &sa; } int[2] sa; this() { // (this.sa = [1,2]) will become ConstructExp auto p = foo(sa = [1,2]); assert(p == &sa); } } assert(new A2().sa[1] == 2); static class A3 { static foo(ref int n) { assert(n == 2); return &n; } int n; this() { const v = 2; // (this.n = v) will become ConstructExp auto p = foo(n = v); assert(p == &n); } } assert(new A3().n == 2); } /***************************************************/ // 13044 void test13044() { static struct Good { const int i; } static struct Bad { const int i; ~this() {} } Good good1, good2; static assert(!__traits(compiles, { good1 = good2; })); // OK Bad bad1, bad2; static assert(!__traits(compiles, { bad1 = bad2; })); // OK <- fails } /***************************************************/ // 12500 void test12500() { size_t foo; ++foo *= 1.5; // Rewrite to: (foo += 1) *= 1.5; } /***************************************************/ // 14672 void test14672() { interface I {} class B {} class D : B, I {} D d = new D(); D[] da = [d]; B[] ba = [null]; I[] ia = [null]; // ba and da points different payloads, // so element-wise assignment should work. ba[] = da[]; // OK <- e2ir ICE assert(ba[0] is d); // Today element-wise assignment is implemented as memcpy, For that reason // the conversion from derived classes to base interfaces is disallowed // because it requries offset adjustments. static assert(!__traits(compiles, { ia[] = da[]; })); // after the assignment, ba will wongly point the payload of da, // that's typed as D[]. To aboid type system breaking, it's disallowed. static assert(!__traits(compiles, { ba = da; })); // the assigned array literal is a new payload, // so rebinding ba should work. ba = [d]; // OK assert(ba[0] is d); } /***************************************************/ // 15044 void destroy15044(T)(ref T obj) { static if (__traits(hasMember, T, "__xdtor")) obj.__xdtor(); else static assert(0, T.stringof); } struct V15044 { ~this() { } RC15044!V15044 dup() { return RC15044!V15044(&this); } } struct RC15044(T) { ~this() { destroy15044(*t); static assert(__traits(hasMember, T, "__xdtor")); } T* t; } /***************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test4424(); test6174a(); test6174b(); test6174c(); test6216a(); test6216b(); test6216c(); test6216d(); test6216e(); test6286(); test6336(); test9154(); test9416(); test11187(); test12131(); test12211(); test4791(); test12212(); test12650(); test13044(); test12500(); test14672(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_contracts.d0000644000175000017500000000040713200164642024377 0ustar matthiasmatthias// REQUIRED_ARGS: -gs // The "-gs" flag is just here to test it somewhere in the entire test suite. public alias extern (C) void function(void*) Bar; public interface Test { public void foo(Bar bar) in { assert(bar); } } void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_340.d0000644000175000017500000000057213200164642024252 0ustar matthiasmatthiasversion(D_InlineAsm_X86_64) version = DMD_InlineAsm; version(D_InlineAsm_X86) version = DMD_InlineAsm; version(InlineAsm) { void fooNormal()() { asm { jmp Llabel; Llabel: nop; } } void fooNaked()() { asm { naked; jmp Llabel; Llabel: ret; } } void main() { fooNormal(); fooNaked(); } } else { void main() {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_119.d0000644000175000017500000000101413200164642024246 0ustar matthiasmatthiasalias ubyte[2] buf; buf initUsingValue() { buf x = 0; return x; } buf initDefault() { return buf.init; } // can just as easily replace buf for typeof(return) buf initUsingValue2() { buf x = 42; return x; } buf initUsingLiteral() { return [ 4, 8 ]; } void main() { buf x = initUsingValue(); assert(x[0] == 0 && x[1] == 0); x = initDefault(); assert(x[0] == 0 && x[1] == 0); x = initUsingValue2(); assert(x[0] == 42 && x[1] == 42); x = initUsingLiteral(); assert(x[0] == 4 && x[1] == 8); }ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test10736.d0000644000175000017500000000020513200164642023131 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test10736a.d // EXTRA_SOURCES: imports/test10736b.d import imports.test10736a; import imports.test10736b; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test34.d0000644000175000017500000005211313200164642022704 0ustar matthiasmatthias module test34; import std.stdio; import std.string; import std.format; import core.exception; /************************************************/ class Foo {} class Bar {} void test1() { TypeInfo ti_foo = typeid(Foo); TypeInfo ti_bar = typeid(Bar); auto hfoo = ti_foo.toHash(); auto hbar = ti_bar.toHash(); writefln("typeid(Foo).toHash: ", hfoo); writefln("typeid(Bar).toHash: ", hbar); assert(hfoo != hbar); auto e = (ti_foo == ti_bar); writefln("opEquals: ", e ? "equal" : "not equal"); assert(!e); auto c = (ti_foo.opCmp(ti_bar) == 0); writefln("opCmp: ", c ? "equal" : "not equal"); assert(!c); } /************************************************/ void test2() { assert( [2,3]!=[2,4] ); assert( [3,2]!=[4,2] ); assert( !([2,3]==[2,4]) ); assert( ([2,3]==[2,3]) ); } /************************************************/ struct Struct { int langID; long _force_nrvo; } Struct[1] table; Struct getfirst() { foreach(v; table) { writeln(v.langID); assert(v.langID == 1); return v; } assert(0); } Struct getsecond() { foreach(ref v; table) { writeln(v.langID); assert(v.langID == 1); return v; } assert(0); } void test3() { table[0].langID = 1; auto v = getfirst(); writeln(v.langID); assert(v.langID == 1); v = getsecond(); writeln(v.langID); assert(v.langID == 1); } /************************************************/ class ExOuter { class ExInner { this() { typeof(this.outer) X; static assert(is(typeof(X) == ExOuter)); } } } void test4() { } /************************************************/ int status5; struct MyStruct5 { } void rec5(int i, MyStruct5 s) { if( i > 0 ) { status5++; rec5(i-1, s); } } void test5() { assert(status5==0); MyStruct5 st; rec5(1030, st); assert(status5==1030); } /************************************************/ class C6 { const int a; this() { a = 3; } this(int x) { this(); } } void test6() { } /************************************************/ template parseUinteger(string s) { static if (s.length == 0) { const char[] value = ""; const char[] rest = ""; } else static if (s[0] >= '0' && s[0] <= '9') { const char[] value = s[0] ~ parseUinteger!(s[1..$]).value; const char[] rest = parseUinteger!(s[1..$]).rest; } else { const char[] value = ""; const char[] rest = s; } } template parseInteger(string s) { static if (s.length == 0) { const char[] value = ""; const char[] rest = ""; } else static if (s[0] >= '0' && s[0] <= '9') { const char[] value = s[0] ~ parseUinteger!(s[1..$]).value; const char[] rest = parseUinteger!(s[1..$]).rest; } else static if (s.length >= 2 && s[0] == '-' && s[1] >= '0' && s[1] <= '9') { const char[] value = s[0..2] ~ parseUinteger!(s[2..$]).value; const char[] rest = parseUinteger!(s[2..$]).rest; } else { const char[] value = ""; const char[] rest = s; } } void test7() { writeln(parseUinteger!("1234abc").value); writeln(parseUinteger!("1234abc").rest); writeln(parseInteger!("-1234abc").value); writeln(parseInteger!("-1234abc").rest); assert(parseUinteger!("1234abc").value == "1234"); assert(parseUinteger!("1234abc").rest == "abc"); assert(parseInteger!("-1234abc").value == "-1234"); assert(parseInteger!("-1234abc").rest == "abc"); } /************************************************/ struct Foo8 { } enum Enum { RED } //typedef int myint; alias int myalias; void test8() { /+ assert((1+2).stringof == "1 + 2"); assert(Foo8.stringof == "Foo8"); assert(test.Foo8.stringof == "test.Foo8"); assert(int.stringof == "int"); assert((int*[5][]).stringof == "int*[5][]"); assert(Enum.RED.stringof == "Enum.RED"); assert(test.myint.stringof == "test.myint"); assert(myalias.stringof == "myalias"); assert((5).stringof == "5"); assert(typeof(5).stringof == "typeof(5)"); +/ } /************************************************/ /+ class Base9 { public void fnc(){ } } class Foo9 : Base9 { alias Base9.fnc fnc; public void fnc(){ } static this(){ alias void function() T; T ptr = & fnc; } } +/ void test9() { } /************************************************/ bool isalnum(dchar c) { return c>='0' && c >= '9'; } char[] toHtmlFilename(char[] fname) { foreach (ref c; fname) { if (!isalnum(c) && c != '.' && c != '-') c = '_'; } return fname; } void test10() { } /************************************************/ class A34 { } class B34 : A34 { } void test11() { A34 test=new B34; writefln("Test is ", test.toString); assert(test.toString == "test34.B34"); A34 test_2=cast(A34)(new B34); writefln("Test 2 is ", test_2.toString); assert(test_2.toString == "test34.B34"); } /************************************************/ template Foo12(T: T[U], U) { alias int Foo12; } void test12() { Foo12!(int[long]) x; assert(is(typeof(x) == int)); } /************************************************/ class C13 { int a = 4; this() { printf("C13.this()\n"); assert(a == 4); a = 5; } } void test13() { C13 c = cast(C13)Object.factory("test34.C13"); assert(c.a == 5); Object o = Object.factory("test35.C13"); assert(o is null); } /************************************************/ class Base15 { int func(int a) { return 1; } } class Foo15 : Base15 { alias Base15.func func; } class Bar15 : Foo15 { alias Foo15.func func; int func(string a) { return 2; } } void test15() { Bar15 b = new Bar15(); assert(b.func("hello") == 2); assert(b.func(5) == 1); } /************************************************/ struct Basic16(T, U) {} struct Iterator16(T : Basic16!(T, U), U) { static void Foo() { writeln(typeid(T), typeid(U)); assert(is(T == int)); assert(is(U == float)); } } void test16() { Iterator16!(Basic16!(int, float)).Foo(); } /************************************************/ struct S17(T) { struct iterator {} } int insert17(T) (S17!(T) lst, S17!(T).iterator i) { return 3; } void test17() { S17!(int) a; S17!(int).iterator i; auto x = insert17(a, i); assert(x == 3); } /************************************************/ void test18() { real t = 0.; for(int i=0; i<10; i++) { t += 1.; real r = (2*t); printf("%Lg %Lg %Lg\n", t, r, 2*t); assert(2*t == (i+1)*2); } } /************************************************/ void test19() { char c = '3'; void[] ca = cast(void[])[c]; char[] x = cast(char[])ca; assert(x[0] == '3'); } /************************************************/ enum type20 { a, b, } class myclass20 { template XX(uint a, uint c) { static uint XX(){ return (a*256+c);} } void testcase() { switch (cast(uint)type20.a) { case XX!(cast(uint)type20.a,cast(uint)type20.b)(): break; default: assert(0); } } } void test20() { } /************************************************/ struct S21 { alias int Foo; int x; } void test21() { S21 s; typeof(s).Foo j; assert(is(typeof(j) == int)); } /************************************************/ void test22() { auto i = 3, j = 4; assert(is(typeof(i) == int)); assert(is(typeof(j) == int)); } /************************************************/ static m23 = 5, n23 = 6; void test23() { auto i = 3, j = 4; assert(is(typeof(i) == int)); assert(is(typeof(j) == int)); assert(is(typeof(m23) == int)); assert(is(typeof(n23) == int)); } /************************************************/ const int a24 = 0; const int foo24 = 4; const int[1] bar24 = [foo24 * 2]; const int zap24 = (1 << bar24[a24]); void test24() { assert(zap24 == 256); } /************************************************/ struct List25(T) { } struct CircularQueue25(T) { } void front25(T)(ref List25!(T) list) { } void front25(T)(ref CircularQueue25!(T) queue) { } void test25() { List25!(int) x; front25(x); } /************************************************/ struct Foo26 { const string x; } static Foo26 foo26 = {"something"}; void test26() { assert(foo26.x == "something"); } /************************************************/ template Mang(alias F) { class G { } alias void function (G ) H; const string mangledname = H.mangleof; } template moo(alias A) { pragma(msg," "); const string a = Mang!(A).mangledname; pragma(msg," "); static assert(Mang!(A).mangledname == a); // FAILS !!! pragma(msg," "); } void test27() { int q; string b = moo!(q).a; } /************************************************/ struct Color { static void fromRgb(uint rgb) { } static void fromRgb(ubyte alpha, uint rgb) { } } void test28() { Color.fromRgb(0); Color.fromRgb(cast(uint)0); } /************************************************/ void test29() { const char[] t="abcd"; const ubyte[] t2=cast(ubyte[])t; const char[] t3=['a','b','c','d']; const ubyte[] t4=cast(ubyte[])t3; assert(t4[1] == 'b'); } /************************************************/ void test30() { const char[] test = "" ~ 'a' ~ 'b' ~ 'c'; char[] test2 = (cast(char[])null)~'a'~'b'~'c'; const char[] test3 = (cast(char[])null)~'a'~'b'~'c'; char[] test4 = (cast(char[])[])~'a'~'b'~'c'; const char[] test5 = (cast(char[])[])~'a'~'b'~'c'; const char[] test6 = null; const char[] test7 = test6~'a'~'b'~'c'; } /************************************************/ class C31 { synchronized invariant() { int x; } } void test31() { } /************************************************/ ulong foo32() { return cast(ulong) (cast(ulong) 1176576512 + cast(float) -2); } void test32() { assert(foo32()==1176576510); } /************************************************/ class RangeCoder { uint[258] cumCount; // 256 + end + total uint lower; uint upper; ulong range; this() { for (int i=0; i", x, y, z); } } class Foo34 { private Vector34 v; public this() { v = Vector34(1, 0, 0); } public void foo() { bar(); } private void bar() { auto s = foobar(); writef("Returned: %s\n", s); assert(std.string.format("%s", s) == "<1.000000, 0.000000, 0.000000>"); } public Vector34 foobar() { writef("Returning %s\n", v); return v; Vector34 b = Vector34(); return b; } } void test34() { Foo34 f = new Foo34(); f.foo(); } /************************************************/ version(D_InlineAsm_X86_64) version = DMD_InlineAsm; version(D_InlineAsm_X86) version = DMD_InlineAsm; void foo35() { uint a; uint b; uint c; extern (Windows) int function(int i, int j, int k) xxx; a = 1; b = 2; c = 3; xxx = cast(typeof(xxx))(a + b); version (DMD_InlineAsm) asm { int 3; } else version (LDC) { import ldc.intrinsics; llvm_debugtrap(); } else assert(false); xxx( 4, 5, 6 ); } void test35() { } /************************************************/ void test36() { int* p = void, c = void; } /************************************************/ void test37() { synchronized { synchronized { writefln("Hello world!"); } } } /************************************************/ struct Rect { int left, top, right, bottom; } void test38() { print38(sizeTest(false)); print38(sizeTest(true)); print38(defaultRect); } static Rect sizeTest(bool empty) { if (empty) { Rect result; return result; //return Rect.init; } else { return defaultRect; /+Rect result = defaultRect; return result;+/ } } void print38(Rect r) { writefln("(%d, %d)-(%d, %d)", r.left, r.top, r.right, r.bottom); assert(r.left == 0); assert(r.right == 0); assert(r.top == 0); assert(r.bottom == 0); } Rect defaultRect() { return Rect.init; } /************************************************/ void test39() { double[][] foo = [[1.0],[2.0]]; writeln(foo[0]); // --> [1] , ok writeln(foo[1]); // --> [2] , ok writeln(foo); // --> [[1],4.63919e-306] ack! writefln("%s", foo); // --> ditto auto f = std.string.format("%s", foo); assert(f == "[[1], [2]]"); double[1][2] bar; bar[0][0] = 1.0; bar[1][0] = 2.0; writeln(bar); // Error: Access violation auto r = std.string.format("%s", bar); assert(r == "[[1], [2]]"); } /************************************************/ void test40() { int[char] x; x['b'] = 123; writeln(x); auto r = std.string.format("%s", x); assert(r == "['b':123]"); writeln(x['b']); } /************************************************/ void test41() { } /************************************************/ enum Enum42 { A = 1 } void test42() { Enum42[] enums = new Enum42[1]; assert(enums[0] == Enum42.A); } /************************************************/ struct A43 {} struct B43(L) { A43 l; } void test43() { A43 a; auto b = B43!(A43)(a); } /************************************************/ void test44() { int[ const char[] ] a = ["abc":3, "def":4]; } /************************************************/ void test45() { //char[3][] a = ["abc", "def"]; //writefln(a); //char[][2] b = ["abc", "def"]; //writefln(b); } /************************************************/ struct bignum { bool smaller() { if (true) return false; else return false; assert(0); } void equal() { if (!smaller) return; } } void test46() { } /************************************************/ static size_t myfind(string haystack, char needle) { foreach (i, c ; haystack) { if (c == needle) return i; } return size_t.max; } static size_t skip_digits(string s) { foreach (i, c ; s) { if (c < '0' || c > '9') return i; } return s.length; } static uint matoi(string s) { uint result = 0; foreach (c ; s) { if (c < '0' || c > '9') break; result = result * 10 + (c - '0'); } return result; } enum { leading, skip, width, modifier, format, fmt_length, extra }; static string GetFormat(string s) { uint pos = 0; string result; // find the percent sign while (pos < s.length && s[pos] != '%') { ++pos; } const leading_chars = pos; result ~= cast(char) pos; if (pos < s.length) ++pos; // go right after the '%' // skip? if (pos < s.length && s[pos] == '*') { result ~= 1; ++pos; } else { result ~= 0; } // width? result ~= cast(char) matoi(s); pos += skip_digits(s[pos .. $]); // modifier? if (pos < s.length && myfind("hjlLqtz", s[pos]) != size_t.max) { // @@@@@@@@@@@@@@@@@@@@@@@@@@@@ static if (true) { result ~= s[pos++]; } else { result ~= s[pos]; ++pos; } // @@@@@@@@@@@@@@@@@@@@@@@@@@@@ } else { result ~= '\0'; } return result; } void test47() { static string test = GetFormat(" %*Lf"); assert(test[modifier] == 'L', "`" ~ test[modifier] ~ "'"); } /************************************************/ class B48() {} class C48 {} int foo48()(B48!()) { return 1; } int foo48()(C48 c) { return 2; } void test48() { auto i = foo48(new B48!()); assert(i == 1); i = foo48(new C48); assert(i == 2); } /************************************************/ void test49() { struct A { int v; } A a = A(10); version (all) { writefln("Before test 1: ", a.v); if (a == a.init) { writeln(a.v,"(a==a.init)"); assert(0); } else { writeln(a.v,"(a!=a.init)"); assert(a.v == 10); } } else { writefln("Before test 1: ", a.v); if (a == a.init) { writeln(a.v,"(a==a.init)"); assert(a.v == 10); } else { writeln(a.v,"(a!=a.init)"); assert(0); } } a.v = 100; writefln("Before test 2: ", a.v); if (a == a.init) { writeln(a.v,"(a==a.init)"); assert(0); } else { writeln(a.v,"(a!=a.init)"); assert(a.v == 100); } a = A(1000); writefln("Before test 3: ", a.v); if (a == a.init) { writeln(a.v,"(a==a.init)"); assert(0); } else { writeln(a.v,"(a!=a.init)"); assert(a.v == 1000); } version (all) assert(a.init.v == 0); else assert(a.init.v == 10); } /************************************************/ struct S51 { int i = 3; void div() { assert(i == 3); } } void test51() { S51().div(); } /************************************************/ void test52() { struct Foo { alias int Y; } with (Foo) { Y y; } } /************************************************/ struct TestStruct { int dummy0 = 0; int dummy1 = 1; int dummy2 = 2; } void func53(TestStruct[2] testarg) { writeln(testarg[0].dummy0); writeln(testarg[0].dummy1); writeln(testarg[0].dummy2); writeln(testarg[1].dummy0); writeln(testarg[1].dummy1); writeln(testarg[1].dummy2); assert(testarg[0].dummy0 == 0); assert(testarg[0].dummy1 == 1); assert(testarg[0].dummy2 == 2); assert(testarg[1].dummy0 == 0); assert(testarg[1].dummy1 == 1); assert(testarg[1].dummy2 == 2); } TestStruct m53[2]; void test53() { writeln(&m53); func53(m53); } /************************************************/ void test54() { double a = 0; double b = 1; // Internal error: ..\ztc\cg87.c 3233 // a += (1? b: 1+1i)*1i; writeln(a); // assert(a == 0); // Internal error: ..\ztc\cod2.c 1680 // a += (b?1:b-1i)*1i; writeln(a); // assert(a == 0); } /************************************************/ class B55 {} class D55 : B55 {} template foo55(S, T : S) { } // doesn't work alias foo55!(B55, D55) bar55; void test55() { } /************************************************/ template t56() { alias Object t56; } pragma(msg, t56!().stringof); void test56() { } /************************************************/ void test57() { alias long[char[]] AA; static if (is(AA T : T[U], U : const char[])) { writeln(typeid(T)); writeln(typeid(U)); assert(is(T == long)); assert(is(U == const(char)[])); } static if (is(AA A : A[B], B : int)) { assert(0); } static if (is(int[10] W : W[V], int V)) { writeln(typeid(W)); assert(is(W == int)); writeln(V); assert(V == 10); } static if (is(int[10] X : X[Y], int Y : 5)) { assert(0); } } /************************************************/ static this() { printf("one\n"); } static this() { printf("two\n"); } static ~this() { printf("~two\n"); } static ~this() { printf("~one\n"); } void test59() { } /************************************************/ class C60 { extern (C++) int bar60(int i, int j, int k) { printf("this = %p\n", this); printf("i = %d\n", i); printf("j = %d\n", j); printf("k = %d\n", k); assert(i == 4); assert(j == 5); assert(k == 6); return 1; } } extern (C++) int foo60(int i, int j, int k) { printf("i = %d\n", i); printf("j = %d\n", j); printf("k = %d\n", k); assert(i == 1); assert(j == 2); assert(k == 3); return 1; } void test60() { foo60(1, 2, 3); C60 c = new C60(); c.bar60(4, 5, 6); } /***************************************************/ template Foo61(alias a) {} struct Bar61 {} const Bar61 bar61 = {}; alias Foo61!(bar61) baz61; void test61() { } /************************************************/ T foo62(T)(lazy T value) { return value; } void test62() { foo62(new float[1]); } /************************************************/ void main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); test28(); test29(); test30(); test31(); test32(); test33(); test34(); test35(); test36(); test37(); test38(); test39(); test40(); test41(); test42(); test43(); test44(); test45(); test46(); test47(); test48(); test49(); test51(); test52(); test53(); test54(); test55(); test56(); test57(); test59(); test60(); test61(); test62(); writefln("Success"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link14425.d0000644000175000017500000000027513200164642023115 0ustar matthiasmatthiasstruct SFoo(I) { I i; } struct SBar(I) { I i; } static assert(is(SFoo!(SBar!string))); class CFoo(I) { I i; } class CBar(I) { I i; } static assert(is(CFoo!(CBar!string))); void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/foreach.d0000644000175000017500000001240213200164642023162 0ustar matthiasmatthias import core.stdc.stdio; /**************************************************/ void test1() { int i; foreach (char c; "abcd") { switch (i++) { case 0: assert(c == 'a'); break; case 1: assert(c == 'b'); break; case 2: assert(c == 'c'); break; case 3: assert(c == 'd'); break; default: assert(0); } } i = 0; foreach (wchar c; "asdf") { switch (i++) { case 0: assert(c == 'a'); break; case 1: assert(c == 's'); break; case 2: assert(c == 'd'); break; case 3: assert(c == 'f'); break; default: assert(0); } } i = 0; foreach (dchar c; "bncd") { switch (i++) { case 0: assert(c == 'b'); break; case 1: assert(c == 'n'); break; case 2: assert(c == 'c'); break; case 3: assert(c == 'd'); break; default: assert(0); } } } /**************************************************/ void test2() { int i; uint[5] a; a[0] = 16; a[1] = 1; a[2] = 5; a[3] = 8; a[4] = 3; foreach (uint u; a) { switch (i++) { case 0: assert(u == 16); break; case 1: assert(u == 1); break; case 2: assert(u == 5); break; case 3: assert(u == 8); break; case 4: assert(u == 3); break; default: assert(0); } } uint[] b = a; i = 0; foreach (uint u; b) { switch (i++) { case 0: assert(u == 16); break; case 1: assert(u == 1); break; case 2: assert(u == 5); break; case 3: assert(u == 8); break; case 4: assert(u == 3); break; default: assert(0); } } test2_x(a); } void test2_x(uint[5] a) { int i; foreach (uint u; a) { switch (i++) { case 0: assert(u == 16); break; case 1: assert(u == 1); break; case 2: assert(u == 5); break; case 3: assert(u == 8); break; case 4: assert(u == 3); break; default: assert(0); } } } /**************************************************/ void test3() { int i; uint[5] a; a[0] = 16; foreach (ref uint u; a) { i += u; u++; } assert(i == 16); assert(a[0] == 17); assert(a[4] == 1); foreach (uint u; a) { printf("u = %d\n", u); //u++; } assert(a[0] == 17); assert(a[4] == 1); } /**************************************************/ enum E4 { m } struct X4 { char [] b; E4 a; } void test4() { X4 [] x; foreach (X4 w; x) {} } /**************************************************/ class Thing5 {} class Things5 { public: int opApply(int delegate(ref Thing5 thing) dg) { Thing5 thing = new Thing5(); return dg(thing); } } void foo5(Things5 things) { foreach(Thing5 t; things) { } } void test5() { } /**************************************************/ void test6() { static long[3] a = [21,22,23]; long[3] b; int sum; foreach (int i, ref long v; a) { printf("a[%d] = %lld\n", i, v); b[i] = v; } for (uint i = 0; i < 3; i++) { assert(b[i] == 21 + i); } foreach (ref long v; a) { printf("a[] = %lld\n", v); sum += v; } assert(sum == 21 + 22 + 23); } /**************************************************/ void test7() { uint[string] a; a["foo"] = 3; a["bar"] = 4; foreach (string s, uint v; a) { printf("a[%.*s] = %d\n", s.length, s.ptr, v); if (s == "bar") assert(v == 4); else if (s == "foo") assert(v == 3); else assert(0); } } /**************************************************/ class Foo8 { int x, y, z; int opApply(int delegate(ref int a, ref int b, ref int c) dg) { int result = dg(x, y, z); return 0; } } void test8() { Foo8 f = new Foo8(); f.x = 63; f.y = 47; f.z = 83; foreach (int a, ref int b, int c; f) { printf("a = %d, b = %d, c = %d\n", a, b, c); assert(a == 63); assert(b == 47); assert(c == 83); a++; b++; c++; } foreach (int a, ref int b, int c; f) { printf("a = %d, b = %d, c = %d\n", a, b, c); assert(a == 63); assert(b == 48); assert(c == 83); a++; b++; c++; } } /**************************************************/ struct S { int opApply(int delegate(ref int a)) { return 0; } int opApplyReverse(int delegate(ref int a)) { return 0; } int dg(int delegate(ref int a)) { return 0; } } void test9() { S s; foreach(a; s) {} foreach_reverse(a; s) {} foreach(a; &s.dg) {} } /**************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/depsprot.sh0000755000175000017500000000204213200164642023604 0ustar matthiasmatthias#!/usr/bin/env bash name=`basename $0 .sh` dir=${RESULTS_DIR}/runnable dmddir=${RESULTS_DIR}${SEP}runnable output_file=${dir}/${name}.sh.out deps_file="${dmddir}${SEP}${name}.deps" die() { cat ${output_file} echo "---- deps file ----" cat ${deps_file} echo echo "$@" rm -f ${output_file} ${deps_file} exit 1 } rm -f ${output_file} $DMD -m${MODEL} -deps=${deps_file} -Irunnable/imports -o- runnable/extra-files/${name}.d >> ${output_file} test $? -ne 0 && die "Error compiling" grep "^${name}.*${name}_default" ${deps_file} | grep -q private || die "Default import protection in dependency file should be 'private'" grep "^${name}.*${name}_public" ${deps_file} | grep -q public || die "Public import protection in dependency file should be 'public'" grep "^${name}.*${name}_private" ${deps_file} | grep -q private|| die "Private import protection in dependency file should be 'private'" echo "Dependencies file:" >> ${output_file} cat ${deps_file} >> ${output_file} echo >> ${output_file} rm ${deps_file} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/hospital.d0000644000175000017500000001363513200164642023407 0ustar matthiasmatthias// REQUIRED_ARGS: // NOTE: the shootout appears to be BSD licensed content. // Including this in the test suite based on that license. /* The Great Computer Language Shootout http://shootout.alioth.debian.org/ Unoptimised reference implementation contributed by Isaac Gouy */ import std.stdio, std.string, std.conv; import core.memory; int main(string[] args) { //std.gc.setV1_0(); int n = args.length > 1 ? to!int(args[1]) : 1000; HealthcareRegion healthcareSystem = HealthcareRegion.Create(); for(int i = 0; i < n; i++) healthcareSystem.TransferPatients(); Totals t = healthcareSystem.AccumulateTotals(); writeln("Patients: ", t.patients ); writeln("Time: ", t.hospitalTime ); writeln("Visits: ", t.hospitalVisits ); if (n == 1000) { assert(t.patients == 102515); assert(t.hospitalTime == 33730654); assert(t.hospitalVisits == 106371); } return 0; } class HealthcareRegion { public: static HealthcareRegion Create() { return HealthcareRegion.Create(LEVELS, 0, 42); } static HealthcareRegion Create(int level, int seed1, int seed2) { HealthcareRegion r = null; if(level > 0) { r = new HealthcareRegion(level, seed1*seed2); for(ptrdiff_t i = r.districts.length-1; i >= 0; i--) r.districts[i] = Create(level-1, cast(int)((seed1*4)+i+1), seed2); } return r; } this(int level, int s) { districts = new HealthcareRegion[DISTRICTS]; localHospital = new Hospital(level == LEVELS, level, s); } private: enum int LEVELS = 5, DISTRICTS = 4; HealthcareRegion[] districts; Hospital localHospital; package: Patient[] TransferPatients() { for(ptrdiff_t i = districts.length-1; i >= 0; i--) if(districts[i]) foreach(Patient p; districts[i].TransferPatients().dup) localHospital.NewArrival(p); localHospital.TriageExaminationTreatment(); return localHospital.RegionalTransferPatients(); } Totals AccumulateTotals() { Totals t = new Totals(); for(ptrdiff_t i = districts.length-1; i >= 0; i--) if(districts[i]) t += districts[i].AccumulateTotals(); localHospital.AccumulateTotals(t); return t; } } class Hospital { public this(bool hasNoRegionalHospital, int level, int seed) { this.hasNoRegionalHospital = hasNoRegionalHospital; availableStaff = 1 << (level - 1); discharged = new Totals(); this.seed = seed; } package: void TriageExaminationTreatment() { DischargePatients(); TreatOrTransferPatients(); TriagePatients(); if(genRandom(1.0) > 0.7) { Patient p = new Patient(); NewArrival(p); } } Patient[] RegionalTransferPatients() { return transfers; } void AccumulateTotals(Totals t) { foreach(Patient p; triage) t.Plus(p); foreach(Patient p; examination) t.Plus(p); foreach(Patient p; treatment) t.Plus(p); t += discharged; } void NewArrival(Patient p) { p.hospitalVisits++; if(availableStaff > 0) { availableStaff--; examination ~= p; p.remainingTime = 3; p.hospitalTime += 3; } else { triage ~= p; } } private: Patient[] triage, examination, treatment, transfers; Totals discharged; int availableStaff; bool hasNoRegionalHospital; void DischargePatients() { for(ptrdiff_t i = treatment.length-1; i >= 0; i--) { Patient p = treatment[i]; p.remainingTime -= 1; if(!p.remainingTime) { availableStaff++; treatment = treatment[0..i] ~ treatment[i+1..$]; discharged.Plus(p); } } } void TreatOrTransferPatients() { delete transfers; for(ptrdiff_t i = examination.length-1; i >= 0; i--) { Patient p = examination[i]; p.remainingTime -= 1; if(!p.remainingTime) { // no transfer if(genRandom(1.0) > 0.1 || hasNoRegionalHospital) { examination = examination[0..i] ~ examination[i+1..$]; treatment ~= p; p.remainingTime = 10; p.hospitalTime += 10; } else { // transfer availableStaff++; examination = examination[0..i] ~ examination[i+1..$]; transfers ~= p; } } } } void TriagePatients() { for(ptrdiff_t i = triage.length-1; i >= 0; i--) { Patient p = triage[i]; if(availableStaff > 0) { availableStaff--; p.remainingTime = 3; p.hospitalTime += 3; triage = triage[0..i] ~ triage[i+1..$]; examination ~= p; } else { p.hospitalTime++; } } } int seed = 42; const int IM = 139968; const int IA = 3877; const int IC = 29573; double genRandom(double max) { return(max * (seed = (seed * IA + IC) % IM) / IM); } } class Patient { package int remainingTime, hospitalTime, hospitalVisits; } class Totals { public Totals opAddAssign(Totals b) { patients += b.patients; hospitalTime += b.hospitalTime; hospitalVisits += b.hospitalVisits; return this; } package: long patients, hospitalTime, hospitalVisits; void Plus(Patient p) { patients++; hospitalTime += p.hospitalTime; hospitalVisits += p.hospitalVisits; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link12144.d0000644000175000017500000000055013200164642023105 0ustar matthiasmatthias// COMPILE_SEPARATELY: -g // EXTRA_SOURCES: imports/link12144a.d import imports.link12144a; void main() { fun(); } struct A12146 { B12146[] tokens; // implicitly generated // bool opEquals(const ref Appender rhs) const // will make // tokens == rhs.tokens // references TypeInfo of B12146 // and it references __xopCmp } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/sieve.d0000644000175000017500000000145113200164642022670 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: -cov // POST_SCRIPT: runnable/extra-files/sieve-postscript.sh // EXECUTE_ARGS: ${RESULTS_DIR}/runnable /* Eratosthenes Sieve prime number calculation. */ import std.stdio; bool flags[8191]; int sieve() { int count; writefln("10 iterations"); for (int iter = 1; iter <= 10; iter++) { count = 0; flags[] = true; for (int i = 0; i < flags.length; i++) { if (flags[i]) { int prime = i + i + 3; int k = i + prime; while (k < flags.length) { flags[k] = false; k += prime; } count += 1; } } } writefln("%d primes", count); return 0; } extern(C) void dmd_coverDestPath(string path); int main(string[] args) { dmd_coverDestPath(args[1]); sieve(); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_328.d0000644000175000017500000000023313200164642024252 0ustar matthiasmatthiasvoid bar() { scope(exit) { } throw new Exception("Enforcement failed"); } void main() { try bar(); catch (Exception) {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_246.d0000644000175000017500000000025613200164642024256 0ustar matthiasmatthiasstruct Foo { this(int a) { val = a; } int val; } void main() { auto a = cast(void*)(new Foo(1)); auto b = cast(Foo*)a; assert(b.val == 1); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test12.d0000644000175000017500000004344713200164642022712 0ustar matthiasmatthias extern(C) int printf(const char*, ...); extern(C) int sprintf(char*, const char*, ...); /**************************************/ void test1() { bool x; int i; i = !("bar" == "bar"); assert(i == 0); i = "bar" != "bar"; assert(i == 0); i = "bar" == "bar"; assert(i == 1); x = "bar" != "bar"; assert(x == false); assert("bar" == "bar"); x = "bar" == "bar"; assert(x == true); /+ ---- +/ i = !("foo" == "bar"); assert(i == 1); i = "foo" != "bar"; assert(i == 1); i = "foo" == "bar"; assert(i == 0); x = "foo" != "bar"; assert(x == true); assert("foo" != "bar"); x = "foo" == "bar"; assert(x == false); } /**************************************/ void test2() { bool x; int i; i = !("bar" <= "bar"); assert(i <= 0); i = "bar" > "bar"; assert(i == 0); i = "bar" >= "bar"; assert(i == 1); x = "bar" < "bar"; assert(x == false); assert("bar" <= "bar"); x = "bar" <= "bar"; assert(x == true); /+ ---- +/ i = !("foo" < "bar"); assert(i == 1); i = "foo" > "bar"; assert(i == 1); i = "foo" < "bar"; assert(i == 0); x = "foo" >= "bar"; assert(x == true); assert("foo" >= "bar"); x = "foo" <= "bar"; assert(x == false); } /**************************************/ bool all(string array, bool function(char) predicate) { for (int i = 0; i < array.length; i++) { if (!predicate(array[i])) { return false; } } return true; } bool all(string array, bool delegate(char) predicate) { for (int i = 0; i < array.length; i++) { if (!predicate(array[i])) { return false; } } return true; } bool isVowel(char c) { return (c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u'); } class Character { private char letter; this(char c) { this.letter = c; } public bool isLetter(char c) { return this.letter == c; } } void test3() { Character a = new Character('a'); bool delegate(char) isLetter; isLetter = &a.isLetter; bool i; i = all("aeiouoeieuiei", &isVowel); assert(i == true); i = all("aeiouoeieuiei", isLetter); assert(i == false); } /**************************************/ int[] fun(int i) in { assert(i > 0); } out (result) { assert(result[0] == 2); } body { char result; int[] res = new int[10]; res[] = i; int isZero = (result == 0xFF); assert(isZero); return res; } void test4() { int[] values = fun(2); } /**************************************/ const uint D3DSP_DSTMOD_SHIFT = 20; const uint D3DSP_DSTMOD_MASK = 0x00F00000; enum D3DSHADER_PARAM_DSTMOD_TYPE { NONE = 0<= 0) || (x < 0)); } struct X21 { float f, g, h; } X21 x21_1; X21 x21_2 = { f: 1.0, h: 2.0 }; char[3] y21_1; char[3] y21_2 = [ 0: 'a', 2: 'b' ]; void test21() { assert(isnan(x21_1.g)); assert(isnan(x21_2.g)); assert(y21_1[1] == '\xff'); assert(y21_2[1] == '\xff'); } /**************************************/ void test22() { wstring a = cast(wstring)"一〇"; } /**************************************/ interface A23 { void x(); } class B23 : A23 { void x() { } } class C23 : B23 { uint y = 12345678; } void stest23(A23 a) { synchronized (a) { } } void test23() { C23 c = new C23; assert(c.y == 12345678 /*c.y.init*/); stest23(c); assert(c.y == 12345678 /*c.y.init*/); } /**************************************/ class A24 { unittest { } } void test24() { } /**************************************/ char rot13(char ret) { if (ret > 'A'-1 && ret < 'N') { ret += 13;} else if(ret > 'M' && ret < 'Z'+1) { ret -= 13;} else if(ret > 'a'-1 && ret < 'n') { ret += 13;} else if(ret > 'm' && ret < 'z'+1) { ret -= 13;} return ret; } void test25() { foreach (char c; "hello World\n") printf("%c %c\n", c, rot13(c)); assert(rot13('h') == 'u'); assert(rot13('o') == 'b'); assert(rot13('W') == 'J'); assert(rot13('H') == 'U'); } /**************************************/ bool b26a = cast(bool)( cast(bool) 2 & cast(bool) 1 ); bool b26b = cast(bool) 2; void test26() { assert( (* cast(byte *) & b26a) == 1 ); assert( (* cast(byte *) & b26b) == 1 ); } /**************************************/ int c27; struct X27 { int x; struct { int a; int b; static this() { c27 = 3; } } } void test27() { assert(c27 == 3); } /**************************************/ void test28() { void bar() { throw new Foo28(); } } class Foo28 : Throwable { private: this() { super(""); } } /**************************************/ struct S29 { ubyte a, b, c, d; } int hoge(S29 s) { char[10] b; printf("%x\n", s); sprintf(b.ptr, "%x", s); assert(b[0 .. 7] == "4030201"); return 0; } void test29() { for (int i = 0; i < 1; i++) { S29 s; s.a = 1; s.b = 2; s.c = 3; s.d = 4; hoge(s); } } /**************************************/ class Qwert { static { deprecated int yuiop() { return 42; } } static deprecated int asdfg() { return yuiop() + 105; } } void test30() { } /**************************************/ void test31() { string foo = "hello"; printf("%s\n", foo.ptr); auto s = typeid(typeof(foo.ptr)).toString(); printf("%.*s\n", s.length, s.ptr); s = typeid(char*).toString(); printf("%.*s\n", s.length, s.ptr); assert(typeid(typeof(foo.ptr)) == typeid(immutable(char)*)); } /**************************************/ class Qwert32 { struct { int yuiop = 13; } int asdfg = 42; void foo() { printf("yuiop = %d, asdfg = %d\n", Qwert32.yuiop.offsetof, Qwert32.asdfg.offsetof); version(D_LP64) { assert(Qwert32.yuiop.offsetof == 16); assert(Qwert32.asdfg.offsetof == 20); } else { assert(Qwert32.yuiop.offsetof == 8); assert(Qwert32.asdfg.offsetof == 12); } } } void test32() { Qwert32 q = new Qwert32; q.foo(); } /**************************************/ int x33; int y33; size_t os_query() { return cast(uint)(cast(char *)&x33 - cast(char *)&y33); } void test33() { os_query(); } /**************************************/ uint x34 = ~(16u-1u); uint y34 = ~(16u-1); void test34() { assert(x34 == 0xFFFFFFF0); assert(y34 == 0xFFFFFFF0); } /**************************************/ private static extern (C) { shared char* function () uloc_getDefault; } static shared void**[] targets = [ cast(shared(void*)*) &uloc_getDefault, ]; void test35() { } /**************************************/ class S36 { int s = 1; this() { } } class A36 : S36 { int a = 2; int b = 3; int c = 4; int d = 5; } void test36() { A36 a = new A36; printf("A36.sizeof = %d\n", a.classinfo.init.length); printf("%d\n", a.s); printf("%d\n", a.a); printf("%d\n", a.b); printf("%d\n", a.c); printf("%d\n", a.d); version(D_LP64) assert(a.classinfo.init.length == 36); else assert(a.classinfo.init.length == 28); assert(a.s == 1); assert(a.a == 2); assert(a.b == 3); assert(a.c == 4); assert(a.d == 5); } /**************************************/ struct MyStruct { StructAlias* MyStruct() { return null; } } alias MyStruct StructAlias; void test37() { } /**************************************/ class Foo38 { static void display_name() { printf("%.*s\n", Object.classinfo.name.length, Object.classinfo.name.ptr); assert(Object.classinfo.name == "object.Object"); assert(super.classinfo.name == "object.Object"); assert(this.classinfo.name == "test12.Foo38"); } } void test38() { Foo38.display_name(); } /**************************************/ // http://www.digitalmars.com/d/archives/digitalmars/D/bugs/2409.html class C39 { C39 c; this() { c = this; } C39 lock() { return c; } } void test39() { C39 c = new C39(); synchronized( c.lock() ) {} synchronized( c.lock ) {} } /**************************************/ class C40 { static int x = 4; static int foo() { return this.x; } } void test40() { C40 c = new C40(); assert(C40.foo() == 4); } /**************************************/ struct Foo42 { Bar42 b; } struct Bar42 { long a; } void test42() { assert(Bar42.sizeof == long.sizeof); assert(Foo42.sizeof == long.sizeof); } /**************************************/ class Foo43 { Bar43 b; } struct Bar43 { long a; } void test43() { assert(Bar43.sizeof == long.sizeof); assert(Foo43.sizeof == (void*).sizeof); } /**************************************/ struct Property { uint attributes; Value value; } struct Value { int a,b,c,d; } struct PropTable { Property[Value] table; PropTable* previous; Value* get(Value* key) { Property *p; p = *key in table; p = &table[*key]; table.remove(*key); return null; } } void test44() { } /**************************************/ import std.algorithm; struct Shell { string str; const int opCmp(ref const Shell s) { return std.algorithm.cmp(this.str, s.str); } } void test45() { Shell[3] a; a[0].str = "hello"; a[1].str = "betty"; a[2].str = "fred"; a.sort; foreach (Shell s; a) { printf("%.*s\n", s.str.length, s.str.ptr); } assert(a[0].str == "betty"); assert(a[1].str == "fred"); assert(a[2].str == "hello"); } /**************************************/ class A46 { char foo() { return 'a'; } } class B46 : A46 { } class C46 : B46 { override char foo() { return 'c'; } char bar() { return B46.foo(); } } void test46() { C46 c = new C46(); assert(c.bar() == 'a'); printf("%c\n", c.bar()); } /**************************************/ class Foo47 { static bool prop() { return false; } static string charprop() { return null; } } void test47() { if (0 || Foo47.prop) { } if (1 && Foo47.prop) { } switch (Foo47.prop) { default: break; } foreach (char ch; Foo47.charprop) { } } /**************************************/ struct foo48 { int x, y, z; } void bar48() {} void test48() { foo48[] arr; foreach(foo48 a; arr) { bar48(); } } /**************************************/ enum E49; void test49() { } /**************************************/ void test50() { S50!() s; assert(s.i == int.sizeof); } struct S50() { int i=f50(0).sizeof; } int f50(...); /**************************************/ enum Enum51 { A, B, C } struct Struct51 { Enum51 e; } void test51() { Struct51 s; assert(s.e == Enum51.A); assert(s.e == 0); } /**************************************/ bool foo52() { int x; for (;;) { if (x == 0) return true; x = 1; } return false; } void test52() { foo52(); } /**************************************/ void foo53() { ret:{} goto ret; } void test53() { } /**************************************/ struct V54 { int x = 3; } class Foo54 { static int y; static V54 prop() { V54 val; return val; } static void prop(V54 val) { y = val.x * 2; } } void test54() { (new Foo54).prop = true ? Foo54.prop : Foo54.prop; assert(Foo54.y == 6); } /**************************************/ void test55() { dchar c; c = 'x'; //writefln("c = '%s', c.init = '%s'", c, c.init); assert(c == 'x'); assert(c.init == dchar.init); } /**************************************/ void writefln(string s) { printf("%.*s\n", s.length, s.ptr); } void test56() { string a = "abcd"; string r; r = a.dup.reverse.idup; writefln(r); assert(r == "dcba"); a = "a\u1235\u1234c"; writefln(a); r = a.dup.reverse.idup; writefln(r); assert(r == "c\u1234\u1235a"); a = "ab\u1234c"; writefln(a); r = a.dup.reverse.idup; writefln(r); assert(r == "c\u1234ba"); } /**************************************/ // DMD 0.114: Fixed .reverse bug of char[] and wchar[] with multibyte encodings. void test57() { wstring a = "abcd"; wchar[] r; r = a.dup.reverse; assert(r == "dcba"); a = "a\U00012356\U00012346c"; r = a.dup.reverse; assert(r == "c\U00012346\U00012356a"); a = "ab\U00012345c"; r = a.dup.reverse; assert(r == "c\U00012345ba"); } /**************************************/ void test58() { int label=1; if (0) { label: int label2=2; assert(label2==2); } else { assert(label==1); goto label; } assert(label==1); } /**************************************/ void test59() { if(0){ label: return; }else{ goto label; } assert(0); } /**************************************/ int main(string[] argv) { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); test28(); test29(); test30(); test31(); test32(); test33(); test34(); test35(); test36(); test37(); test38(); test39(); test40(); test42(); test43(); test44(); test45(); test46(); test47(); test48(); test49(); test50(); test51(); test52(); test53(); test54(); test55(); test56(); test57(); test58(); test59(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test13504.d0000644000175000017500000000016613200164642023133 0ustar matthiasmatthias// REQUIRED_ARGS: -O -cov bool func(T)() { return true; } void main() { assert(func!int() || int.sizeof); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/linktypeinfo.d0000644000175000017500000000076413200164642024276 0ustar matthiasmatthias// EXTRA_SOURCES: imports/linktypeinfo_file.d // PERMUTE_ARGS: -g -inline -unittest -debug // COMPILE_SEPARATELY import imports.linktypeinfo_file; struct Only(T) { private T _val; } auto only(V)(V v) { return Only!V(v); } static struct Chain(R...) { R source; } auto chain(R...)(R rs) { return Chain!R(rs); } void main() { string docRoot; const r = dirEntries(docRoot); typeof(r)[] a; a.length = 0; // require TypeInfo for const(FilterResult!(DirIterator)) } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test57.d0000644000175000017500000000027113200164642022707 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test57a.d imports/test57b.d // PERMUTE_ARGS: // REQUIRED_ARGS: -inline -release module test57; import imports.test57a; void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test8182.d0000644000175000017500000000016713200164642023062 0ustar matthiasmatthiasstruct S { ~this() { assert(false); } } void lazily(lazy S) { } void main() { lazily(S()); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ifti.d0000644000175000017500000000516513200164642022516 0ustar matthiasmatthiasimport std.stdio; struct S { int x = 3; void fun(T)(T x) { writefln("S.fun(%s)(%s)",typeid(T),x); this.x += x; } } class Tst(TST, int v = 2) { int x = 3; int z = 4; final private void proc(int x) { writefln("proc(%s) -> %s",x,this.x); } void fun(T)(T x) { writefln("fun(%s)(%s) -> %s",typeid(T),x,this.x);} void fun()() { writefln("fun()() -> %s",this.x); } void fun2()() { writefln("fun2"); } class Inner { int y = 99; Tst outer; void f3() { z = 55; } // Make sure the correct this-ptr is used void f1() { writefln("Inner.f1"); proc(-11); outer.proc(-11); } void f2() { writefln("Inner.f2"); fun(-17); outer.fun(-17); } } Inner inner; this() { inner = new Inner; inner.outer = this; } void callInnerf1() { writefln("callInnerf1"); inner.f1(); } void callInnerf2() { writefln("callInnerf2"); inner.f2(); } // void opAdd(T)(T x) { this.x += x; writefln("opAdd(%s)",x); } void opPos()() { writefln("opPos()"); } //void opPos() { writefln("xxx"); } void opIndex(T)(T x) { writefln("opIndex[%s]",x); } void opIndex(A,B,C)(A a, B b, C c) { writefln("opIndex[(%s)%s,(%s)%s,(%s)%s]",typeid(A),a, typeid(B),b,typeid(C),c); } static if (v > 1) { void opCall(A = int, B = float)(A a = 1, B b = 8.2) { writefln("opCall(%s,%s)",a,b); this.x++; } } void opSlice(A,B)(A a, B b) { writefln("opSlice(%s,%s)",a,b); } void opSlice()() { writefln("opSlice()"); } void opIndexAssign(A,B)(A a, B b) { writefln("opIndexAssign((%s)%s,(%s)%s)",typeid(A),a,typeid(B),b); } void opSliceAssign(A,B,C)(A a, B b, C c) { writefln("opSliceAssign(%s,%s,%s)",a,b,c); } bool opEquals(A)(A x) { writefln("opEquals((%s))",typeid(A));return true; } int opApply(T)(int delegate(ref T)dg) { for (int i = 0; i < 5; i++) { T d = cast(T)(i+0.1); if (auto result = dg(d)) return result; } return 0; } } class Y : Tst!(float) {} void main() { Tst!(int) t = new Tst!(int); Y u = new Y; S s; t.x = 7; t.proc(5); t.fun(5); t.fun(); t.callInnerf1(); t.callInnerf2(); u.fun(5); u.fun(); u.callInnerf1(); u.callInnerf2(); s.fun(5); t.fun2(); +t; t+5; t[55]; t[1,2,3.0]; u[1,2,3.0]; t(1,2.5); t(2); t(); t[]; t[1..2]; u[1..2.5]; t[1i] = 5; t[-4.5..7i] = "hello"; t == t; auto b = t != t; // without assignment -> "! has no effect in expression" t == u; u == t; u == u; b = u != u; foreach(int i;t) { writefln("%s",i); } foreach(double i;t) { writefln("%s",i); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/mixin1.d0000644000175000017500000005174713200164642022777 0ustar matthiasmatthias module mixin1; import std.stdio; alias TypeTuple(T...) = T; /*******************************************/ mixin template Foo(T) { T x; } mixin Foo!(uint); struct Bar { template Abc(T) { T y; } template Def(T) { T z; } } mixin Bar.Abc!(int); Bar b; mixin typeof(b).Def!(int); void test1() { x = 3; assert(x == 3); y = 4; assert(y == 4); z = 5; assert(z == 5); } /*******************************************/ template Foo2(T) { T x2 = T.sizeof; } mixin Foo2!(uint) B2; mixin Foo2!(long) C2; mixin Foo2!(int); void test2() { B2.x2 = 3; assert(B2.x2 == 3); assert(C2.x2 == long.sizeof); // assert(x2 == int.sizeof); } /*******************************************/ template Foo3(T) { int func() { printf("Foo3.func()\n"); return 1; } } class Bar3 { mixin Foo3!(int); } class Code3 : Bar3 { override int func() { printf("Code3.func()\n"); return 2; } } void test3() { int i; Bar3 b = new Bar3(); i = b.func(); assert(i == 1); b = new Code3(); i = b.func(); assert(i == 2); } /*******************************************/ template Foo4(T) { int func() { printf("Foo4.func()\n"); return 1; } } struct Bar4 { mixin Foo4!(int); } void test4() { int i; Bar4 b; i = b.func(); assert(i == 1); } /*******************************************/ template Foo5() { int func() { printf("Foo5.func()\n"); return 1; } } struct Bar5 { mixin Foo5; } void test5() { int i; Bar5 b; i = b.func(); assert(i == 1); } /*******************************************/ template Foo6() { int x = 5; } struct Bar6 { mixin Foo6; } void test6() { int i; Bar6 b; i = b.x; assert(i == 5); assert(b.sizeof == int.sizeof); } /*******************************************/ template Foo7() { int x = 5; } class Bar7 { int y = 6; mixin Foo7; } void test7() { int i; Bar7 b = new Bar7(); i = b.x; printf("b.x = %d\n", b.x); assert(i == 5); } /*******************************************/ template Foo8() { int x = 5; int bar() { return 7; } } void test8() { mixin Foo8; printf("x = %d\n", x); assert(x == 5); assert(bar() == 7); } /*******************************************/ template Foo9() { int abc() { return y; } } void test9() { int y = 8; mixin Foo9; assert(abc() == 8); } /*******************************************/ template Foo10(alias b) { typeof(b) abc() { return b; } } void test10() { int y = 8; mixin Foo10!(y); assert(abc() == 8); } /*******************************************/ template Foo11(alias b) { int abc() { return b; } } void test11() { int y = 8; mixin Foo11!(y) B; assert(B.abc() == 8); } /*******************************************/ template duff_for(alias id1, alias id2, alias s) { void duff_for() { printf("duff_for(%d, %d)\n", id1, id2); typeof(id1) id = id1; printf("fid = %d, %d\n", id, (id2 - id) % 8); switch ((id2 - id) % 8) { case 0: while (id != id2) { printf("wid = %d\n", id); s(); ++id; goto case; case 7: s(); ++id; goto case; case 6: s(); ++id; goto case; case 5: s(); ++id; goto case; case 4: s(); ++id; goto case; case 3: s(); ++id; goto case; case 2: s(); ++id; goto case; case 1: s(); ++id; break; default: assert(0); } } } } void foo12() { printf("foo12\n"); } void test12() { int i = 1; int j = 11; mixin duff_for!(i, j, delegate void() { foo12(); }); duff_for(); } /*******************************************/ template duff(alias id1, alias id2, alias s) { void duff() { s(); s(); } } void foo13(int j) { printf("foo13 j = %d\n", j); assert(j == 1); } void test13() { int i = 1; int j = 11; mixin duff!(i, j, delegate { foo13(i); }); duff(); } /*******************************************/ template Foo14() { int x14 = 5; } void test14() { int x14 = 6; mixin Foo14; printf("x14 = %d\n", x14); assert(x14 == 6); } /*******************************************/ template Foo15() { int x15 = 5; int bar15() { return x15; } } int x15 = 6; mixin Foo15; void test15() { printf("x15 = %d\n", x15); printf("bar15() = %d\n", bar15()); assert(x15 == 6); assert(bar15() == 5); } /*******************************************/ template Foo16() { int x16 = 5; int bar() { return x16; } } mixin Foo16 A16; int x16 = 6; mixin Foo16 B16; void test16() { printf("x16 = %d\n", x16); printf("bar() = %d\n", A16.bar()); assert(x16 == 6); assert(A16.x16 == 5); assert(B16.x16 == 5); assert(A16.bar() == 5); assert(B16.bar() == 5); } /*******************************************/ template Foo17() { int x17 = 5; } mixin Foo17; struct Bar17 { mixin Foo17; } void test17() { printf("x17 = %d\n", x17); // prints 5 assert(x17 == 5); { Bar17 b; int x17 = 3; printf("b.x17 = %d\n", b.x17); // prints 5 assert(b.x17 == 5); printf("x17 = %d\n", x17); // prints 3 assert(x17 == 3); { mixin Foo17; printf("x17 = %d\n", x17); // prints 5 assert(x17 == 5); x17 = 4; printf("x17 = %d\n", x17); // prints 4 assert(x17 == 4); } printf("x17 = %d\n", x17); // prints 3 assert(x17 == 3); } printf("x17 = %d\n", x17); // prints 5 assert(x17 == 5); } /*******************************************/ template Foo18() { int z = 3; } struct Bar18(alias Tmpl) { mixin Tmpl; } Bar18!(Foo18) b18; void test18() { assert(b18.z == 3); } /*******************************************/ template Mix1(T) { int foo19(T a) { return 2*a; } } template Mix2(T) { mixin Mix1!(T); int bar19(T a) { return foo19(a); } } mixin Mix2!(int); void test19() { int i; i = bar19(7); assert(i == 14); } /*******************************************/ interface A20 { int f(); } template Foo20() { int f() { printf("in C20.f()\n"); return 6; } } class C20 : A20 { mixin Foo20; // void f() { printf("in C20.f()\n"); } } void test20() { C20 c = new C20(); int i = c.f(); assert(i == 6); } /*******************************************/ template Mix21() { this(int x) { printf("mix1\n"); }} class Bar21 { int myx; mixin Mix21; // wouldn't compile this() { myx = 15; } // mixin Mix21; // placing it here compiles } void test21() { Bar21 bar = new Bar21(); } /*******************************************/ template A22(T) { this() { int i; i = super.foo(); assert(i == 67); } } class B22 { int foo() { printf("B22.foo()\n"); return 67; } } class C22 : B22 { mixin A22!(C22); } void test22() { C22 c = new C22; } /*******************************************/ template Foo23() { const int x = 5; } class C23 { mixin Foo23 F; } struct D23 { mixin Foo23 F; } void test23() { C23 c = new C23; printf("%d\n",c.F.x); assert(c.F.x == 5); D23 d; printf("%d\n",d.F.x); assert(d.F.x == 5); } /*******************************************/ template T24() { void foo24() { return cast(void)0; } // alias foo24 foo24; } mixin T24; void test24() { foo24(); } /*******************************************/ template ctor25() { this() { this(null); } this( Object o ) {} } class Foo25 { mixin ctor25; } void test25() { Foo25 foo = new Foo25(); } /*******************************************/ template Get26(T) { Reader get (ref T x) { return this; } } class Reader { mixin Get26!(byte) bar; alias bar.get get; mixin Get26!(int) beq; alias beq.get get; } void test26() { Reader r = new Reader; Reader s; byte q; s = r.get (q); assert(s == r); } /*******************************************/ template Template(int L) { int i = L; int foo(int b = Template!(9).i) { return b; } } void test27() { int i = 10; int foo(int b = Template!(9).i) { return b; } assert(foo()==9); } /*******************************************/ template Blah28(int a, alias B) { mixin Blah28!(a-1, B); //mixin Blah28!(0, B); } template Blah28(int a:0, alias B) { } void test28() { int a; mixin Blah28!(5,a); printf("a = %d\n", a); } /*******************************************/ template T29() { int x; } struct S29 { mixin T29; int y; } const S29 s29 = { x:2, y:3 }; void test29() { assert(s29.x == 2); assert(s29.y == 3); } /*******************************************/ class A30 { template ctor(Type) { this(Type[] arr) { foreach(Type v; arr) writeln(typeid(typeof(v))); } } mixin ctor!(int); } void test30() { static int[] ints = [0,1,2,3]; A30 a = new A30(ints); } /*******************************************/ template Share(T) { const bool opEquals(ref const T x) { return true; } } struct List31(T) { //int opEquals(List31 x) { return 0; } mixin Share!(List31); } void test31() { List31!(int) x; List31!(int) y; int i = x == y; assert(i == 1); } /*******************************************/ template Blah(int a, alias B) { mixin Blah!(a-1, B); } template Blah(int a:0, alias B) { int foo() { return B + 1; } } void test32() { int a = 3; mixin Blah!(5,a); assert(foo() == 4); } /*******************************************/ template T33( int i ) { int foo() { printf("foo %d\n", i ); return i; } int opCall() { printf("opCall %d\n", i ); return i; } } class C33 { mixin T33!( 1 ) t1; mixin T33!( 2 ) t2; } void test33() { int i; C33 c1 = new C33; i = c1.t1.foo(); assert(i == 1); i = c1.t2.foo(); assert(i == 2); i = c1.t1(); assert(i == 1); i = c1.t2(); assert(i == 2); } /*******************************************/ template mix34() { int i; void print() { printf( "%d %d\n", i, j ); assert(i == 0); assert(j == 0); } } void test34() { int j; mixin mix34!(); print(); //printf( "%i\n", i ); } /*******************************************/ mixin T35!(int) m35; template T35(t) { t a; } void test35() { m35.a = 3; } /*******************************************/ struct Foo36 { int a; mixin T!(int) m; template T(t) { t b; } int c; } void test36() { Foo36 f; printf("f.sizeof = %d\n", f.sizeof); assert(f.sizeof == 12); f.a = 1; f.m.b = 2; f.c = 3; assert(f.a == 1); assert(f.m.b == 2); assert(f.c == 3); } /*******************************************/ template Foo37() { template func() { int func() { return 6; } } } class Baz37 { mixin Foo37 bar; } void test37() { Baz37 b = new Baz37; auto i = b.bar.func!()(); assert(i == 6); i = (new Baz37).bar.func!()(); assert(i == 6); } /*******************************************/ template Foo38() { int a = 4; ~this() { printf("one\n"); assert(a == 4); assert(b == 5); c++; } } class Outer38 { int b = 5; static int c; mixin Foo38!() bar; mixin Foo38!() abc; ~this() { printf("two\n"); assert(b == 5); assert(c == 0); c++; } } void test38() { Outer38 o = new Outer38(); delete o; assert(Outer38.c == 3); } /*******************************************/ template TDtor() { ~this() { printf("Mixed-in dtor\n"); } } class Base39 { ~this() { printf("Base39 dtor\n"); } } class Class39 : Base39 { mixin TDtor A; mixin TDtor B; ~this() { printf("Class39 dtor\n"); } } void test39() { auto test = new Class39; } /*******************************************/ template Mix40() { int i; } struct Z40 { union { mixin Mix40; } } void test40() { Z40 z; z.i = 3; } /*******************************************/ class X41(P...) { alias P[0] Q; mixin Q!(); } template MYP() { void foo() { } } void test41() { X41!(MYP) x; } /*******************************************/ // 2245 template TCALL2245a(ARGS...) { int makecall(ARGS args) { return args.length; } } template TCALL2245b(int n) { int makecall2(ARGS...)(ARGS args) if (ARGS.length == n) { return args.length; } } class C2245 { mixin TCALL2245a!(); mixin TCALL2245a!(int); mixin TCALL2245a!(int,int); mixin TCALL2245b!(0); mixin TCALL2245b!(1); mixin TCALL2245b!(2); } struct S2245 { mixin TCALL2245a!(); mixin TCALL2245a!(int); mixin TCALL2245a!(int,int); mixin TCALL2245b!(0); mixin TCALL2245b!(1); mixin TCALL2245b!(2); } void test2245() { auto c = new C2245; assert(c.makecall() == 0); assert(c.makecall(0) == 1); assert(c.makecall(0,1) == 2); assert(c.makecall2() == 0); assert(c.makecall2(0) == 1); assert(c.makecall2(0,1) == 2); assert(c.makecall2!()() == 0); assert(c.makecall2!(int)(0) == 1); assert(c.makecall2!(int, int)(0,1) == 2); auto s = S2245(); assert(s.makecall() == 0); assert(s.makecall(0) == 1); assert(s.makecall(0,1) == 2); assert(s.makecall2() == 0); assert(s.makecall2(0) == 1); assert(s.makecall2(0,1) == 2); assert(s.makecall2!()() == 0); assert(s.makecall2!(int)(0) == 1); assert(s.makecall2!(int, int)(0,1) == 2); } /*******************************************/ // 2481 template M2481() { int i; } class Z2481a { struct { mixin M2481!(); } } class Z2481b { struct { int i; } } void test2481() { Z2481a z1; Z2481b z2; static assert(z1.i.offsetof == z2.i.offsetof); } /*******************************************/ // 2740 interface IFooable2740 { bool foo(); } abstract class CFooable2740 { bool foo(); } mixin template MFoo2740() { override bool foo() { return true; } } class Foo2740i1 : IFooable2740 { override bool foo() { return false; } mixin MFoo2740; } class Foo2740i2 : IFooable2740 { mixin MFoo2740; override bool foo() { return false; } } class Foo2740c1 : CFooable2740 { override bool foo() { return false; } mixin MFoo2740; } class Foo2740c2 : CFooable2740 { mixin MFoo2740; override bool foo() { return false; } } void test2740() { { auto p = new Foo2740i1(); IFooable2740 i = p; assert(p.foo() == false); assert(i.foo() == false); } { auto p = new Foo2740i2(); IFooable2740 i = p; assert(p.foo() == false); assert(i.foo() == false); } { auto p = new Foo2740c1(); CFooable2740 i = p; assert(p.foo() == false); assert(i.foo() == false); } { auto p = new Foo2740c2(); CFooable2740 i = p; assert(p.foo() == false); assert(i.foo() == false); } } /*******************************************/ mixin template MTestFoo() { int foo(){ return 2; } } class TestFoo { mixin MTestFoo!() test; int foo(){ return 1; } } void test42() { auto p = new TestFoo(); assert(p.foo() == 1); assert(p.test.foo() == 2); } /*******************************************/ // 7744 class ZeroOrMore7744(Expr) { enum name = "ZeroOrMore7744!("~Expr.name~")"; } class Range7744(char begin, char end) { enum name = "Range7744!("~begin~","~end~")"; } mixin(q{ class RubySource7744 : ZeroOrMore7744!(DecLiteral7744) { } class DecLiteral7744 : Range7744!('0','9') { } }); /*******************************************/ // 8032 mixin template T8032() { void f() { } } class A8032a { mixin T8032; // Named mixin causes the error too void f() { } } class B8032a : A8032a { override void f() { } } class A8032b { void f() { } mixin T8032; // Named mixin causes the error too } class B8032b : A8032b { override void f() { } } /*********************************************/ // 9417 mixin template Foo9417() { void foo() {} } void test9417() { struct B { mixin Foo9417; } } /*******************************************/ // 11487 template X11487() { struct R() { C11487 c; ~this() { static assert(is(typeof(c.front) == void)); } } template Mix(alias R) { R!() range; @property front() inout {} } } class C11487 { alias X11487!() M; mixin M.Mix!(M.R); } /*******************************************/ // 11767 mixin template M11767() { struct S11767 {} } mixin M11767!(); mixin M11767!(); // OK static assert(!__traits(compiles, S11767)); void test11767() { mixin M11767!(); alias S1 = S11767; { mixin M11767!(); alias S2 = S11767; static assert(!is(S1 == S2)); static assert(S1.mangleof == "S6mixin19test11767FZ8__mixin16S11767"); static assert(S2.mangleof == "S6mixin19test11767FZ8__mixin26S11767"); } mixin M11767!(); static assert(!__traits(compiles, S11767)); } /*******************************************/ // 12023 void Delete12023(Object obj) {} template MessageCode12023() { alias typeof(this) C; struct MessageDeinitHelper { C m_outer; ~this() { m_outer.DoDeinitMessaging(); } } CToClient toClient = null; TypeTuple!(CToClient) toClients; class CToClient {} void DoDeinitMessaging() { Delete12023(toClient); Delete12023(toClients); } } class TurretCannon12023(ProjectileClass) { mixin MessageCode12023; } void test12023() { auto tc = new TurretCannon12023!Object(); } /*******************************************/ // 14243 mixin template Mix14243a(int n) { static assert(n > 0); import core.stdc.stdio; enum { enumMember = 1 } auto a = A14243(n); } mixin template Mix14243b(int n) { static if (n > 0) { auto b = A14243(n); } } template foo14243(alias v) { auto bar() { return &v; } } mixin template Mix14243c(alias v) { // instantiate template in TemplateMixin auto c = foo14243!v.bar(); } mixin template Mix14243d(int n) { // Type declaration in TemplateMixin struct NS { int x = n; } mixin("auto d" ~ ('0' + n) ~ " = NS();"); } mixin template Mix14243e(int n) { @safe: nothrow: int foo() { return var; } static: struct S { int x; void f() {} } int bar() { return n; } } int test14243() { int[] ctor; int[] dtor; struct A14243 { int x; this(int x) { ctor ~= x; this.x = x; } ~this() { dtor ~= x; } } { /**/ assert(ctor == [] && dtor == []); mixin Mix14243a!(1); assert(ctor == [1] && dtor == []); mixin Mix14243b!(12) b1; assert(ctor == [1,12] && dtor == []); mixin Mix14243b!(24) b2; assert(ctor == [1,12,24] && dtor == []); assert(a.x == 1); static assert(!__traits(compiles, b > 0)); // ambiguous symbol access assert(b1.b.x == 12); assert(b2.b.x == 24); int x; mixin Mix14243c!(x); assert(c == &x); mixin Mix14243d!(1); mixin Mix14243d!(2); static assert(!is(typeof(d1) == typeof(d2))); assert(d1.x == 1); assert(d2.x == 2); assert(ctor == [1,12,24] && dtor == []); } assert(ctor == [1,12,24] && dtor == [24,12,1]); { int var = 1; mixin Mix14243e!12; static assert(is(typeof(&foo) == int delegate() @safe nothrow)); static assert(is(typeof(&bar) == int function() @safe nothrow)); static assert(S.sizeof == int.sizeof); // s is static struct assert(foo() == 1); assert(bar() == 12); } return 1; } static assert(test14243()); // changed to be workable /*******************************************/ // 10492 class TestClass10492 {} mixin template mix10492(string name) { mixin("scope " ~ name ~ " = new TestClass10492;" ); } void test10492() { mixin mix10492!("var"); } /*******************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); test28(); test29(); test30(); test31(); test32(); test33(); test34(); test35(); test36(); test37(); test38(); test39(); test40(); test41(); test2245(); test2740(); test42(); test9417(); test11767(); test12023(); test14243(); test10492(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test7511.d0000644000175000017500000002012113200164642023045 0ustar matthiasmatthiasextern(C) int printf(const char*, ...); /**********************************/ // 7511 struct S7511(T) { // this is a pure function for T==int T foo(T x) { return 2 * x; } } void test7511a() pure { S7511!int s; s.foo(2); // error -> OK } /**********************************/ // certain case - wrapper range //import std.range; @property bool empty(T)(in T[] a) { return !a.length; } @property ref T front(T)(T[] a) { return a[0]; } void popFront(T)(ref T[] a) { a = a[1 .. $]; } struct S(T) { int foo() { auto t = T(); return t.bar(); } } struct Wrap(R) { R original; this(T : R)(T t) { original = t; } this(A...)(A args) { original = R(args); } @property auto empty() { return original.empty; } @property auto front() { return original.front; } void popFront() { original.popFront(); } } void test7511b() pure @safe { static struct Iota { size_t curr; size_t max; @property bool empty() pure @safe { return curr == max; } @property size_t front() pure @safe { return curr; } void popFront() pure @safe { ++curr; } } { auto a = Iota(0, 3); size_t i = 0; foreach (e; a) { assert(e == i++); } // OK } { auto a = Wrap!(int[])([0,1,2]); size_t i = 0; foreach (e; a) { assert(e == i++); } // errors! } { auto a = Wrap!Iota(0, 3); size_t i = 0; foreach (e; a) { assert(e == i++); } // errors! } } /**********************************/ // with attribute inheritance struct X { static int bar() pure nothrow @safe { return 1; } } class Class(T) { int foo() { // inferred to pure nothrow @safe return T.bar(); } } alias Class!X C; class D : C { override int foo() { // inherits attributes from Class!X.foo return 2; } } void test7511c() pure nothrow @safe { // Disabled for Bigzilla 9952 /+ assert((new C()).foo() == 1); assert((new D()).foo() == 2); static assert(typeof(&C.init.foo).stringof == "int delegate() pure nothrow @safe"); static assert(typeof(&D.init.foo).stringof == "int delegate() pure nothrow @safe"); +/ } /**********************************/ // curiously recurring template pattern (CRTP) class BX(T, bool mutual) { int foo() { static if (mutual) return (cast(T)this).foo(); else return 0; } } class D1 : BX!(D1, true) { alias typeof(super) B; int val; this(int n) { val = n; } override int foo() { return val; } } class D2 : BX!(D2, false) { alias typeof(super) B; int val; this(int n) { val = n; } override int foo() { return val; } } class D3 : BX!(D3, true) { alias typeof(super) B; int val; this(int n) { val = n; } override int foo() pure nothrow { return val; } } class D4 : BX!(D4, false) { alias typeof(super) B; int val; this(int n) { val = n; } override int foo() pure nothrow { return val; } } void test7511d() { // Disabled for Bigzilla 9952 /+ // mutual dependent and attribute inference impure, un-@safe, and may throw is default. auto d1 = new D1(10); static assert(is(typeof(&d1.B.foo) == int function())); static assert(is(typeof(&d1.foo) == int delegate())); assert(d1.foo() == 10); // no mutual dependent. auto d2 = new D2(10); static assert(is(typeof(&d2.B.foo) == int function() pure nothrow @safe)); static assert(is(typeof(&d2 .foo) == int delegate() pure nothrow @safe)); assert(d2.foo() == 10); // mutual dependent with explicit attribute specification. auto d3 = new D3(10); static assert(is(typeof(&d3.B.foo) == int function() pure nothrow)); static assert(is(typeof(&d3 .foo) == int delegate() pure nothrow)); assert(d3.foo() == 10); // no mutual dependent with explicit attribute specification. auto d4 = new D4(10); static assert(is(typeof(&d4.B.foo) == int function() pure nothrow @safe)); static assert(is(typeof(&d4 .foo) == int delegate() pure nothrow @safe)); assert(d4.foo() == 10); +/ } /**********************************/ // 9952 @system void writeln9952(int) {} // impure throwable class C9952(T) { T foo() { return 2; } } class D9952 : C9952!int { override int foo() { writeln9952(super.foo()); return 3; } } void test9952() { static assert(typeof(&C9952!int.init.foo).stringof == "int delegate()"); static assert(typeof(&D9952 .init.foo).stringof == "int delegate()"); } /**********************************/ // 10373 template isMutable10373(T) { enum isMutable10373 = !is(T == const) && !is(T == immutable) && !is(T == inout); } struct Test10373a(T, int N = 0) { static if (N == 0) T[ ] mBuffer; else T[N] mBuffer; static if (is(T == class)) {} else { T* at_(size_t n) { return &mBuffer[n]; } static if (is(typeof(*at_(0) = T.init))) { T opIndexAssign(T v, size_t i) { return (*at_(i) = v); } } } } struct Test10373b(T, int N = 0) { static if (is(T == class)) {} else { T* at_(size_t n) { return &mBuffer[n]; } static if (is(typeof(*at_(0) = T.init))) { T opIndexAssign(T v, size_t i) { return (*at_(i) = v); } } } static if (N == 0) T[ ] mBuffer; else T[N] mBuffer; } struct Test10373c(T, int N = 0) { static if (is(T == class)) {} else { T* at_(size_t n) { return &mBuffer[n]; } static if (isMutable10373!T) { T opIndexAssign(T v, size_t i) { return (*at_(i) = v); } } } static if (N == 0) T[ ] mBuffer; else T[N] mBuffer; } void test10373() { static assert(is(Test10373a!(int, 2))); static assert(is(Test10373b!(int, 2))); static assert(is(Test10373c!(int, 2))); Test10373a!(int, 2) testa; // dmd2.062:OK dmd2.063:OK Test10373b!(int, 2) testb; // dmd2.062:OK dmd2.063:NG Test10373c!(int, 2) testc; // dmd2.062:OK dmd2.063:OK } /**********************************/ // 10329 auto foo10329(T)(T arg) { auto bar() { return arg; } static assert(is(typeof(&bar) == T delegate() pure nothrow @nogc @safe)); return bar(); } auto make10329(T)(T arg) { struct S { auto front() { return T.init; } } S s; static assert(is(typeof(&s.front) == T delegate() pure nothrow @nogc @safe)); return s; } void test10329() pure nothrow @safe { assert(foo10329(1) == 1); auto s = make10329(1); assert(s.front() == 0); } /**********************************/ // 11896 class Foo11896a(T = int) { static if (!__traits(isVirtualMethod, zoo)) {} else { Undefined x; } static void bar() {} static void bar(Foo11896a foo) {} static void zoo() { bar(new Foo11896a); } } Foo11896a!(int) baz11896a; // ---- Frop11896b!(int) frop11896b; mixin template baz11896b() { public void bar11896b() {} } mixin baz11896b; class Foo11896b(T) { static if (! __traits(isVirtualMethod, zoo)) {} static void zoo() { bar11896b(); } } class Frop11896b(T) : Foo11896b!T {} // ---- static bool flag11896c = false; class Bar11896c {} class Foo11896c(T = Bar11896c) { static if (! __traits(isVirtualMethod, foo)) {} alias Foo11896c!(T) this_type; this() { flag11896c = true; } static public this_type foo() { auto c = new this_type(); return flag11896c ? c : null; } } void test11896c() { alias Foo11896c!Bar11896c FooBar; assert(FooBar.foo() !is null); } /**********************************/ // 12392 void f12392(T)() {} alias fa12392 = f12392; void test12392() pure nothrow @safe { fa12392!int(); } /**********************************/ int main() { test7511a(); test7511b(); test7511c(); test7511d(); test9952(); test10373(); test10329(); test11896c(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test10441.d0000644000175000017500000000017113200164642023124 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test10441b.d imports/test10441c.d import test10441b; void main() { boo(1); foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test7932.d0000644000175000017500000000070113200164642023056 0ustar matthiasmatthias// 7932 import std.stdio; size_t N; class C { protected void f(size_t n) out { printf("out: this=%p &n=%p n=%zu\n", cast(void*) this, &n, n); assert (N == n); } body { int dummy; //printf("\n"); N = n; printf("body: this=%p &dummy=%p &N=%p N=%zu\n", cast(void*) this, &dummy, &N, N); } } void main() { auto x = new C; x.f(1); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/interface2.d0000644000175000017500000003661513200164642023611 0ustar matthiasmatthias// PERMUTE_ARGS: extern(C) int printf(const char*, ...); /*******************************************************/ interface Foo { int bar(); } void* p1; class Bar : Foo { int bar() { printf("Bar.bar(this = %p)\n", this); p1 = cast(void*)this; return 0; } } void test1() { Bar b = new Bar(); Foo f = b; printf("b = %p\n", b); printf("f = %p\n", f); assert(cast(void*)b !is cast(void*)f); printf("f.class = '%.*s'\n", f.classinfo.name.length, f.classinfo.name.ptr); assert(f.classinfo.name == "interface2.Foo"); f.bar(); assert(p1 is cast(void*)b); Bar b2 = cast(Bar)f; printf("cast(Bar)f = %p\n", b2); assert(b is b2); delete f; } /*******************************************************/ interface A {} interface B:A {} interface C {} class D:B,C {} void test2() { D x = new D(); printf("D: %p\n",x); Object o = x; printf("o: %p\n",o); B b = cast(B)o; printf("B: %p\n",b); C c = cast(C)o; // boom printf("C: %p\n",c); } /*******************************************************/ interface B3 { void close(); } interface C3 : B3 { } class A3 : B3 { void close() { } } class D3 : A3 { } class E3 : D3, C3 { } void test3() { C3 c = new E3(); delete c; } /*******************************************************/ interface K { } interface X { } interface Y : X { } class Z : Y { } void test4() { Z z = new Z(); if (cast(K) z) { printf("not ok\n"); assert(0); } } /*******************************************************/ interface I5 { char M (); } interface J5 : I5 { char N (); } class A5 : I5 { char M () { printf("M()\n"); return 'M'; } } class B5 : A5, J5 { char N () { printf("N()\n"); return 'N'; } } void test5() { I5 f = new B5 (); char c = f.M(); assert(c == 'M'); } /*******************************************************/ interface A6 { void ma (); } interface B6 { void mb (); } class C6 : A6, B6 { void ma () { } void mb () { } } void test6() { A6 x = new C6 (); assert (cast (B6) x); } /*******************************************************/ interface D7 { int foo(); } class A7 : D7 { int foo() { return 1; } } class B7 : A7 { override int foo() { return 2; } D7 me() { return this; } } void test7() { A7 a = new A7; B7 b = new B7; assert(b.me().foo() != a.foo()); } /*******************************************************/ interface D8 { void foo(); } class A8 : D8 { void foo() { printf("A8.foo()\n"); } } class B8 : A8 {} void test8() { B8 b = new B8(); D8 d = cast(D8) b; d.foo(); } /*******************************************************/ interface IA9 { int i1(); } interface IB9 { int i2(); } interface IC9 : IA9, IB9 { } class C9 : IC9 { int i1() { printf("i1\n"); return 1; } int i2() { printf("i2\n"); return 2; } } void f9(IA9 i1, IB9 i2) { int i; printf("f9\n"); i = i1.i1(); assert(i == 1); i = i2.i2(); assert(i == 2); } void test9() { IC9 i3 = new C9(); C9 c = new C9(); f9(c, c); //printf("c = %p, IC9 = %p, IA9 = %p, IB9 = %p\n", c, i3, cast(IA9)i3, cast(IB9)i3); f9(i3, i3); } /*******************************************************/ interface IOne { int one (); } interface ITwo { int two (); } interface IThree : IOne, ITwo { int three (); } class Three : IThree { int one () { printf ("one\n"); return 1; } int two () { printf ("two\n"); return 2; } int three () { printf ("three\n"); return 3; } } void test10() { int i; IThree three = new Three; i = three.one(); assert(i == 1); i = three.two(); assert(i == 2); i = three.three(); assert(i == 3); ITwo two = cast(ITwo) three; i = two.two(); assert(i == 2); } /*******************************************************/ interface A11{ } interface B11 : A11{ } class MyClass : B11{ } void test11() { B11 b = new MyClass(); Object o = cast(Object)b; printf("o = %p\n", o); } /*******************************************************/ interface I12 { int foo(); } class IA12 : I12 { int foo() { return 1; } } class A12 { I12 i; I12 clone() { return i; } } class B12 : A12 { IA12 ia; override IA12 clone() // covariant return value out (result) { printf("B12.clone()\n"); } body { return ia; } } void test12() { IA12 ia = new IA12; assert(ia.foo() == 1); I12 i = ia; assert(i.foo() == 1); A12 a = new A12; a.i = i; assert(a.clone().foo() == 1); B12 b = new B12; b.ia = ia; assert(b.clone().foo() == 1); a = b; assert(a.clone().foo() == 1); } /*******************************************************/ class I13 { int foo() { return 0; } } class IA13 : I13 { override int foo() { return 1; } } class A13 { I13 i; I13 clone() { return i; } } class B13 : A13 { IA13 ia; override IA13 clone() out (result) { printf("B13.clone()\n"); } body { return ia; } } void test13() { IA13 ia = new IA13; assert(ia.foo() == 1); I13 i = ia; assert(i.foo() == 1); A13 a = new A13; a.i = i; assert(a.clone().foo() == 1); B13 b = new B13; b.ia = ia; assert(b.clone().foo() == 1); a = b; assert(a.clone().foo() == 1); bar(&b.clone); } void bar(IA13 delegate() dg) { } /*******************************************************/ interface I14 { I14 clone(); } interface BabyI14: I14 { } class A14: BabyI14 { int x; BabyI14 clone() { A14 a = new A14; a.x = x; return a; } } I14 foo14(I14 i) { return i.clone(); } void test14() { A14 a = new A14; a.x = 3; a = cast(A14)a.clone(); assert(a.x == 3); A14 b = cast(A14)foo14(a); a.x = 4; assert(b.x == 3); } /*******************************************************/ interface I15 { Object clone(); } class A15 : I15 { int x; A15 clone() { return this; } } void test15() { A15 a = new A15; a.x = 3; A15 a1 = a.clone(); assert(a1.x == 3); I15 i = a1; Object o = i.clone(); A15 a2 = cast(A15) o; assert(a2.x == 3); } /*******************************************************/ interface I16 {} class A16 { I16 foo() { printf("Called A.foo\n"); return new B16(42); } } class B16 : A16, I16 { int data; this(int d) { data = d; } override B16 foo() { printf("Called B.foo\n"); return new B16(69); } } void test16() { B16 b = new B16(105); b.foo(); A16 a = b; a.foo(); printf("foo\n"); B16 b2 = cast(B16) a.foo(); } /*******************************************************/ interface Father { int showData(); } class Mother { Father test() { printf("Called Mother.test\n"); return new Child(42); } } class Child : Mother, Father { int data; this(int d) { data = d; } override Child test() { printf("Called Child.test\n"); return new Child(69); } int showData() { printf("%d\n", data); return data; } } void test17() { Child aChild = new Child(105); Mother childsMum = aChild; aChild.test(); Father mumTest = childsMum.test(); int i; i = aChild.showData(); assert(i == 105); i = mumTest.showData(); assert(i == 69); } /*******************************************************/ int status18; interface I18 { int showData(); } class Parent18 { I18 test() { status18 += 7; return new Child18(42); } } class Child18 : Parent18, I18 { int data; this(int d) { data = d; } override Child18 test() { status18 += 1; return new Child18(69); } override int showData(){ return data; } } void test18() { Child18 a = new Child18(105); assert(a); assert(status18 == 0); assert(a.data == 105); Parent18 p = a; assert(a); assert(status18 == 0); a.test(); assert(status18 == 1); I18 i = p.test(); assert(i); assert(status18 == 2); assert(a.data == 105); assert(a.showData() == 105); assert(i.showData() == 69); } /*******************************************************/ interface IFoo19 { } interface ICov19 { IFoo19 covfunc(); } class Child19 : ICov19, IFoo19 { Child19 covfunc() { printf("in Child19.covfunc()\n"); return this; } } void test19() { Child19 c = new Child19(); ICov19 icov = c; IFoo19 ifoo = icov.covfunc(); printf("c = %p\n", c); printf("icov = %p\n", icov); printf("ifoo = %p\n", ifoo); assert(cast(void*)c + (2*(void*).sizeof) == cast(void*)icov); assert(cast(void*)c + (3*(void*).sizeof) == cast(void*)ifoo); string s = ifoo.classinfo.name; printf("%.*s\n", s.length, s.ptr); assert(s == "interface2.IFoo19"); s = (cast(Object)ifoo).toString; printf("%.*s\n", s.length, s.ptr); assert(s == "interface2.Child19"); } /*******************************************************/ interface Iface1 { Iface2 func1(); } interface Iface2 { Iface1 func2(); } class C1_20 : Iface1 { C2_20 func1(){ return null; } } class C2_20 : Iface2 { C1_20 func2(){ return null; } } void test20() { C1_20 c1 = new C1_20(); printf("c1.func1() == %p\n", c1.func1()); assert(c1.func1() is null); printf("test1\n"); C2_20 c2 = new C2_20(); printf("c2.func2() == %p\n", c2.func2()); assert(c2.func2() is null); } /*******************************************************/ interface I21 { int test(int); } class C21 : I21 { int test(int i){ return i+1; } } void test21() { C21[I21] aa; C21 o = new C21(); aa[o] = o; I21 i = aa[o]; assert(i.test(3) == 4); } /*******************************************************/ interface IFoo22 { int foo(); } class Foo22: IFoo22 { final int foo() { return 7; } } void test22() { Foo22 f = new Foo22; assert(f.foo() == 7); IFoo22 i = f; assert(i.foo() == 7); } /*******************************************************/ interface IFoo23 { int foo(); } class Foo23: IFoo23 { final int foo() { return 7; } } class Baz23 : Foo23 { } void test23() { Baz23 f = new Baz23; assert(f.foo() == 7); IFoo23 i = f; assert(i.foo() == 7); } /*******************************************************/ interface I24B() : I24A { } interface I24A { I24B!() func (); } class Foo24 : I24B!() { I24B!() func() { return null; } } void test24() { auto foo = new Foo24(); foo.func(); printf("foo.func() call passed\n"); I24A ifA = foo; assert(ifA !is null); ifA.func(); } /*******************************************************/ interface IA25 { char a(); } interface IB25 { char b(); } interface IC25 : IA25, IB25 { char c(); } interface ID25 { char d(); } interface IE25 : IC25, ID25 { char e(); } class Foo25 : IE25 { char a() { return('a'); } char b() { return('b'); } char c() { return('c'); } char d() { return('d'); } char e() { return('e'); } } void test25() { auto foo = new Foo25; printf("Foo: %c %c %c %c %c\n", foo.a, foo.b, foo.c, foo.d, foo.e); IA25 a = foo; printf("A: %c\n", a.a); assert(a.a == 'a'); IB25 b = foo; printf("B: %c\n", b.b); assert(b.b == 'b'); IC25 c = foo; printf("C: %c %c %c\n", c.a, c.b, c.c); assert(c.a == 'a'); assert(c.b == 'b'); assert(c.c == 'c'); ID25 d = foo; printf("D: %c\n", d.d); assert(d.d == 'd'); IE25 e = foo; printf("E: %c %c %c %c %c\n", e.a, e.b, e.c, e.d, e.e); assert(e.a == 'a'); assert(e.b == 'b'); assert(e.c == 'c'); assert(e.d == 'd'); assert(e.e == 'e'); b = e; printf("IB25: %c\n", b.b); assert(b.b == 'b'); } /*******************************************************/ interface VisualElement { void draw(); } interface Actor { } interface VisualActor : Actor, VisualElement { } class Sprite3 : Actor, VisualActor { override void draw() { } } void test26() { } /*******************************************************/ interface I27 { static int foo() { return 3; } final int bar() { return 7 + abc(); } int abc(); } class C27 : I27 { int x; int abc() { return x * 10; } } void test27() { C27 c = new C27(); c.x = 8; I27 i = c; assert(i.foo() == 3); assert(I27.foo() == 3); assert(i.bar() == 87); } /*******************************************************/ private interface IFoo { void foo(); } void test2553() { IFoo foo; if (0) foo.foo; } /*******************************************************/ interface I2524 { void foo(); } class C2524 : I2524 { final override void foo() { } } /*******************************************************/ interface Test4088 {} bool foo4088(Test4088 x, Test4088 y) { return x == y; } /*******************************************************/ // 7950 template TypeTuple7950(T...){alias T TypeTuple7950;} interface I7950a {} // ok interface I7950b : I7950a, TypeTuple7950!() {} // fail /*******************************************************/ // 10007 struct A10007 {} interface IFoo10007 { void bar(ref const A10007); } class Foo10007 : IFoo10007 { void bar(ref const A10007 a) {} void bar( const A10007 a) { return this.bar(a); } } /*******************************************************/ // 10744 interface A10744 { int x(); Foo10744 foo(); } class B10744 : A10744 { int x() { return 0; } Bar10744 foo() { return null; } } class Foo10744 { } class Bar10744 : Foo10744 { } interface C10744 { int x(); Baz10744 foo(); } class D10744 : C10744 { int x() { return 0; } Qux10744 foo() { return null; } } interface Baz10744 { } interface Qux10744 : Baz10744 { } /*******************************************************/ // 11034 class A11034(T) { A11034!int view() { return null; } } class B11034(T) : A11034!int { override: C11034!int view() { return null; } } class C11034(T) : B11034!int {} void test11034() { auto b = new B11034!int; // Check that B!int.view() overrides A!int.view() auto tiobj = typeid(Object); assert(typeid(A11034!int).vtbl.length == tiobj.vtbl.length + 1); assert(typeid(B11034!int).vtbl.length == tiobj.vtbl.length + 1); } /*******************************************************/ void testTypeid() { interface I { } interface J : I { } class C : J { } class D : C { } D d = new D(); Object o = d; I i = d; assert(typeid(typeof(o)) is typeid(Object)); assert(typeid(o) is typeid(D)); assert(o.classinfo is typeid(D)); assert(typeid(typeof(i)) is typeid(I)); assert(typeid(i) !is typeid(J)); assert(i.classinfo !is typeid(J)); } /*******************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); test2553(); test11034(); testTypeid(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testline.d0000644000175000017500000000120613200164642023402 0ustar matthiasmatthias// PERMUTE_ARGS: // $HeadURL$ // $Date$ // $Author$ module dstress.run.line_token_03; import std.stdio; import core.exception; int main(){ try{ #line 1 "" assert(0); }catch(AssertError o){ checkFileSpec(o); return 0; } assert(0); } import std.stdio; /* * @WARNING@: this code depends on the phobos implementation. * char[]s returned by wrong assertions have to look like: * "blah blah "filename" blah blah" */ void checkFileSpec(Object o){ string str=o.toString(); int start; for(start=0; start v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); static assert(!__traits(compiles, v1 && v2)); static assert(!__traits(compiles, v1 || v2)); static assert(!__traits(compiles, ~v1)); static assert(!__traits(compiles, -v1)); static assert(!__traits(compiles, +v1)); static assert(!__traits(compiles, !v1)); static assert(!__traits(compiles, v1 += v2)); static assert(!__traits(compiles, v1 -= v2)); static assert(!__traits(compiles, v1 *= v2)); static assert(!__traits(compiles, v1 /= v2)); static assert(!__traits(compiles, v1 %= v2)); static assert(!__traits(compiles, v1 &= v2)); static assert(!__traits(compiles, v1 |= v2)); static assert(!__traits(compiles, v1 ^= v2)); static assert(!__traits(compiles, v1 ~= v2)); static assert(!__traits(compiles, v1 ^^= v2)); static assert(!__traits(compiles, v1 <<= 1)); static assert(!__traits(compiles, v1 >>= 1)); static assert(!__traits(compiles, v1 >>>= 1)); // A cast from vector to non-vector is allowed only when the target is same size Tsarray. static assert(!__traits(compiles, cast(byte)v1)); // 1byte static assert(!__traits(compiles, cast(short)v1)); // 2byte static assert(!__traits(compiles, cast(int)v1)); // 4byte static assert(!__traits(compiles, cast(long)v1)); // 8byte static assert(!__traits(compiles, cast(float)v1)); // 4byte static assert(!__traits(compiles, cast(double)v1)); // 8byte static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK } /*****************************************/ void test2() { byte16 v1,v2,v3; v1 = v2; v1 = v2 + v3; v1 = v2 - v3; static assert(!__traits(compiles, v1 * v2)); static assert(!__traits(compiles, v1 / v2)); static assert(!__traits(compiles, v1 % v2)); v1 = v2 & v3; v1 = v2 | v3; v1 = v2 ^ v3; static assert(!__traits(compiles, v1 ~ v2)); static assert(!__traits(compiles, v1 ^^ v2)); static assert(!__traits(compiles, v1 is v2)); static assert(!__traits(compiles, v1 !is v2)); static assert(!__traits(compiles, v1 == v2)); static assert(!__traits(compiles, v1 != v2)); static assert(!__traits(compiles, v1 < v2)); static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); static assert(!__traits(compiles, v1 && v2)); static assert(!__traits(compiles, v1 || v2)); v1 = ~v2; v1 = -v2; v1 = +v2; static assert(!__traits(compiles, !v1)); v1 += v2; v1 -= v2; static assert(!__traits(compiles, v1 *= v2)); static assert(!__traits(compiles, v1 /= v2)); static assert(!__traits(compiles, v1 %= v2)); v1 &= v2; v1 |= v2; v1 ^= v2; static assert(!__traits(compiles, v1 ~= v2)); static assert(!__traits(compiles, v1 ^^= v2)); static assert(!__traits(compiles, v1 <<= 1)); static assert(!__traits(compiles, v1 >>= 1)); static assert(!__traits(compiles, v1 >>>= 1)); // A cast from vector to non-vector is allowed only when the target is same size Tsarray. static assert(!__traits(compiles, cast(byte)v1)); // 1byte static assert(!__traits(compiles, cast(short)v1)); // 2byte static assert(!__traits(compiles, cast(int)v1)); // 4byte static assert(!__traits(compiles, cast(long)v1)); // 8byte static assert(!__traits(compiles, cast(float)v1)); // 4byte static assert(!__traits(compiles, cast(double)v1)); // 8byte static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK } /*****************************************/ void test2b() { ubyte16 v1,v2,v3; v1 = v2; v1 = v2 + v3; v1 = v2 - v3; static assert(!__traits(compiles, v1 * v2)); static assert(!__traits(compiles, v1 / v2)); static assert(!__traits(compiles, v1 % v2)); v1 = v2 & v3; v1 = v2 | v3; v1 = v2 ^ v3; static assert(!__traits(compiles, v1 ~ v2)); static assert(!__traits(compiles, v1 ^^ v2)); static assert(!__traits(compiles, v1 is v2)); static assert(!__traits(compiles, v1 !is v2)); static assert(!__traits(compiles, v1 == v2)); static assert(!__traits(compiles, v1 != v2)); static assert(!__traits(compiles, v1 < v2)); static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); static assert(!__traits(compiles, v1 && v2)); static assert(!__traits(compiles, v1 || v2)); v1 = ~v2; v1 = -v2; v1 = +v2; static assert(!__traits(compiles, !v1)); v1 += v2; v1 -= v2; static assert(!__traits(compiles, v1 *= v2)); static assert(!__traits(compiles, v1 /= v2)); static assert(!__traits(compiles, v1 %= v2)); v1 &= v2; v1 |= v2; v1 ^= v2; static assert(!__traits(compiles, v1 ~= v2)); static assert(!__traits(compiles, v1 ^^= v2)); static assert(!__traits(compiles, v1 <<= 1)); static assert(!__traits(compiles, v1 >>= 1)); static assert(!__traits(compiles, v1 >>>= 1)); // A cast from vector to non-vector is allowed only when the target is same size Tsarray. static assert(!__traits(compiles, cast(byte)v1)); // 1byte static assert(!__traits(compiles, cast(short)v1)); // 2byte static assert(!__traits(compiles, cast(int)v1)); // 4byte static assert(!__traits(compiles, cast(long)v1)); // 8byte static assert(!__traits(compiles, cast(float)v1)); // 4byte static assert(!__traits(compiles, cast(double)v1)); // 8byte static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK } /*****************************************/ void test2c() { short8 v1,v2,v3; v1 = v2; v1 = v2 + v3; v1 = v2 - v3; v1 = v2 * v3; static assert(!__traits(compiles, v1 / v2)); static assert(!__traits(compiles, v1 % v2)); v1 = v2 & v3; v1 = v2 | v3; v1 = v2 ^ v3; static assert(!__traits(compiles, v1 ~ v2)); static assert(!__traits(compiles, v1 ^^ v2)); static assert(!__traits(compiles, v1 is v2)); static assert(!__traits(compiles, v1 !is v2)); static assert(!__traits(compiles, v1 == v2)); static assert(!__traits(compiles, v1 != v2)); static assert(!__traits(compiles, v1 < v2)); static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); static assert(!__traits(compiles, v1 && v2)); static assert(!__traits(compiles, v1 || v2)); v1 = ~v2; v1 = -v2; v1 = +v2; static assert(!__traits(compiles, !v1)); v1 += v2; v1 -= v2; v1 *= v2; static assert(!__traits(compiles, v1 /= v2)); static assert(!__traits(compiles, v1 %= v2)); v1 &= v2; v1 |= v2; v1 ^= v2; static assert(!__traits(compiles, v1 ~= v2)); static assert(!__traits(compiles, v1 ^^= v2)); static assert(!__traits(compiles, v1 <<= 1)); static assert(!__traits(compiles, v1 >>= 1)); static assert(!__traits(compiles, v1 >>>= 1)); // A cast from vector to non-vector is allowed only when the target is same size Tsarray. static assert(!__traits(compiles, cast(byte)v1)); // 1byte static assert(!__traits(compiles, cast(short)v1)); // 2byte static assert(!__traits(compiles, cast(int)v1)); // 4byte static assert(!__traits(compiles, cast(long)v1)); // 8byte static assert(!__traits(compiles, cast(float)v1)); // 4byte static assert(!__traits(compiles, cast(double)v1)); // 8byte static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK } /*****************************************/ void test2d() { ushort8 v1,v2,v3; v1 = v2; v1 = v2 + v3; v1 = v2 - v3; v1 = v2 * v3; static assert(!__traits(compiles, v1 / v2)); static assert(!__traits(compiles, v1 % v2)); v1 = v2 & v3; v1 = v2 | v3; v1 = v2 ^ v3; static assert(!__traits(compiles, v1 ~ v2)); static assert(!__traits(compiles, v1 ^^ v2)); static assert(!__traits(compiles, v1 is v2)); static assert(!__traits(compiles, v1 !is v2)); static assert(!__traits(compiles, v1 == v2)); static assert(!__traits(compiles, v1 != v2)); static assert(!__traits(compiles, v1 < v2)); static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); static assert(!__traits(compiles, v1 && v2)); static assert(!__traits(compiles, v1 || v2)); v1 = ~v2; v1 = -v2; v1 = +v2; static assert(!__traits(compiles, !v1)); v1 += v2; v1 -= v2; v1 *= v2; static assert(!__traits(compiles, v1 /= v2)); static assert(!__traits(compiles, v1 %= v2)); v1 &= v2; v1 |= v2; v1 ^= v2; static assert(!__traits(compiles, v1 ~= v2)); static assert(!__traits(compiles, v1 ^^= v2)); static assert(!__traits(compiles, v1 <<= 1)); static assert(!__traits(compiles, v1 >>= 1)); static assert(!__traits(compiles, v1 >>>= 1)); // A cast from vector to non-vector is allowed only when the target is same size Tsarray. static assert(!__traits(compiles, cast(byte)v1)); // 1byte static assert(!__traits(compiles, cast(short)v1)); // 2byte static assert(!__traits(compiles, cast(int)v1)); // 4byte static assert(!__traits(compiles, cast(long)v1)); // 8byte static assert(!__traits(compiles, cast(float)v1)); // 4byte static assert(!__traits(compiles, cast(double)v1)); // 8byte static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK } /*****************************************/ void test2e() { int4 v1,v2,v3; v1 = v2; v1 = v2 + v3; v1 = v2 - v3; static assert(!__traits(compiles, v1 * v2)); static assert(!__traits(compiles, v1 / v2)); static assert(!__traits(compiles, v1 % v2)); v1 = v2 & v3; v1 = v2 | v3; v1 = v2 ^ v3; static assert(!__traits(compiles, v1 ~ v2)); static assert(!__traits(compiles, v1 ^^ v2)); static assert(!__traits(compiles, v1 is v2)); static assert(!__traits(compiles, v1 !is v2)); static assert(!__traits(compiles, v1 == v2)); static assert(!__traits(compiles, v1 != v2)); static assert(!__traits(compiles, v1 < v2)); static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); static assert(!__traits(compiles, v1 && v2)); static assert(!__traits(compiles, v1 || v2)); v1 = ~v2; v1 = -v2; v1 = +v2; static assert(!__traits(compiles, !v1)); v1 += v2; v1 -= v2; static assert(!__traits(compiles, v1 *= v2)); static assert(!__traits(compiles, v1 /= v2)); static assert(!__traits(compiles, v1 %= v2)); v1 &= v2; v1 |= v2; v1 ^= v2; static assert(!__traits(compiles, v1 ~= v2)); static assert(!__traits(compiles, v1 ^^= v2)); static assert(!__traits(compiles, v1 <<= 1)); static assert(!__traits(compiles, v1 >>= 1)); static assert(!__traits(compiles, v1 >>>= 1)); // A cast from vector to non-vector is allowed only when the target is same size Tsarray. static assert(!__traits(compiles, cast(byte)v1)); // 1byte static assert(!__traits(compiles, cast(short)v1)); // 2byte static assert(!__traits(compiles, cast(int)v1)); // 4byte static assert(!__traits(compiles, cast(long)v1)); // 8byte static assert(!__traits(compiles, cast(float)v1)); // 4byte static assert(!__traits(compiles, cast(double)v1)); // 8byte static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK } /*****************************************/ void test2f() { uint4 v1,v2,v3; v1 = v2; v1 = v2 + v3; v1 = v2 - v3; static assert(!__traits(compiles, v1 * v2)); static assert(!__traits(compiles, v1 / v2)); static assert(!__traits(compiles, v1 % v2)); v1 = v2 & v3; v1 = v2 | v3; v1 = v2 ^ v3; static assert(!__traits(compiles, v1 ~ v2)); static assert(!__traits(compiles, v1 ^^ v2)); static assert(!__traits(compiles, v1 is v2)); static assert(!__traits(compiles, v1 !is v2)); static assert(!__traits(compiles, v1 == v2)); static assert(!__traits(compiles, v1 != v2)); static assert(!__traits(compiles, v1 < v2)); static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); static assert(!__traits(compiles, v1 && v2)); static assert(!__traits(compiles, v1 || v2)); v1 = ~v2; v1 = -v2; v1 = +v2; static assert(!__traits(compiles, !v1)); v1 += v2; v1 -= v2; static assert(!__traits(compiles, v1 *= v2)); static assert(!__traits(compiles, v1 /= v2)); static assert(!__traits(compiles, v1 %= v2)); v1 &= v2; v1 |= v2; v1 ^= v2; static assert(!__traits(compiles, v1 ~= v2)); static assert(!__traits(compiles, v1 ^^= v2)); static assert(!__traits(compiles, v1 <<= 1)); static assert(!__traits(compiles, v1 >>= 1)); static assert(!__traits(compiles, v1 >>>= 1)); // A cast from vector to non-vector is allowed only when the target is same size Tsarray. static assert(!__traits(compiles, cast(byte)v1)); // 1byte static assert(!__traits(compiles, cast(short)v1)); // 2byte static assert(!__traits(compiles, cast(int)v1)); // 4byte static assert(!__traits(compiles, cast(long)v1)); // 8byte static assert(!__traits(compiles, cast(float)v1)); // 4byte static assert(!__traits(compiles, cast(double)v1)); // 8byte static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK } /*****************************************/ void test2g() { long2 v1,v2,v3; v1 = v2; v1 = v2 + v3; v1 = v2 - v3; static assert(!__traits(compiles, v1 * v2)); static assert(!__traits(compiles, v1 / v2)); static assert(!__traits(compiles, v1 % v2)); v1 = v2 & v3; v1 = v2 | v3; v1 = v2 ^ v3; static assert(!__traits(compiles, v1 ~ v2)); static assert(!__traits(compiles, v1 ^^ v2)); static assert(!__traits(compiles, v1 is v2)); static assert(!__traits(compiles, v1 !is v2)); static assert(!__traits(compiles, v1 == v2)); static assert(!__traits(compiles, v1 != v2)); static assert(!__traits(compiles, v1 < v2)); static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); static assert(!__traits(compiles, v1 && v2)); static assert(!__traits(compiles, v1 || v2)); v1 = ~v2; v1 = -v2; v1 = +v2; static assert(!__traits(compiles, !v1)); v1 += v2; v1 -= v2; static assert(!__traits(compiles, v1 *= v2)); static assert(!__traits(compiles, v1 /= v2)); static assert(!__traits(compiles, v1 %= v2)); v1 &= v2; v1 |= v2; v1 ^= v2; static assert(!__traits(compiles, v1 ~= v2)); static assert(!__traits(compiles, v1 ^^= v2)); static assert(!__traits(compiles, v1 <<= 1)); static assert(!__traits(compiles, v1 >>= 1)); static assert(!__traits(compiles, v1 >>>= 1)); // A cast from vector to non-vector is allowed only when the target is same size Tsarray. static assert(!__traits(compiles, cast(byte)v1)); // 1byte static assert(!__traits(compiles, cast(short)v1)); // 2byte static assert(!__traits(compiles, cast(int)v1)); // 4byte static assert(!__traits(compiles, cast(long)v1)); // 8byte static assert(!__traits(compiles, cast(float)v1)); // 4byte static assert(!__traits(compiles, cast(double)v1)); // 8byte static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK } /*****************************************/ void test2h() { ulong2 v1,v2,v3; v1 = v2; v1 = v2 + v3; v1 = v2 - v3; static assert(!__traits(compiles, v1 * v2)); static assert(!__traits(compiles, v1 / v2)); static assert(!__traits(compiles, v1 % v2)); v1 = v2 & v3; v1 = v2 | v3; v1 = v2 ^ v3; static assert(!__traits(compiles, v1 ~ v2)); static assert(!__traits(compiles, v1 ^^ v2)); static assert(!__traits(compiles, v1 is v2)); static assert(!__traits(compiles, v1 !is v2)); static assert(!__traits(compiles, v1 == v2)); static assert(!__traits(compiles, v1 != v2)); static assert(!__traits(compiles, v1 < v2)); static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); static assert(!__traits(compiles, v1 && v2)); static assert(!__traits(compiles, v1 || v2)); v1 = ~v2; v1 = -v2; v1 = +v2; static assert(!__traits(compiles, !v1)); v1 += v2; v1 -= v2; static assert(!__traits(compiles, v1 *= v2)); static assert(!__traits(compiles, v1 /= v2)); static assert(!__traits(compiles, v1 %= v2)); v1 &= v2; v1 |= v2; v1 ^= v2; static assert(!__traits(compiles, v1 ~= v2)); static assert(!__traits(compiles, v1 ^^= v2)); static assert(!__traits(compiles, v1 <<= 1)); static assert(!__traits(compiles, v1 >>= 1)); static assert(!__traits(compiles, v1 >>>= 1)); // A cast from vector to non-vector is allowed only when the target is same size Tsarray. static assert(!__traits(compiles, cast(byte)v1)); // 1byte static assert(!__traits(compiles, cast(short)v1)); // 2byte static assert(!__traits(compiles, cast(int)v1)); // 4byte static assert(!__traits(compiles, cast(long)v1)); // 8byte static assert(!__traits(compiles, cast(float)v1)); // 4byte static assert(!__traits(compiles, cast(double)v1)); // 8byte static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK } /*****************************************/ void test2i() { float4 v1,v2,v3; v1 = v2; v1 = v2 + v3; v1 = v2 - v3; v1 = v2 * v3; v1 = v2 / v3; static assert(!__traits(compiles, v1 % v2)); static assert(!__traits(compiles, v1 & v2)); static assert(!__traits(compiles, v1 | v2)); static assert(!__traits(compiles, v1 ^ v2)); static assert(!__traits(compiles, v1 ~ v2)); static assert(!__traits(compiles, v1 ^^ v2)); static assert(!__traits(compiles, v1 is v2)); static assert(!__traits(compiles, v1 !is v2)); static assert(!__traits(compiles, v1 == v2)); static assert(!__traits(compiles, v1 != v2)); static assert(!__traits(compiles, v1 < v2)); static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); static assert(!__traits(compiles, v1 && v2)); static assert(!__traits(compiles, v1 || v2)); static assert(!__traits(compiles, ~v1)); v1 = -v2; v1 = +v2; static assert(!__traits(compiles, !v1)); v1 += v2; v1 -= v2; v1 *= v2; v1 /= v2; static assert(!__traits(compiles, v1 %= v2)); static assert(!__traits(compiles, v1 &= v2)); static assert(!__traits(compiles, v1 |= v2)); static assert(!__traits(compiles, v1 ^= v2)); static assert(!__traits(compiles, v1 ~= v2)); static assert(!__traits(compiles, v1 ^^= v2)); static assert(!__traits(compiles, v1 <<= 1)); static assert(!__traits(compiles, v1 >>= 1)); static assert(!__traits(compiles, v1 >>>= 1)); // A cast from vector to non-vector is allowed only when the target is same size Tsarray. static assert(!__traits(compiles, cast(byte)v1)); // 1byte static assert(!__traits(compiles, cast(short)v1)); // 2byte static assert(!__traits(compiles, cast(int)v1)); // 4byte static assert(!__traits(compiles, cast(long)v1)); // 8byte static assert(!__traits(compiles, cast(float)v1)); // 4byte static assert(!__traits(compiles, cast(double)v1)); // 8byte static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK } /*****************************************/ void test2j() { double2 v1,v2,v3; v1 = v2; v1 = v2 + v3; v1 = v2 - v3; v1 = v2 * v3; v1 = v2 / v3; static assert(!__traits(compiles, v1 % v2)); static assert(!__traits(compiles, v1 & v2)); static assert(!__traits(compiles, v1 | v2)); static assert(!__traits(compiles, v1 ^ v2)); static assert(!__traits(compiles, v1 ~ v2)); static assert(!__traits(compiles, v1 ^^ v2)); static assert(!__traits(compiles, v1 is v2)); static assert(!__traits(compiles, v1 !is v2)); static assert(!__traits(compiles, v1 == v2)); static assert(!__traits(compiles, v1 != v2)); static assert(!__traits(compiles, v1 < v2)); static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); static assert(!__traits(compiles, v1 && v2)); static assert(!__traits(compiles, v1 || v2)); static assert(!__traits(compiles, ~v1)); v1 = -v2; v1 = +v2; static assert(!__traits(compiles, !v1)); v1 += v2; v1 -= v2; v1 *= v2; v1 /= v2; static assert(!__traits(compiles, v1 %= v2)); static assert(!__traits(compiles, v1 &= v2)); static assert(!__traits(compiles, v1 |= v2)); static assert(!__traits(compiles, v1 ^= v2)); static assert(!__traits(compiles, v1 ~= v2)); static assert(!__traits(compiles, v1 ^^= v2)); static assert(!__traits(compiles, v1 <<= 1)); static assert(!__traits(compiles, v1 >>= 1)); static assert(!__traits(compiles, v1 >>>= 1)); // A cast from vector to non-vector is allowed only when the target is same size Tsarray. static assert(!__traits(compiles, cast(byte)v1)); // 1byte static assert(!__traits(compiles, cast(short)v1)); // 2byte static assert(!__traits(compiles, cast(int)v1)); // 4byte static assert(!__traits(compiles, cast(long)v1)); // 8byte static assert(!__traits(compiles, cast(float)v1)); // 4byte static assert(!__traits(compiles, cast(double)v1)); // 8byte static assert(!__traits(compiles, cast(int[2])v1)); // 8byte Tsarray static assert( __traits(compiles, cast(int[4])v1)); // 16byte Tsarray, OK static assert( __traits(compiles, cast(long[2])v1)); // 16byte Tsarray, OK } /*****************************************/ float4 test3() { float4 a; a = __simd(XMM.PXOR, a, a); return a; } /*****************************************/ void test4() { int4 c = 7; (cast(int[4])c)[3] = 4; (cast(int*)&c)[2] = 4; c.array[1] = 4; c.ptr[3] = 4; assert(c.length == 4); } /*****************************************/ void BaseTypeOfVector(T : __vector(T[N]), size_t N)(int i) { assert(is(T == int)); assert(N == 4); } void test7411() { BaseTypeOfVector!(__vector(int[4]))(3); } /*****************************************/ // 7951 float[4] test7951() { float4 v1; float4 v2; return cast(float[4])(v1+v2); } /*****************************************/ void test7951_2() { float[4] v1 = [1,2,3,4]; float[4] v2 = [1,2,3,4]; float4 f1, f2, f3; f1.array = v1; f2.array = v2; f3 = f1 + f2; } /*****************************************/ void test7949() { int[4] o = [1,2,3,4]; int4 v1; v1.array = o; int4 v2; v2.array = o; auto r = __simd(XMM.ADDPS, v1,v2); writeln(r.array); } /*****************************************/ immutable ulong2 gulong2 = 0x8000_0000_0000_0000; immutable uint4 guint4 = 0x8000_0000; immutable ushort8 gushort8 = 0x8000; immutable ubyte16 gubyte16 = 0x80; immutable long2 glong2 = 0x7000_0000_0000_0000; immutable int4 gint4 = 0x7000_0000; immutable short8 gshort8 = 0x7000; immutable byte16 gbyte16 = 0x70; immutable float4 gfloat4 = 4.0; immutable double2 gdouble2 = 8.0; void test7414() { immutable ulong2 lulong2 = 0x8000_0000_0000_0000; assert(memcmp(&lulong2, &gulong2, gulong2.sizeof) == 0); immutable uint4 luint4 = 0x8000_0000; assert(memcmp(&luint4, &guint4, guint4.sizeof) == 0); immutable ushort8 lushort8 = 0x8000; assert(memcmp(&lushort8, &gushort8, gushort8.sizeof) == 0); immutable ubyte16 lubyte16 = 0x80; assert(memcmp(&lubyte16, &gubyte16, gubyte16.sizeof) == 0); immutable long2 llong2 = 0x7000_0000_0000_0000; assert(memcmp(&llong2, &glong2, glong2.sizeof) == 0); immutable int4 lint4 = 0x7000_0000; assert(memcmp(&lint4, &gint4, gint4.sizeof) == 0); immutable short8 lshort8 = 0x7000; assert(memcmp(&lshort8, &gshort8, gshort8.sizeof) == 0); immutable byte16 lbyte16 = 0x70; assert(memcmp(&lbyte16, &gbyte16, gbyte16.sizeof) == 0); immutable float4 lfloat4 = 4.0; assert(memcmp(&lfloat4, &gfloat4, gfloat4.sizeof) == 0); immutable double2 ldouble2 = 8.0; assert(memcmp(&ldouble2, &gdouble2, gdouble2.sizeof) == 0); } /*****************************************/ void test7413() { byte16 b = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; assert(b.array[0] == 1); assert(b.array[1] == 2); assert(b.array[2] == 3); assert(b.array[3] == 4); assert(b.array[4] == 5); assert(b.array[5] == 6); assert(b.array[6] == 7); assert(b.array[7] == 8); assert(b.array[8] == 9); assert(b.array[9] == 10); assert(b.array[10] == 11); assert(b.array[11] == 12); assert(b.array[12] == 13); assert(b.array[13] == 14); assert(b.array[14] == 15); assert(b.array[15] == 16); ubyte16 ub = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; assert(ub.array[0] == 1); assert(ub.array[1] == 2); assert(ub.array[2] == 3); assert(ub.array[3] == 4); assert(ub.array[4] == 5); assert(ub.array[5] == 6); assert(ub.array[6] == 7); assert(ub.array[7] == 8); assert(ub.array[8] == 9); assert(ub.array[9] == 10); assert(ub.array[10] == 11); assert(ub.array[11] == 12); assert(ub.array[12] == 13); assert(ub.array[13] == 14); assert(ub.array[14] == 15); assert(ub.array[15] == 16); short8 s = [1,2,3,4,5,6,7,8]; assert(s.array[0] == 1); assert(s.array[1] == 2); assert(s.array[2] == 3); assert(s.array[3] == 4); assert(s.array[4] == 5); assert(s.array[5] == 6); assert(s.array[6] == 7); assert(s.array[7] == 8); ushort8 us = [1,2,3,4,5,6,7,8]; assert(us.array[0] == 1); assert(us.array[1] == 2); assert(us.array[2] == 3); assert(us.array[3] == 4); assert(us.array[4] == 5); assert(us.array[5] == 6); assert(us.array[6] == 7); assert(us.array[7] == 8); int4 i = [1,2,3,4]; assert(i.array[0] == 1); assert(i.array[1] == 2); assert(i.array[2] == 3); assert(i.array[3] == 4); uint4 ui = [1,2,3,4]; assert(ui.array[0] == 1); assert(ui.array[1] == 2); assert(ui.array[2] == 3); assert(ui.array[3] == 4); long2 l = [1,2]; assert(l.array[0] == 1); assert(l.array[1] == 2); ulong2 ul = [1,2]; assert(ul.array[0] == 1); assert(ul.array[1] == 2); float4 f = [1,2,3,4]; assert(f.array[0] == 1); assert(f.array[1] == 2); assert(f.array[2] == 3); assert(f.array[3] == 4); double2 d = [1,2]; assert(d.array[0] == 1); assert(d.array[1] == 2); } /*****************************************/ byte16 b = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; ubyte16 ub = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; short8 s = [1,2,3,4,5,6,7,8]; ushort8 us = [1,2,3,4,5,6,7,8]; int4 i = [1,2,3,4]; uint4 ui = [1,2,3,4]; long2 l = [1,2]; ulong2 ul = [1,2]; float4 f = [1,2,3,4]; double2 d = [1,2]; void test7413_2() { assert(b.array[0] == 1); assert(b.array[1] == 2); assert(b.array[2] == 3); assert(b.array[3] == 4); assert(b.array[4] == 5); assert(b.array[5] == 6); assert(b.array[6] == 7); assert(b.array[7] == 8); assert(b.array[8] == 9); assert(b.array[9] == 10); assert(b.array[10] == 11); assert(b.array[11] == 12); assert(b.array[12] == 13); assert(b.array[13] == 14); assert(b.array[14] == 15); assert(b.array[15] == 16); assert(ub.array[0] == 1); assert(ub.array[1] == 2); assert(ub.array[2] == 3); assert(ub.array[3] == 4); assert(ub.array[4] == 5); assert(ub.array[5] == 6); assert(ub.array[6] == 7); assert(ub.array[7] == 8); assert(ub.array[8] == 9); assert(ub.array[9] == 10); assert(ub.array[10] == 11); assert(ub.array[11] == 12); assert(ub.array[12] == 13); assert(ub.array[13] == 14); assert(ub.array[14] == 15); assert(ub.array[15] == 16); assert(s.array[0] == 1); assert(s.array[1] == 2); assert(s.array[2] == 3); assert(s.array[3] == 4); assert(s.array[4] == 5); assert(s.array[5] == 6); assert(s.array[6] == 7); assert(s.array[7] == 8); assert(us.array[0] == 1); assert(us.array[1] == 2); assert(us.array[2] == 3); assert(us.array[3] == 4); assert(us.array[4] == 5); assert(us.array[5] == 6); assert(us.array[6] == 7); assert(us.array[7] == 8); assert(i.array[0] == 1); assert(i.array[1] == 2); assert(i.array[2] == 3); assert(i.array[3] == 4); assert(ui.array[0] == 1); assert(ui.array[1] == 2); assert(ui.array[2] == 3); assert(ui.array[3] == 4); assert(l.array[0] == 1); assert(l.array[1] == 2); assert(ul.array[0] == 1); assert(ul.array[1] == 2); assert(f.array[0] == 1); assert(f.array[1] == 2); assert(f.array[2] == 3); assert(f.array[3] == 4); assert(d.array[0] == 1); assert(d.array[1] == 2); } /*****************************************/ float bug8060(float x) { int i = *cast(int*)&x; ++i; return *cast(float*)&i; } /*****************************************/ float4 test5(float4 a, float4 b) { a = __simd(XMM.ADDPD, a, b); a = __simd(XMM.ADDSS, a, b); a = __simd(XMM.ADDSD, a, b); a = __simd(XMM.ADDPS, a, b); a = __simd(XMM.PADDB, a, b); a = __simd(XMM.PADDW, a, b); a = __simd(XMM.PADDD, a, b); a = __simd(XMM.PADDQ, a, b); a = __simd(XMM.SUBPD, a, b); a = __simd(XMM.SUBSS, a, b); a = __simd(XMM.SUBSD, a, b); a = __simd(XMM.SUBPS, a, b); a = __simd(XMM.PSUBB, a, b); a = __simd(XMM.PSUBW, a, b); a = __simd(XMM.PSUBD, a, b); a = __simd(XMM.PSUBQ, a, b); a = __simd(XMM.MULPD, a, b); a = __simd(XMM.MULSS, a, b); a = __simd(XMM.MULSD, a, b); a = __simd(XMM.MULPS, a, b); a = __simd(XMM.PMULLW, a, b); a = __simd(XMM.DIVPD, a, b); a = __simd(XMM.DIVSS, a, b); a = __simd(XMM.DIVSD, a, b); a = __simd(XMM.DIVPS, a, b); a = __simd(XMM.PAND, a, b); a = __simd(XMM.POR, a, b); a = __simd(XMM.UCOMISS, a, b); a = __simd(XMM.UCOMISD, a, b); a = __simd(XMM.XORPS, a, b); a = __simd(XMM.XORPD, a, b); a = __simd_sto(XMM.STOSS, a, b); a = __simd_sto(XMM.STOSD, a, b); a = __simd_sto(XMM.STOAPS, a, b); a = __simd_sto(XMM.STOAPD, a, b); a = __simd_sto(XMM.STODQA, a, b); //a = __simd_sto(XMM.STOD, a, b); a = __simd_sto(XMM.STOQ, a, b); a = __simd(XMM.LODSS, a); a = __simd(XMM.LODSD, a); a = __simd(XMM.LODAPS, a); a = __simd(XMM.LODAPD, a); a = __simd(XMM.LODDQA, a); //a = __simd(XMM.LODD, a); a = __simd(XMM.LODQ, a); a = __simd(XMM.LODDQU, a); a = __simd_sto(XMM.STODQU, a, b); //MOVDQ2Q = 0xF20FD6, // MOVDQ2Q mmx, xmm F2 0F D6 /r /+ LODHPD = 0x660F16, // MOVHPD xmm, mem64 66 0F 16 /r STOHPD = 0x660F17, // MOVHPD mem64, xmm 66 0F 17 /r LODHPS = 0x0F16, // MOVHPS xmm, mem64 0F 16 /r STOHPS = 0x0F17, // MOVHPS mem64, xmm 0F 17 /r MOVLHPS = 0x0F16, // MOVLHPS xmm1, xmm2 0F 16 /r LODLPD = 0x660F12, // MOVLPD xmm, mem64 66 0F 12 /r STOLPD = 0x660F13, // MOVLPD mem64, xmm 66 0F 13 /r a = __simd(XMM.LODLPS, a, b); STOLPS = 0x0F13, // MOVLPS mem64, xmm 0F 13 /r MOVMSKPD = 0x660F50, // MOVMSKPD reg32, xmm 66 0F 50 /r MOVMSKPS = 0x0F50, // MOVMSKPS reg32, xmm 0F 50 /r MOVNTDQ = 0x660FE7, // MOVNTDQ mem128, xmm 66 0F E7 /r MOVNTI = 0x0FC3, // MOVNTI m32,r32 0F C3 /r // MOVNTI m64,r64 0F C3 /r MOVNTPD = 0x660F2B, // MOVNTPD mem128, xmm 66 0F 2B /r MOVNTPS = 0x0F2B, // MOVNTPS mem128, xmm 0F 2B /r //MOVNTQ = 0x0FE7, // MOVNTQ m64, mmx 0F E7 /r //MOVQ2DQ = 0xF30FD6, // MOVQ2DQ xmm, mmx F3 0F D6 /r +/ a = __simd(XMM.LODUPD, a, b); a = __simd_sto(XMM.STOUPD, a, b); a = __simd(XMM.LODUPS, a, b); a = __simd_sto(XMM.STOUPS, a, b); a = __simd(XMM.PACKSSDW, a, b); a = __simd(XMM.PACKSSWB, a, b); a = __simd(XMM.PACKUSWB, a, b); a = __simd(XMM.PADDSB, a, b); a = __simd(XMM.PADDSW, a, b); a = __simd(XMM.PADDUSB, a, b); a = __simd(XMM.PADDUSW, a, b); a = __simd(XMM.PANDN, a, b); a = __simd(XMM.PCMPEQB, a, b); a = __simd(XMM.PCMPEQD, a, b); a = __simd(XMM.PCMPEQW, a, b); a = __simd(XMM.PCMPGTB, a, b); a = __simd(XMM.PCMPGTD, a, b); a = __simd(XMM.PCMPGTW, a, b); a = __simd(XMM.PMADDWD, a, b); a = __simd(XMM.PSLLW, a, b); a = __simd_ib(XMM.PSLLW, a, cast(ubyte)0x7A); a = __simd(XMM.PSLLD, a, b); a = __simd_ib(XMM.PSLLD, a, cast(ubyte)0x7A); a = __simd(XMM.PSLLQ, a, b); a = __simd_ib(XMM.PSLLQ, a, cast(ubyte)0x7A); a = __simd(XMM.PSRAW, a, b); a = __simd_ib(XMM.PSRAW, a, cast(ubyte)0x7A); a = __simd(XMM.PSRAD, a, b); a = __simd_ib(XMM.PSRAD, a, cast(ubyte)0x7A); a = __simd(XMM.PSRLW, a, b); a = __simd_ib(XMM.PSRLW, a, cast(ubyte)0x7A); a = __simd(XMM.PSRLD, a, b); a = __simd_ib(XMM.PSRLD, a, cast(ubyte)0x7A); a = __simd(XMM.PSRLQ, a, b); a = __simd_ib(XMM.PSRLQ, a, cast(ubyte)0x7A); a = __simd(XMM.PSUBSB, a, b); a = __simd(XMM.PSUBSW, a, b); a = __simd(XMM.PSUBUSB, a, b); a = __simd(XMM.PSUBUSW, a, b); a = __simd(XMM.PUNPCKHBW, a, b); a = __simd(XMM.PUNPCKHDQ, a, b); a = __simd(XMM.PUNPCKHWD, a, b); a = __simd(XMM.PUNPCKLBW, a, b); a = __simd(XMM.PUNPCKLDQ, a, b); a = __simd(XMM.PUNPCKLWD, a, b); a = __simd(XMM.PXOR, a, b); a = __simd(XMM.ANDPD, a, b); a = __simd(XMM.ANDPS, a, b); a = __simd(XMM.ANDNPD, a, b); a = __simd(XMM.ANDNPS, a, b); a = __simd(XMM.CMPPD, a, b, 0x7A); a = __simd(XMM.CMPSS, a, b, 0x7A); a = __simd(XMM.CMPSD, a, b, 0x7A); a = __simd(XMM.CMPPS, a, b, 0x7A); a = __simd(XMM.CVTDQ2PD, a, b); a = __simd(XMM.CVTDQ2PS, a, b); a = __simd(XMM.CVTPD2DQ, a, b); //a = __simd(XMM.CVTPD2PI, a, b); a = __simd(XMM.CVTPD2PS, a, b); a = __simd(XMM.CVTPI2PD, a, b); a = __simd(XMM.CVTPI2PS, a, b); a = __simd(XMM.CVTPS2DQ, a, b); a = __simd(XMM.CVTPS2PD, a, b); //a = __simd(XMM.CVTPS2PI, a, b); //a = __simd(XMM.CVTSD2SI, a, b); //a = __simd(XMM.CVTSD2SI, a, b); a = __simd(XMM.CVTSD2SS, a, b); //a = __simd(XMM.CVTSI2SD, a, b); //a = __simd(XMM.CVTSI2SD, a, b); //a = __simd(XMM.CVTSI2SS, a, b); //a = __simd(XMM.CVTSI2SS, a, b); a = __simd(XMM.CVTSS2SD, a, b); //a = __simd(XMM.CVTSS2SI, a, b); //a = __simd(XMM.CVTSS2SI, a, b); //a = __simd(XMM.CVTTPD2PI, a, b); a = __simd(XMM.CVTTPD2DQ, a, b); a = __simd(XMM.CVTTPS2DQ, a, b); //a = __simd(XMM.CVTTPS2PI, a, b); //a = __simd(XMM.CVTTSD2SI, a, b); //a = __simd(XMM.CVTTSD2SI, a, b); //a = __simd(XMM.CVTTSS2SI, a, b); //a = __simd(XMM.CVTTSS2SI, a, b); a = __simd(XMM.MASKMOVDQU, a, b); //a = __simd(XMM.MASKMOVQ, a, b); a = __simd(XMM.MAXPD, a, b); a = __simd(XMM.MAXPS, a, b); a = __simd(XMM.MAXSD, a, b); a = __simd(XMM.MAXSS, a, b); a = __simd(XMM.MINPD, a, b); a = __simd(XMM.MINPS, a, b); a = __simd(XMM.MINSD, a, b); a = __simd(XMM.MINSS, a, b); a = __simd(XMM.ORPD, a, b); a = __simd(XMM.ORPS, a, b); a = __simd(XMM.PAVGB, a, b); a = __simd(XMM.PAVGW, a, b); a = __simd(XMM.PMAXSW, a, b); //a = __simd(XMM.PINSRW, a, b); a = __simd(XMM.PMAXUB, a, b); a = __simd(XMM.PMINSB, a, b); a = __simd(XMM.PMINUB, a, b); //a = __simd(XMM.PMOVMSKB, a, b); a = __simd(XMM.PMULHUW, a, b); a = __simd(XMM.PMULHW, a, b); a = __simd(XMM.PMULUDQ, a, b); a = __simd(XMM.PSADBW, a, b); a = __simd(XMM.PUNPCKHQDQ, a, b); a = __simd(XMM.PUNPCKLQDQ, a, b); a = __simd(XMM.RCPPS, a, b); a = __simd(XMM.RCPSS, a, b); a = __simd(XMM.RSQRTPS, a, b); a = __simd(XMM.RSQRTSS, a, b); a = __simd(XMM.SQRTPD, a, b); a = __simd(XMM.SHUFPD, a, b, 0xA7); a = __simd(XMM.SHUFPS, a, b, 0x7A); a = __simd(XMM.SQRTPS, a, b); a = __simd(XMM.SQRTSD, a, b); a = __simd(XMM.SQRTSS, a, b); a = __simd(XMM.UNPCKHPD, a, b); a = __simd(XMM.UNPCKHPS, a, b); a = __simd(XMM.UNPCKLPD, a, b); a = __simd(XMM.UNPCKLPS, a, b); a = __simd(XMM.PSHUFD, a, b, 0x7A); a = __simd(XMM.PSHUFHW, a, b, 0x7A); a = __simd(XMM.PSHUFLW, a, b, 0x7A); //a = __simd(XMM.PSHUFW, a, b, 0x7A); a = __simd_ib(XMM.PSLLDQ, a, cast(ubyte)0x7A); a = __simd_ib(XMM.PSRLDQ, a, cast(ubyte)0x7A); /**/ a = __simd(XMM.BLENDPD, a, b, 0x7A); a = __simd(XMM.BLENDPS, a, b, 0x7A); a = __simd(XMM.DPPD, a, b, 0x7A); a = __simd(XMM.DPPS, a, b, 0x7A); a = __simd(XMM.MPSADBW, a, b, 0x7A); a = __simd(XMM.PBLENDW, a, b, 0x7A); a = __simd(XMM.ROUNDPD, a, b, 0x7A); a = __simd(XMM.ROUNDPS, a, b, 0x7A); a = __simd(XMM.ROUNDSD, a, b, 0x7A); a = __simd(XMM.ROUNDSS, a, b, 0x7A); return a; } /*****************************************/ /+ // 9200 void bar9200(double[2] a) { assert(a[0] == 1); assert(a[1] == 2); } double2 * v9200(double2* a) { return a; } void test9200() { double2 a = [1, 2]; *v9200(&a) = a; bar9200(a.array); } +/ /*****************************************/ // 9304 and 9322 float4 foo9304(float4 a) { return -a; } void test9304() { auto a = foo9304([0, 1, 2, 3]); //writeln(a.array); assert(a.array == [0,-1,-2,-3]); } /*****************************************/ void test9910() { float4 f = [1, 1, 1, 1]; auto works = f + 3; auto bug = 3 + f; assert (works.array == [4,4,4,4]); assert (bug.array == [4,4,4,4]); // no property 'array' for type 'int' } /*****************************************/ bool normalize(double[] range, double sum = 1) { double s = 0; const length = range.length; foreach (e; range) { s += e; } if (s == 0) { return false; } return true; } void test12852() { double[3] range = [0.0, 0.0, 0.0]; assert(normalize(range[]) == false); range[1] = 3.0; assert(normalize(range[]) == true); } /*****************************************/ void test9449() { ubyte16 table[1]; } /*****************************************/ void test9449_2() { float[4][2] m = [[2.0, 1, 3, 4], [5.0, 6, 7, 8]]; // segfault assert(m[0][0] == 2.0); assert(m[0][1] == 1); assert(m[0][2] == 3); assert(m[0][3] == 4); assert(m[1][0] == 5.0); assert(m[1][1] == 6); assert(m[1][2] == 7); assert(m[1][3] == 8); } /*****************************************/ // 13841 void test13841() { alias Vector16s = TypeTuple!( void16, byte16, short8, int4, long2, ubyte16, ushort8, uint4, ulong2, float4, double2); foreach (V1; Vector16s) { foreach (V2; Vector16s) { V1 v1 = void; V2 v2 = void; static if (is(V1 == V2)) { static assert( is(typeof(true ? v1 : v2) == V1)); } else { static assert(!is(typeof(true ? v1 : v2))); } } } } /*****************************************/ // 12776 void test12776() { alias Vector16s = TypeTuple!( void16, byte16, short8, int4, long2, ubyte16, ushort8, uint4, ulong2, float4, double2); foreach (V; Vector16s) { static assert(is(typeof( V .init) == V )); static assert(is(typeof( const(V).init) == const(V))); static assert(is(typeof( inout( V).init) == inout( V))); static assert(is(typeof( inout(const V).init) == inout(const V))); static assert(is(typeof(shared( V).init) == shared( V))); static assert(is(typeof(shared( const V).init) == shared( const V))); static assert(is(typeof(shared(inout V).init) == shared(inout V))); static assert(is(typeof(shared(inout const V).init) == shared(inout const V))); static assert(is(typeof( immutable(V).init) == immutable(V))); } } /*****************************************/ void foo13988(double[] arr) { static ulong repr(double d) { return *cast(ulong*)&d; } foreach (x; arr) assert(repr(arr[0]) == *cast(ulong*)&(arr[0])); } void test13988() { double[] arr = [3.0]; foo13988(arr); } /*****************************************/ int main() { test1(); test2(); test2b(); test2c(); test2d(); test2e(); test2f(); test2g(); test2h(); test2i(); test2j(); test3(); test4(); test7411(); test7951(); test7951_2(); test7949(); test7414(); test7413(); test7413_2(); // test9200(); test9304(); test9910(); test12852(); test9449(); test9449_2(); test13988(); return 0; } } else { int main() { return 0; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testclass.d0000644000175000017500000000202313200164642023556 0ustar matthiasmatthiasextern(C) int printf(const char*, ...); /******************************************/ // 12078 class B12078(T) { static assert(is(T : B12078!T), "not related"); } class D12078 : B12078!D12078 { } interface X12078(T) { static assert(is(T : X12078!T), "not related"); } interface Y12078 : X12078!Y12078 { } void test12078() { static assert(is(D12078 : B12078!D12078)); static assert(is(Y12078 : X12078!Y12078)); } /******************************************/ // 12143 class Node12143 { alias typeof(true ? Node12143.init : Class12143.init) V; static assert(is(V == Node12143)); } class Type12143 : Node12143 {} class Class12143 : Type12143 {} /***************************************************/ // 13353 interface Base13353(T) { static assert(is(T : Base13353!T)); } interface Derived13353 : Base13353!Derived13353 { void func(); } class Concrete13353 : Derived13353 { void func() {} } /***************************************************/ int main() { printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/gdb14276.d0000644000175000017500000000043213200164642022713 0ustar matthiasmatthias/* REQUIRED_ARGS: -g PERMUTE_ARGS: GDB_SCRIPT: --- b 21 r echo RESULT= p v[0] + v[1] + v[2] + v[3] --- GDB_MATCH: RESULT=.*1234 */ import core.simd; void main() { version (X86_64) int4 v = [1000, 200, 30, 4]; else int[4] v = [1000, 200, 30, 4]; // BP } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test_shared.sh0000755000175000017500000000115713200164642024257 0ustar matthiasmatthias#!/usr/bin/env bash dir=${RESULTS_DIR}/runnable dmddir=${RESULTS_DIR}${SEP}runnable output_file=${dir}/test_shared.sh.out rm -f ${output_file} if [ ${OS} != "linux" ]; then echo "Skipping shared library test on ${OS}." touch ${output_file} exit 0 fi die() { cat ${output_file} rm -f ${output_file} exit 1 } $DMD -m${MODEL} -of${dmddir}${SEP}test_shared${EXE} -defaultlib=libphobos2.so runnable/extra-files/test_shared.d >> ${output_file} if [ $? -ne 0 ]; then die; fi LD_LIBRARY_PATH=../../phobos/generated/${OS}/release/${MODEL} ${dmddir}${SEP}test_shared${EXE} if [ $? -ne 0 ]; then die; fi ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link11069a.d0000644000175000017500000000033013200164642023247 0ustar matthiasmatthias// REQUIRED_ARGS: -noboundscheck // <-- To remove necessity of _D7imports13std11069array7__arrayZ class Bar { import imports.std11069container; BinaryHeap!(Foo[]) Heap; struct Foo {} } void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/overload.d0000644000175000017500000006770513200164642023406 0ustar matthiasmatthias// EXTRA_SOURCES: imports/ovs1528a.d imports/ovs1528b.d // EXTRA_SOURCES: imports/template_ovs1.d imports/template_ovs2.d imports/template_ovs3.d import imports.template_ovs1; import imports.template_ovs2; import imports.template_ovs3; extern(C) int printf(const char* fmt, ...); template TypeTuple(T...){ alias T TypeTuple; } template Id( T){ alias T Id; } template Id(alias A){ alias A Id; } /***************************************************/ // 1528 int foo1528(long){ return 1; } int foo1528(int[]){ return 2; } int foo1528(T)(T) if ( is(T:real)) { return 3; } int foo1528(T)(T) if (!is(T:real)) { return 4; } int bar1528(T)(T) if (!is(T:real)) { return 4; } int bar1528(T)(T) if ( is(T:real)) { return 3; } int bar1528(int[]){ return 2; } int bar1528(long){ return 1; } @property auto getfoo1528 () { return 1; } @property auto getfoo1528(T)() { return 2; } @property auto getbar1528(T)() { return 2; } @property auto getbar1528 () { return 1; } @property auto setfoo1528 (int) { return 1; } @property auto setfoo1528(T)(int) { return 2; } @property auto setbar1528(T)(int) { return 2; } @property auto setbar1528 (int) { return 1; } struct S1528 { int foo(long){ return 1; } int foo(int[]){ return 2; } int foo(T)(T) if ( is(T:real)) { return 3; } int foo(T)(T) if (!is(T:real)) { return 4; } int bar(T)(T) if (!is(T:real)) { return 4; } int bar(T)(T) if ( is(T:real)) { return 3; } int bar(int[]){ return 2; } int bar(long){ return 1; } @property auto getfoo () { return 1; } @property auto getfoo(T)() { return 2; } @property auto getbar(T)() { return 2; } @property auto getbar () { return 1; } @property auto setfoo (int) { return 1; } @property auto setfoo(T)(int) { return 2; } @property auto setbar(T)(int) { return 2; } @property auto setbar (int) { return 1; } @property auto propboo () { return 1; } @property auto propboo(T)(T) { return 2; } @property auto propbaz(T)(T) { return 2; } @property auto propbaz () { return 1; } } auto ufoo1528 (S1528) { return 1; } auto ufoo1528(T)(S1528) { return 2; } auto ubar1528(T)(S1528) { return 2; } auto ubar1528 (S1528) { return 1; } @property auto ugetfoo1528 (S1528) { return 1; } @property auto ugetfoo1528(T)(S1528) { return 2; } @property auto ugetbar1528(T)(S1528) { return 2; } @property auto ugetbar1528 (S1528) { return 1; } @property auto usetfoo1528 (S1528, int) { return 1; } @property auto usetfoo1528(T)(S1528, int) { return 2; } @property auto usetbar1528(T)(S1528, int) { return 2; } @property auto usetbar1528 (S1528, int) { return 1; } @property auto upropboo1528 (S1528) { return 1; } @property auto upropboo1528(T)(S1528, T) { return 2; } @property auto upropbaz1528(T)(S1528, T) { return 2; } @property auto upropbaz1528 (S1528) { return 1; } void test1528a() { // global assert(foo1528(100) == 1); assert(foo1528(10L) == 1); assert(foo1528([1]) == 2); assert(foo1528(1.0) == 3); assert(foo1528("a") == 4); assert(bar1528(100) == 1); assert(bar1528(10L) == 1); assert(bar1528([1]) == 2); assert(bar1528(1.0) == 3); assert(bar1528("a") == 4); assert(getfoo1528 == 1); assert(getfoo1528!string == 2); assert(getbar1528 == 1); assert(getbar1528!string == 2); assert((setfoo1528 = 1) == 1); assert((setfoo1528!string = 1) == 2); assert((setbar1528 = 1) == 1); assert((setbar1528!string = 1) == 2); S1528 s; // member assert(s.foo(100) == 1); assert(s.foo(10L) == 1); assert(s.foo([1]) == 2); assert(s.foo(1.0) == 3); assert(s.foo("a") == 4); assert(s.bar(100) == 1); assert(s.bar(10L) == 1); assert(s.bar([1]) == 2); assert(s.bar(1.0) == 3); assert(s.bar("a") == 4); assert(s.getfoo == 1); assert(s.getfoo!string == 2); assert(s.getbar == 1); assert(s.getbar!string == 2); assert((s.setfoo = 1) == 1); assert((s.setfoo!string = 1) == 2); assert((s.setbar = 1) == 1); assert((s.setbar!string = 1) == 2); assert((s.propboo = 1) == 2); assert( s.propboo == 1); assert((s.propbaz = 1) == 2); assert( s.propbaz == 1); // UFCS assert(s.ufoo1528 () == 1); assert(s.ufoo1528!string() == 2); assert(s.ubar1528 () == 1); assert(s.ubar1528!string() == 2); assert(s.ugetfoo1528 == 1); assert(s.ugetfoo1528!string == 2); assert(s.ugetbar1528 == 1); assert(s.ugetbar1528!string == 2); assert((s.usetfoo1528 = 1) == 1); assert((s.usetfoo1528!string = 1) == 2); assert((s.usetbar1528 = 1) == 1); assert((s.usetbar1528!string = 1) == 2); assert((s.upropboo1528 = 1) == 2); assert( s.upropboo1528 == 1); assert((s.upropbaz1528 = 1) == 2); assert( s.upropbaz1528 == 1); // overload set import imports.ovs1528a, imports.ovs1528b; assert(func1528() == 1); assert(func1528(1.0) == 2); assert(func1528("a") == 3); assert(func1528([1.0]) == 4); assert(bunc1528() == 1); assert(bunc1528(1.0) == 2); assert(bunc1528("a") == 3); assert(bunc1528([1.0]) == 4); assert(vunc1528(100) == 1); assert(vunc1528("a") == 2); assert(wunc1528(100) == 1); assert(wunc1528("a") == 2); //assert(opUnary1528!"+"(10) == 1); //assert(opUnary1528!"-"(10) == 2); } // ---- int doo1528a(int a, double=10) { return 1; } int doo1528a(int a, string="") { return 2; } int doo1528b(int a) { return 1; } int doo1528b(T:int)(T b) { return 2; } int doo1528c(T:int)(T b, double=10) { return 2; } int doo1528c(T:int)(T b, string="") { return 2; } int doo1528d(int a) { return 1; } int doo1528d(T)(T b) { return 2; } void test1528b() { // MatchLevel by tiargs / by fargs static assert(!__traits(compiles, doo1528a(1))); // 1: MATCHexact / MATCHexact // 2: MATCHexact / MATCHexact static assert(!__traits(compiles, doo1528a(1L))); // 1: MATCHexact / MATCHconvert // 2: MATCHexact / MATCHconvert static assert(!__traits(compiles, doo1528b(1))); // 1: MATCHexact / MATCHexact // 2: MATCHexact / MATCHexact assert(doo1528b(1L) == 1); // 1: MATCHexact / MATCHconvert // 2: MATCHnomatch / - static assert(!__traits(compiles, doo1528c(1))); // 1: MATCHexact / MATCHexact // 2: MATCHexact / MATCHexact static assert(!__traits(compiles, doo1528c(1L))); // 1: MATCHnomatch / - // 2: MATCHnomatch / - assert(doo1528d(1) == 1); // 1: MATCHexact / MATCHexact // 2: MATCHconvert / MATCHexact assert(doo1528d(1L) == 1); // 1: MATCHexact / MATCHconvert // 2: MATCHconvert / MATCHexact // -> not sure, may be ambiguous...? } // ---- char[num*2] toHexString1528(int order, size_t num)(in ubyte[num] digest) { return typeof(return).init; } string toHexString1528(int order)(in ubyte[] digest) { assert(0); } char[8] test1528c() { ubyte[4] foo() { return typeof(return).init; } return toHexString1528!10(foo); } // ---- int f1528d1(int a, double=10) { return 1; } int f1528d1(int a, string="") { return 2; } int f1528d2(T:int)(T b, double=10) { return 1; } int f1528d2(T:int)(T b, string="") { return 2; } // vs deduced parameter int f1528d3(int a) { return 1; } int f1528d3(T)(T b) { return 2; } // vs specialized parameter int f1528d4(int a) { return 1; } int f1528d4(T:int)(T b) { return 2; } // vs deduced parameter + template constraint (1) int f1528d5(int a) { return 1; } int f1528d5(T)(T b) if (is(T == int)) { return 2; } // vs deduced parameter + template constraint (2) int f1528d6(int a) { return 1; } int f1528d6(T)(T b) if (is(T : int)) { return 2; } // vs nallowing conversion int f1528d7(ubyte a) { return 1; } int f1528d7(T)(T b) if (is(T : int)) { return 2; } int f1528d10(int, int) { return 1; } int f1528d10(T)(T, int) { return 2; } void test1528d() { static assert(!__traits(compiles, f1528d1(1))); // ambiguous static assert(!__traits(compiles, f1528d1(1L))); // ambiguous static assert(!__traits(compiles, f1528d2(1))); // ambiguous static assert(!__traits(compiles, f1528d2(1L))); // no match assert(f1528d3(1) == 1); assert(f1528d3(1L) == 1); // '1L' matches int short short_val = 42; assert(f1528d3(cast(short) 42) == 1); assert(f1528d3(short_val) == 1); static assert(!__traits(compiles, f1528d4(1))); assert(f1528d4(1L) == 1); assert(f1528d5(1) == 1); assert(f1528d5(1L) == 1); assert(f1528d6(1) == 1); assert(f1528d6(1L) == 1); static assert(!__traits(compiles, f1528d6(ulong.max))); // no match // needs to fix bug 9617 ulong ulval = 1; static assert(!__traits(compiles, f1528d6(ulval))); // no match assert(f1528d7(200u) == 1); // '200u' matches ubyte assert(f1528d7(400u) == 2); uint uival = 400; // TDPL-like range knowledge lost here. assert(f1528d7(uival) == 2); uival = 200; // Ditto. assert(f1528d7(uival) == 2); assert(f1528d10( 1, 9) == 1); assert(f1528d10( 1U, 9) == 1); assert(f1528d10( 1L, 9) == 1); assert(f1528d10( 1LU, 9) == 1); assert(f1528d10( long.max, 9) == 2); assert(f1528d10(ulong.max, 9) == 2); assert(f1528d10( 1, 9L) == 1); assert(f1528d10( 1U, 9L) == 1); assert(f1528d10( 1L, 9L) == 1); assert(f1528d10( 1LU, 9L) == 1); assert(f1528d10( long.max, 9L) == 2); assert(f1528d10(ulong.max, 9L) == 2); } /***************************************************/ // 1680 struct S1680 { ulong _y; ulong blah1() { return _y; } static S1680 blah1(ulong n) { return S1680(n); } static S1680 blah2(ulong n) { return S1680(n); } static S1680 blah2(char[] n) { return S1680(n.length); } } class C1680 { ulong _y; this(ulong n){} ulong blah1() { return _y; } static C1680 blah1(ulong n) { return new C1680(n); } static C1680 blah2(ulong n) { return new C1680(n); } static C1680 blah2(char[] n) { return new C1680(n.length); } } void test1680() { // OK S1680 s = S1680.blah1(5); void fs() { S1680 s1 = S1680.blah2(5); // OK S1680 s2 = S1680.blah2("hello".dup); // OK S1680 s3 = S1680.blah1(5); // Error: 'this' is only allowed in non-static member functions, not f } C1680 c = C1680.blah1(5); void fc() { C1680 c1 = C1680.blah2(5); C1680 c2 = C1680.blah2("hello".dup); C1680 c3 = C1680.blah1(5); } } /***************************************************/ // 7418 int foo7418(uint a) { return 1; } int foo7418(char[] a) { return 2; } alias foo7418 foo7418a; template foo7418b(T = void) { alias foo7418 foo7418b; } void test7418() { assert(foo7418a(1U) == 1); assert(foo7418a("a".dup) == 2); assert(foo7418b!()(1U) == 1); assert(foo7418b!()("a".dup) == 2); } /***************************************************/ // 7552 struct S7552 { static void foo(){} static void foo(int){} } struct T7552 { alias TypeTuple!(__traits(getOverloads, S7552, "foo")) FooInS; alias FooInS[0] foo; // should be S7552.foo() static void foo(string){} } struct U7552 { alias TypeTuple!(__traits(getOverloads, S7552, "foo")) FooInS; alias FooInS[1] foo; // should be S7552.foo(int) static void foo(string){} } void test7552() { alias TypeTuple!(__traits(getOverloads, S7552, "foo")) FooInS; static assert(FooInS.length == 2); FooInS[0](); static assert(!__traits(compiles, FooInS[0](0))); static assert(!__traits(compiles, FooInS[1]())); FooInS[1](0); Id!(FooInS[0])(); static assert(!__traits(compiles, Id!(FooInS[0])(0))); static assert(!__traits(compiles, Id!(FooInS[1])())); Id!(FooInS[1])(0); alias TypeTuple!(__traits(getOverloads, T7552, "foo")) FooInT; static assert(FooInT.length == 2); // fail FooInT[0](); static assert(!__traits(compiles, FooInT[0](0))); static assert(!__traits(compiles, FooInT[0](""))); static assert(!__traits(compiles, FooInT[1]())); static assert(!__traits(compiles, FooInT[1](0))); // fail FooInT[1](""); // fail alias TypeTuple!(__traits(getOverloads, U7552, "foo")) FooInU; static assert(FooInU.length == 2); static assert(!__traits(compiles, FooInU[0]())); FooInU[0](0); static assert(!__traits(compiles, FooInU[0](""))); static assert(!__traits(compiles, FooInU[1]())); static assert(!__traits(compiles, FooInU[1](0))); FooInU[1](""); } /***************************************************/ // 8668 import imports.m8668a; import imports.m8668c; //replace with m8668b to make it work void test8668() { split8668("abc"); split8668(123); } /***************************************************/ // 8943 void test8943() { struct S { void foo(); } alias TypeTuple!(__traits(getOverloads, S, "foo")) Overloads; alias TypeTuple!(__traits(parent, Overloads[0])) P; // fail static assert(is(P[0] == S)); } /***************************************************/ // 9410 struct S {} int foo(float f, ref S s) { return 1; } int foo(float f, S s) { return 2; } void test9410() { S s; assert(foo(1, s ) == 1); // works fine. Print: ref assert(foo(1, S()) == 2); // Fails with: Error: S() is not an lvalue } /***************************************************/ // 10171 struct B10171(T) { static int x; } void test10171() { auto mp = &B10171!(B10171!int).x; } /***************************************************/ // 1900 - template overload set void test1900a() { // function vs function template with IFTI call assert(foo1900a(100) == 1); assert(foo1900a("s") == 2); assert(foo1900b(100) == 1); assert(foo1900b("s") == 2); // function template call with explicit template arguments assert(foo1900a!string("s") == 2); assert(foo1900b!string("s") == 2); // function template overloaded set call with IFTI assert(bar1900a(100) == 1); assert(bar1900a("s") == 2); assert(bar1900b(100) == 1); assert(bar1900b("s") == 2); // function template overloaded set call with explicit template arguments assert(bar1900a!double(100) == 1); assert(bar1900a!string("s") == 2); assert(bar1900b!double(100) == 1); assert(bar1900b!string("s") == 2); // function template overloaded set call with IFTI assert(baz1900(1234567890) == 1); assert(baz1900([1:1, 2:2]) == 2); assert(baz1900(new Object) == 3); assert(baz1900("deadbeaf") == 4); // function template overloaded set call with explicit template arguments assert(baz1900!(double)(14142135) == 1); assert(baz1900!(int[int])([12:34]) == 2); assert(baz1900!(Object)(new Object) == 3); assert(baz1900!(string)("cafe babe") == 4); static assert(!__traits(compiles, bad1900!"++"())); } void test1900b() { S1900 s; // function vs function template with IFTI call assert(s.foo1900a(100) == 1); assert(s.foo1900a("s") == 2); assert(s.foo1900b(100) == 1); assert(s.foo1900b("s") == 2); // function template call with explicit template arguments assert(s.foo1900a!string("s") == 2); assert(s.foo1900b!string("s") == 2); // function template overloaded set call with IFTI assert(s.bar1900a(100) == 1); assert(s.bar1900a("s") == 2); assert(s.bar1900b(100) == 1); assert(s.bar1900b("s") == 2); // function template overloaded set call with explicit template arguments assert(s.bar1900a!double(100) == 1); assert(s.bar1900a!string("s") == 2); assert(s.bar1900b!double(100) == 1); assert(s.bar1900b!string("s") == 2); // function template overloaded set call with IFTI assert(s.baz1900(1234567890) == 1); assert(s.baz1900([1:1, 2:2]) == 2); assert(s.baz1900(new Object) == 3); assert(s.baz1900("deadbeaf") == 4); // function template overloaded set call with explicit template arguments assert(s.baz1900!(double)(14142135) == 1); assert(s.baz1900!(int[int])([12:34]) == 2); assert(s.baz1900!(Object)(new Object) == 3); assert(s.baz1900!(string)("cafe babe") == 4); static assert(!__traits(compiles, s.bad1900!"++"())); } void test1900c() { S1900 s; // This is a kind of Issue 1528 - [tdpl] overloading template and non-template functions //s.funca(); //s.funca(10); //s.funcb(); //s.funcb(10); // Call function template overload set through mixin member lookup assert(s.mixfooa() == 1); assert(s.mixfooa(10) == 2); assert(s.mixfoob() == 1); assert(s.mixfoob(10) == 2); // Call function template overload set through mixin^2 member lookup assert(s.mixsubfooa() == 1); assert(s.mixsubfooa(10) == 2); assert(s.mixsubfoob() == 1); assert(s.mixsubfoob(10) == 2); // Using mixin identifier can limit overload set assert(s.a.mixfooa() == 1); static assert(!__traits(compiles, s.a.mixfooa(10))); assert(s.b.mixfooa(10) == 2); static assert(!__traits(compiles, s.b.mixfooa())); assert(s.b.mixfoob() == 1); static assert(!__traits(compiles, s.b.mixfoob(10))); assert(s.a.mixfoob(10) == 2); static assert(!__traits(compiles, s.a.mixfoob())); } alias merge1900 = imports.template_ovs1.merge1900; alias merge1900 = imports.template_ovs2.merge1900; void test1900d() { assert( merge1900!double(100) == 1); assert(.merge1900!double(100) == 1); } mixin template Foo1900e(T) { void foo(U : T)() { v++;} } void test1900e() { struct S { int v; mixin Foo1900e!double; mixin Foo1900e!string; void test() { foo!(int); // ScopeExp(ti->tempovers != NULL) foo!(typeof(null)); // ScopeExp(ti->tempovers != NULL) } } S s; assert(s.v == 0); s.test(); assert(s.v == 2); } /***************************************************/ // 1900 void test1900() { AClass1900 a; BClass1900 b; static assert(Traits1900!(AClass1900).name == "AClass"); static assert(Traits1900!(BClass1900).name == "BClass"); static assert(Traits1900!(int).name == "any"); Traits1900!(long) obj; static assert(Value1900a!double == 1); static assert(Value1900b!double == 1); static assert(Value1900a!string == 2); static assert(Value1900b!string == 2); } alias imports.template_ovs1.Traits1900 Traits1900X; alias imports.template_ovs2.Traits1900 Traits1900X; alias imports.template_ovs3.Traits1900 Traits1900X; static assert(Traits1900X!(AClass1900).name == "AClass"); static assert(Traits1900X!(BClass1900).name == "BClass"); static assert(Traits1900X!(int).name == "any"); // Traits1900Y is exact same as imports.template_ovs1.Traits1900. alias imports.template_ovs1.Traits1900 Traits1900Y1; alias imports.template_ovs1.Traits1900 Traits1900Y2; alias Traits1900Y1 Traits1900Y; alias Traits1900Y2 Traits1900Y; static assert(Traits1900Y!(AClass1900).name == "AClass"); static assert(!__traits(compiles, Traits1900Y!(BClass1900))); static assert(!__traits(compiles, Traits1900Y!(int))); template Foo1900(T) { template Bar1900(U : T) { } } mixin Foo1900!(int) A; mixin Foo1900!(char) B; alias Bar1900!(int) bar; //error /***************************************************/ // 7780 mixin template A7780() { template C(int n : 0) { int C = 0; } } mixin template B7780() { template C(int n : 1) { int C = 1; } } class Foo7780 { mixin A7780!(); mixin B7780!(); } void test7780() { assert(Foo7780.C!0 == 0); } /***************************************************/ auto foo7849(string) { return 1; } auto foo7849(dstring) { return 2; } enum str7849a = "string"; immutable str7849ai = "string"; immutable str7849bi = str7849ai; enum str7849b = str7849ai; enum str7849c = str7849bi; void test7849() { assert(foo7849(str7849a) == 1); assert(foo7849(str7849b) == 1); assert(foo7849(str7849c) == 1); } /***************************************************/ // 8352 void test8352() { [1, 2].remove8352a!(x => x == 2)(); [1, 2].remove8352b!(x => x == 2)(); remove8352a("deleteme"); remove8352b("deleteme"); } /***************************************************/ // 8441 mixin template T8441a(string i) { auto j(string s = "a", U)(U u1, U u2) { return 0; } auto j(int i,string s = "a", W)(W u1, W u2) { return i; } mixin(" class F" ~ i ~ " { auto j(string s = \"a\", U)(U u1, U u2) { return this.outer.t" ~ i ~ ".j!(s, U)(u1, u2); } auto j(int i, string s = \"a\", W)(W u1, W u2) { return this.outer.t" ~ i ~ ".j!(i, s, W)(u1, u2); // <- dmd is giving error for j!(...).j's type } } auto f" ~ i ~ "() { return new F" ~ i ~ "(); } "); } class X8441a { mixin T8441a!("1") t0; alias t0 t1; } void test8441a() { auto x = new X8441a(); x.f1().j!(3,"a")(2.2, 3.3); } // ---- mixin template T8441b() { void k()() {} void j()() {} void j(int i)() {} } class X8441b { mixin T8441b t0; } void test8441b() { auto x = new X8441b(); x.k!()(); // Fine x.j!()(); // Fine x.t0.k!()(); // Fine x.t0.j!()(); // Derp } // ---- mixin template Signal8441c(Args...) { bool call = false; final void connect(string method, ClassType)(ClassType obj) if (is(ClassType == class) && __traits(compiles, { void delegate(Args) dg = mixin("&obj."~method); })) { call = true; } } void test8441c() { class Observer { void watchInt(string str, int i) {} } class Bar { mixin Signal8441c!(string, int) s1; mixin Signal8441c!(string, int) s2; mixin Signal8441c!(string, long) s3; } auto a = new Bar; auto o1 = new Observer; a.s1.connect!"watchInt"(o1); assert( a.s1.call); assert(!a.s2.call); assert(!a.s3.call); } /***************************************************/ // 9235 template FlowEvaluator9235() { // if control flow bool execute(Command cmd)() if (cmd == Command.Jump || cmd == Command.Fork) { return false; } } template MatchEvaluator9235() { // if operation bool execute(Command cmd)() if (cmd == Command.Char || cmd == Command.Any || cmd == Command.End) { return true; } } void test9235a() { enum Command { Char, Any, Fork, Jump, End } struct Machine { mixin FlowEvaluator9235; mixin MatchEvaluator9235; bool exec_flow() { return execute!(Command.Jump)(); } bool exec_match() { return execute!(Command.Any)(); } } Machine m; assert(!m.exec_flow()); assert( m.exec_match()); } // ---- mixin template mixA9235() { int foo(string s)() if (s == "a") { return 1; } } mixin template mixB9235() { int foo(string s)() if (s == "b") { return 2; } } struct Foo9235 { mixin mixA9235 A; mixin mixB9235 B; alias A.foo foo; alias B.foo foo; } void test9235b() { Foo9235 f; assert(f.foo!"a"() == 1); assert(f.foo!"b"() == 2); } /***************************************************/ // 10658 alias Val10658 = imports.template_ovs1.Val10658; alias Val10658 = imports.template_ovs2.Val10658; static assert(Val10658!1 == 1); static assert(Val10658!1L == 2); // ---- template Foo10658(T) if (is(T == double)) { enum Foo10658 = 1; } template Bar10658(T) if (is(T == string)) { enum Bar10658 = 2; } alias Baz10658 = Foo10658; alias Baz10658 = Bar10658; template Voo10658(T) if (is(T == cfloat)) { enum Voo10658 = 5; } template Voo10658(T) if (is(T == Object)) { enum Voo10658 = 6; } alias Vaz10658 = Baz10658; // OvarDeclaration alias Vaz10658 = Voo10658; // TemplateDeclaration (overnext != NULL) template Merge10658a(alias A) { enum Merge10658a = A!double + A!string; } template Merge10658b(alias A) { enum Merge10658b = A!double + A!string + A!cfloat + A!Object; } void test10658a() { static assert(Baz10658!double == 1); static assert(Baz10658!string == 2); static assert(Voo10658!cfloat == 5); static assert(Voo10658!Object == 6); // pass OverDeclaration through TemplateAliasParameter static assert(Merge10658a!Baz10658 == 1 + 2); static assert(Merge10658b!Vaz10658 == 1 + 2 + 5 + 6); } // ---- mixin template mix10658A() { int f10658(string s)() if (s == "a") { return 1; } } mixin template mix10658B() { int f10658(string s)() if (s == "b") { return 2; } } mixin mix10658A A10658; mixin mix10658B B10658; alias A10658.f10658 foo10658; alias B10658.f10658 foo10658; mixin template mix10658C() { int f10658(string s, T)(T arg) if (s == "c") { return 3; } } mixin template mix10658D() { int f10658(string s, T)(T arg) if (s == "d") { return 4; } } struct S10658 { mixin mix10658C C10658; mixin mix10658D D10658; alias C10658.f10658 foo10658; alias D10658.f10658 foo10658; } void test10658b() { assert( foo10658!"a"() == 1); assert(.foo10658!"b"() == 2); S10658 s; assert(s.foo10658!"c"(0) == 3); assert(s.foo10658!"d"(0) == 4); } /***************************************************/ class InputStream11785 { long read(ubyte* bytes, long len) { return 0; } void read(T)(ref T val) { read(cast(ubyte*)&val, cast(long)val.sizeof); } } long read11785(ubyte* bytes, long len) { return 0; } void read11785(T)(ref T val) { read11785(cast(ubyte*)&val, cast(long)val.sizeof); } void test11785() { int v; read11785(v); auto input = new InputStream11785(); input.read(v); } /***************************************************/ // 11915 int f11915( int) { return 1; } int f11915(ref int) { return 2; } int g11915( int) { return 1; } int g11915(out int) { return 2; } void test11915() { const int n = 1; assert(f11915(n) == 1); assert(g11915(n) == 1); } /***************************************************/ // 11916 auto f11916(T)( T) { return 1; } auto f11916(T)(out T) if (false) { return 2; } auto g11916(T)( T) { return 1; } auto g11916(T)(out T) { return 2; } void test11916() { const int c = 1; int m = 2; // 'out const int' is invalid function parameter, so (out T) version will be dropped // from overload candidates before template constraint evaluated. assert(f11916(c) == 1); // Both (T) and (out T) have valid signatures with T == int, but the 2nd overload will be // dropped from overload candidates because of the template constraint. assert(f11916(m) == 1); // 'out const int' parameter is invalid, so non-out version is selected. assert(g11916(c) == 1); // MATCHconst for (T) version, and MATCHexact for (out T) version. assert(g11916(m) == 2); } /***************************************************/ // 13783 enum E13783 { a = 5 } inout(int) f( inout(int) t) { return t * 2; } ref inout(int) f(ref inout(int) t) { return t; } void test13783() { const E13783 e = E13783.a; assert(f(e) == 10); } /***************************************************/ int main() { test1528a(); test1528b(); test1528c(); test1528d(); test1680(); test7418(); test7552(); test8668(); test8943(); test9410(); test10171(); test1900a(); test1900b(); test1900c(); test1900d(); test1900e(); test7780(); test7849(); test8352(); test8441a(); test8441b(); test8441c(); test9235a(); test9235b(); test10658a(); test10658b(); test11785(); test11915(); test11916(); test13783(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/arrayop.d0000644000175000017500000004750513200164642023244 0ustar matthiasmatthiasimport std.math; extern(C) int printf(const char*, ...); string abc; template Floating(T) { T[3] a; T[3] b; T[3] c; T[] A() { printf("A\n"); abc ~= "A"; return a; } T[] B() { printf("B\n"); abc ~= "B"; return b; } T[] C() { printf("C\n"); abc ~= "C"; return c; } T D() { printf("D\n"); abc ~= "D"; return 4; } void testx() { a = [11, 22, 33]; b = [1, 2, 3]; c = [4, 5, 6]; abc = null; A()[] = B()[] + C()[]; assert(abc == "BCA"); assert(a[0] == 5); assert(a[1] == 7); assert(a[2] == 9); abc = null; A()[] = B()[] + 4; assert(abc == "BA"); assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 7); abc = null; A()[] = 4 + B()[]; assert(abc == "BA"); assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 7); abc = null; A()[] = D() + B()[]; assert(abc == "DBA"); assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 7); a = [11, 22, 33]; abc = null; A()[] += B()[]; assert(abc == "BA"); assert(a[0] == 12); assert(a[1] == 24); assert(a[2] == 36); a = [11, 22, 33]; A()[] += 4; assert(a[0] == 15); assert(a[1] == 26); assert(a[2] == 37); a = [11, 22, 33]; A()[] -= 4; assert(a[0] == 7); assert(a[1] == 18); assert(a[2] == 29); a = [11, 22, 33]; A()[] *= 4; assert(a[0] == 44); assert(a[1] == 88); assert(a[2] == 132); a = [4, 8, 32]; A()[] /= 4; assert(a[0] == 1); assert(a[1] == 2); assert(a[2] == 8); a = [4, 8, 33]; A()[] %= 4; assert(a[0] == 0); assert(a[1] == 0); assert(a[2] == 1); a = [11, 22, 33]; abc = null; A()[] += 4 + B()[]; assert(abc == "BA"); assert(a[0] == 16); assert(a[1] == 28); assert(a[2] == 40); abc = null; A()[] = B()[] - C()[]; assert(abc == "BCA"); printf("%Lg, %Lg, %Lg\n", cast(real)a[0], cast(real)a[1], cast(real)a[2]); assert(a[0] == -3); assert(a[1] == -3); assert(a[2] == -3); abc = null; A()[] = -B()[] - C()[]; assert(abc == "BCA"); printf("%Lg, %Lg, %Lg\n", cast(real)a[0], cast(real)a[1], cast(real)a[2]); assert(a[0] == -5); assert(a[1] == -7); assert(a[2] == -9); abc = null; A()[] = B()[] + C()[] * 4; assert(abc == "BCA"); printf("%Lg, %Lg, %Lg\n", cast(real)a[0], cast(real)a[1], cast(real)a[2]); assert(a[0] == 17); assert(a[1] == 22); assert(a[2] == 27); abc = null; A()[] = B()[] + C()[] * B()[]; assert(abc == "BCBA"); printf("%Lg, %Lg, %Lg\n", cast(real)a[0], cast(real)a[1], cast(real)a[2]); assert(a[0] == 5); assert(a[1] == 12); assert(a[2] == 21); abc = null; A()[] = B()[] + C()[] / 2; assert(abc == "BCA"); printf("%Lg, %Lg, %Lg\n", cast(real)a[0], cast(real)a[1], cast(real)a[2]); assert(a[0] == 3); assert(a[1] == 4.5); assert(a[2] == 6); abc = null; A()[] = B()[] + C()[] % 2; assert(abc == "BCA"); printf("%Lg, %Lg, %Lg\n", cast(real)a[0], cast(real)a[1], cast(real)a[2]); assert(a[0] == 1); assert(a[1] == 3); assert(a[2] == 3); } } mixin Floating!(float) Ffloat; mixin Floating!(double) Fdouble; mixin Floating!(real) Freal; void test1() { Ffloat.testx(); Fdouble.testx(); Freal.testx(); } /************************************************************************/ template Integral(T) { T[3] a; T[3] b; T[3] c; T[] A() { printf("A\n"); abc ~= "A"; return a; } T[] B() { printf("B\n"); abc ~= "B"; return b; } T[] C() { printf("C\n"); abc ~= "C"; return c; } T D() { printf("D\n"); abc ~= "D"; return 4; } void testx() { a = [11, 22, 33]; b = [1, 2, 3]; c = [4, 5, 6]; abc = null; A()[] = B()[] + C()[]; assert(abc == "BCA"); assert(a[0] == 5); assert(a[1] == 7); assert(a[2] == 9); abc = null; A()[] = B()[] + 4; assert(abc == "BA"); assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 7); abc = null; A()[] = 4 + B()[]; assert(abc == "BA"); assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 7); abc = null; A()[] = D() + B()[]; assert(abc == "DBA"); assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 7); a = [11, 22, 33]; abc = null; A()[] += B()[]; assert(abc == "BA"); assert(a[0] == 12); assert(a[1] == 24); assert(a[2] == 36); a = [11, 22, 33]; A()[] += 4; assert(a[0] == 15); assert(a[1] == 26); assert(a[2] == 37); a = [11, 22, 33]; A()[] -= 4; assert(a[0] == 7); assert(a[1] == 18); assert(a[2] == 29); a = [11, 22, 27]; A()[] *= 4; assert(a[0] == 44); assert(a[1] == 88); assert(a[2] == 108); a = [11, 22, 33]; A()[] /= 4; assert(a[0] == 2); assert(a[1] == 5); assert(a[2] == 8); a = [11, 22, 33]; A()[] %= 4; assert(a[0] == 3); assert(a[1] == 2); assert(a[2] == 1); a = [1, 2, 7]; A()[] &= 4; assert(a[0] == 0); assert(a[1] == 0); assert(a[2] == 4); a = [1, 2, 7]; A()[] |= 4; assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 7); a = [1, 2, 7]; A()[] ^= 4; assert(a[0] == 5); assert(a[1] == 6); assert(a[2] == 3); a = [11, 22, 33]; abc = null; A()[] += 4 + B()[]; assert(abc == "BA"); assert(a[0] == 16); assert(a[1] == 28); assert(a[2] == 40); abc = null; A()[] = B()[] - C()[]; assert(abc == "BCA"); printf("%lld, %lld, %lld\n", cast(long)a[0], cast(long)a[1], cast(long)a[2]); assert(a[0] == -3); assert(a[1] == -3); assert(a[2] == -3); abc = null; A()[] = -B()[] - C()[]; assert(abc == "BCA"); printf("%lld, %lld, %lld\n", cast(long)a[0], cast(long)a[1], cast(long)a[2]); assert(a[0] == -5); assert(a[1] == -7); assert(a[2] == -9); abc = null; A()[] = B()[] + C()[] * 4; assert(abc == "BCA"); printf("%lld, %lld, %lld\n", cast(long)a[0], cast(long)a[1], cast(long)a[2]); assert(a[0] == 17); assert(a[1] == 22); assert(a[2] == 27); abc = null; A()[] = B()[] + C()[] * B()[]; assert(abc == "BCBA"); printf("%lld, %lld, %lld\n", cast(long)a[0], cast(long)a[1], cast(long)a[2]); assert(a[0] == 5); assert(a[1] == 12); assert(a[2] == 21); abc = null; A()[] = B()[] + C()[] / 2; assert(abc == "BCA"); printf("%lld, %lld, %lld\n", cast(long)a[0], cast(long)a[1], cast(long)a[2]); assert(a[0] == 3); assert(a[1] == 4); assert(a[2] == 6); abc = null; A()[] = B()[] + C()[] % 2; assert(abc == "BCA"); printf("%lld, %lld, %lld\n", cast(long)a[0], cast(long)a[1], cast(long)a[2]); assert(a[0] == 1); assert(a[1] == 3); assert(a[2] == 3); abc = null; A()[] = ~B()[]; assert(abc == "BA"); assert(a[0] == ~cast(T)1); assert(a[1] == ~cast(T)2); assert(a[2] == ~cast(T)3); abc = null; A()[] = B()[] & 2; assert(abc == "BA"); assert(a[0] == 0); assert(a[1] == 2); assert(a[2] == 2); abc = null; A()[] = B()[] | 2; assert(abc == "BA"); assert(a[0] == 3); assert(a[1] == 2); assert(a[2] == 3); abc = null; A()[] = B()[] ^ 2; assert(abc == "BA"); assert(a[0] == 3); assert(a[1] == 0); assert(a[2] == 1); } } /************************************************************************/ mixin Integral!(byte) Fbyte; mixin Integral!(short) Fshort; mixin Integral!(int) Fint; mixin Integral!(long) Flong; void test2() { Fbyte.testx(); Fshort.testx(); Fint.testx(); Flong.testx(); } /************************************************************************/ void test3() { auto a = new double[10], b = a.dup, c = a.dup, d = a.dup; a[] = -(b[] * (c[] + 4)) + 5 * d[] / 3.0; } /************************************************************************/ void test4() { int[] a, b; if (a && b) {} } /***************************************************/ void test4662() { immutable double[] nums = [1.0, 2.0]; static assert(!is(typeof({ nums[] += nums[]; }))); static assert(!is(typeof({ nums[] -= nums[]; }))); static assert(!is(typeof({ nums[] /= nums[]; }))); static assert(!is(typeof({ nums[] += 4; }))); static assert(!is(typeof({ nums[] /= 7; }))); } /***************************************************/ // 5284 void bug5284_1() { class C { int v; } C [] mda; immutable(C)[] ida; static assert(!__traits(compiles, (mda[] = ida[]))); C [1] msa; immutable(C)[1] isa; static assert(!__traits(compiles, (msa[] = isa[]))); C m; immutable(C) i; static assert(!__traits(compiles, m = i)); } void bug5284_2a() { struct S { int v; } S [] mda; immutable(S)[] ida; mda[] = ida[]; S [1] msa; immutable(S)[1] isa; msa[] = isa[]; S m = S(); immutable(S) i = immutable(S)(); m = i; } void bug5284_2b() { struct S { int v; int[] arr; } S [] mda; immutable(S)[] ida; static assert(!__traits(compiles, (mda[] = ida[]))); S [1] msa; immutable(S)[1] isa; static assert(!__traits(compiles, (msa[] = isa[]))); S m; immutable(S) i; static assert(!__traits(compiles, m = i)); } void bug5284_3() { int [] ma; immutable(int)[] ia; ma[] = ia[]; int m; immutable(int) i; m = i; } void test5() { bug5284_1(); bug5284_2a(); bug5284_2b(); bug5284_3(); } /************************************************************************/ void test6() { int[10] a = [1,2,3,4,5,6,7,8,9,10]; int[10] b; b = a[] ^^ 2; assert(b[0] == 1); assert(b[1] == 4); assert(b[2] == 9); assert(b[3] == 16); assert(b[4] == 25); assert(b[5] == 36); assert(b[6] == 49); assert(b[7] == 64); assert(b[8] == 81); assert(b[9] == 100); int[10] c = 3; b = a[] ^^ c[]; assert(b[0] == 1); assert(b[1] == 8); assert(b[2] == 27); assert(b[3] == 64); assert(b[4] == 125); assert(b[5] == 216); assert(b[6] == 343); assert(b[7] == 512); assert(b[8] == 729); assert(b[9] == 1000); } /************************************************************************/ void test8390() { const int[] a = new int[5]; int[] b = new int[5]; b[] += a[]; } /************************************************************************/ // 8651 void test8651() { void test(T)() @safe pure nothrow { T[3] a = [11, 22, 33]; T[3] b = [1, 2, 3]; T[3] c = [4, 5, 6]; T d = 4; // Arithmetic array ops { a[] = b[] + c[]; a[] = b[] + 4; a[] = 4 + b[]; a[] = d + b[]; a[] += b[]; a[] += 4; a[] -= 4; a[] *= 4; a[] /= 4; a[] %= 4; a[] += 4 + b[]; a[] = b[] - c[]; a[] = -b[] - c[]; a[] = b[] + c[] * 4; a[] = b[] + c[] * b[]; a[] = b[] + c[] / 2; a[] = b[] + c[] % 2; } // Bitwise array ops static if (is(typeof(T.init & T.init))) { a[] &= 4; a[] |= 4; a[] ^= 4; a[] = ~b[]; a[] = b[] & 2; a[] = b[] | 2; a[] = b[] ^ 2; } } test!float(); test!double(); test!real(); test!byte(); test!short(); test!int(); test!long(); } /************************************************************************/ // 9656 void test9656() { static class C {} static struct S { immutable int[] narr1; immutable int[] narr2; immutable C[] carr1; immutable C[] carr2; this(int n) { narr1 = new int[](3); // OK, expected narr2 = [1,2,3].dup; // NG -> OK carr1 = [new C].dup; // NG -> OK C c = new C; static assert(!__traits(compiles, carr2 = [c])); } } { int[] ma = [1,2,3]; immutable ia = ma.dup; } { static struct V { int val; } V[] ma = [V(1), V(2)]; immutable ia = ma.dup; } { static struct R { int* ptr; } R[] ma = [R(new int), R(null)]; static assert(!__traits(compiles, { immutable ia = rarr.dup; })); } { C[] ma = [new C(), new C()]; static assert(!__traits(compiles, { immutable ia = carr.dup; })); } } /************************************************************************/ // 10282 void test10282() { int[3] a1 = [1, 3, 6]; int[3] a2 = [1, 3, 6] * 3; // OK const int[3] a3 = a1[] * 3; // OK <- Error const int[3] a4 = [1, 3, 6] * 3; // OK <- Error immutable int[3] a5 = [1, 3, 6] * 3; // OK <- Error } /************************************************************************/ // 10433 void test10433() { void foo(T)(in int[] v1, in T v2) { int[2] r; r[] = v1[] + v2[]; } immutable int[] v = [10, 20]; foo(v, v); } /************************************************************************/ // 10684 void test10684a() { int[] a = [0, 0]; a[] += [10, 20][]; } void test10684b() { int[] a = [1, 2, 3]; int[] b = [4, 5, 6]; // Allow array literal as the operand of array oeration a[] += [1, 2, 3]; assert(a == [2, 4, 6]); a[] *= b[] + [1, 1, 1]; assert(a == [2*(4+1), 4*(5+1), 6*(6+1)]); a[] = [9, 8, 7] - [1, 2, 3]; assert(a == [8, 6, 4]); a[] = [2, 4, 6] / 2; assert(a == [1,2,3]); // Disallow: [1,2,3] is not an lvalue static assert(!__traits(compiles, { [1,2,3] = a[] * 2; })); static assert(!__traits(compiles, { [1,2,3] += a[] * b[]; })); } /************************************************************************/ // 11376 template TL11376(T...) { alias TL11376 = T; } auto sumArrs11376(T0, T1)(T0[] a, T1[] b) { a[] += b[]; //no ICE without this line return a; } static assert(!__traits(compiles, sumArrs11376(TL11376!(string[], string).init))); /************************************************************************/ // 11525 void test11525() { static struct Complex(T) { T re, im; ref opOpAssign(string op : "*")(Complex z) { auto temp = re*z.re - im*z.im; im = im*z.re + re*z.im; re = temp; return this; } } auto a = [Complex!double(2, 2)]; assert(a.length == 1 && a[0].re == 2 && a[0].im == 2); a[] *= a[]; assert(a.length == 1 && a[0].re == 0 && a[0].im == 8); } /************************************************************************/ // 12250 void f12250(inout int[] p, inout int[] q, int[] r) { r[] = p[] + q[]; assert(r == [5,7,9]); r[] -= p[] - q[]; assert(r == [8,10,12]); } void test12250() { immutable int[3] x = [1,2,3], y = [4,5,6]; int[3] z; f12250(x[], y[], z[]); } /************************************************************************/ // 12179 void test12179() { void foo(int[]) {} int[1] a; foo(a[] = a[]); foo(a[] += a[]); foo(a[] -= a[]); foo(a[] *= a[]); foo(a[] /= a[]); foo(a[] %= a[]); foo(a[] ^= a[]); foo(a[] &= a[]); foo(a[] |= a[]); foo(a[] ^^= a[]); // from issue 11992 int[] arr1; int[][] arr2; arr1 ~= (a[] = [1] + a[]); // OK arr2 ~= (a[] = [1] + a[]); // OK } /************************************************************************/ // 12780 void test12780() { int ival = 2; int[] iarr = [1, 2, 3]; double dval = 2.0; double[] darr = [4, 5, 6]; double[] oarr = [0, 0, 0]; // multiply array operations oarr[] = dval * iarr[]; assert(oarr == [dval * iarr[0], dval * iarr[1], dval * iarr[2]]); oarr[] = iarr[] / dval; assert(oarr == [iarr[0] / dval, iarr[1] / dval, iarr[2] / dval]); oarr[] = dval * (ival + iarr[]); assert(oarr == [dval * (ival + iarr[0]), dval * (ival + iarr[1]), dval * (ival + iarr[2])]); oarr[] = (iarr[] & ival) / dval; assert(oarr == [(iarr[0] & ival) / dval, (iarr[1] & ival) / dval, (iarr[2] & ival) / dval]); oarr[] = darr[] + iarr[]; assert(oarr == [darr[0] + iarr[0], darr[1] + iarr[1], darr[2] + iarr[2]]); oarr[] = iarr[] - darr[]; assert(oarr == [iarr[0] - darr[0], iarr[1] - darr[1], iarr[2] - darr[2]]); oarr[] = darr[] * (ival & iarr[]); assert(oarr == [darr[0] * (ival & iarr[0]), darr[1] * (ival & iarr[1]), darr[2] * (ival & iarr[2])]); oarr[] = (iarr[] ^ ival) / darr[]; assert(oarr == [(iarr[0] ^ ival) / darr[0], (iarr[1] ^ ival) / darr[1], (iarr[2] ^ ival) / darr[2]]); } /************************************************************************/ // 13497 void test13497() { int[1] a = [2], b = [3]; int[1] c1 = a[] * b[]; int[1] c2 = (a[] * b[])[]; assert(c1 == [6]); assert(c2 == [6]); } /************************************************************************/ // 14649 void test14649() { char[] a = "abc".dup; char[] b = [char(1), char(2), char(3)]; string x = "abc"; string y = [char(1), char(2), char(3)]; char[] r = new char[](3); r[] = a[] + b[]; assert(r == "bdf"); r[] = x[] + y[]; assert(r == "bdf"); r[] = "hel"[] + "lo."[]; assert(r == [('h'+'l'), ('e'+'o'), ('l'+'.')]); enum s = "abc"; r[] = s[0..3] + "def"[0..3]; assert(r == [('a'+'d'), ('b'+'e'), ('c'+'f')]); } /************************************************************************/ // 14851 void test14851() { int[8] a, b, c; c = a[] | b[]; // OK <- NG from 2.068.0-b2 c = a[] ^ b[]; // OK <- NG from 2.068.0-b2 c[] = a[] | b[]; // OK c[] = a[] ^ b[]; // OK } /************************************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test8390(); test8651(); test9656(); test10282(); test10433(); test10684a(); test10684b(); test11525(); test12250(); test12780(); test13497(); test14649(); test14851(); printf("Success\n"); return 0; } version (none) { extern (C) T[] _arraySliceSliceAddSliceAssignd(T[] a, T[] c, T[] b) { foreach (i; 0 .. a.length) a[i] = b[i] + c[i]; return a; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/template3.d0000644000175000017500000000701513200164642023455 0ustar matthiasmatthias import core.stdc.stdio; /*********************************************************/ template Foo(T) { static if (is(T : int)) alias T t1; static if (T.sizeof == 4) alias T t2; static if (is(T U : int)) alias U t3; static if (is(T* V : V*)) alias V t4; static if (is(T W)) alias W t5; else alias char t5; static if (is(T* X : X*)) { } } void test1() { Foo!(int).t1 x1; assert(typeid(typeof(x1)) == typeid(int)); Foo!(int).t2 x2; assert(typeid(typeof(x2)) == typeid(int)); Foo!(int).t3 x3; assert(typeid(typeof(x3)) == typeid(int)); Foo!(int*).t4 x4; assert(typeid(typeof(x4)) == typeid(int*)); Foo!(int).t5 x5; assert(typeid(typeof(x5)) == typeid(int)); Foo!(int).X x6; assert(typeid(typeof(x6)) == typeid(int)); } /*********************************************************/ void test2() { alias int T; static if (is(T : int)) alias T t1; static if (T.sizeof == 4) alias T t2; static if (is(T U : int)) alias U t3; static if (is(T* V : V*)) alias V t4; static if (is(T W)) alias W t5; else alias char t5; static if (is(T* X : X*)) { } t1 x1; assert(typeid(typeof(x1)) == typeid(int)); t2 x2; assert(typeid(typeof(x2)) == typeid(int)); t3 x3; assert(typeid(typeof(x3)) == typeid(int)); t4 x4; assert(typeid(typeof(x4)) == typeid(int)); t5 x5; assert(typeid(typeof(x5)) == typeid(int)); X x6; assert(typeid(typeof(x6)) == typeid(int)); } /*********************************************************/ void test3() { static if (is(short : int)) { printf("1\n"); } else assert(0); static if (is(short == int)) assert(0); static if (is(int == int)) { printf("3\n"); } else assert(0); } /*********************************************************/ template TValue(int i:1) { pragma(msg,"last instantiation!!!"); const int TValue = 1; } template TValue(int i) { pragma(msg,"instantiating..."); const int TValue = i * TValue!(i-1); } void test4() { assert(TValue!(3) == 6); } /*********************************************************/ template Reverse(string s: "") { const char[] Reverse = ""; } template Reverse(string s) { const char[] Reverse = Reverse!(s[1..$]) ~ s[0]; } void test5() { assert(Reverse!("Recursive string template") == "etalpmet gnirts evisruceR"); } /*********************************************************/ template foo6(alias V) { int foo6() { return V; } } class bar6(alias V) { int abc() { return V; } } void test6() { int j = 3; int k = 4; int i = foo6!(j)(); i += foo6!(j)(); i += foo6!(k)(); bar6!(j) b = new bar6!(j); i -= b.abc(); assert(i == 7); } /*********************************************************/ template Bind7(alias dg) { int Bind7() { dg('c'); return 0; } } void test7() { char[] v; void foo(char c) { v ~= c; } alias Bind7!(foo) intv; intv(); assert(v[0] == 'c'); } /*********************************************************/ template sum8(real x) { static if (x <= 1.0L){ const real sum8 = x; }else{ const real sum8 = x + sum8!(x - 1.0L); } } void test8() { real x = sum8!(3.0L); if(x != 6.0L){ assert(0); } } /*********************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link2500.d0000644000175000017500000000037413200164642023024 0ustar matthiasmatthias// EXTRA_SOURCES: imports/link2500a.d // EXTRA_SOURCES: imports/link2500b.d // COMPILE_SEPARATELY: module link2500; import imports.link2500a; import imports.link2500b; public class A { S!A c; } void main() { A a = new A(); a.c.foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test42a.d0000644000175000017500000005350013200164642023045 0ustar matthiasmatthias// PERMUTE_ARGS: module test42; import core.stdc.stdio; /***************************************************/ void test1() { ubyte[] data2 = [ 3,3,3,3, 3,3,3,3, 3,3,3,3, 3,3,3, ]; foreach (i; data2) { //printf("i = %d\n", i); assert(i == 3); } ubyte[] data = [ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7]; foreach (i; data) { //printf("i = %d\n", i); assert(i == 7); } } /***************************************************/ int main() { test1(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/template13478.d0000644000175000017500000000034713200164642024002 0ustar matthiasmatthias/// Tests emission of templates also referenced in speculative contexts. /// Failure triggered with -inline. module template13478; import imports.template13478a; import imports.template13478b; int main() { return foo!int(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testthread2.d0000644000175000017500000000476013200164642024014 0ustar matthiasmatthias// PERMUTE_ARGS: import std.algorithm : map; import std.random : Random, uniform, unpredictableSeed; import std.range : repeat; import std.stdio : writeln; // Quick, dirty and inefficient AA using linear search, useful for testing. struct LinearAA(K, V) { K[] keys; V[] values; V opIndex(K key) { foreach(i, k; keys) { if(k == key) { return values[i]; } } assert(0, "Key not present."); } V opIndexAssign(V val, K key) { foreach(i, k; keys) { if(k == key) { return values[i] = val; } } keys ~= key; values ~= val; return val; } V* opIn_r(K key) { foreach(i, k; keys) { if(key == k) { return values.ptr + i; } } return null; } void remove(K key) { size_t i = 0; for(; i < keys.length; i++) { if(keys[i] == key) { break; } } assert(i < keys.length); for(; i < keys.length - 1; i++) { keys[i] = keys[i + 1]; values[i] = values[i + 1]; } keys = keys[0..$ - 1]; values = values[0..$ - 1]; } size_t length() { return values.length; } } void main() { Random gen; uint[] seed; gen.seed(map!((a) { seed ~= unpredictableSeed; return seed[$-1]; })(repeat(0))); writeln(seed); foreach(iter; 0..10) { // Bug only happens after a few iterations. writeln(iter); uint[size_t] builtin; LinearAA!(size_t, uint) linAA; uint[] nums = new uint[100_000]; foreach(ref num; nums) { num = uniform(0U, uint.max, gen); } foreach(i; 0..10_000) { auto index = uniform(0, nums.length, gen); if(index in builtin) { assert(index in linAA); assert(builtin[index] == nums[index]); assert(linAA[index] == nums[index]); builtin.remove(index); linAA.remove(index); } else { assert(!(index in linAA)); builtin[index] = nums[index]; linAA[index] = nums[index]; } } assert(builtin.length == linAA.length); foreach(k, v; builtin) { assert(k in linAA); assert(*(k in builtin) == *(k in linAA)); assert(linAA[k] == v); } } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_214.d0000644000175000017500000000051413200164642024246 0ustar matthiasmatthiasextern(C) int printf(const char*, ...); struct ArrayContainer { int[size_t] _myArray; @property auto myArray() { return _myArray; } void add(size_t i) { _myArray[i] = 0; } } void main() { ArrayContainer x; x.add(10); foreach(i; x.myArray.keys) printf("%d\n", i); }ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/issue8671.d0000644000175000017500000000011313200164642023225 0ustar matthiasmatthiasimport std.random; void main() { double t = 1.0 - uniform(0.0, 1.0); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link13415.d0000644000175000017500000000027013200164642023106 0ustar matthiasmatthias// EXTRA_SOURCES: imports/link13415a.d // REQUIRED_ARGS: -inline // PERMUTE_ARGS: -allinst -unittest -debug // COMPILE_SEPARATELY import imports.link13415a; void main() { f(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_1101.d0000644000175000017500000000016113200164642024320 0ustar matthiasmatthiasstruct Foo { Foo[] bar = []; this(const int x) {} } void main() { Foo f; assert(f.bar.length == 0); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test7494.d0000644000175000017500000000072713200164642023071 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test7494a.d // PERMUTE_ARGS: // REQUIRED_ARGS: module test7494; void main() { import imports.test7494a : map; // selective import imports.test7494a : put = writeln; // selective + rename auto r = map!(a=>a)([1,2,3]); assert(r == [4,5,6]); put(r); static assert(!__traits(compiles, foo())); import core.bitop : bsr; // ^ or just any selective import statements bsr(1); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/stress.d0000644000175000017500000007154613200164642023114 0ustar matthiasmatthias// PERMUTE_ARGS: import core.stdc.stdio : printf; import std.string : splitLines; import std.utf : toUTF16, toUTF32; /***********************************************/ void test3() { char[] str; str ~= "test"; // segfault } /***********************************************/ class A { private: int _i; public: this(int i) { _i = i; } int i() { return _i; }; } class B : A { private: char[] s; public: this(int i) { super(i); } } int main() { printf("Testing array of Chars\n"); CHAR(); printf("Testing array of WChars\n"); WCHAR(); printf("Testing array of DChars\n"); DCHAR(); printf("Testing array of Bytes\n"); BYTE(); printf("Testing array of UBytes\n"); UBYTE(); printf("Testing array of Shorts\n"); SHORT(); printf("Testing array of UShorts\n"); USHORT(); printf("Testing array of Ints\n"); INT(); printf("Testing array of UInts\n"); UINT(); printf("Testing array of Longs\n"); LONG(); printf("Testing array of ULongs\n"); ULONG(); printf("Testing array of Floats\n"); FLOAT(); printf("Testing array of Doubles\n"); DOUBLE(); printf("Testing array of Reals\n"); REAL(); printf("Testing multi-dim array of Chars\n"); MDCHAR(); printf("Testing array of Objects\n"); CLASS(); test3(); return 0; } void MDCHAR() { const int ITERS = 100; alias char typ; typ[][] str; str.length = ITERS; for(int idx = 0; idx < ITERS; idx++) { str[idx] = str[idx] ~ "TEST LINE\n"; } if(str.length != ITERS) printf("Length Error: %d\n",str.length); if(str[0].length != 10) printf("Length Error: %d\n",str[0].length); if(str[ITERS-1].sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str[ITERS-1].sizeof); if(str[ITERS-1][0].sizeof != (typ).sizeof) printf("Size Error: %d\n",str[ITERS-1][0].sizeof); foreach(s; str) { int lstart; foreach(int idx, char c; s) { if(c == '\n') { typ[] t = s[lstart..idx]; if(t != "TEST LINE") { printf("Error testing character array\n"); break; } lstart = idx + 1; } } } typ[] tmp; foreach(char[] s; str) { tmp = tmp ~ s; } foreach(s; splitLines(cast(string)tmp)) { int lstart; foreach(int idx, char c; s) { if(c == '\n') { if(s[lstart..idx] != "TEST LINE") { printf("Error testing character array\n"); break; } lstart = idx + 1; } } } } void CHAR() { const int ITERS = 1000; alias char typ; typ[] str; for(int idx = 0; idx < ITERS; idx++) { str = str ~ "TEST LINE\n"; } if(str.length != (ITERS * 10)) printf("Length Error: %d\n",str.length); if(str.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str.sizeof); int lstart; foreach(int idx, char c; str) { if(c == '\n') { if(str[lstart..idx] != "TEST LINE") { printf("Error testing character array\n"); break; } lstart = idx + 1; } } } void WCHAR() { const int ITERS = 1000; alias wchar typ; typ[] str; for(int idx = 0; idx < ITERS; idx++) { str = str ~ toUTF16(cast(char[])"TEST LINE\n"); } if(str.length != (ITERS * 10)) printf("Length Error: %d\n",str.length); if(str.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str.sizeof); int lstart; foreach(int idx, char c; str) { if(c == '\n') { if(str[lstart..idx] != toUTF16(cast(char[])"TEST LINE")) { printf("Error testing character array\n"); break; } lstart = idx + 1; } } } void DCHAR() { const int ITERS = 1000; alias dchar typ; typ[] str; for(int idx = 0; idx < ITERS; idx++) { str = str ~ toUTF32(cast(char[])"TEST LINE\n"); } if(str.length != (ITERS * 10)) printf("Length Error: %d\n",str.length); if(str.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str.sizeof); int lstart; foreach(int idx, char c; str) { if(c == '\n') { if(str[lstart..idx] != toUTF32(cast(char[])"TEST LINE")) { printf("Error testing character array\n"); break; } lstart = idx + 1; } } } void BYTE() { const int ITERS = 100; alias byte typ; typ[] a; for(typ idx = 0; idx < ITERS; idx++) { a ~= idx; } if(a.length != ITERS) printf("Length Error: %d\n",a.length); if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); break; } } a.reverse; for(int idx = 0; idx < ITERS; idx++) { if(a[a.length - idx - 1] != idx) { printf("a Reverse Error: %d\n",a[idx]); break; } } a.sort; for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Sort Error: %d\n",a[idx]); break; } } typ[] b = a[]; if(b.length != ITERS) printf("Length Error: %d\n",b.length); if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); break; } } b.reverse; for(int idx = 0; idx < ITERS; idx++) { if(b[b.length - idx - 1] != idx) { printf("b Reverse Error: %d\n",b[idx]); break; } } b.sort; for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Sort Error: %d\n",b[idx]); break; } } typ[] c; c = a[0..ITERS/2] ~ b[ITERS/2..$]; if(c.length != ITERS) printf("Length Error: %d\n",c.length); if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); break; } } c.reverse; for(int idx = 0; idx < ITERS; idx++) { if(c[c.length - idx - 1] != idx) { printf("c Reverse Error: %d\n",c[idx]); break; } } c.sort; for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Sort Error: %d\n",c[idx]); break; } } } void UBYTE() { const int ITERS = 100; alias ubyte typ; typ[] a; for(typ idx = 0; idx < ITERS; idx++) { a ~= idx; } if(a.length != ITERS) printf("Length Error: %d\n",a.length); if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); break; } } a.reverse; for(int idx = 0; idx < ITERS; idx++) { if(a[a.length - idx - 1] != idx) { printf("a Reverse Error: %d\n",a[idx]); break; } } a.sort; for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Sort Error: %d\n",a[idx]); break; } } typ[] b = a[]; if(b.length != ITERS) printf("Length Error: %d\n",b.length); if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); break; } } b.reverse; for(int idx = 0; idx < ITERS; idx++) { if(b[b.length - idx - 1] != idx) { printf("b Reverse Error: %d\n",b[idx]); break; } } b.sort; for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Sort Error: %d\n",b[idx]); break; } } typ[] c; c = a[0..ITERS/2] ~ b[ITERS/2..$]; if(c.length != ITERS) printf("Length Error: %d\n",c.length); if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); break; } } c.reverse; for(int idx = 0; idx < ITERS; idx++) { if(c[c.length - idx - 1] != idx) { printf("c Reverse Error: %d\n",c[idx]); break; } } c.sort; for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Sort Error: %d\n",c[idx]); break; } } } void SHORT() { const int ITERS = 10000; alias short typ; typ[] a; for(typ idx = 0; idx < ITERS; idx++) { a ~= idx; } if(a.length != ITERS) printf("Length Error: %d\n",a.length); if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); break; } } a.reverse; for(int idx = 0; idx < ITERS; idx++) { if(a[a.length - idx - 1] != idx) { printf("a Reverse Error: %d\n",a[idx]); break; } } a.sort; for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Sort Error: %d\n",a[idx]); break; } } typ[] b = a[]; if(b.length != ITERS) printf("Length Error: %d\n",b.length); if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); break; } } b.reverse; for(int idx = 0; idx < ITERS; idx++) { if(b[b.length - idx - 1] != idx) { printf("b Reverse Error: %d\n",b[idx]); break; } } b.sort; for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Sort Error: %d\n",b[idx]); break; } } typ[] c; c = a[0..ITERS/2] ~ b[ITERS/2..$]; if(c.length != ITERS) printf("Length Error: %d\n",c.length); if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); break; } } c.reverse; for(int idx = 0; idx < ITERS; idx++) { if(c[c.length - idx - 1] != idx) { printf("c Reverse Error: %d\n",c[idx]); break; } } c.sort; for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Sort Error: %d\n",c[idx]); break; } } } void USHORT() { const int ITERS = 10000; alias ushort typ; typ[] a; for(typ idx = 0; idx < ITERS; idx++) { a ~= idx; } if(a.length != ITERS) printf("Length Error: %d\n",a.length); if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); break; } } a.reverse; for(int idx = 0; idx < ITERS; idx++) { if(a[a.length - idx - 1] != idx) { printf("a Reverse Error: %d\n",a[idx]); break; } } a.sort; for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Sort Error: %d\n",a[idx]); break; } } typ[] b = a[]; if(b.length != ITERS) printf("Length Error: %d\n",b.length); if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); break; } } b.reverse; for(int idx = 0; idx < ITERS; idx++) { if(b[b.length - idx - 1] != idx) { printf("b Reverse Error: %d\n",b[idx]); break; } } b.sort; for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Sort Error: %d\n",b[idx]); break; } } typ[] c; c = a[0..ITERS/2] ~ b[ITERS/2..$]; if(c.length != ITERS) printf("Length Error: %d\n",c.length); if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); break; } } c.reverse; for(int idx = 0; idx < ITERS; idx++) { if(c[c.length - idx - 1] != idx) { printf("c Reverse Error: %d\n",c[idx]); break; } } c.sort; for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Sort Error: %d\n",c[idx]); break; } } } void INT() { const int ITERS = 1000000; alias int typ; typ[] a; for(int idx = 0; idx < ITERS; idx++) { a ~= idx; } if(a.length != ITERS) printf("Length Error: %d\n",a.length); if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); break; } } a.reverse; for(int idx = 0; idx < ITERS; idx++) { if(a[a.length - idx - 1] != idx) { printf("a Reverse Error: %d\n",a[idx]); break; } } a.sort; for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Sort Error: %d\n",a[idx]); break; } } typ[] b = a[]; if(b.length != ITERS) printf("Length Error: %d\n",b.length); if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); break; } } b.reverse; for(int idx = 0; idx < ITERS; idx++) { if(b[b.length - idx - 1] != idx) { printf("b Reverse Error: %d\n",b[idx]); break; } } b.sort; for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Sort Error: %d\n",b[idx]); break; } } typ[] c; c = a[0..ITERS/2] ~ b[ITERS/2..$]; if(c.length != ITERS) printf("Length Error: %d\n",c.length); if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); break; } } c.reverse; for(int idx = 0; idx < ITERS; idx++) { if(c[c.length - idx - 1] != idx) { printf("c Reverse Error: %d\n",c[idx]); break; } } c.sort; for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Sort Error: %d\n",c[idx]); break; } } } void UINT() { const int ITERS = 1000000; alias uint typ; typ[] a; for(int idx = 0; idx < ITERS; idx++) { a ~= idx; } if(a.length != ITERS) printf("Length Error: %d\n",a.length); if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); break; } } a.reverse; for(int idx = 0; idx < ITERS; idx++) { if(a[a.length - idx - 1] != idx) { printf("a Reverse Error: %d\n",a[idx]); break; } } a.sort; for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Sort Error: %d\n",a[idx]); break; } } typ[] b = a[]; if(b.length != ITERS) printf("Length Error: %d\n",b.length); if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); break; } } b.reverse; for(int idx = 0; idx < ITERS; idx++) { if(b[b.length - idx - 1] != idx) { printf("b Reverse Error: %d\n",b[idx]); break; } } b.sort; for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Sort Error: %d\n",b[idx]); break; } } typ[] c; c = a[0..ITERS/2] ~ b[ITERS/2..$]; if(c.length != ITERS) printf("Length Error: %d\n",c.length); if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); break; } } c.reverse; for(int idx = 0; idx < ITERS; idx++) { if(c[c.length - idx - 1] != idx) { printf("c Reverse Error: %d\n",c[idx]); break; } } c.sort; for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Sort Error: %d\n",c[idx]); break; } } } void LONG() { const int ITERS = 1000000; alias long typ; typ[] a; for(int idx = 0; idx < ITERS; idx++) { a ~= idx; } if(a.length != ITERS) printf("Length Error: %d\n",a.length); if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); break; } } a.reverse; for(int idx = 0; idx < ITERS; idx++) { if(a[a.length - idx - 1] != idx) { printf("a Reverse Error: %d\n",a[idx]); break; } } a.sort; for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Sort Error: %d\n",a[idx]); break; } } typ[] b = a[]; if(b.length != ITERS) printf("Length Error: %d\n",b.length); if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); break; } } b.reverse; for(int idx = 0; idx < ITERS; idx++) { if(b[b.length - idx - 1] != idx) { printf("b Reverse Error: %d\n",b[idx]); break; } } b.sort; for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Sort Error: %d\n",b[idx]); break; } } typ[] c; c = a[0..ITERS/2] ~ b[ITERS/2..$]; if(c.length != ITERS) printf("Length Error: %d\n",c.length); if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); break; } } c.reverse; for(int idx = 0; idx < ITERS; idx++) { if(c[c.length - idx - 1] != idx) { printf("c Reverse Error: %d\n",c[idx]); break; } } c.sort; for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Sort Error: %d\n",c[idx]); break; } } } void ULONG() { const int ITERS = 1000000; alias ulong typ; typ[] a; for(int idx = 0; idx < ITERS; idx++) { a ~= idx; } if(a.length != ITERS) printf("Length Error: %d\n",a.length); if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); break; } } a.reverse; for(int idx = 0; idx < ITERS; idx++) { if(a[a.length - idx - 1] != idx) { printf("a Reverse Error: %d\n",a[idx]); break; } } a.sort; for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Sort Error: %d\n",a[idx]); break; } } typ[] b = a[]; if(b.length != ITERS) printf("Length Error: %d\n",b.length); if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); break; } } b.reverse; for(int idx = 0; idx < ITERS; idx++) { if(b[b.length - idx - 1] != idx) { printf("b Reverse Error: %d\n",b[idx]); break; } } b.sort; for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Sort Error: %d\n",b[idx]); break; } } typ[] c; c = a[0..ITERS/2] ~ b[ITERS/2..$]; if(c.length != ITERS) printf("Length Error: %d\n",c.length); if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); break; } } c.reverse; for(int idx = 0; idx < ITERS; idx++) { if(c[c.length - idx - 1] != idx) { printf("c Reverse Error: %d\n",c[idx]); break; } } c.sort; for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Sort Error: %d\n",c[idx]); break; } } } void FLOAT() { const int ITERS = 1000000; alias float typ; typ[] a; for(int idx = 0; idx < ITERS; idx++) { a ~= idx; } if(a.length != ITERS) printf("Length Error: %d\n",a.length); if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); break; } } a.reverse; for(int idx = 0; idx < ITERS; idx++) { if(a[a.length - idx - 1] != idx) { printf("a Reverse Error: %d\n",a[idx]); break; } } a.sort; for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Sort Error: %d\n",a[idx]); break; } } typ[] b = a[]; if(b.length != ITERS) printf("Length Error: %d\n",b.length); if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); break; } } b.reverse; for(int idx = 0; idx < ITERS; idx++) { if(b[b.length - idx - 1] != idx) { printf("b Reverse Error: %d\n",b[idx]); break; } } b.sort; for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Sort Error: %d\n",b[idx]); break; } } typ[] c; c = a[0..ITERS/2] ~ b[ITERS/2..$]; if(c.length != ITERS) printf("Length Error: %d\n",c.length); if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); break; } } c.reverse; for(int idx = 0; idx < ITERS; idx++) { if(c[c.length - idx - 1] != idx) { printf("c Reverse Error: %d\n",c[idx]); break; } } c.sort; for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Sort Error: %d\n",c[idx]); break; } } } void DOUBLE() { const int ITERS = 1000000; alias double typ; typ[] a; for(int idx = 0; idx < ITERS; idx++) { a ~= idx; } if(a.length != ITERS) printf("Length Error: %d\n",a.length); if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); break; } } a.reverse; for(int idx = 0; idx < ITERS; idx++) { if(a[a.length - idx - 1] != idx) { printf("a Reverse Error: %d\n",a[idx]); break; } } a.sort; for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Sort Error: %d\n",a[idx]); break; } } typ[] b = a[]; if(b.length != ITERS) printf("Length Error: %d\n",b.length); if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); break; } } b.reverse; for(int idx = 0; idx < ITERS; idx++) { if(b[b.length - idx - 1] != idx) { printf("b Reverse Error: %d\n",b[idx]); break; } } b.sort; for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Sort Error: %d\n",b[idx]); break; } } typ[] c; c = a[0..ITERS/2] ~ b[ITERS/2..$]; if(c.length != ITERS) printf("Length Error: %d\n",c.length); if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); break; } } c.reverse; for(int idx = 0; idx < ITERS; idx++) { if(c[c.length - idx - 1] != idx) { printf("c Reverse Error: %d\n",c[idx]); break; } } c.sort; for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Sort Error: %d\n",c[idx]); break; } } } void REAL() { const int ITERS = 1000000; alias real typ; typ[] a; for(int idx = 0; idx < ITERS; idx++) { a ~= idx; } if(a.length != ITERS) printf("Length Error: %d\n",a.length); if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Data Error: %d\n",a[idx]); break; } } a.reverse; for(int idx = 0; idx < ITERS; idx++) { if(a[a.length - idx - 1] != idx) { printf("a Reverse Error: %d\n",a[idx]); break; } } a.sort; for(int idx = 0; idx < ITERS; idx++) { if(a[idx] != idx) { printf("a Sort Error: %d\n",a[idx]); break; } } typ[] b = a[]; if(b.length != ITERS) printf("Length Error: %d\n",b.length); if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Data Error: %d\n",b[idx]); break; } } b.reverse; for(int idx = 0; idx < ITERS; idx++) { if(b[b.length - idx - 1] != idx) { printf("b Reverse Error: %d\n",b[idx]); break; } } b.sort; for(int idx = 0; idx < ITERS; idx++) { if(b[idx] != idx) { printf("b Sort Error: %d\n",b[idx]); break; } } typ[] c; c = a[0..ITERS/2] ~ b[ITERS/2..$]; if(c.length != ITERS) printf("Length Error: %d\n",c.length); if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Data Error: %d\n",c[idx]); break; } } c.reverse; for(int idx = 0; idx < ITERS; idx++) { if(c[c.length - idx - 1] != idx) { printf("c Reverse Error: %d\n",c[idx]); break; } } c.sort; for(int idx = 0; idx < ITERS; idx++) { if(c[idx] != idx) { printf("c Sort Error: %d\n",c[idx]); break; } } } void CLASS() { const int ITERS = 1000000; alias B typ; typ[] a; for(int idx = 0; idx < ITERS; idx++) { typ tc = new typ(idx); a ~= tc; } if(a.length != ITERS) printf("Length Error: %d\n",a.length); if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(a[idx].i != idx) { printf("a Data Error: %d\n",a[idx].i); break; } } typ[] b = a[]; if(b.length != ITERS) printf("Length Error: %d\n",b.length); if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(b[idx].i != idx) { printf("b Data Error: %d\n",b[idx].i); break; } } typ[] c; c = a[0..ITERS/2] ~ b[ITERS/2..$]; if(c.length != ITERS) printf("Length Error: %d\n",c.length); if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof); for(int idx = 0; idx < ITERS; idx++) { if(c[idx].i != idx) { printf("c Data Error: %d\n",c[idx].i); break; } } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_cabi1.d0000644000175000017500000003154713200164642023367 0ustar matthiasmatthias// EXTRA_CPP_SOURCES: ldc_cabi2.cpp import core.stdc.stdarg; import core.stdc.stdio; extern (C) { __gshared byte a = 1, b = -42, c = 3, d = -10, e = 0, f = -50, g = 20, h = -77; __gshared uint errors; } void test(bool b, string file = __FILE__, size_t line = __LINE__) { if (!b) { printf("%.*s:%u: failed check\n", file.length, file.ptr, line); ++errors; } } // private doesn't work like static here - bug? private bool testar(byte[] a, byte a0) { for (size_t i = 0; i < a.length; ++i) { if (a[i] != cast(byte)(a0+i)) { return false; } } return true; } int main() { enum a = D4.alignof; pragma(msg, typeid(a)); pragma(msg, D4.alignof); pragma(msg, F4.alignof); pragma(msg, S9.alignof); printf("%zu\n", a.sizeof); printf("%u\n", a); dcall(); ccall(); return (errors != 0) ? 1 : 0; } extern(C): struct EMPTY {}; struct B1 {byte a;} struct B2 {byte a, b;} struct I1 {int a;} struct I2 {int a, b;} union UI1 {int a; short b; byte c;} union UI1a {short a; byte b; int c;} struct NI1 {I1 a;} struct NUI1 {UI1 a;} union UNI1 {UI1 a; NI1 b; int c;} struct S3 {char a; short b;} struct S6 {char a; int b; char c;} struct S9 {char a; double b;} struct S19 {char a; double b, c;} struct F2 {float a, b;} struct F2i {ifloat a, b;} struct F2ir {ifloat a; float b;} struct F2ri {float a; ifloat b;} struct F4 {float a, b, c, d;} //enum DD : double {x=0.0, b=1.0}; //struct Dx {DD a;} struct D1 {double a;} struct D2 {double a, b;} struct D4 {double a, b, c, d;} struct D5 {double a, b, c, d, e;} struct D8 {double a, b, c, d, e, f, g, h;} union UD4 {D1 a; D2 b; D4 c; double e;} struct CX1 {creal a;} struct CX2 {creal a, b;} struct CX3 {creal a, b, c;} struct CX1D2 {creal a; D2 b;} struct DA0 {double[0] a;} struct DA2 {double[2] a;} struct DA3 {double[3] a;} struct DA4 {double[4] a;} struct DA5 {double[5] a;} struct DA8 {double[8] a;} struct CA4 {char[4] a;} struct DHFA1 {EMPTY a; double d;} //struct DHFA1 {EMPTY a; EMPTY b; double[0] c; double d;} struct DHFA2 {double a; D1 b;} struct DHFA2a {D1 a; double b;} struct DHFA4 {D1 a; double b; D2 c;} struct DHFA4a {D1 a; real b; D2 c;} struct DHFA4b {DHFA2 a; DHFA2a b;} struct DHFA4c {DHFA2 a; double[2] b;} struct DHFA4d {DHFA2 a; DA2 b;} struct DHFA4e {DA2 a; double b, c;} struct DHFA4x {D2[2] a;}; struct DHFAx {D1 a; F2 b; double d;} struct DHFA5 {D1 a; double b; D2 c; double d;} struct S40 {D2 a; double b; D2 c;} struct S1 { byte a; ~this() {} } struct S2 { byte a; this(this) {} } struct SA64 {byte[64] a;} struct SA65 {byte[65] a;} void cvfun(int s, ...); B1 cretb1(B1 x); B1 dretb1(B1 x) { test(x.a == a); B1 r = {++a}; return r; } B2 cretb2(B2 x); B2 dretb2(B2 x) { test(x.a == a); test(x.b == b); B2 r = {++a, ++b}; return r; } I1 creti1(I1 x); I1 dreti1(I1 x) { test(x.a == a); I1 r = {++a}; return r; } I2 creti2(I2 x); I2 dreti2(I2 x) { test(x.a == a); test(x.b == b); I2 r = {++a, ++b}; return r; } UNI1 cretuni1(UNI1 x); UNI1 dretuni1(UNI1 x) { test(x.a.a == a); UNI1 r = {{++a}}; return r; } F2 cretf2(F2 x); F2 dretf2(F2 x) { test(x.a == a); test(x.b == b); F2 r = {++a, ++b}; return r; } F2ir cretf2ir(F2ir x); F2ir dretf2ir(F2ir x) { test(x.a == a*1i); test(x.b == b); F2ir r = {++a*1i, ++b}; return r; } F2ri cretf2ri(F2ri x); F2ri dretf2ri(F2ri x) { test(x.a == a); test(x.b == b*1i); F2ri r = {++a, ++b*1i}; return r; } F4 cretf4(F4 x); F4 dretf4(F4 x) { test(x.a == a); test(x.b == b); test(x.c == c); test(x.d == d); F4 r = {++a, ++b, ++c, ++d}; return r; } // Dx cretdx(Dx x); // Dx dretdx(Dx x) // { // test(x.a == a); // Dx r; // return r; // } D4 cretd4(D4 x); D4 dretd4(D4 x) { test(x.a == a); test(x.b == b); test(x.c == c); test(x.d == d); D4 r = {++a, ++b, ++c, ++d}; return r; } D5 cretd5(D5 x); D5 dretd5(D5 x) { test(x.a == a); test(x.b == b); test(x.c == c); test(x.d == d); test(x.e == e); D5 r = {++a, ++b, ++c, ++d, ++e}; return r; } D8 cretd8(D8 x); D8 dretd8(D8 x) { test(x.a == a); test(x.b == b); test(x.c == c); test(x.d == d); test(x.e == e); test(x.f == f); test(x.g == g); test(x.h == h); D8 r = {++a, ++b, ++c, ++d, ++e, ++f, ++g, ++h}; return r; } UD4 cretud4(UD4 x); UD4 dretud4(UD4 x) { test(x.c.a == a); test(x.c.b == b); test(x.c.c == c); test(x.c.d == d); UD4 r; r.c = D4(++a, ++b, ++c, ++d); return r; } DA0 cretda0(DA0 x); DA0 dretda0(DA0 x) { DA0 r; return r; } DA4 cretda4(DA4 x); DA4 dretda4(DA4 x) { test(x.a[0] == a); test(x.a[1] == b); test(x.a[2] == c); test(x.a[3] == d); DA4 r = {[++a, ++b, ++c, ++d]}; return r; } DA5 cretda5(DA5 x); DA5 dretda5(DA5 x) { test(x.a[0] == a); test(x.a[1] == b); test(x.a[2] == c); test(x.a[3] == d); test(x.a[4] == e); DA5 r = {[++a, ++b, ++c, ++d, ++e]}; return r; } DA8 cretda8(DA8 x); DA8 dretda8(DA8 x) { test(x.a[0] == a); test(x.a[1] == b); test(x.a[2] == c); test(x.a[3] == d); test(x.a[4] == e); test(x.a[5] == f); test(x.a[6] == g); test(x.a[7] == h); DA8 r = {[++a, ++b, ++c, ++d, ++e, ++f, ++g, ++h]}; return r; } CX1 cretcx1(CX1 x); CX1 dretcx1(CX1 x) { test(x.a == a + b*1i); CX1 r = {++a + ++b*1i}; return r; } CX2 cretcx2(CX2 x); CX2 dretcx2(CX2 x) { test(x.a == a + b*1i); test(x.b == c + d*1i); CX2 r = {++a + ++b*1i, ++c + ++d*1i}; return r; } CX3 cretcx3(CX3 x); CX3 dretcx3(CX3 x) { test(x.a == a + b*1i); test(x.b == c + d*1i); test(x.c == e + f*1i); CX3 r = {++a + ++b*1i, ++c + ++d*1i, ++e + ++f*1i}; return r; } CX1D2 cretcx1d2(CX1D2 x); CX1D2 dretcx1d2(CX1D2 x) { test(x.a == a + b*1i); test(x.b.a == c); test(x.b.b == d); CX1D2 r = {++a + ++b*1i, {++c, ++d}}; return r; } DHFA1 cretdhfa1(DHFA1 x); DHFA1 dretdhfa1(DHFA1 x) { test(x.d == a); DHFA1 r; r.d = ++a; return r; } DHFA2 cretdhfa2(DHFA2 x); DHFA2 dretdhfa2(DHFA2 x) { test(x.a == a); test(x.b.a == b); DHFA2 r = {++a, {++b}}; return r; } DHFA2a cretdhfa2a(DHFA2a x); DHFA2a dretdhfa2a(DHFA2a x) { test(x.a.a == a); test(x.b == b); DHFA2a r = {{++a}, ++b}; return r; } DHFA4 cretdhfa4(DHFA4 x); DHFA4 dretdhfa4(DHFA4 x) { test(x.a.a == a); test(x.b == b); test(x.c.a == c); test(x.c.b == d); DHFA4 r = {{++a}, ++b, {++c, ++d}}; return r; } DHFA4a cretdhfa4a(DHFA4a x); DHFA4a dretdhfa4a(DHFA4a x) { test(x.a.a == a); test(x.b == b); test(x.c.a == c); test(x.c.b == d); DHFA4a r = {{++a}, ++b, {++c, ++d}}; return r; } DHFA4b cretdhfa4b(DHFA4b x); DHFA4b dretdhfa4b(DHFA4b x) { test(x.a.a == a); test(x.a.b.a == b); test(x.b.a.a == c); test(x.b.b == d); DHFA4b r = {{++a, {++b}}, {{++c}, ++d}}; return r; } DHFA4c cretdhfa4c(DHFA4c x); DHFA4c dretdhfa4c(DHFA4c x) { test(x.a.a == a); test(x.a.b.a == b); test(x.b[0] == c); test(x.b[1] == d); DHFA4c r = {{++a, {++b}}, [++c, ++d]}; return r; } DHFA4d cretdhfa4d(DHFA4d x); DHFA4d dretdhfa4d(DHFA4d x) { test(x.a.a == a); test(x.a.b.a == b); test(x.b.a[0] == c); test(x.b.a[1] == d); DHFA4d r = {{++a, {++b}}, {[++c, ++d]}}; return r; } DHFA4e cretdhfa4e(DHFA4e x); DHFA4e dretdhfa4e(DHFA4e x) { test(x.a.a[0] == a); test(x.a.a[1] == b); test(x.b == c); test(x.c == d); DHFA4e r = {{[++a, ++b]}, ++c, ++d}; return r; } DHFA4x cretdhfa4x(DHFA4x x); DHFA4x dretdhfa4x(DHFA4x x) { test(x.a[0].a == a); test(x.a[0].b == b); test(x.a[1].a == c); test(x.a[1].b == d); DHFA4x r = {[{++a, ++b}, {++c, ++d}]}; return r; } DHFA5 cretdhfa5(DHFA5 x); DHFA5 dretdhfa5(DHFA5 x) { test(x.a.a == a); test(x.b == b); test(x.c.a == c); test(x.c.b == d); test(x.d == 42); DHFA5 r = {{++a}, ++b, {++c, ++d}, 42.0}; return r; } S1 crets1(S1 x); S1 drets1(S1 x) { test(x.a == a); S1 r = S1(++a); return r; } S2 crets2(S2 x); S2 drets2(S2 x) { test(x.a == a); S2 r = S2(++a); return r; } SA64 cretsa64(SA64 x); SA64 dretsa64(SA64 x) { test(testar(x.a, a)); SA64 r; ++a; for (size_t i = 0; i < 64; ++i) { r.a[i] = cast(byte)(a+i); } return r; } SA65 cretsa65(SA65 x); SA65 dretsa65(SA65 x) { test(testar(x.a, a)); SA65 r; ++a; for (size_t i = 0; i < 65; ++i) { r.a[i] = cast(byte)(a+i); } return r; } void dvfun(int s, ...) { va_list args; va_start(args, s); final switch (s) { case 0: dretb1(va_arg!B1(args)); break; case 1: dretb2(va_arg!B2(args)); break; case 2: dreti2(va_arg!I2(args)); break; case 3: dretf4(va_arg!F4(args)); break; case 4: dretd4(va_arg!D4(args)); break; case 5: dretdhfa2(va_arg!DHFA2(args)); break; case 6: dretdhfa2a(va_arg!DHFA2a(args)); break; case 7: dretuni1(va_arg!UNI1(args)); break; } } version(none){ struct CR1 {cdouble a;} cdouble cretcd(cdouble x); CR1 cretcr1(CR1 x); } version (none) { struct Foo { double a; this(double x) {a = x;} } class Bar { double a; this(double x) {a = x;} } } extern (D) void xvfun(...); void ccall(); void dcall() { //xvfun(2.0f); version (none) { cdouble cd = cretcd(4.5+2i); test(cd == 0); CR1 cr1 = cretcr1(CR1(4.5+2i)); test(cr1.a == 0); } version (none) { Foo f = Foo(1.0); Bar z = new Bar(1.0); cvfun(1, f, z); } B1 b1 = cretb1(B1(++a)); test(b1.a == a); B2 b2 = cretb2(B2(++a, ++b)); test(b2.a == a); test(b2.b == b); I2 i2 = creti2(I2(++a, ++b)); test(i2.a == a); test(i2.b == b); UNI1 uni1i = {{++a}}; UNI1 uni1 = cretuni1(uni1i); test(uni1.a.a == a); F4 f4 = cretf4(F4(++a, ++b, ++c, ++d)); test(f4.a == a); test(f4.b == b); test(f4.c == c); test(f4.d == d); D4 d4 = cretd4(D4(++a, ++b, ++c, ++d)); test(d4.a == a); test(d4.b == b); test(d4.c == c); test(d4.d == d); D5 d5 = cretd5(D5(++a, ++b, ++c, ++d, ++e)); test(d5.a == a); test(d5.b == b); test(d5.c == c); test(d5.d == d); test(d5.e == e); D8 d8 = cretd8(D8(++a, ++b, ++c, ++d, ++e, ++f, ++g, ++h)); test(d8.a == a); test(d8.b == b); test(d8.c == c); test(d8.d == d); test(d8.e == e); test(d8.f == f); test(d8.g == g); test(d8.h == h); UD4 ud4; ud4.c = D4(++a, ++b, ++c, ++d); UD4 ud4r = cretud4(ud4); test(ud4r.c.a == a); test(ud4r.c.b == b); test(ud4r.c.c == c); test(ud4r.c.d == d); DA4 da4 = cretda4(DA4([++a, ++b, ++c, ++d])); test(da4.a[0] == a); test(da4.a[1] == b); test(da4.a[2] == c); test(da4.a[3] == d); DA5 da5 = cretda5(DA5([++a, ++b, ++c, ++d, ++e])); test(da5.a[0] == a); test(da5.a[1] == b); test(da5.a[2] == c); test(da5.a[3] == d); test(da5.a[4] == e); DA8 da8 = cretda8(DA8([++a, ++b, ++c, ++d, ++e, ++f, ++g, ++h])); test(da8.a[0] == a); test(da8.a[1] == b); test(da8.a[2] == c); test(da8.a[3] == d); test(da8.a[4] == e); test(da8.a[5] == f); test(da8.a[6] == g); test(da8.a[7] == h); DHFA2 dhfa2 = cretdhfa2(DHFA2(++a, D1(++b))); test(dhfa2.a == a); test(dhfa2.b.a == b); DHFA2a dhfa2a = cretdhfa2a(DHFA2a(D1(++a), ++b)); test(dhfa2a.a.a == a); test(dhfa2a.b == b); DHFA4x dhfa4xi = {[{++a, ++b}, {++c, ++d}]}; DHFA4x dhfa4x = cretdhfa4x(dhfa4xi); test(dhfa4x.a[0].a == a); test(dhfa4x.a[0].b == b); test(dhfa4x.a[1].a == c); test(dhfa4x.a[1].b == d); // structs with postblit or dtor may not be passed like a similar POD // struct. Depends on target, although would be undefined behavior since // C code can't obey struct life cycle. // going to be obey version (none) { S1 s1 = crets1(S1(++a)); test(s1.a == a); S2 s2 = crets2(S2(++a)); test(s2.a == a); } SA64 s64; ++a; for (size_t i = 0; i < 64; ++i) { s64.a[i] = cast(byte)(a+i); } SA64 s64r = cretsa64(s64); test(testar(s64r.a, a)); SA65 s65; ++a; for (size_t i = 0; i < 65; ++i) { s65.a[i] = cast(byte)(a+i); } SA65 s65r = cretsa65(s65); test(testar(s65r.a, a)); b1.a = ++a; cvfun(0, b1); b2.a = ++a; b2.b = ++b; cvfun(1, b2); i2.a = ++a; i2.b = ++b; cvfun(2, i2); uni1.a.a = ++a; cvfun(7, uni1); f4.a = ++a; f4.b = ++b; f4.c = ++c; f4.d = ++d; cvfun(3, f4); d4.a = ++a; d4.b = ++b; d4.c = ++c; d4.d = ++d; cvfun(4, d4); dhfa2.a = ++a; dhfa2.b.a = ++b; cvfun(5, dhfa2); dhfa2a.a.a = ++a; dhfa2a.b = ++b; cvfun(6, dhfa2a); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test7603.d0000644000175000017500000000062613200164642023057 0ustar matthiasmatthiasvoid test7603() { int g; void foo(int n, ref int r = g) { r = n; } int x; foo(1, x); assert(x == 1); foo(2); assert(g == 2); int h = 100; void bar(int n, out int r = h) { if (n != 0) r = n; } bar(0); assert(h == 0); bar(10); assert(h == 10); bar(10, x); assert(x == 10); bar(0, x); assert(x == 0); } void main() { test7603(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_795.d0000644000175000017500000000243613200164642024271 0ustar matthiasmatthiasdebug import core.stdc.stdio; struct Int { static int count; this(int) { ++count; debug printf("CONSTRUCT count = %d\n", count); } this(this) { ++count; debug printf("COPY count = %d\n", count); } ~this() { --count; debug printf("DESTROY count = %d\n", count); } } struct Only { Int front; bool empty; void popFront() { empty = true; } } struct Map { Only r; bool empty; auto front() @property { return Only(r.front); } void popFront() { empty = true; } } void test1() { { auto sm = Map(Only(Int(42))); bool condition = !sm.empty && sm.front.empty; } assert(Int.count == 0); } void test2() { { auto sm = Map(Only(Int(42))); bool condition = sm.empty || sm.front.empty; } assert(Int.count == 0); } void test3() { { auto sm = Map(Only(Int(42))); bool condition = sm.empty ? false : sm.front.empty; } assert(Int.count == 0); } void test4() { { auto sm = Map(Only(Int(42))); bool condition = !sm.empty ? sm.front.empty : false; } assert(Int.count == 0); } void main() { test1(); test2(); test3(); test4(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testbounds_safeonly.d0000644000175000017500000000120613200164642025645 0ustar matthiasmatthias// REQUIRED_ARGS: -boundscheck=safeonly // PERMUTE_ARGS: -inline -g -O import core.exception : RangeError; // Check for RangeError is thrown bool thrown(T)(lazy T cond) { import core.exception; bool f = false; try { cond(); } catch (RangeError e) { f = true; } return f; } @safe int safeIndex (int[] arr) { return arr[2]; } @trusted int trustedIndex(int[] arr) { return arr[2]; } @system int systemIndex (int[] arr) { return arr[2]; } void main() { int[3] data = [1,2,3]; int[] arr = data[0..2]; assert(arr. safeIndex().thrown); assert(arr.trustedIndex() == 3); assert(arr. systemIndex() == 3); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test3574c.d0000644000175000017500000000022613200164642023221 0ustar matthiasmatthias//int g = 0; //static ~this() { assert(g == 100); } void main() //out //{ // g = 100; //} //body { return; // expected return code == 0 } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testconstsection.d0000644000175000017500000000237013200164642025171 0ustar matthiasmatthias string tls_var = "tls_string"; __gshared string data_var = "data_string"; __gshared string bss_var; struct Range { const(void)* bot; const(void)* top; // consider inclusive void addPtr(const(void)* p) { if (!bot || p < bot) bot = p; if (!top || p > top) top = p; } bool intersect(Range other) { return (bot <= other.top && top >= other.bot); } } void testStrings() { // check that the strings don't overlap with the variables Range tls; Range data; Range bss; Range cdata; static string local_tls_var = "tls_string"; static __gshared string local_data_var = "data_string"; static __gshared string local_bss_var; tls.addPtr(&tls_var); tls.addPtr(&local_tls_var); data.addPtr(&data_var); data.addPtr(&local_data_var); bss.addPtr(&bss_var); bss.addPtr(&local_bss_var); cdata.addPtr(tls_var.ptr); cdata.addPtr(local_tls_var.ptr); cdata.addPtr(data_var.ptr); cdata.addPtr(local_data_var.ptr); assert(!cdata.intersect(tls), "overlap with tls"); assert(!cdata.intersect(data), "overlap with data"); assert(!cdata.intersect(bss), "overlap with bss"); } void main() { testStrings(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/polysemous.d0000644000175000017500000000423713200164642024001 0ustar matthiasmatthias// PERMUTE_ARGS: // Prefer immutable(char)[] to all others int foo( char[] a) { return 11; } int foo( const char[] a) { return 12; } int foo(immutable char[] a) { return 13; } int foo( wchar[] a) { return 21; } int foo( const wchar[] a) { return 22; } int foo(immutable wchar[] a) { return 23; } int foo( dchar[] a) { return 31; } int foo( const dchar[] a) { return 32; } int foo(immutable dchar[] a) { return 33; } // Prefer const conversion over polysemous conversion int bar( char[] a) { return 11; } int bar( const char[] a) { return 12; } // bar(immutable char[] a); int bar( wchar[] a) { return 21; } int bar( const wchar[] a) { return 22; } // bar(immutable wchar[] a); int bar( dchar[] a) { return 31; } int bar( const dchar[] a) { return 32; } // bar(immutable dchar[] a); // No conversion to mutable int baz( char[] a) { return 11; } // baz( const char[] a); // baz(immutable char[] a); int baz( wchar[] a) { return 21; } // baz( const wchar[] a); // baz(immutable wchar[] a); int baz( dchar[] a) { return 31; } // baz( const dchar[] a); // baz(immutable dchar[] a); int main() { auto strn = "a"; auto strc = "a"c; auto strw = "a"w; auto strd = "a"d; assert(foo("a" ) == 13); assert(foo(strn) == 13); assert(foo("a"c) == 13); assert(foo(strc) == 13); assert(foo("a"w) == 23); assert(foo(strw) == 23); assert(foo("a"d) == 33); assert(foo(strd) == 33); assert(bar("a" ) == 12); assert(bar(strn) == 12); assert(bar("a"c) == 12); assert(bar(strc) == 12); assert(bar("a"w) == 22); assert(bar(strw) == 22); assert(bar("a"d) == 32); assert(bar(strd) == 32); static assert(!__traits(compiles, baz("a" ) )); static assert(!__traits(compiles, baz(strn) )); static assert(!__traits(compiles, baz("a"c) )); static assert(!__traits(compiles, baz(strc) )); static assert(!__traits(compiles, baz("a"w) )); static assert(!__traits(compiles, baz(strw) )); static assert(!__traits(compiles, baz("a"d) )); static assert(!__traits(compiles, baz(strd) )); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/gdb14330.d0000644000175000017500000000031313200164642022700 0ustar matthiasmatthias/* REQUIRED_ARGS: -g PERMUTE_ARGS: GDB_SCRIPT: --- b 20 r echo RESULT= p str --- GDB_MATCH: RESULT=.*something */ module gdb; __gshared ulong x; void main() { string str = "something"; // BP } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/mangle.d0000644000175000017500000003403513200164642023024 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_SOURCES: imports/mangle10077.d /***************************************************/ // 10077 - pragma(mangle) pragma(mangle, "_test10077a_") int test10077a; static assert(test10077a.mangleof == "_test10077a_"); __gshared pragma(mangle, "_test10077b_") ubyte test10077b; static assert(test10077b.mangleof == "_test10077b_"); pragma(mangle, "_test10077c_") void test10077c() {} static assert(test10077c.mangleof == "_test10077c_"); pragma(mangle, "_test10077f_") __gshared char test10077f; static assert(test10077f.mangleof == "_test10077f_"); pragma(mangle, "_test10077g_") @system { void test10077g() {} } static assert(test10077g.mangleof == "_test10077g_"); template getModuleInfo(alias mod) { pragma(mangle, "_D"~mod.mangleof~"12__ModuleInfoZ") static __gshared extern ModuleInfo mi; enum getModuleInfo = &mi; } void test10077h() { assert(getModuleInfo!(object).name == "object"); } //UTF-8 chars __gshared extern pragma(mangle, "test_ÑльфийÑкие_пиÑьмена_9") ubyte test10077i_evar; void test10077i() { import imports.mangle10077; setTest10077i(); assert(test10077i_evar == 42); } /***************************************************/ // 13050 void func13050(int); template decl13050(Arg) { void decl13050(Arg); } template problem13050(Arg) { pragma(mangle, "foobar") void problem13050(Arg); } template workaround13050(Arg) { pragma(mangle, "foobar") void func(Arg); alias workaround13050 = func; } static assert(is(typeof(&func13050) == void function(int))); static assert(is(typeof(&decl13050!int) == void function(int))); static assert(is(typeof(&problem13050!int) == void function(int))); static assert(is(typeof(&workaround13050!int) == void function(int))); /***************************************************/ // 2774 int foo2774(int n) { return 0; } static assert(foo2774.mangleof == "_D6mangle7foo2774FiZi"); class C2774 { int foo2774() { return 0; } } static assert(C2774.foo2774.mangleof == "_D6mangle5C27747foo2774MFZi"); template TFoo2774(T) {} static assert(TFoo2774!int.mangleof == "6mangle15__T8TFoo2774TiZ"); void test2774() { int foo2774(int n) { return 0; } static assert(foo2774.mangleof == "_D6mangle8test2774FZ7foo2774MFiZi"); } /*******************************************/ // 8847 auto S8847() { static struct Result { inout(Result) get() inout { return this; } } return Result(); } void test8847a() { auto a = S8847(); auto b = a.get(); alias typeof(a) A; alias typeof(b) B; assert(is(A == B), A.stringof~ " is different from "~B.stringof); } // -------- enum result8847a = "S6mangle9iota8847aFZ6Result"; enum result8847b = "S6mangle9iota8847bFZ4iotaMFZ6Result"; enum result8847c = "C6mangle9iota8847cFZ6Result"; enum result8847d = "C6mangle9iota8847dFZ4iotaMFZ6Result"; auto iota8847a() { static struct Result { this(int) {} inout(Result) test() inout { return cast(inout)Result(0); } } static assert(Result.mangleof == result8847a); return Result.init; } auto iota8847b() { auto iota() { static struct Result { this(int) {} inout(Result) test() inout { return cast(inout)Result(0); } } static assert(Result.mangleof == result8847b); return Result.init; } return iota(); } auto iota8847c() { static class Result { this(int) {} inout(Result) test() inout { return cast(inout)new Result(0); } } static assert(Result.mangleof == result8847c); return Result.init; } auto iota8847d() { auto iota() { static class Result { this(int) {} inout(Result) test() inout { return cast(inout)new Result(0); } } static assert(Result.mangleof == result8847d); return Result.init; } return iota(); } void test8847b() { static assert(typeof(iota8847a().test()).mangleof == result8847a); static assert(typeof(iota8847b().test()).mangleof == result8847b); static assert(typeof(iota8847c().test()).mangleof == result8847c); static assert(typeof(iota8847d().test()).mangleof == result8847d); } // -------- struct Test8847 { enum result1 = "S6mangle8Test88478__T3fooZ3fooMFZ6Result"; enum result2 = "S6mangle8Test88478__T3fooZ3fooMxFiZ6Result"; auto foo()() { static struct Result { inout(Result) get() inout { return this; } } static assert(Result.mangleof == Test8847.result1); return Result(); } auto foo()(int n) const { static struct Result { inout(Result) get() inout { return this; } } static assert(Result.mangleof == Test8847.result2); return Result(); } } void test8847c() { static assert(typeof(Test8847().foo( ).get()).mangleof == Test8847.result1); static assert(typeof(Test8847().foo(1).get()).mangleof == Test8847.result2); } // -------- void test8847d() { enum resultS = "S6mangle9test8847dFZ3fooMFZ3barMFZ3bazMFZ1S"; enum resultX = "S6mangle9test8847dFZ3fooMFZ1X"; // Return types for test8847d and bar are mangled correctly, // and return types for foo and baz are not mangled correctly. auto foo() { struct X { inout(X) get() inout { return inout(X)(); } } string bar() { auto baz() { struct S { inout(S) get() inout { return inout(S)(); } } return S(); } static assert(typeof(baz() ).mangleof == resultS); static assert(typeof(baz().get()).mangleof == resultS); return ""; } return X(); } static assert(typeof(foo() ).mangleof == resultX); static assert(typeof(foo().get()).mangleof == resultX); } // -------- void test8847e() { enum resultHere = "6mangle"~"9test8847eFZ"~"8__T3fooZ"~"3foo"; enum resultBar = "S"~resultHere~"MFNaNfNgiZ3Bar"; enum resultFoo = "_D"~resultHere~"MFNaNbNiNfNgiZNg"~resultBar; // added 'Nb' // Make template function to infer 'nothrow' attributes auto foo()(inout int) pure @safe { struct Bar {} static assert(Bar.mangleof == resultBar); return inout(Bar)(); } auto bar = foo(0); static assert(typeof(bar).stringof == "Bar"); static assert(typeof(bar).mangleof == resultBar); static assert(foo!().mangleof == resultFoo); } // -------- pure f8847a() { struct S {} return S(); } pure { auto f8847b() { struct S {} return S(); } } static assert(typeof(f8847a()).mangleof == "S6mangle6f8847aFNaZ1S"); static assert(typeof(f8847b()).mangleof == "S6mangle6f8847bFNaZ1S"); /*******************************************/ // 12352 auto bar12352() { struct S { int var; void func() {} } static assert(!__traits(compiles, bar12352.mangleof)); // forward reference to bar static assert(S .mangleof == "S6mangle8bar12352FZ1S"); static assert(S.func.mangleof == "_D6mangle8bar12352FZ1S4funcMFZv"); return S(); } static assert( bar12352 .mangleof == "_D6mangle8bar12352FNaNbNiNfZS6mangle8bar12352FZ1S"); static assert(typeof(bar12352()) .mangleof == "S6mangle8bar12352FZ1S"); static assert(typeof(bar12352()).func.mangleof == "_D6mangle8bar12352FZ1S4funcMFZv"); auto baz12352() { class C { int var; void func() {} } static assert(!__traits(compiles, baz12352.mangleof)); // forward reference to baz static assert(C .mangleof == "C6mangle8baz12352FZ1C"); static assert(C.func.mangleof == "_D6mangle8baz12352FZ1C4funcMFZv"); return new C(); } static assert( baz12352 .mangleof == "_D6mangle8baz12352FNaNbNfZC6mangle8baz12352FZ1C"); static assert(typeof(baz12352()) .mangleof == "C6mangle8baz12352FZ1C"); static assert(typeof(baz12352()).func.mangleof == "_D6mangle8baz12352FZ1C4funcMFZv"); /*******************************************/ // 9525 void f9525(T)(in T*) { } void test9525() { enum result1 = "S6mangle8test9525FZ26__T5test1S136mangle5f9525Z5test1MFZ1S"; enum result2 = "S6mangle8test9525FZ26__T5test2S136mangle5f9525Z5test2MFNaNbZ1S"; void test1(alias a)() { static struct S {} static assert(S.mangleof == result1); S s; a(&s); // Error: Cannot convert &S to const(S*) at compile time } static assert((test1!f9525(), true)); void test2(alias a)() pure nothrow { static struct S {} static assert(S.mangleof == result2); S s; a(&s); // Error: Cannot convert &S to const(S*) at compile time } static assert((test2!f9525(), true)); } /******************************************/ // 10249 template Seq10249(T...) { alias Seq10249 = T; } mixin template Func10249(T) { void func10249(T) {} } mixin Func10249!long; mixin Func10249!string; void f10249(long) {} class C10249 { mixin Func10249!long; mixin Func10249!string; static assert(Seq10249!(.func10249)[0].mangleof == "6mangle9func10249"); // <- 9func10249 static assert(Seq10249!( func10249)[0].mangleof == "6mangle6C102499func10249"); // <- 9func10249 static: // necessary to make overloaded symbols accessible via __traits(getOverloads, C10249) void foo(long) {} void foo(string) {} static assert(Seq10249!(foo)[0].mangleof == "6mangle6C102493foo"); // <- _D6mangle6C102493fooFlZv static assert(Seq10249!(__traits(getOverloads, C10249, "foo"))[0].mangleof == "_D6mangle6C102493fooFlZv"); // <- static assert(Seq10249!(__traits(getOverloads, C10249, "foo"))[1].mangleof == "_D6mangle6C102493fooFAyaZv"); // <- void g(string) {} alias bar = .f10249; alias bar = g; static assert(Seq10249!(bar)[0].mangleof == "6mangle6C102496f10249"); // <- _D6mangle1fFlZv (todo!) static assert(Seq10249!(__traits(getOverloads, C10249, "bar"))[0].mangleof == "_D6mangle6f10249FlZv"); // <- static assert(Seq10249!(__traits(getOverloads, C10249, "bar"))[1].mangleof == "_D6mangle6C102491gFAyaZv"); // <- } /*******************************************/ // 11718 struct Ty11718(alias sym) {} auto fn11718(T)(T a) { return Ty11718!(a).mangleof; } auto fn11718(T)() { T a; return Ty11718!(a).mangleof; } void test11718() { string TyName(string tail)() { enum s = "__T7Ty11718" ~ tail; enum int len = s.length; return "S6mangle" ~ len.stringof ~ s; } string fnName(string paramPart)() { enum s = "_D6mangle35__T7fn11718T"~ "S6mangle9test11718FZ1AZ7fn11718"~paramPart~"1a"~ "S6mangle9test11718FZ1A"; enum int len = s.length; return len.stringof ~ s; } enum result1 = TyName!("S" ~ fnName!("F"~"S6mangle9test11718FZ1A"~"Z") ~ "Z") ~ "7Ty11718"; enum result2 = TyName!("S" ~ fnName!("F"~"" ~"Z") ~ "Z") ~ "7Ty11718"; struct A {} static assert(fn11718(A.init) == result1); static assert(fn11718!A() == result2); } /*******************************************/ // 11776 struct S11776(alias fun) { } void test11776() { auto g = () { if (1) return; // fill tf->next if (1) { auto s = S11776!(a => 1)(); static assert(typeof(s).mangleof == "S"~"6mangle"~"56"~( "__T"~"6S11776"~"S42"~("6mangle"~"9test11776"~"FZ"~"9__lambda1MFZ"~"9__lambda1")~"Z" )~"6S11776"); } }; } /***************************************************/ // 12044 struct S12044(T) { void f()() { new T[1]; } bool opEquals(O)(O) { f(); } } void test12044() { () { enum E { e } auto arr = [E.e]; S12044!E s; } (); } /*******************************************/ // 12217 void test12217(int) { static struct S {} void bar() {} int var; template X(T) {} static assert( S.mangleof == "S6mangle9test12217FiZ1S"); static assert( bar.mangleof == "_D6mangle9test12217FiZ3barMFZv"); static assert( var.mangleof == "_D6mangle9test12217FiZ3vari"); static assert(X!int.mangleof == "6mangle9test12217FiZ8__T1XTiZ"); } void test12217() {} /***************************************************/ // 12231 void func12231a()() if (is(typeof({ class C {} static assert(C.mangleof == "C6mangle16__U10func12231aZ10func12231aFZ9__lambda1MFZ1C"); // ### L # }))) {} void func12231b()() if (is(typeof({ class C {} static assert(C.mangleof == "C6mangle16__U10func12231bZ10func12231bFZ9__lambda1MFZ1C"); // L__L L LL })) && is(typeof({ class C {} static assert(C.mangleof == "C6mangle16__U10func12231bZ10func12231bFZ9__lambda2MFZ1C"); // L__L L LL }))) {} void func12231c()() if (is(typeof({ class C {} static assert(C.mangleof == "C6mangle16__U10func12231cZ10func12231cFZ9__lambda1MFZ1C"); // L__L L LL }))) { (){ class C {} static assert(C.mangleof == "C6mangle16__T10func12231cZ10func12231cFZ9__lambda1MFZ1C"); // L__L L LL }(); } void func12231c(X)() if (is(typeof({ class C {} static assert(C.mangleof == "C6mangle20__U10func12231cTAyaZ10func12231cFZ9__lambda1MFZ1C"); // L__L L___L LL }))) { (){ class C {} static assert(C.mangleof == "C6mangle20__T10func12231cTAyaZ10func12231cFZ9__lambda1MFZ1C"); // L__L L___L LL }(); } void test12231() { func12231a(); func12231b(); func12231c(); func12231c!string(); } /***************************************************/ void main() { test10077h(); test10077i(); test12044(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link8023.d0000644000175000017500000000034413200164642023027 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/link8023b.d // PERMUTE_ARGS: -inline -release import imports.link8023b; private void t(alias Code)() { return Code(); } void f() { t!( () { } )(); } void main() { f(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/traits_getVirtualIndex.d0000644000175000017500000000500313200164642026256 0ustar matthiasmatthiasmodule traits_getVirtualIndex; class VirtualIndexBase { protected int _foo; int doubler() { return foo * 2; } @property int foo() const { return _foo; } @property void foo(int val) { _foo = val; } final void finalFunc() { } } class VirtualIndexDerived : VirtualIndexBase { @property override int foo() const { return super.foo; } @property override void foo(int val) { super.foo = val; } @property @safe int foo() pure nothrow { return _foo * 2; } final void otherFinalFunc() { } } final class VirtualIndexFinal : VirtualIndexDerived { @property final override int foo() const { return super.foo; } @property final override void foo(int val) { super.foo = val; } @property @safe final override int foo() pure nothrow { return super.foo; } } private @property ptrdiff_t getIndex(T, string m, size_t index = 0)() { return __traits(getVirtualIndex, __traits(getOverloads, T, m)[index]); } void main() { ptrdiff_t doublerIndex = getIndex!(VirtualIndexBase, "doubler"); assert(doublerIndex > 0); ptrdiff_t firstIndex = getIndex!(VirtualIndexBase, "foo", 0); ptrdiff_t secondIndex = getIndex!(VirtualIndexBase, "foo", 1); assert(firstIndex > 0 && secondIndex > 0); // Virtual index is in definition order. assert(secondIndex == firstIndex + 1); assert(firstIndex == doublerIndex + 1); ptrdiff_t finalIndex = getIndex!(VirtualIndexBase, "finalFunc"); assert(finalIndex == -1); assert(getIndex!(VirtualIndexDerived, "doubler") == doublerIndex); assert(getIndex!(VirtualIndexDerived, "foo", 0) == firstIndex); assert(getIndex!(VirtualIndexDerived, "foo", 1) == secondIndex); assert(getIndex!(VirtualIndexDerived, "finalFunc") == finalIndex); assert(getIndex!(VirtualIndexDerived, "otherFinalFunc") == -1); ptrdiff_t newOverloadIndex = getIndex!(VirtualIndexDerived, "foo", 2); assert(newOverloadIndex == secondIndex + 1); foreach(i, overload; __traits(getOverloads, VirtualIndexFinal, "foo")) { // It should still return the initial virtual index even if overridden to be final. ptrdiff_t finalOverrideIndex = getIndex!(VirtualIndexFinal, __traits(identifier, overload), i); ptrdiff_t originalIndex = getIndex!(VirtualIndexDerived, __traits(identifier, overload), i); assert(finalOverrideIndex == originalIndex); } }ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test11863.d0000644000175000017500000000026113200164642023135 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/std11863conv.d import imports.std11863conv; void main() { auto s = to!string(15, 10); assert(s == "15"); // failure } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test5854.d0000644000175000017500000000136313200164642023064 0ustar matthiasmatthiasstruct S1 { long x1, x2; int opCmp(ref const S1 s) const { if (x2 - s.x2 != 0) return x2 < s.x2 ? -1 : 1; return x1 < s.x1 ? -1 : x1 == s.x1 ? 0 : 1; } } struct S2 { long x1, x2; int opCmp(in S2 s) const { if (x2 - s.x2 != 0) return x2 < s.x2 ? -1 : 1; return x1 < s.x1 ? -1 : x1 == s.x1 ? 0 : 1; } } void test5854() { auto arr1 = [S1(4, 4), S1(1, 3), S1(2, 9), S1(3, 22)].sort; foreach (i; 0 .. arr1.length - 1) { assert(arr1[i] < arr1[i + 1]); } auto arr2 = [S2(4, 4), S2(1, 3), S2(2, 9), S2(3, 22)].sort; foreach (i; 0 .. arr2.length - 1) { assert(arr2[i] < arr2[i + 1]); } } void main() { test5854(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test3574a.d0000644000175000017500000000021013200164642023210 0ustar matthiasmatthiasint g = 0; static ~this() { assert(g == 100); } void main() out { g = 100; } body { return; // expected return code == 0 } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/template8.d0000644000175000017500000000664713200164642023474 0ustar matthiasmatthias// NOTE: comes from std.bitmanip // PERMUTE_ARGS: private string myToString(ulong n) { return n < 10 ? "" ~ cast(char) (n + '0') : myToString(n / 10) ~ myToString(n % 10); } private string toStringSfx(ulong n) { return myToString(n) ~ (n > uint.max ? "UL" : "U"); } private string CreateAccessors( string store, T, string name, size_t len, size_t offset)() { static if (!name.length) { // No need to create any accessor return ""; } else { static const maskAllElse = ((1uL << len) - 1u) << offset, maskMyself = ~maskAllElse, signBitCheck = 1uL << (len - 1), extendSign = ~((1uL << len) - 1); string result; static if (is(T == bool)) { static assert(len == 1); // getter result ~= "bool " ~ name ~ "(){ return " "("~store~" & "~toStringSfx(maskAllElse)~") != 0;}"; // setter result ~= "void " ~ name ~ "(bool v){" "if (v) "~store~" |= "~toStringSfx(maskAllElse)~";" "else "~store~" &= "~toStringSfx(maskMyself)~";}"; } else { // getter result ~= T.stringof ~ " " ~ name ~ "(){ auto result = " "("~store~" & " ~ toStringSfx(maskAllElse) ~ ") >>" ~ toStringSfx(offset) ~ ";"; static if (T.min < 0) { result ~= "if (result >= " ~ toStringSfx(signBitCheck) ~ ") result |= " ~ toStringSfx(extendSign) ~ ";"; } result ~= " return cast(" ~ T.stringof ~ ") result;}"; // setter result ~= "void " ~ name ~ "(" ~ T.stringof ~ " v){ "~store~" = ("~store~" & " ~ toStringSfx(maskMyself) ~ ") | " ~ "((cast(typeof("~store~")) v << " ~ toStringSfx(offset) ~ ") & " ~ toStringSfx(maskAllElse) ~ ");}"; } return result; } } private string createStoreName(Ts...)() { static if (Ts.length == 0) return ""; else return Ts[1] ~ createStoreName!(Ts[3 .. $])(); } private string CreateFields(string store, size_t offset, Ts...)() { static if (!Ts.length) { static if (offset == ubyte.sizeof * 8) return "private ubyte " ~ store ~ ";"; else static if (offset == ushort.sizeof * 8) return "private ushort " ~ store ~ ";"; else static if (offset == uint.sizeof * 8) return "private uint " ~ store ~ ";"; else static if (offset == ulong.sizeof * 8) return "private ulong " ~ store ~ ";"; else static assert(false, ToString!(offset)); } else { return CreateAccessors!(store, Ts[0], Ts[1], Ts[2], offset)() ~ CreateFields!(store, offset + Ts[2], Ts[3 .. $])(); } } template BitFields(T...) { //pragma(msg, CreateFields!(createStoreName!(T)(), 0, T)()); mixin(CreateFields!(createStoreName!(T)(), 0, T)()); } struct FloatRep { mixin BitFields!( uint, "fraction", 23, uint, "exponent", 8, bool, "sign", 1); } struct DoubleRep { mixin BitFields!( ulong, "fraction", 52, uint, "exponent", 11, bool, "sign", 1); } struct Bug2355(string x) {} static assert(is(Bug2355!"a" U : Bug2355!V, string V)); int main() { return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test60.d0000644000175000017500000000043213200164642022700 0ustar matthiasmatthiasimport std.stdio; import std.algorithm; void test1() { int[] a = [1,2,3,4,5]; writeln( remove!("a < 3")(a) ); } void test2() { auto arr = [1,2,3,4,5]; auto m = map!"a + 1"(filter!"a < 4"(arr)); } void main() { test1(); test2(); writeln("Success"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/delegate.d0000644000175000017500000001303313200164642023326 0ustar matthiasmatthias// REQUIRED_ARGS: import core.stdc.stdio; /********************************************************/ //int delegate(int, char[]) *p; class Foo { int bar(int i, char[] s) { return 4; } } class Bar : Foo { override int bar(int i, char[] s) { return 5; } } void test1() { int delegate(int, char[]) dg; Foo f = new Foo(); Bar b = new Bar(); int x; dg = &f.bar; x = dg(3, null); assert(x == 4); f = b; dg = &f.bar; x = dg(3, null); assert(x == 5); } /********************************************************/ int foo2() { return 3; } void test2() { int function () fp; fp = &foo2; assert(fp() == 3); } /********************************************************/ class Foo3 { int bar(int i, char[] s) { return 47; } void test() { int delegate(int, char[]) dg; dg = &bar; printf("%d %d\n", dg(3, null), result()); assert(dg(3, null) == result()); dg = &this.bar; printf("%d %d\n", dg(3, null), result()); assert(dg(3, null) == result()); } int result() { return 47; } } class Bar3 : Foo3 { override int bar(int i, char[] s) { return 48; } override int result() { return 48; } void test2() { int delegate(int, char[]) dg; dg = &super.bar; assert(dg(3, null) == 47); } } void test3() { Foo3 f = new Foo3(); f.test(); Bar3 b = new Bar3(); b.test(); b.test2(); } /********************************************************/ int foo4(int x) { return 1; } int foo4(char x) { return 2; } int foo4(int x, int y) { return 3; } void test4() { int function (char) fp; fp = &foo4; assert(fp(0) == 2); } /********************************************************/ class Abc { int foo1(int x) { return 1; } int foo1(char x) { return 2; } int foo1(int x, int y) { return 3; } } void test5() { int delegate(char) dg; Abc a = new Abc(); dg = &a.foo1; assert(dg(0) == 2); } /********************************************************/ int delegate(int) bar6; int[int delegate(int)] aa6; void test6() { aa6[bar6] = 0; } /********************************************************/ void foo7(void delegate(int) dg) { dg(1); //writefln("%s", dg(3)); } void test7() { foo7(delegate(int i) { printf("i = %d\n", i); } ); } /********************************************************/ void foo8(int delegate(int) dg) { printf("%d\n", dg(3)); assert(dg(3) == 6); } void test8() { foo8(delegate(int i) { return i * 2; } ); } /********************************************************/ void foo9(int delegate(int) dg) { assert(dg(3) == 6); } void test9() { foo9( (int i) { return i * 2; } ); } /********************************************************/ // 8257 struct S8257 { static int g() { return 6; } } void test8257() { S8257 s; int w = 2; S8257 func() { ++w; return s; } auto k = &(func()).g; // check that the call to func() still happened assert(w == 3); assert( k() == 6); } auto f8257(string m)() { return &__traits(getMember, S8257.init, m); } static assert (__traits(compiles, f8257!"g"())); /********************************************************/ void foo10(int delegate() dg) { assert(dg() == 6); } void test10() { int i = 3; foo10( { return i * 2; } ); } /********************************************************/ class A12 { public: int delegate(int, int) dgs[4]; int function(int, int) fps[4]; int delegate(int, int) dg; int function(int, int) fp; int f(int x, int y) { printf("here "); int res = x + y; printf("%d\n", res); return res; } void bug_1() { // fp = &f; // fp(1,2); dg = &f; dg(1,2); // fps[] = [&f, &f, &f, &(f)]; // bug 1: this line shouldn't compile // this.fps[0](1, 2); // seg-faults here! dgs[] = [&(f), &(f), &(f), &(f)]; // bug 1: why this line can't compile? this.dgs[0](1, 2); dgs[] = [&(this.f), &(this.f), &(this.f), &(this.f)]; this.dgs[0](1, 2); } } void test12() { A12 a = new A12(); a.bug_1(); } /********************************************************/ // 1570 class A13 { int f() { return 1; } } class B13 : A13 { override int f() { return 2; } } void test13() { B13 b = new B13; assert(b.f() == 2); assert(b.A13.f() == 1); assert((&b.f)() == 2); assert((&b.A13.f)() == 1); } /********************************************************/ // 2472 class A2472 { void foo() {} } void test2472() { auto a = new A2472; auto fp1 = (&a.foo).funcptr; auto dg = &a.foo; auto fp2 = dg.funcptr; assert(fp1 == fp2); } /********************************************************/ void testAssign() { static class C { int a; this(int a) { this.a = a; } int funca() { return a; } int funcb() { return a + 1; } } auto x = new C(5); auto y = new C(7); auto dg = &x.funca; assert(dg() == 5); dg.funcptr = &C.funcb; assert(dg() == 6); dg.ptr = cast(void*)y; assert(dg() == 8); dg.funcptr = &C.funca; assert(dg() == 7); } /********************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test12(); test13(); test2472(); test8257(); testAssign(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/sctor.d0000644000175000017500000001330313200164642022706 0ustar matthiasmatthias// REQUIRED_ARGS: // PERMUTE_ARGS: -w -d -de -dw extern(C) int printf(const char*, ...); /***************************************************/ // mutable field struct S1A { int v; this(int) { v = 1; v = 2; // multiple initialization } } struct S1B { int v; this(int) { if (true) v = 1; else v = 2; v = 3; // multiple initialization } this(long) { if (true) v = 1; v = 3; // multiple initialization } this(string) { if (true) {} else v = 2; v = 3; // multiple initialization } } struct S1C { int v; this(int) { true ? (v = 1) : (v = 2); v = 3; // multiple initialization } this(long) { auto x = true ? (v = 1) : 2; v = 3; // multiple initialization } this(string) { auto x = true ? 1 : (v = 2); v = 3; // multiple initialization } } /***************************************************/ // with control flow struct S2 { immutable int v; immutable int w; int x; this(int) { if (true) v = 1; else v = 2; true ? (w = 1) : (w = 2); x = 1; // initialization L: x = 2; // assignment after labels } this(long n) { if (n > 0) return; v = 1; // skipped initialization // w skipped initialization x = 1; // initialization foreach (i; 0..1) x = 2; // assignment in loops } } /***************************************************/ // with immutable constructor struct S3 { int v; int w; this(int) immutable { if (true) v = 1; else v = 2; true ? (w = 1) : (w = 2); } } /***************************************************/ // in typeof struct S4 { immutable int v; this(int) { static assert(is(typeof(v = 1))); v = 1; } } /***************************************************/ // 8117 struct S8117 { @disable this(); this(int) {} } class C8117 { S8117 s = S8117(1); } void test8117() { auto t = new C8117(); } /***************************************************/ // 9665 struct X9665 { static uint count; ulong payload; this(int n) { payload = n; count += 1; } this(string s) immutable { payload = s.length; count += 10; } void opAssign(X9665 x) { payload = 100; count += 100; } } struct S9665 { X9665 mval; immutable X9665 ival; this(int n) { X9665.count = 0; mval = X9665(n); // 1st, initializing ival = immutable X9665("hi"); // 1st, initializing mval = X9665(1); // 2nd, assignment static assert(!__traits(compiles, ival = immutable X9665(1))); // 2nd, assignment //printf("X9665.count = %d\n", X9665.count); assert(X9665.count == 112); } this(int[]) { X9665.count = 0; mval = 1; // 1st, initializing (implicit constructor call) ival = "hoo"; // ditto assert(X9665.count == 11); } } void test9665() { S9665 s1 = S9665(1); assert(s1.mval.payload == 100); assert(s1.ival.payload == 2); S9665 s2 = S9665([]); assert(s2.mval.payload == 1); assert(s2.ival.payload == 3); } /***************************************************/ // 11246 struct Foo11246 { static int ctor = 0; static int dtor = 0; this(int i) { ++ctor; } ~this() { ++dtor; } } struct Bar11246 { Foo11246 foo; this(int) { foo = Foo11246(5); assert(Foo11246.ctor == 1); assert(Foo11246.dtor == 0); } } void test11246() { { auto bar = Bar11246(1); assert(Foo11246.ctor == 1); assert(Foo11246.dtor == 0); } assert(Foo11246.ctor == 1); assert(Foo11246.dtor == 1); } /***************************************************/ // 13515 Object[string][100] aa13515; static this() { aa13515[5]["foo"] = null; } struct S13515 { Object[string][100] aa; this(int n) { aa[5]["foo"] = null; } } void test13515() { assert(aa13515[5].length == 1); assert(aa13515[5]["foo"] is null); auto s = S13515(1); assert(s.aa[5].length == 1); assert(s.aa[5]["foo"] is null); } /***************************************************/ // 14409 class B14409 { this(int) {} } class C14409 : B14409 { this(int n) { if (true) super(n); else assert(0); } } /***************************************************/ // 14376 auto map14376() { return MapResult14376!(e => 0)(); } struct MapResult14376(alias pred) { @property int front() { return pred(0); } } struct S14376 { typeof(map14376()) x; this(int dummy) { if (true) this.x = map14376(); else assert(0); } } /***************************************************/ // 14351 class B14351 { this(inout int[]) inout { } } class D14351a : B14351 { this(int[] arr) { super(arr); } } class D14351b : B14351 { this(const int[] arr) const { super(arr); } } class D14351c : B14351 { this(inout int[] arr) inout { super(arr); } } /***************************************************/ // 14944 static int[2] tbl14944; static this() { foreach (ref v; tbl14944) { // This is an initialization of referenced memory // rather than the initialization of the reference. v = 1; } } void test14944() { assert(tbl14944[0] == 1); } /***************************************************/ int main() { test8117(); test9665(); test11246(); test13515(); test14944(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/bug846.d0000644000175000017500000000030013200164642022564 0ustar matthiasmatthias// see also: bug 8 // EXTRA_SOURCES: imports/bug846.d import imports.bug846; void main() { auto num = removeIf( "abcdef".dup, ( char c ) { return c == 'c'; } ); assert(num == 5); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/builtin.d0000644000175000017500000000554713200164642023235 0ustar matthiasmatthias import std.stdio; import std.math; import core.bitop; version (X86_64) version = AnyX86; else version (X86) version = AnyX86; /*******************************************/ void test1() { writefln("%a", sin(6.8L)); auto f = 6.8L; writefln("%a", sin(f)); assert(sin(f) == sin(6.8L)); static assert(approxEqual(sin(6.8L), 0x1.f9f8d9aea10fdf1cp-2)); writefln("%a", cos(6.8L)); f = 6.8L; writefln("%a", cos(f)); assert(cos(f) == cos(6.8L)); static assert(approxEqual(cos(6.8L), 0x1.bd21aaf88dcfa13ap-1)); writefln("%a", tan(6.8L)); f = 6.8L; writefln("%a", tan(f)); version (Win64) { } else assert(tan(f) == tan(6.8L)); static assert(approxEqual(tan(6.8L), 0x1.22fd752af75cd08cp-1)); } /*******************************************/ void test2() { float i = 3; i = i ^^ 2; assert(i == 9); int j = 2; j = j ^^ 1; assert(j == 2); i = 4; i = i ^^ .5; assert(i == 2); } /**** Bug 5703 *****************************/ static assert({ int a = 0x80; int f = bsf(a); int r = bsr(a); a = 0x22; assert(bsf(a)==1); assert(bsr(a)==5); a = 0x8000000; assert(bsf(a)==27); assert(bsr(a)==27); a = 0x13f562c0; assert(bsf(a) == 6); assert(bsr(a) == 28); assert(bswap(0xAABBCCDD) == 0xDDCCBBAA); return true; }()); /*******************************************/ void test3() { version (AnyX86) { static assert( _popcnt( cast(ushort)0 ) == 0 ); static assert( _popcnt( cast(ushort)7 ) == 3 ); static assert( _popcnt( cast(ushort)0xAA )== 4); static assert( _popcnt( cast(ushort)0xFFFF ) == 16 ); static assert( _popcnt( cast(ushort)0xCCCC ) == 8 ); static assert( _popcnt( cast(ushort)0x7777 ) == 12 ); static assert( _popcnt( cast(uint)0 ) == 0 ); static assert( _popcnt( cast(uint)7 ) == 3 ); static assert( _popcnt( cast(uint)0xAA )== 4); static assert( _popcnt( cast(uint)0x8421_1248 ) == 8 ); static assert( _popcnt( cast(uint)0xFFFF_FFFF ) == 32 ); static assert( _popcnt( cast(uint)0xCCCC_CCCC ) == 16 ); static assert( _popcnt( cast(uint)0x7777_7777 ) == 24 ); version (X86_64) { static assert( _popcnt( cast(ulong)0 ) == 0 ); static assert( _popcnt( cast(ulong)7 ) == 3 ); static assert( _popcnt( cast(ulong)0xAA )== 4); static assert( _popcnt( cast(ulong)0x8421_1248 ) == 8 ); static assert( _popcnt( cast(ulong)0xFFFF_FFFF_FFFF_FFFF ) == 64 ); static assert( _popcnt( cast(ulong)0xCCCC_CCCC_CCCC_CCCC ) == 32 ); static assert( _popcnt( cast(ulong)0x7777_7777_7777_7777 ) == 48 ); } } } /*******************************************/ int main() { test1(); test2(); test3(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link14588.d0000644000175000017500000000026013200164642023121 0ustar matthiasmatthias// EXTRA_SOURCES: imports/link14588a.d // PERMUTE_ARGS: -allinst -unittest -debug -inline // COMPILE_SEPARATELY import imports.link14588a; void main() { new A().all(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test11.d0000644000175000017500000004523013200164642022701 0ustar matthiasmatthias// REQUIRED_ARGS: extern(C) int printf(const char*, ...); extern(C) size_t strlen(const char*); /**************************************/ alias strlen foo1; void test1() { const(char) *p = "bar"; size_t i = foo1(p); assert(i == 3); } /**************************************/ template Foo2(T) { alias T t; } alias Foo2!(int) t1; alias Foo2!(int).t t2; alias t1.t t3; alias t2 t4; alias Foo2!(int) t5; void test2() { t1.t v1; t2 v2; t3 v3; t4 v4; t5.t v5; int *p; p = &v1; p = &v2; p = &v3; p = &v4; p = &v5; } /**************************************/ debug = stdchar; debug(mychar) { alias byte mychar; } void test3() { debug(mychar) { mychar[] line=cast(mychar[])cast(char[])"It is a long line."; mychar[] delimiter=cast(mychar[])cast(string)"is"; } debug(stdchar) { string line="It is a long line."; string delimiter="is"; } debug(stdbyte) { byte[] line=cast(byte[])cast(string)"It is a long line."; byte[] delimiter=cast(byte[])cast(string)"is"; } debug(stdwchar) { wstring line="It is a long line."; wstring delimiter="is"; } int ptr=3; size_t dl=delimiter.length; size_t pl=ptr+dl; assert(line[ptr..pl]==delimiter[]); } /**************************************/ void test4() { byte* p; version(D_LP64) assert(p.sizeof == 8); else assert(p.sizeof == 4); } /**************************************/ class Foo6 { } void test6() { Foo6 foo = new Foo6(); with (foo) { int x; x = 4; } } /**************************************/ int i7 = 3; void test7() { switch (i7) { default: assert(0); case 3: int x; x = 4; } } /**************************************/ void test8() { string a = "a b c"; assert(a.length == 5); assert(a[1] == '\n'); } /**************************************/ struct Foo9 { char c; char bar() { return c; } } Foo9 makeFoo() { Foo9 f; return f; } void callFoo (Foo9 a) { a.bar(); } void test9() { callFoo(makeFoo ()); } /**************************************/ struct Foo10 { } Foo10 makeFoo10() { Foo10 f; return f; } void callFoo (Foo10 a) { } void test10() { callFoo(makeFoo10()); } /**************************************/ struct Color { int x; } Color[3] colors; Color eval(float x, float y) { colors[1].x = 7; return colors[1]; } void test11() { Color c; c = eval(1.0, 2.0); assert(c.x == 7); } /**************************************/ struct Size12 { int width; int height; } int x12; void foo12(out Size12 sz) { sz.width = 2; if(sz.width == 2) x12 = 1; } void test12() { Size12 sz; foo12(sz); assert(x12 == 1); assert(sz.width == 2); } /**************************************/ interface D13 { void setHostFrame(); } class A13 : D13 { void setHostFrame() { } char group; } void setLayout(D13 lo) { printf("lo = %p\n", lo); lo.setHostFrame(); printf("ok\n"); } void test13() { A13 a = new A13(); printf("a = %p\n", a); setLayout(a); } /**************************************/ void test14() { while(false) { static int a; } } /**************************************/ alias void delegate(int) t_func; class Foo15 { t_func func1; int x; void dothis() { if (func1) func1(4); else x = 3; } void func(int num) { x = num; } } void test15() { Foo15 a = new Foo15; a.dothis(); assert(a.x == 3); a.func1 = &a.func; a.dothis(); assert(a.x == 4); } /**************************************/ int[] foo16(byte[] a) { return cast(int[])a; } void test16() { byte[12] b; int[] i; i = foo16(b); assert(i.length == 3); } /**************************************/ void test17() { { float x = 10; x %= 4; printf("x = %g\n", x); assert(x == 2); x = 10; x = x % 4; printf("x = %g\n", x); assert(x == 2); x = 4; x = 10 % x; printf("x = %g\n", x); assert(x == 2); } { double y = 10; y %= 4; printf("y = %g\n", y); assert(y == 2); y = 10; y = y % 4; printf("y = %g\n", y); assert(y == 2); y = 4; y = 10 % y; printf("y = %g\n", y); assert(y == 2); } { real z = 10; z %= 4; printf("z = %Lg\n", z); assert(z == 2); z = 10; z = z % 4; printf("z = %Lg\n", z); assert(z == 2); z = 4; z = 10 % z; printf("z = %Lg\n", z); assert(z == 2); } } /**************************************/ struct Bar18 { } struct Foo18 { static Bar18 x = { }; } void test18() { const Bar18 b = Foo18.x; } /**************************************/ int x19 = 10; void test19() { bool b; b = cast(bool)x19; assert(b == true); } /**************************************/ class A20 { int abc() { return 3; } alias abc def; } void test20() { int i; A20 a = new A20(); i = a.def(); assert(i == 3); } /**************************************/ void test21() { string s; s = 1 ? "a" : "b"; assert(s == "a"); } /**************************************/ class Foo22 { } class Bar22 : Foo22 { } class Abc22 { Foo22 test() { return null; } } class Def22 : Abc22 { override Bar22 test() { return new Bar22; } } void testx22(Abc22 a) { assert(a.test() !is null); } void test22() { Def22 d = new Def22(); testx22(d); } /**************************************/ struct foo23 { static struct bar { int x; } } void test23() { //printf ("%d\n", foo23.bar.sizeof); assert(foo23.bar.sizeof == int.sizeof); } /**************************************/ void test24() { struct Test { int i; bool bar(int a) { i = a; return true; } } Test t; assert(t.bar(3)); } /**************************************/ void test25() { { const int [] list = [ 1, 2 ]; assert(list[0] == 1); assert(list[1] == 2); } { const int [] list = [ 3, 4 ]; assert(list[0] == 3); assert(list[1] == 4); } } /**************************************/ void test26() { while (0) { int x; } while (0) { int x; } } /**************************************/ struct NODE27 { int data; shared(NODE27) *next; } static shared NODE27 nodetbl[3] = [ { 0,cast(shared(NODE27)*)nodetbl + 1}, { 0,cast(shared(NODE27)*)nodetbl + 2}, { 0,null} ]; static shared NODE27 nodetbl2[3] = [ { 0,&nodetbl2[1]}, { 0,&nodetbl2[2]}, { 0,null} ]; void test27() { } /**************************************/ class Foo28 { protected int x; static class Bar { Foo28 f; int method () { return f.x; } } } void test28() { } /**************************************/ void test29() { int[immutable(byte)[]] foo; static immutable(byte)[] bar = [ 65, 66, 67 ]; foo[bar] = 1; assert(foo[bar] == 1); } /**************************************/ class A30 { static class Child { } } class B30 { static class Child { static int value = 6; } } void test30() { printf ("%d\n", B30.Child.value); assert(B30.Child.value == 6); } /**************************************/ void test31() { float b; b -= 1.0; b += 1.0; } /**************************************/ class Foo32 { struct Bar { int x; } } void test32() { with (new Foo32) { Bar z; z.x = 5; } } /**************************************/ string[2][] foo33; void test33() { string[2] bar; bar[1] = "hello"; foo33 ~= bar; assert(foo33[0][1] == "hello"); } /**************************************/ void test34() { try { int i = 0; printf( "i:%d\n", i ); } finally { printf( "Done\n" ); } try { int i = 1; printf( "i:%d\n", i ); } finally { printf( "Done\n" ); } } /**************************************/ class Bar35 {} template Foo35( T ) { void func() { }; } void test35() { try { alias Foo35!( Bar35 ) filter; } catch (Exception e) { printf( "Exception %.*s", e.msg.length, e.msg.ptr ); } finally { printf( "Done0." ); } } /**************************************/ void test36() { enum {A=1} enum {B=A?0:1} assert(A == 1); assert(B == 0); } /**************************************/ struct A37 { int a; } struct B37 { int a; int b; } struct C37 { int a; int b; int c; } struct D37 { byte a,b,c; } void test37() { A37 a; B37 b; C37 c; D37 d; assert(a.a == 0); assert(b.a == 0 && b.b == 0); assert(c.a == 0 && c.b == 0 && c.c == 0); assert(d.a == 0 && d.b == 0 && d.c == 0); } /**************************************/ int function() fp18; extern(Windows) int func18() { static int otherfunc() { return 18; } fp18 = &otherfunc; return fp18(); } void test38() { assert(func18() == 18); } /**************************************/ class bar39 { struct _sub { bool a; string d; }; _sub mySub; }; class foo39 { bar39._sub[] subArray; this(bar39[] arr) { for(int i=0; i= 1); assert(0 <> 1); assert(!(0 !<>= 1)); assert(!(0 !<> 1)); assert(!(0 !<= 1)); assert(!(0 !< 1)); assert(0 !>= 1); assert(0 !> 1); } /**************************************/ struct Bar48 { uint k; ubyte m; } Bar48 makebar48() { Bar48 b; return b; } void test48() { Bar48 b = makebar48(); } /**************************************/ void testx49() { printf("testx49()\n"); } void test49() { return testx49(); } /**************************************/ int testx50() { printf("testx50()\n"); return 3; } void test50() { return cast(void)testx50(); } /**************************************/ class A51 { static typeof(this) foo() { return new A51(); } this() { bar = 3; } int bar; } class B51 : A51 { static typeof(super) b; } struct C51 { typeof(&this) x; } void test51() { A51 a = A51.foo(); assert(a.bar == 3); B51.b = a; assert(B51.b.bar == 3); assert(B51.b.classinfo == A51.classinfo); C51 c; c.x = &c; } /**************************************/ class A52 { char get() { return 'A'; } char foo() { return typeof(this).get(); } char bar() { return A52.get(); } } class B52 : A52 { override char get() { return 'B'; } } void test52() { B52 b = new B52(); assert(b.foo() == 'A'); assert(b.bar() == 'A'); assert(b.get() == 'B'); } /**************************************/ struct A53 { int b() { return 1; } } int x53() { A53 a; return a.b; } void test53() { assert(x53() == 1); } /**************************************/ class A54 { void a() { printf("A54.a\n"); } void b() { typeof(this).a(); } } class B54 : A54 { override void a() { printf("B54.a\n"); assert(0); } } void test54() { B54 b = new B54(); b.b(); } /**************************************/ int foo55(int x = 5) { printf("x = %d\n", x); return x; } void test55() { int i; i = foo55(6); assert(i == 6); i = foo55(); assert(i == 5); } /**************************************/ class A56 { int foo(int x = 5) { printf("A56.x = %d\n", x); return x; } } class B56 : A56 { override int foo(int x = 7) { printf("B56.x = %d\n", x); return x; } } void test56() { int i; B56 b = new B56(); i = b.foo(6); assert(i == 6); i = b.foo(); assert(i == 7); } /**************************************/ void test57() { char c; wchar w; dchar d; printf("c = %x, w = %x, d = %x\n", c, w, d); assert(c == 0xFF); assert(w == 0xFFFF); assert(d == 0xFFFF); } /**************************************/ void test58() { static int x; static class S { static this() { printf ("static constructor\n"); x = 10; } this() { printf ("class constructor\n"); } } assert(x == 10); new S; } /**************************************/ struct S61 { int a, b, c, d; } void rec(int n, S61 t) { if (n > 0) { t.b++; rec(n-1,t); } } void test61() { S61 F; rec(100, F); } /**************************************/ class A62 { static A62 test(int q=0) { return null; } } A62 foo62() { return A62.test; } void test62() { foo62(); } /**************************************/ class A63 { private import std.file; alias std.file.getcwd getcwd; } void test63() { A63 f = new A63(); auto s = f.getcwd(); printf("%.*s\n", s.length, s.ptr); } /**************************************/ debug = 3; void test64() { debug(5) { assert(0); } debug(3) { int x = 3; } assert(x == 3); } /**************************************/ version = 3; void test65() { version(5) { assert(0); } version(3) { int x = 3; } assert(x == 3); } /**************************************/ // 8809 void test8809() { static class B { char foo() { return 'B'; } } static class C : B { char test1Bx() { return B.foo(); } char test1Cx() { return C.foo(); } char test1Dx() { return foo(); } char test1By() { return this.B.foo(); } char test1Cy() { return this.C.foo(); } // cannot compile -> OK char test1Dy() { return this. foo(); } char test1Bz() { return typeof(super).foo(); } char test1Cz() { return typeof(this). foo(); } //char test1Dz(); char test2Bx() { return { return B.foo(); }(); } char test2Cx() { return { return C.foo(); }(); } char test2Dx() { return { return foo(); }(); } char test2By() { return { return this.B.foo(); }(); } char test2Cy() { return { return this.C.foo(); }(); } // cannot compile -> OK char test2Dy() { return { return this. foo(); }(); } char test2Bz() { return { return typeof(super).foo(); }(); } char test2Cz() { return { return typeof(this). foo(); }(); } //char test2Dz(); char test3Bx() { return (new class Object { char bar() { return B.foo(); } }).bar(); } char test3Cx() { return (new class Object { char bar() { return C.foo(); } }).bar(); } char test3Dx() { return (new class Object { char bar() { return foo(); } }).bar(); } char test3By() { return (new class Object { char bar() { return this.outer.B.foo(); } }).bar(); } char test3Cy() { return (new class Object { char bar() { return this.outer.C.foo(); } }).bar(); } char test3Dy() { return (new class Object { char bar() { return this.outer. foo(); } }).bar(); } override char foo() { return 'C'; } } static class D : C { override char foo() { return 'D'; } } C c = new D(); assert(c.test1Bx() == 'B'); assert(c.test1Cx() == 'C'); assert(c.test1Dx() == 'D'); assert(c.test1By() == 'B'); assert(c.test1Cy() == 'C'); assert(c.test1Dy() == 'D'); assert(c.test1Bz() == 'B'); // NG('D') -> OK assert(c.test1Cz() == 'C'); //assert(c.test1Dz() == 'D'); assert(c.test2Bx() == 'B'); // NG('D') -> OK assert(c.test2Cx() == 'C'); // NG('D') -> OK assert(c.test2Dx() == 'D'); assert(c.test2By() == 'B'); assert(c.test2Cy() == 'C'); assert(c.test2Dy() == 'D'); assert(c.test2Bz() == 'B'); // NG('D') -> OK assert(c.test2Cz() == 'C'); // NG('D') -> OK //assert(c.test2Dz() == 'D'); assert(c.test3Bx() == 'B'); // NG('D') -> OK assert(c.test3Cx() == 'C'); // NG('D') -> OK assert(c.test3Dx() == 'D'); assert(c.test3By() == 'B'); assert(c.test3Cy() == 'C'); assert(c.test3Dy() == 'D'); } /**************************************/ // 9734 void test9734() { class C {} class D : C { static bool test(C) { return true; } void foo()() if (is(typeof(test(super)))) {} void bar()() if (is(typeof(super) == C)) {} } void baz()() if (is(typeof(super))) {} auto d = new D(); d.foo(); d.bar(); static assert(!__traits(compiles, baz())); } /**************************************/ int main(string[] argv) { test1(); test2(); test3(); test4(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); test28(); test29(); test30(); test31(); test32(); test33(); test34(); test35(); test36(); test37(); test38(); test39(); test40(); test41(); test42(); test43(); test44(); test45(); test46(); test47(); test48(); test49(); test50(); test51(); test52(); test53(); test54(); test55(); test56(); test57(); test58(); test61(); test62(); test63(); test64(); test65(); test8809(); test9734(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/mixin2.d0000644000175000017500000001365013200164642022767 0ustar matthiasmatthiasimport std.stdio; /*********************************************/ int foo(int x) { return mixin("x + 1"w); } void test1() { assert(foo(3) == 4); } /*********************************************/ void test2() { int j; mixin(" int x = 3; for (int i = 0; i < 10; i++) writeln(x + i, ++j); "); assert(j == 10); } /*********************************************/ mixin("int abc3 = 5;"); void test3() { writeln(abc3); assert(abc3 == 5); } /*********************************************/ mixin(" void test4() { writeln(\"test4\"); " ~ "}"); /*********************************************/ int x5; scope class Foo5 { this () { writeln ("Constructor"); assert(x5 == 0); x5++; } ~this () { writeln ("Destructor"); assert(x5 == 2); x5++; } } void test5() { { mixin ("scope Foo5 f = new Foo5;\n"); writeln (" Inside Scope"); assert(x5 == 1); x5++; } assert(x5 == 3); } /*********************************************/ void test6() { static const b = "printf(`hey\n`);"; if (true) mixin(b); } /*********************************************/ template Foo7(alias f) { } class Bar7 { mixin Foo7!( function {} ); } void test7() { } /*********************************************/ template TupleDecls(T, R ...) { T value; static if (R.length) mixin TupleDecls!(R) Inner; } struct TupleStruct(T ...) { mixin TupleDecls!(T); } void test8() { alias TupleStruct!(char[], char[]) twoStrings; } /*********************************************/ template Magic() { void* magic = null; } struct Item { mixin Magic A; } struct Foo9(alias S) { } void test9() { Foo9!(Item.A) bar; } /*********************************************/ pragma(msg, "hello"); pragma(msg, ['h', 'e', 'l', 'l', 'o']); pragma(msg, ""); pragma(msg, []); pragma(msg, null); mixin("string hello;"); mixin(['i', 'n', 't', ' ', 't', 'e', 's', 't', '1', '0', 'x', ';']); mixin(""); mixin([]); mixin(null); void test10() { pragma(msg, "hello"); pragma(msg, ['h', 'e', 'l', 'l', 'o']); pragma(msg, ""); pragma(msg, []); pragma(msg, null); mixin("string hello;"); mixin(['i', 'n', 't', ' ', 'a', ';']); mixin(""); mixin([]); mixin(null); } /*********************************************/ // 7560 class Base7560 { template getter(T) { void get(ref T[] i, uint n) {} } mixin getter!uint; mixin getter!char; } class Derived7560 : Base7560 { alias Base7560.get get; void get(ref char[] x) {} } /*********************************************/ // 10577 enum sync10577; public template get_sync10577(size_t I, A...) { static if (I == A.length) enum bool get_sync10577 = false; else static if (is(A[I] == sync10577)) enum bool get_sync10577 = true; else enum bool get_sync10577 = get_sync!10577(I+1, A); } template add_sync10577(T, size_t ITER=0) { static if (ITER == (__traits(derivedMembers, T).length)) { enum string add_sync10577 = ""; } else { enum string mem = __traits(derivedMembers, T)[ITER]; enum string add_sync10577 = "static if (! __traits(isVirtualMethod, " ~ mem ~ ")) {" ~ "mixin(add_sync10577!(get_sync10577!(0, __traits(getAttributes, " ~ mem ~ ")), \"" ~ mem ~ "\"));} " ~ add_sync10577!(T, ITER+1); } } template add_sync10577(bool A, string M) { static if (A) { enum string add_sync10577 = " auto " ~ M[1..$] ~ "() { synchronized(this) return " ~ M ~ "; }"; } else { enum string add_sync10577 = ""; } } class base10577 { public void foo() {} } class derived10577 : base10577 { mixin(add_sync10577!(derived10577)); @sync10577 private bool _bar; public override void foo() {} } /*********************************************/ // 10583 enum sync10583; public template get_sync10583(size_t I, A...) { static if (I == A.length) enum bool get_sync10583 = false; else static if (is(A[I] == sync10583)) enum bool get_sync10583 = true; else enum bool get_sync10583 = get_sync10583!(I+1, A); } template add_sync10583(T, size_t ITER = 0) { static if (ITER == (__traits(derivedMembers, T).length)) { enum string add_sync10583 = ""; } else { enum string mem = __traits(derivedMembers, T)[ITER]; enum string add_sync10583 = "mixin(add_sync10583!(get_sync10583!(0, __traits(getAttributes, " ~ mem ~ ")), __traits(getProtection, " ~ mem ~ "), \"" ~ mem ~ "\"));\n" ~ add_sync10583!(T, ITER+1); } } template add_sync10583(bool A, string P, string M) { static if (A) { enum string add_sync10583 = " auto " ~ M[1..$] ~ "() { synchronized(this) return " ~ M ~ "; }"; } else enum string add_sync10583 = ""; } class derived10583 { mixin(add_sync10583!(derived10583)); @sync10583 private bool _bar; void frop() {} } /*********************************************/ string rep(string s, int n) { return n > 1 ? s ~ rep(s, n-1) : s; } void test7156() { int i; mixin(rep("++i;", 200)); } /*********************************************/ // 7553 template Foo7553() { struct Range7553 {} } template Biz7553() { struct Range7553 {} } class Bar7553 { mixin Foo7553!() index0; mixin Biz7553!() index1; auto to_range(Range)(Range r) { return r; } } void test7553() { auto r2 = new Bar7553().to_range(1); } /*********************************************/ // 13479 mixin template F13479() { void t()() { } alias t!() a; } void test13479() { mixin F13479!(); a(); } /*********************************************/ void main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test7156(); test13479(); writeln("Success"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/xtestenum.d0000644000175000017500000000361313200164642023613 0ustar matthiasmatthias// PERMUTE_ARGS: extern(C) int printf(const char*, ...); /***********************************/ enum : float { E1a, E1b, E1c } void test1() { assert(E1a == 0.0f); assert(E1b == 1.0f); assert(E1c == 2.0f); } /***********************************/ enum : string { E2a = "foo", E2b = "bar", E2c = "abc" } void test2() { assert(E2a == "foo"); assert(E2b == "bar"); assert(E2c == "abc"); } /***********************************/ enum E3 : string { E3a = "foo", E3b = "bar", E3c = "abc" } void test3() { printf("%.*s\n", E3.E3a.length, E3.E3a.ptr); assert(E3.E3a == "foo"); assert(E3.E3b == "bar"); assert(E3.E3c == "abc"); } /***********************************/ enum E4 : char { Tvoid = 'v', Tbool = 'b', } void test4() { E4 m; } /***********************************/ enum E5 : byte { e1, e2 } void test5() { E5 m; } /***********************************/ enum : ubyte { REend, REchar, REichar, REdchar, REidchar, REanychar, } void foo6(ubyte) { } void foo6(int) { assert(0); } void test6() { foo6(REchar); } /***********************************/ enum { foo7 = 1, long bar7 = 2, abc7, } enum x7 = 3; void test7() { assert(x7 == 3); assert(is(typeof(foo7) == int)); assert(is(typeof(bar7) == long)); assert(is(typeof(abc7) == long)); assert(abc7 == 3L); } /***********************************/ enum E8 : real { a, b } /***********************************/ struct S7379 { enum ENUM { M1, M2, M3 } alias ENUM this; } class C7379 { this(S7379 test) { } this(string test) { this(S7379()); } } /***********************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test46.d0000644000175000017500000000021613200164642022704 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test46b.d imports/test46a.d imports/test46c.d // PERMUTE_ARGS: module test46; void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/lexer.d0000644000175000017500000000265713200164642022705 0ustar matthiasmatthias// REQUIRED_ARGS: /*********************************************************/ void test6() { string s = q"(foo(xxx))"; assert(s == "foo(xxx)"); s = q"[foo[xxx]]"; assert(s == "foo[xxx]"); s = q"{foo{xxx}}"; assert(s == "foo{xxx}"); s = q">"; assert(s == "foo"); s = q"[foo(]"; assert(s == "foo("); s = q"/foo]/"; assert(s == "foo]"); s = q"HERE foo HERE"; //writefln("'%s'", s); assert(s == "foo\n"); s = q{ foo(xxx) }; assert(s ==" foo(xxx) "); s = q{foo(}; assert(s == "foo("); s = q{{foo}/*}*/}; assert(s == "{foo}/*}*/"); s = q{{foo}"}"}; assert(s == "{foo}\"}\""); } /*********************************************************/ void test7() { // auto str = \xDB; // assert(str.length == 1); } /*********************************************************/ // 4633 template Types(alias v) { alias typeof(v) Types; } typeof({return 1;}()) a; // ok Types!({return 1;}()) x; // ok void test8() { typeof({return 1;}()) b; Types!({return 1;}()) y; } /*********************************************************/ // bug 6584 version(9223372036854775807){} debug(9223372036854775807){} /*********************************************************/ enum e13102=184467440737095516153.6L; /*********************************************************/ int main() { test6(); test7(); test8(); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/externmangle2.d0000644000175000017500000000547113200164642024336 0ustar matthiasmatthias// EXTRA_CPP_SOURCES: externmangle2.cpp version(Windows) { void main() { } } else { extern(C++): struct Test32NS1 { struct Foo(X) { X *v; } struct Bar(X) { X *v; } }; struct Test32NS2 { struct Foo(X) { X *v; } }; struct Test32(alias Y, alias Z) { Y!(int)* field; }; void test32a(Test32!(Test32NS1.Foo, Test32NS1.Foo) arg); void test32b(Test32!(Test32NS1.Foo, Test32NS1.Bar) arg); void test32c(Test32!(Test32NS1.Foo, Test32NS2.Foo) arg); void test32d(Test32!(Test32NS1.Foo, Test32NS2.Foo) arg1, Test32!(Test32NS2.Foo, Test32NS1.Foo) arg2); interface XXX { } void test33a(XXX, XXX*); struct Test33(alias A, alias B) { } /* void test33(XXX, Test33!(test33a, test33a) arg, XXX); struct Test34(alias A) { }; struct Test34A { static void foo(int); }; void test34(Test34!(Test34A.foo) arg); */ __gshared extern int test36; /* struct Test37(alias A) { }; struct Test37A { __gshared extern int t38; }; void test37(Test37!(test36) arg); void test38(Test37!(Test37A.t38) arg); */ struct Test39 { struct T39A(X) { } } struct T39A { } void test39(Test39.T39A!(.T39A)); version(none) { version(Posix) //Only for g++ with -std=c++0x and Visual Studio 2013+ { struct Test40(T, V...) { } void test40(Test40!(int, double, void)) { } } else version(Win64) //Only for g++ with -std=c++0x and Visual Studio 2013+ { struct Test40(T, V...) { } void test40(Test40!(int, double, void)) { } } } __gshared extern const XXX test41; struct Test42 { __gshared extern const XXX test42; } __gshared extern int[4] test43; const(XXX) test44(); void main() { test32a(Test32!(Test32NS1.Foo, Test32NS1.Foo)()); test32b(Test32!(Test32NS1.Foo, Test32NS1.Bar)()); test32c(Test32!(Test32NS1.Foo, Test32NS2.Foo)()); test32d(Test32!(Test32NS1.Foo, Test32NS2.Foo)(), Test32!(Test32NS2.Foo, Test32NS1.Foo)()); //test33a(null, null); //test33(null, Test33!(test33a, test33a)(), null); //test34(Test34!(Test34A.foo)()); assert(test36 == 36); //test37(Test37!(test36)()); //test38(Test37!(Test37A.t38)()); test39(Test39.T39A!(.T39A)()); assert(test41 is null); assert(Test42.test42 is null); assert(test43 == [1, 2, 3, 4]); auto ptr = &test44; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link10920.d0000644000175000017500000000064613200164642023113 0ustar matthiasmatthias// PERMUTE_ARGS: -version=A // It's imported but won't be linked. import imports.link10920a; void main() { BitArray ba; version(A) { // Run semantic3 of BitArray.toString() // before the FormatSpec instantiation in main(). pragma(msg, typeof(ba.toString())); } // The instance codegen should be run always, unrelated with -version=A. FormatSpec!char fs; fs.func(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/template4.d0000644000175000017500000005216613200164642023465 0ustar matthiasmatthiasimport std.stdio; import core.stdc.stdio; /*********************************************************/ template Foo(T) { static if ( is(T : int) ) alias T t1; static if (T.sizeof == 4) alias T t2; static if ( is(T AB : int) ) alias AB t3; static if ( is(T* V : V*) ) alias V t4; static if ( is(T W) ) alias W t5; else alias char t5; static if ( is(T* X : X*) ) { } } void test1() { Foo!(int).t1 x1; assert(typeid(typeof(x1)) == typeid(int)); Foo!(int).t2 x2; assert(typeid(typeof(x2)) == typeid(int)); Foo!(int).t3 x3; assert(typeid(typeof(x3)) == typeid(int)); Foo!(int).t4 x4; assert(typeid(typeof(x4)) == typeid(int)); Foo!(int).t5 x5; assert(typeid(typeof(x5)) == typeid(int)); Foo!(int).X x6; assert(typeid(typeof(x6)) == typeid(int)); } /*********************************************************/ void test2() { alias int T; static if ( is(T : int) ) alias T t1; static if (T.sizeof == 4) alias T t2; static if ( is(T U : int) ) alias U t3; static if ( is(T* V : V*) ) alias V t4; static if ( is(T W) ) alias W t5; else alias char t5; static if ( is(T* X : X*) ) { } t1 x1; assert(typeid(typeof(x1)) == typeid(int)); t2 x2; assert(typeid(typeof(x2)) == typeid(int)); t3 x3; assert(typeid(typeof(x3)) == typeid(int)); t4 x4; assert(typeid(typeof(x4)) == typeid(int)); t5 x5; assert(typeid(typeof(x5)) == typeid(int)); X x6; assert(typeid(typeof(x6)) == typeid(int)); } /*********************************************************/ void test3() { static if ( is(short : int) ) { printf("1\n"); } else assert(0); static if ( is(short == int) ) assert(0); static if ( is(int == int) ) { printf("3\n"); } else assert(0); } /*********************************************************/ void test4() { alias void Function(int); static if (is(Function Void == function)) printf("if\n"); else assert(0); // static if (is(Void == void)) // printf("if\n"); // else // assert(0); alias byte delegate(int) Delegate; static if (is(Delegate Foo == delegate)) printf("if\n"); else assert(0); static if (is(Foo Byte == function)) printf("if\n"); else assert(0); // static if (is(Byte == byte)) // printf("if\n"); // else // assert(0); union Union { } static if (is(Union == union)) printf("if\n"); else assert(0); struct Struct { } static if (is(Struct == struct)) printf("if\n"); else assert(0); enum Enum : short { EnumMember } static if (is(Enum Short == enum)) printf("if\n"); else assert(0); static if (is(Short == short)) printf("if\n"); else assert(0); class Class { } static if (is(Class == class)) printf("if\n"); else assert(0); interface Interface { } static if (is(Interface == interface)) printf("if\n"); else assert(0); } /*********************************************************/ class Foo5(T) { Node sentinel; struct Node { int value; } } void test5() { Foo5!(int) bar=new Foo5!(int); bar.sentinel.value = 7; } /*********************************************************/ template factorial6(int n) { static if (n == 1) const int factorial6 = 1; else const int factorial6 = n * .factorial6!(n-1); } void test6() { int i = factorial6!(4); printf("%d\n", i); assert(i == 24); } /*********************************************************/ template factorial7(float n, cdouble c, string sss, string ttt) { static if (n == 1) const float factorial7 = 1; else const float factorial7 = n * 2; } template bar7(wstring abc, dstring def) { const int x = 3; } void test7() { float f = factorial7!(4.25, 6.8+3i, "hello", null); printf("%g\n", f); assert(f == 8.5); int i = bar7!("abc"w, "def"d).x; printf("%d\n", i); assert(i == 3); } /*********************************************************/ template whale(string walrus) { const char [] whale = walrus; } template dolphin(string fish) { const char [] dolphin = whale!(fish[0..3]); } const char [] urchin1 = dolphin!("anenome"); const char [] urchin2 = whale!("anenome"[0..3]); template dolphin3(string fish) { const char [] dolphin3 = fish[0..3]; } const char [] urchin3 = dolphin3!("anenome"); template dolphin4(string fish) { const char [] dolphin4 = whale!(fish[0..(3)]); } const char [] urchin4 = dolphin4!("anenome"); template dolphin5(string fish) { const char [] dolphin5 = whale!(fish[(0)..3]); } const char [] urchin5 = dolphin5!("anenome"); void test8() { assert(urchin1 == "ane"); assert(urchin2 == "ane"); assert(urchin3 == "ane"); assert(urchin4 == "ane"); assert(urchin5 == "ane"); } /*********************************************************/ int testEmpty(string s) { return 0; } template Recurse(string pattern){ } template slice(string str, int from, int to) { const string slice = str[from..to]; } template Compile(string pattern) { const string left = slice!(pattern,4,pattern.length); const string remaining = slice!(left,1,left.length); alias Recurse!(remaining) fn; } template Match(string pattern) { alias Compile!(pattern) Match; } void test9() { alias Match!("abcdefghijk") f; } /*********************************************************/ template Foo10(string s) { const string Foo10 = s; } void test10() { string s; s = Foo10!("abc" ~ "e"); assert(s == "abce"); s = Foo10!("abc" ~ 'f'); assert(s == "abcf"); s = Foo10!('g' ~ "abc"); assert(s == "gabc"); s = Foo10!('g' ~ "abc" ~ 'h'); assert(s == "gabch"); } /*********************************************************/ template Foo11(string s) { const string Foo11 = s; } void test11() { string s; s = Foo11!("abcdef"[1..$ - 1]); assert(s == "bcde"); } /*********************************************************/ template Foo12(int i) { const int Foo12 = i; } void test12() { int i; i = Foo12!("abcdef" == "abcdef"); assert(i == 1); i = Foo12!("abcdef" == "abcqef"); assert(i == 0); i = Foo12!("abcdef" == "abc"); assert(i == 0); i = Foo12!("abc" == "abcdef"); assert(i == 0); } /*********************************************************/ const a13 = 3; static if (a13 == 3) int b13 = 7; template Foo13(int i) { const int j = i + 1; static if (j == 3) const int k = 2; } void test13() { assert(b13 == 7); assert(Foo13!(2).k == 2); } /*********************************************************/ template zebra(string w) { static if (w.length > 2 && w[1] == 'q') const bool zebra = true; else const bool zebra = false; } template horse(string w) { static if (w.length == 1 || w[1] == 'q') const bool horse = true; else const bool horse = false; } void test14() { bool lion = zebra!("a"); writeln(lion); assert(!lion); lion = zebra!("aqb"); writeln(lion); assert(lion); lion = horse!("a"); writeln(lion); assert(lion); lion = horse!("aqb"); writeln(lion); assert(lion); lion = horse!("ab"); writeln(lion); assert(!lion); } /*********************************************************/ template factorial15(int n) { static if (n<2) const int factorial15 = 1; else const int factorial15 = n * factorial15!(n-1); } template rhino15(alias hippo) { const int rhino15 = hippo!(3); } void test15() { const int lion = rhino15!(factorial15); assert(lion == 6); } /*********************************************************/ // Create a constant array of int or uint sized items // as a dstring string. n is the index of the last item. template makeLookup(alias entry, int n) { static if (n == -1) // start with an empty array... const dchar [] makeLookup = ""; else // ... and fill it up const dchar [] makeLookup = makeLookup!(entry, n-1) ~ cast(dchar)entry!(n); } template factorial16(uint n) { static if (n<2) const uint factorial16 = 1; else const factorial16 = n * factorial16!(n-1); } // Make an array of factorials from 0 to 13 (14!> uint.max) const smallfactorials = makeLookup!(factorial16, 13); const uint[14] testtable = [ 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 1932053504, ]; void test16() { for (int i=0; i99 && fish!( (bird[95])) ) const int dog = 2; else const int dog = 3; } const int pig = dog!("a"); void test23() { } /*********************************************************/ T delegate (T) acc24 (T) (T n) { return (T i) { return n += i; }; } void test24() { auto acc1 = acc24 (4); } /*********************************************************/ T func25(T, T c = 1)(T x) { return x * c; } void test25() { double d; d = func25(1.0); assert(d == 1.0); d = func25(2.0); assert(d == 2.0); d = func25!(double)(2.0); assert(d == 2.0); d = func25!(double, 3)(2.0); assert(d == 6.0); } /*********************************************************/ class Foo26 {} class Bar26 {} string name26; template aliastest(alias A) { pragma(msg,"Alias Test instantiated"); void aliastest() { name26 = (new A!().al).classinfo.name; //writefln("Alias Test: ", name26); } } template boxtpl(alias A) { template box() { alias A al; } } void test26() { aliastest!(boxtpl!(Foo26).box) (); assert(name26 == "template4.Foo26"); aliastest!(boxtpl!(Bar26).box) (); assert(name26 == "template4.Bar26"); } /*********************************************************/ struct TFoo27(int x) { } alias TFoo27!(3) a; alias TFoo27!(2+1) b; alias TFoo27!(3u) c; static assert(is(TFoo27!(3) == TFoo27!(2 + 1))); static assert(is(TFoo27!(3) == TFoo27!(3u))); void test27() { } /*********************************************************/ struct SiQuantity { real value = 0; static assert(SiQuantity.sizeof == real.sizeof); template AddDimensions(int mul, U) { } } void test28() { } /*********************************************************/ template Count29() { const Count29 = 5; } void test29() { int[Count29!()] x; assert(x.length == 5); } /*********************************************************/ class FooClass(T) { T data; } struct FooStruct(T) { T data; } void bar_struct(T)(FooStruct!(T) a) {} void bar_class(T)(FooClass!(T) a) {} void test30() { auto C = new FooClass!(double); FooStruct!(double) S; bar_struct(S); bar_class!(double)(C); bar_class(C); } /*********************************************************/ V get31(V,K)(V[K] dict, K key, V def = V.init) { V* ptr = key in dict; return ptr? *ptr: def; } string get31x(string[int] dict, int key, string def = null) { string* ptr = key in dict; return ptr? *ptr: def; } void test31() { string[int] i2s; i2s[1] = "Hello"; i2s[5] = "There"; writeln( i2s.get31(1, "yeh") ); writeln( i2s.get31(2, "default") ); writeln( i2s.get31(1) ); writeln( i2s.get31(2) ); } /*********************************************************/ void delegate(T, S) Concat(S, T...)(void delegate(T) one, void delegate(S) two) { return( delegate void(T t, S s){} ); } void test32() { void delegate(char, char, int) wtf = Concat( delegate void(char a, char b) {}, delegate void(int lol) {} ); } /*********************************************************/ struct Composer(T) { alias T delegate(T) Fun; Fun[] funs; public T opCall()(T x) { T result = x; foreach_reverse (f; funs) { result = f(result); } return result; } public void opAddAssign(Fun f) { funs ~= f; } } struct square(T) { T opCall(T t) { return t*t; } } struct plus1(T) { T opCall(T t) { return t+1; } } struct div3(T) { T opCall(T t) { return t/3.0; } } T delegate(T) tofp(T : S!(T), alias S)() { class Foo { div3!(T) arg; T bar(T t) { return arg(t); } } Foo f = new Foo; return &f.bar; } void test33() { Composer!(double) comp; comp += delegate double (double x) { return x/3.0;}; comp += delegate double (double x) { return x*x;}; comp += (double x) => x + 1.0; writefln("%f", comp(2.0)); // Try function objects Composer!(double) comp2; comp2 += tofp!(div3!(double))(); comp2 += tofp!(square!(double))(); comp2 += tofp!(plus1!(double))(); writefln("%f", comp2( 2.0)); } /*********************************************************/ template Print34(Ts ...) { pragma (msg, Ts.stringof); } template Tuple34(Ts ...) { alias Ts Tuple34; } template Decode34( T ) { alias Tuple34!() Types; } template Decode34( T : TT!(U1), alias TT, U1 ) { alias Tuple34!(U1) Types; } template Decode34( T : TT!(U1,U2), alias TT, U1, U2 ) { alias Tuple34!(U1,U2) Types; } template Decode34( T : TT!(U1,U2,U3), alias TT, U1, U2, U3 ) { alias Tuple34!(U1,U2,U3) Types; } struct S34_1(T1) {} struct S34_2(T1, T2) {} struct S34_3(T1, T2, T3) {} alias Decode34!( bool ).Types SQ0; alias Decode34!( S34_1!(bool) ).Types SQ1; alias Decode34!( S34_2!(bool,short) ).Types SQ2; alias Decode34!( S34_3!(bool,short,int) ).Types SQ3; mixin Print34!(SQ0); mixin Print34!(SQ1); mixin Print34!(SQ2); mixin Print34!(SQ3); void test34() { } /*********************************************************/ template strof(T) { static string strof = T.stringof; } void test35() { alias typeof(delegate () { return (char[]).init;} ) del; auto a = strof!(del); auto aa = strof!(int); auto ab = strof!(typeof(5)); auto meth = delegate () { return (char[]).init;}; auto b = strof!(typeof(meth)); auto c = strof!(typeof(delegate () { return 5; } )); auto d = strof!(typeof(delegate () { return (char[]).init;} )); } /*********************************************************/ struct Number36(int N) { const int value = N; } struct Foo36(T) { int talk() { printf("Not so special:\n"); return 1; } } struct Foo36(T : Number36!(N), int N) { int talk() { printf("Ooh special - NUMBER N\n"); return 2; } } void test36() { Foo36!(Number36!(5)) x; auto i = x.talk(); assert(i == 2); } /*********************************************************/ struct Base37(T) {} alias Base37 Alias37; void foo37(T)(Alias37!(T) x) {} void test37() { Base37!(float) b; foo37(b); // fails! } /*********************************************************/ void sort(alias dg, T)(T[] arr) { bool a = dg(1,2); printf("a = %d\n", a); assert(a == true); } void test38() { int[] arr; int i = 3; sort!( (x,y){ return x + i > y; } )(arr); sort!( (int x,int y){ return x + i > y; } )(arr); } /*********************************************************/ void bug4652(U, T...)(long y, T x, U num) {} void bug4652default(T) (T value, int x=2) {} void bug4652default(T) (T value, int y) {} void bug4676(T...)(T args, string str) {} void bug4676(T...)(T args) {} void instantiate4652() { bug4652(2, 'c', 27, 'e', 'f',1); // rejects-valid bug4652(2, 1); // infinite loop on valid code bug4652default(true); bug4676(1, 2, 3); } /*********************************************************/ // 7589 struct T7589(T) { void n; } static assert(!__traits(compiles, T7589!(int))); int bug7589b(T)() @safe { int *p; *(p + 8) = 6; } static assert(!__traits(compiles, bug7589b!(int)()+7 )); /*********************************************************/ int bar39(alias dg)(int i) { return dg(i); } void test39() { auto i = bar39!(a => a + 1)(3); if (i != 4) assert(0); } /*********************************************************/ // 6701 uint foo_6701(uint v:0)() { return 1; } uint foo_6701(uint v)() { return 0; } uint foo2_6701(uint v:0, string op)() { return 1; } uint foo2_6701(uint v, string op)() { return 0; } void test6701() { assert(foo_6701!(0u)() == 1); assert(foo2_6701!(0u, "+")() == 1); } /******************************************/ // 7469 struct Foo7469a(int x) { } struct Foo7469b(int x) { } struct Foo7469c(alias v) { } struct Foo7469d(T...) { } struct Foo7469e(int a, T...) { } struct Foo7469f(T, int k=1) { } struct Foo7469g(T, int k=1) { } void test7469() { static assert(Foo7469a!(3 ) .mangleof[$-28 .. $] == "17__T8Foo7469aVii3Z8Foo7469a"); static assert(Foo7469a!(3u) .mangleof[$-28 .. $] == "17__T8Foo7469aVii3Z8Foo7469a"); static assert(Foo7469b!(3u) .mangleof[$-28 .. $] == "17__T8Foo7469bVii3Z8Foo7469b"); static assert(Foo7469b!(3 ) .mangleof[$-28 .. $] == "17__T8Foo7469bVii3Z8Foo7469b"); static assert(Foo7469c!(3 ) .mangleof[$-28 .. $] == "17__T8Foo7469cVii3Z8Foo7469c"); static assert(Foo7469c!(3u) .mangleof[$-28 .. $] == "17__T8Foo7469cVki3Z8Foo7469c"); static assert(Foo7469d!(3 ) .mangleof[$-28 .. $] == "17__T8Foo7469dVii3Z8Foo7469d"); static assert(Foo7469d!(3u) .mangleof[$-28 .. $] == "17__T8Foo7469dVki3Z8Foo7469d"); static assert(Foo7469e!(3u, 5u).mangleof[$-32 .. $] == "21__T8Foo7469eVii3Vki5Z8Foo7469e"); static assert(Foo7469f!(int, 1).mangleof[$-30 .. $] == "19__T8Foo7469fTiVii1Z8Foo7469f"); static assert(Foo7469f!(int) .mangleof[$-30 .. $] == "19__T8Foo7469fTiVii1Z8Foo7469f"); static assert(Foo7469g!(int) .mangleof[$-30 .. $] == "19__T8Foo7469gTiVii1Z8Foo7469g"); static assert(Foo7469g!(int, 1).mangleof[$-30 .. $] == "19__T8Foo7469gTiVii1Z8Foo7469g"); } /******************************************/ template foo7698a(T, T val : 0) { enum foo7698a = val; } T foo7698b(T, T val : 0)() { return val; } T foo7698c(T, T val : T.init)() { return val; } void test7698() { static assert(foo7698a!(int, 0) == 0); assert(foo7698b!(int, 0)() == 0); assert(foo7698c!(int, 0)() == 0); } /*********************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); test28(); test29(); test30(); test31(); test32(); test33(); test34(); test35(); test36(); test37(); test38(); test39(); test6701(); test7698(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testv.d0000644000175000017500000000406313200164642022724 0ustar matthiasmatthias extern(C) int printf(const char*, ...); /*********************************************************/ int sum(int[] xx ...) { int s; foreach (int x; xx) s += x; return s; } void test1() { static int[3] a = [5, 8, 10]; int[] b = a; int i; i = sum(); assert(i == 0); i = sum(10); assert(i == 10); i = sum(10, 20); assert(i == 30); i = sum(11, 22, 34); assert(i == 67); i = sum(a); assert(i == 23); i = sum(b); assert(i == 23); printf("%d\n", sum()); } /*********************************************************/ int sum2(int[3] xx ...) { int s; foreach (int x; xx) s += x; return s; } void test2() { static int[3] a = [5, 8, 10]; int i; i = sum2(11, 22, 34); assert(i == 67); i = sum2(a); assert(i == 23); printf("%d\n", i); } /*********************************************************/ int[4] bb3 = [5,6,7,8]; int sum3(int[] xx = bb3 ...) { int s; foreach (int x; xx) s += x; return s; } void test3() { static int[3] a = [5, 8, 10]; int i; i = sum3(11, 22, 34); assert(i == 67); i = sum3(a); assert(i == 23); i = sum3(); assert(i == 26); printf("%d\n", i); } /*********************************************************/ class Foo4 { int a; float f; double d; this(int a, float f, double d) { this.a = a; this.f = f; this.d = d; } } int sum4(Foo4 f ...) { return cast(int)(f.a + f.f + f.d); } void test4() { int i; Foo4 foo = new Foo4(1, 2f, 3.0); i = sum4(foo); assert(i == 1+2+3); i = sum4(4, 5f, 6.0); assert(i == 4+5+6); printf("%d\n", i); } /*********************************************************/ void bug1993(int[][] y...) { } void test5() { bug1993(null); bug1993(null, null); bug1993([0], null); bug1993([0], [0]); bug1993(null, [0]); } /*********************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/inline.d0000644000175000017500000002414513200164642023040 0ustar matthiasmatthias import std.stdio; // Test function inlining debug = NRVO; /************************************/ int foo(int i) { return i; } int bar() { return foo(3) + 4; } void test1() { printf("%d\n", bar()); assert(bar() == 7); } /************************************/ struct Foo2 { int a,b,c,e,f,g; } int foo2(Foo2 f) { f.b += 73; return f.b; } int bar2() { Foo2 gg; gg.b = 6; return foo2(gg) + 4; } void test2() { printf("%d\n", bar2()); assert(bar2() == 83); } /************************************/ struct Foo3 { int bar() { return y + 3; } int y = 4; } void test3() { Foo3 f; assert(f.bar() == 7); } /************************************/ void func(void function () v) { } void test4() { static void f1() { } func(&f1); //func(f1); } /************************************/ void foo5(ubyte[16] array) { bar5(array.ptr); } void bar5(ubyte *array) { } void abc5(ubyte[16] array) { foo5(array); } void test5() { } /************************************/ struct Struct { real foo() { return 0; } void bar(out Struct Q) { if (foo() < 0) Q = this; } } void test6() { } /************************************/ struct S7(T) { immutable(T)[] s; } T foo7(T)(T t) { enum S7!(T)[] i = [{"hello"},{"world"}]; auto x = i[0].s; return t; } void test7() { auto x = foo7('c'); } /************************************/ // 10833 string fun10833(T...)() { foreach (v ; T) return v; assert(0); } void test10833() { auto a = fun10833!("bar")(); } /************************************/ // Bugzilla 4825 int a8() { int r; return r; } int b8() { return a8(); } void test8() { void d() { auto e = b8(); } static const int f = b8(); } /************************************/ // 4841 auto fun4841a() { int i = 42; struct Result { this(int u) {} auto bar() { // refer context of fun4841a return i; } } return Result(); } void test4841a() { auto t = fun4841a(); auto x = t.bar(); assert(x == 42); } auto fun4841b() { int i = 40; auto foo() // hasNestedFrameRefs() == false { // struct Result { this(int u) {} auto bar() { // refer context of fun4841b return i + 2; } } return Result(); } return foo(); } void test4841b() { auto t = fun4841b(); assert(cast(void*)t.tupleof[$-1] !is null); // Result to fun4841b auto x = t.bar(); assert(x == 42); } auto fun4841c() { int i = 40; auto foo() // hasNestedFrameRefs() == true { int g = 2; struct Result { this(int u) {} auto bar() { // refer context of fun4841c and foo return i + g; } } return Result(); } return foo(); } void test4841c() { auto t = fun4841c(); assert( cast(void*)t.tupleof[$-1] !is null); // Result to foo assert(*cast(void**)t.tupleof[$-1] !is null); // foo to fun4841c auto x = t.bar(); assert(x == 42); } void test4841() { test4841a(); test4841b(); test4841c(); } /************************************/ // 7261 struct AbstractTask { ubyte taskStatus; } struct Task { AbstractTask base; alias base this; void opAssign(Task rhs) { } ~this() { if (taskStatus != 3) { } } } /************************************/ // 9356 void test9356() { static inout(char)[] bar (inout(char)[] a) { return a; } string result; result ~= bar("abc"); assert(result == "abc"); } /************************************/ // 12079 void test12079() { string[string][string] foo; foo.get("bar", null).get("baz", null); } /************************************/ // 12243 char f12243() { return 'a'; } void test12243() { string s; s ~= f12243(); } /************************************/ // 11201 struct Foo11201 { int a; float b; Foo11201 func()() const { return this; } } auto f11201()(Foo11201 a) { return a; } void test11201() { auto a = Foo11201(0, 1); assert(f11201(a.func!()()) == a); } /************************************/ // 11223 struct Tuple11223(T...) { T values; void opAssign(Tuple11223 rhs) { if (0) values = rhs.values; else assert(1); } } void test11223() { Tuple11223!string tmp; tmp = Tuple11223!string(); } /************************************/ void foo3918() { import core.stdc.stdlib : alloca; void[] mem = alloca(1024)[0..1024]; } void test3918() { foreach(i; 0 .. 10_000_000) { foo3918(); } } /************************************/ // 11314 struct Tuple11314(T...) { T values; void opAssign(typeof(this) rhs) { if (0) values[] = rhs.values[]; else assert(1); } } struct S11314 {} void test11314() { Tuple11314!S11314 t; t = Tuple11314!S11314(S11314.init); } /************************************/ // 11224 S11224* ptr11224; struct S11224 { this(int) { ptr11224 = &this; /*printf("ctor &this = %p\n", &this);*/ } this(this) { /*printf("cpctor &this = %p\n", &this);*/ } int num; } S11224 foo11224() { S11224 s = S11224(1); //printf("foo &this = %p\n", &s); assert(ptr11224 is &s); return s; } void test11224() { auto s = foo11224(); //printf("main &this = %p\n", &s); assert(ptr11224 is &s); } /************************************/ // 11322 bool b11322; uint n11322; ref uint fun11322() { if (b11322) return n11322; else return n11322; } void test11322() { fun11322()++; assert(n11322 == 1); fun11322() *= 5; assert(n11322 == 5); } /************************************/ // 11394 debug(NRVO) static void* p11394a, p11394b, p11394c; static int[3] make11394(in int x) pure { typeof(return) a; a[0] = x; a[1] = x + 1; a[2] = x + 2; debug(NRVO) p11394a = cast(void*)a.ptr; return a; } struct Bar11394 { immutable int[3] arr; this(int x) { this.arr = make11394(x); // NRVO should work debug(NRVO) p11394b = cast(void*)this.arr.ptr; } } void test11394() { auto b = Bar11394(5); debug(NRVO) p11394c = cast(void*)b.arr.ptr; //debug(NRVO) printf("p1 = %p\np2 = %p\np3 = %p\n", p11394a, p11394b, p11394c); debug(NRVO) assert(p11394a == p11394b); debug(NRVO) assert(p11394b == p11394c); } /**********************************/ // 12080 class TZ12080 {} struct ST12080 { ST12080 opBinary()() const pure nothrow { auto retval = ST12080(); return retval; // NRVO } long _stdTime; immutable TZ12080 _timezone; } class Foo12080 { ST12080 bar; bool quux; public ST12080 sysTime() out {} body { if (quux) return ST12080(); return bar.opBinary(); // returned value is set to __result // --> Inliner wrongly created the second DeclarationExp for __result. } } /**********************************/ // 13503 void f13503a(string[] s...) { assert(s[0] == "Cheese"); } auto f13503b(string arg) { string result = arg; return result; } string f13503c(string arg) { string result = arg; return result; } void test13503() { f13503a(f13503b("Cheese")); f13503a(f13503c("Cheese")); } /**********************************/ // 14267 // EXTRA_SOURCES: imports/a14267.d import imports.a14267; void test14267() { foreach (m; __traits(allMembers, SysTime14267)) { static if (is(typeof(__traits(getMember, SysTime14267, m)))) { foreach (func; __traits(getOverloads, SysTime14267, m)) { auto prot = __traits(getProtection, func); static if (__traits(isStaticFunction, func)) { static assert(func.stringof == "min()"); auto result = func; } } } } } /**********************************/ // 14306 struct MapResult(alias fun) { void front() { // while (1) { break; } fun(1); } } void bar(R)(R r) { foreach (i; 0..100) { r.front(); } } struct S { int x; int bump() { while (1) { break; } ++x; return x; } } void fun(ref S s) { MapResult!(y => s.bump())().bar; // MapResult!((int x) => s.bump())().bar; if (s.x != 100) assert(0); } void test14306() { S t; fun(t); } /**********************************/ // 14754 auto aafunc14754(string k) { enum aa = [ "K": "V" ]; auto p = k in aa; return null; } struct MapResult14754(alias fun, R) { R _input; @property auto ref front() { return fun(_input[0]); } } auto array14754(R)(R r) { alias E = typeof(r.front); E[] result; result ~= r.front; return result; } auto mapfun14754(R)(R words, string k) { return array14754(MapResult14754!(s => aafunc14754(k), R)(words)); } void test14754() { auto r = mapfun14754([""], ""); } /**********************************/ // 14606 struct S14606 { this(long stdTime) { _stdTime = stdTime; } long _stdTime; } S14606 getS14606() { S14606 sysTime = S14606(0); return sysTime; } struct T14606 { this(string) { uint[3] arr; s = getS14606(); } S14606 s; } void test14606() { auto t = T14606(null); } /**********************************/ // 14753 pragma(inline) void test14753(string) { } /**********************************/ int main() { test1(); test2(); test3(); test3918(); test4(); test5(); test9356(); test6(); test7(); test8(); test4841(); test11201(); test11223(); test11314(); test11224(); test11322(); test11394(); test13503(); test14306(); test14754(); test14606(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test48.d0000644000175000017500000000216713200164642022715 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test48a.d // PERMUTE_ARGS: import std.stdio; import imports.test48a; void main() { S s; auto i = s.tupleof[0] + s.tupleof[1] + s.tupleof[2]; printf("i = %d\n", i); assert(i == 6); auto t = s.tupleof; i = t[0] + t[1] + t[2]; printf("i = %d\n", i); assert(i == 6); printf("a = %d %d %d\n", S.tupleof.offsetof); auto o = S.tupleof.offsetof; assert(o[0] == 0); assert(o[1] == 4); assert(o[2] == 8); printf("a = %d %d %d\n", S.tupleof[0].offsetof, S.tupleof[1].offsetof, S.tupleof[2].offsetof); assert(S.tupleof[0].offsetof == 0); assert(S.tupleof[1].offsetof == 4); assert(S.tupleof[2].offsetof == 8); auto offset0 = cast(void*)&s.tupleof[0] - cast(void*)&s; printf("offset0 = %d\n", offset0); assert(offset0 == 0); auto offset1 = cast(void*)&s.tupleof[1] - cast(void*)&s; printf("offset1 = %d\n", offset1); assert(offset1 == 4); auto offset2 = cast(void*)&s.tupleof[2] - cast(void*)&s; printf("offset2 = %d\n", offset2); assert(offset2 == 8); int t1[S.tupleof.offsetof[1]]; assert(t1.length == 4); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_440.d0000644000175000017500000000036713200164642024255 0ustar matthiasmatthiasimport std.stdio; enum E : string { A = "A", B = "B", C = "C", } void main(string[] args) { string[E] aa = [E.A : "a", E.B : "b", E.C : "c"]; assert(aa[E.A] == "a"); assert(aa[E.B] == "b"); assert(aa[E.C] == "c"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/iasm64.d0000644000175000017500000061704113200164642022670 0ustar matthiasmatthias// PERMUTE_ARGS: // Copyright (c) 1999-2011 by Digital Mars // All Rights Reserved // written by Walter Bright // http://www.digitalmars.com import core.stdc.stdio; version (D_PIC) { int main() { return 0; } } else version (D_InlineAsm_X86_64) { struct M128 { int a,b,c,d; }; struct M64 { int a,b; }; /+ __gshared byte b; __gshared short w; __gshared int i; __gshared long l; +/ /****************************************************/ void test1() { int foo; int bar; static const int x = 4; asm { align x; ; mov EAX, __LOCAL_SIZE ; mov foo[RBP], EAX ; } assert(foo == 16); // stack must be 16 byte aligned } /****************************************************/ void test2() { int foo; int bar; asm { even ; mov EAX,0 ; inc EAX ; mov foo[RBP], EAX ; } assert(foo == 1); } /****************************************************/ void test3() { int foo; int bar; asm { mov EAX,5 ; jmp $ + 2 ; dw 0xC0FF,0xC8FF ; // inc EAX, dec EAX mov foo[RBP],EAX ; } assert(foo == 4); } /****************************************************/ void test4() { int foo; int bar; asm { xor EAX,EAX ; add EAX,5 ; jne L1 ; dw 0xC0FF,0xC8FF ; // inc EAX, dec EAX L1: dw 0xC8FF ; mov foo[RBP],EAX ; } assert(foo == 4); } /****************************************************/ void test5() { int foo; ubyte *p; ushort *w; uint *u; ulong *ul; float *f; double *d; real *e; static float fs = 1.1; static double ds = 1.2; static real es = 1.3; asm { call L1 ; db 0xFF,0xC0; ; // inc EAX db "abc" ; ds "def" ; di "ghi" ; dl 0x12345678ABCDEF; df 1.1 ; dd 1.2 ; de 1.3 ; L1: pop RBX ; mov p[RBP],RBX ; } assert(p[0] == 0xFF); assert(p[1] == 0xC0); assert(p[2] == 'a'); assert(p[3] == 'b'); assert(p[4] == 'c'); w = cast(ushort *)(p + 5); assert(w[0] == 'd'); assert(w[1] == 'e'); assert(w[2] == 'f'); u = cast(uint *)(w + 3); assert(u[0] == 'g'); assert(u[1] == 'h'); assert(u[2] == 'i'); ul = cast(ulong *)(u + 3); assert(ul[0] == 0x12345678ABCDEF); f = cast(float *)(ul + 1); assert(*f == fs); d = cast(double *)(f + 1); assert(*d == ds); e = cast(real *)(d + 1); assert(*e == es); } /****************************************************/ void test6() { ubyte *p; static ubyte data[] = [ 0x8B, 0x01, // mov EAX,[RCX] 0x8B, 0x04, 0x19, // mov EAX,[RBX][RCX] 0x8B, 0x04, 0x4B, // mov EAX,[RCX*2][RBX] 0x8B, 0x04, 0x5A, // mov EAX,[RBX*2][RDX] 0x8B, 0x04, 0x8E, // mov EAX,[RCX*4][RSI] 0x8B, 0x04, 0xF9, // mov EAX,[RDI*8][RCX] 0x2B, 0x1C, 0x19, // sub EBX,[RBX][RCX] 0x3B, 0x0C, 0x4B, // cmp ECX,[RCX*2][RBX] 0x03, 0x14, 0x5A, // add EDX,[RBX*2][RDX] 0x33, 0x34, 0x8E, // xor ESI,[RCX*4][RSI] 0x29, 0x1C, 0x19, // sub [RBX][RCX],EBX 0x39, 0x0C, 0x4B, // cmp [RCX*2][RBX],ECX 0x01, 0x24, 0x5A, // add [RBX*2][RDX],ESP 0x31, 0x2C, 0x8E, // xor [RCX*4][RSI],EBP 0xA8, 0x03, // test AL,3 0x66, 0xA9, 0x04, 0x00, // test AX,4 0xA9, 0x05, 0x00, 0x00, 0x00, // test EAX,5 0x85, 0x3C, 0xF9, // test [RDI*8][RCX],EDI ]; int i; asm { call L1 ; mov EAX,[RCX] ; mov EAX,[RCX][RBX] ; mov EAX,[RCX*2][RBX] ; mov EAX,[RDX][RBX*2] ; mov EAX,[RCX*4][RSI] ; mov EAX,[RCX][RDI*8] ; sub EBX,[RCX][RBX] ; cmp ECX,[RCX*2][RBX] ; add EDX,[RDX][RBX*2] ; xor ESI,[RCX*4][RSI] ; sub [RCX][RBX],EBX ; cmp [RCX*2][RBX],ECX ; add [RDX][RBX*2],ESP ; xor [RCX*4][RSI],EBP ; test AL,3 ; test AX,4 ; test EAX,5 ; test [RCX][RDI*8],EDI ; L1: pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ /+ void test7() { ubyte *p; static ubyte data[] = [ 0x26,0xA1,0x24,0x13,0x00,0x00, // mov EAX,ES:[01324h] 0x36,0x66,0xA1,0x78,0x56,0x00,0x00, // mov AX,SS:[05678h] 0xA0,0x78,0x56,0x00,0x00, // mov AL,[05678h] 0x2E,0x8A,0x25,0x78,0x56,0x00,0x00, // mov AH,CS:[05678h] 0x64,0x8A,0x1D,0x78,0x56,0x00,0x00, // mov BL,FS:[05678h] 0x65,0x8A,0x3D,0x78,0x56,0x00,0x00, // mov BH,GS:[05678h] ]; int i; asm { call L1 ; mov EAX,ES:[0x1324] ; mov AX,SS:[0x5678] ; mov AL,DS:[0x5678] ; mov AH,CS:[0x5678] ; mov BL,FS:[0x5678] ; mov BH,GS:[0x5678] ; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } +/ /****************************************************/ void test8() { ubyte *p; static ubyte data[] = [ 0x8C,0xD0, // mov AX,SS 0x8C,0xDB, // mov BX,DS 0x8C,0xC1, // mov CX,ES 0x8C,0xCA, // mov DX,CS 0x8C,0xE6, // mov SI,FS 0x8C,0xEF, // mov DI,GS 0x8E,0xD0, // mov SS,AX 0x8E,0xDB, // mov DS,BX 0x8E,0xC1, // mov ES,CX 0x8E,0xCA, // mov CS,DX 0x8E,0xE6, // mov FS,SI 0x8E,0xEF, // mov GS,DI 0x0F,0x22,0xC0, // mov CR0,EAX 0x0F,0x22,0xD3, // mov CR2,EBX 0x0F,0x22,0xD9, // mov CR3,ECX 0x0F,0x22,0xE2, // mov CR4,EDX 0x0F,0x20,0xC0, // mov EAX,CR0 0x0F,0x20,0xD3, // mov EBX,CR2 0x0F,0x20,0xD9, // mov ECX,CR3 0x0F,0x20,0xE2, // mov EDX,CR4 0x0F,0x23,0xC0, // mov DR0,EAX 0x0F,0x23,0xCE, // mov DR1,ESI 0x0F,0x23,0xD3, // mov DR2,EBX 0x0F,0x23,0xD9, // mov DR3,ECX 0x0F,0x23,0xE2, // mov DR4,EDX 0x0F,0x23,0xEF, // mov DR5,EDI 0x0F,0x23,0xF4, // mov DR6,ESP 0x0F,0x23,0xFD, // mov DR7,EBP 0x0F,0x21,0xC4, // mov ESP,DR0 0x0F,0x21,0xCD, // mov EBP,DR1 0x0F,0x21,0xD0, // mov EAX,DR2 0x0F,0x21,0xDB, // mov EBX,DR3 0x0F,0x21,0xE1, // mov ECX,DR4 0x0F,0x21,0xEA, // mov EDX,DR5 0x0F,0x21,0xF6, // mov ESI,DR6 0x0F,0x21,0xFF, // mov EDI,DR7 0xA4, // movsb 0x66,0xA5, // movsw 0xA5, // movsd ]; int i; asm { call L1 ; mov AX,SS ; mov BX,DS ; mov CX,ES ; mov DX,CS ; mov SI,FS ; mov DI,GS ; mov SS,AX ; mov DS,BX ; mov ES,CX ; mov CS,DX ; mov FS,SI ; mov GS,DI ; mov CR0,EAX ; mov CR2,EBX ; mov CR3,ECX ; mov CR4,EDX ; mov EAX,CR0 ; mov EBX,CR2 ; mov ECX,CR3 ; mov EDX,CR4 ; mov DR0,EAX ; mov DR1,ESI ; mov DR2,EBX ; mov DR3,ECX ; mov DR4,EDX ; mov DR5,EDI ; mov DR6,ESP ; mov DR7,EBP ; mov ESP,DR0 ; mov EBP,DR1 ; mov EAX,DR2 ; mov EBX,DR3 ; mov ECX,DR4 ; mov EDX,DR5 ; mov ESI,DR6 ; mov EDI,DR7 ; movsb ; movsw ; movsd ; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test9() { ubyte *p; static ubyte data[] = [ 0x67,0x66,0x8B,0x00, // mov AX,[BX+SI] 0x67,0x66,0x8B,0x01, // mov AX,[BX+DI] 0x67,0x66,0x8B,0x02, // mov AX,[BP+SI] 0x67,0x66,0x8B,0x03, // mov AX,[BP+DI] 0x67,0x66,0x8B,0x04, // mov AX,[SI] 0x67,0x66,0x8B,0x05, // mov AX,[DI] 0x66,0xB8,0xD2,0x04, // mov AX,04D2h 0x67,0x66,0x8B,0x07, // mov AX,[BX] 0x67,0x66,0x8B,0x40,0x01, // mov AX,1[BX+SI] 0x67,0x66,0x8B,0x41,0x02, // mov AX,2[BX+DI] 0x67,0x66,0x8B,0x42,0x03, // mov AX,3[BP+SI] 0x67,0x66,0x8B,0x43,0x04, // mov AX,4[BP+DI] 0x67,0x66,0x8B,0x44,0x05, // mov AX,5[SI] 0x67,0x66,0x8B,0x45,0x06, // mov AX,6[DI] 0x67,0x66,0x8B,0x43,0x07, // mov AX,7[BP+DI] 0x67,0x66,0x8B,0x47,0x08, // mov AX,8[BX] 0x67,0x8B,0x80,0x21,0x01, // mov EAX,0121h[BX+SI] 0x67,0x66,0x8B,0x81,0x22,0x01, // mov AX,0122h[BX+DI] 0x67,0x66,0x8B,0x82,0x43,0x23, // mov AX,02343h[BP+SI] 0x67,0x66,0x8B,0x83,0x54,0x45, // mov AX,04554h[BP+DI] 0x67,0x66,0x8B,0x84,0x45,0x66, // mov AX,06645h[SI] 0x67,0x66,0x8B,0x85,0x36,0x12, // mov AX,01236h[DI] 0x67,0x66,0x8B,0x86,0x67,0x45, // mov AX,04567h[BP] 0x67,0x8A,0x87,0x08,0x01, // mov AL,0108h[BX] ]; int i; asm { call L1 ; mov AX,[BX+SI] ; mov AX,[BX+DI] ; mov AX,[BP+SI] ; mov AX,[BP+DI] ; mov AX,[SI] ; // mov AX,[DI] ; Internal error: backend/cod3.c 4652 mov AX,[1234] ; mov AX,[BX] ; mov AX,1[BX+SI] ; mov AX,2[BX+DI] ; mov AX,3[BP+SI] ; mov AX,4[BP+DI] ; mov AX,5[SI] ; mov AX,6[DI] ; mov AX,7[DI+BP] ; mov AX,8[BX] ; mov EAX,0x121[BX+SI] ; mov AX,0x122[BX+DI] ; mov AX,0x2343[BP+SI] ; mov AX,0x4554[BP+DI] ; mov AX,0x6645[SI] ; mov AX,0x1236[DI] ; mov AX,0x4567[BP] ; mov AL,0x108[BX] ; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ shared int bar10 = 78; shared int baz10[2]; void test10() { ubyte *p; int foo; static ubyte data[] = [ ]; int i; asm { mov bar10,0x12 ; // mov baz10,0x13 ;// does not compile, ( should it? ) mov int ptr baz10,0x13 ;// but this does mov ESI,1 ; mov baz10[RSI*4],0x14 ; } assert(bar10 == 0x12); assert(baz10[0] == 0x13); assert(baz10[1] == 0x14); } /****************************************************/ struct Foo11 { int c; int a; int b; } void test11() { ubyte *p; int x1; int x2; int x3; int x4; asm { mov x1,Foo11.a.sizeof ; mov x2,Foo11.b.offsetof ; mov x3,Foo11.sizeof ; mov x4,Foo11.sizeof + 7 ; } assert(x1 == int.sizeof); assert(x2 == 8); assert(x3 == 12); assert(x4 == 19); } /****************************************************/ void test12() { ubyte *p; static ubyte data[] = [ 0x14,0x05, // adc AL,5 0x83,0xD0,0x14, // adc EAX,014h 0x80,0x55,0xF8,0x17, // adc byte ptr -8[RBP],017h 0x83,0x55,0xFC,0x17, // adc dword ptr -4[RBP],017h 0x81,0x55,0xFC,0x34,0x12,0x00,0x00, // adc dword ptr -4[RBP],01234h 0x10,0x7D,0xF8, // adc -8[RBP],BH 0x11,0x5D,0xFC, // adc -4[RBP],EBX 0x12,0x5D,0xF8, // adc BL,-8[RBP] 0x13,0x55,0xFC, // adc EDX,-4[RBP] 0x04,0x05, // add AL,5 0x83,0xC0,0x14, // add EAX,014h 0x80,0x45,0xF8,0x17, // add byte ptr -8[RBP],017h 0x83,0x45,0xFC,0x17, // add dword ptr -4[RBP],017h 0x81,0x45,0xFC,0x34,0x12,0x00,0x00, // add dword ptr -4[RBP],01234h 0x00,0x7D,0xF8, // add -8[RBP],BH 0x01,0x5D,0xFC, // add -4[RBP],EBX 0x02,0x5D,0xF8, // add BL,-8[RBP] 0x03,0x55,0xFC, // add EDX,-4[RBP] 0x24,0x05, // and AL,5 0x83,0xE0,0x14, // and EAX,014h 0x80,0x65,0xF8,0x17, // and byte ptr -8[RBP],017h 0x83,0x65,0xFC,0x17, // and dword ptr -4[RBP],017h 0x81,0x65,0xFC,0x34,0x12,0x00,0x00, // and dword ptr -4[RBP],01234h 0x20,0x7D,0xF8, // and -8[RBP],BH 0x21,0x5D,0xFC, // and -4[RBP],EBX 0x22,0x5D,0xF8, // and BL,-8[RBP] 0x23,0x55,0xFC, // and EDX,-4[RBP] 0x3C,0x05, // cmp AL,5 0x83,0xF8,0x14, // cmp EAX,014h 0x80,0x7D,0xF8,0x17, // cmp byte ptr -8[RBP],017h 0x83,0x7D,0xFC,0x17, // cmp dword ptr -4[RBP],017h 0x81,0x7D,0xFC,0x34,0x12,0x00,0x00, // cmp dword ptr -4[RBP],01234h 0x38,0x7D,0xF8, // cmp -8[RBP],BH 0x39,0x5D,0xFC, // cmp -4[RBP],EBX 0x3A,0x5D,0xF8, // cmp BL,-8[RBP] 0x3B,0x55,0xFC, // cmp EDX,-4[RBP] 0x0C,0x05, // or AL,5 0x83,0xC8,0x14, // or EAX,014h 0x80,0x4D,0xF8,0x17, // or byte ptr -8[RBP],017h 0x83,0x4D,0xFC,0x17, // or dword ptr -4[RBP],017h 0x81,0x4D,0xFC,0x34,0x12,0x00,0x00, // or dword ptr -4[RBP],01234h 0x08,0x7D,0xF8, // or -8[RBP],BH 0x09,0x5D,0xFC, // or -4[RBP],EBX 0x0A,0x5D,0xF8, // or BL,-8[RBP] 0x0B,0x55,0xFC, // or EDX,-4[RBP] 0x1C,0x05, // sbb AL,5 0x83,0xD8,0x14, // sbb EAX,014h 0x80,0x5D,0xF8,0x17, // sbb byte ptr -8[RBP],017h 0x83,0x5D,0xFC,0x17, // sbb dword ptr -4[RBP],017h 0x81,0x5D,0xFC,0x34,0x12,0x00,0x00, // sbb dword ptr -4[RBP],01234h 0x18,0x7D,0xF8, // sbb -8[RBP],BH 0x19,0x5D,0xFC, // sbb -4[RBP],EBX 0x1A,0x5D,0xF8, // sbb BL,-8[RBP] 0x1B,0x55,0xFC, // sbb EDX,-4[RBP] 0x2C,0x05, // sub AL,5 0x83,0xE8,0x14, // sub EAX,014h 0x80,0x6D,0xF8,0x17, // sub byte ptr -8[RBP],017h 0x83,0x6D,0xFC,0x17, // sub dword ptr -4[RBP],017h 0x81,0x6D,0xFC,0x34,0x12,0x00,0x00, // sub dword ptr -4[RBP],01234h 0x28,0x7D,0xF8, // sub -8[RBP],BH 0x29,0x5D,0xFC, // sub -4[RBP],EBX 0x2A,0x5D,0xF8, // sub BL,-8[RBP] 0x2B,0x55,0xFC, // sub EDX,-4[RBP] 0xA8,0x05, // test AL,5 0xA9,0x14,0x00,0x00,0x00, // test EAX,014h 0xF6,0x45,0xF8,0x17, // test byte ptr -8[RBP],017h 0xF7,0x45,0xFC,0x17,0x00,0x00,0x00, // test dword ptr -4[RBP],017h 0xF7,0x45,0xFC,0x34,0x12,0x00,0x00, // test dword ptr -4[RBP],01234h 0x84,0x7D,0xF8, // test -8[RBP],BH 0x85,0x5D,0xFC, // test -4[RBP],EBX 0x34,0x05, // xor AL,5 0x83,0xF0,0x14, // xor EAX,014h 0x80,0x75,0xF8,0x17, // xor byte ptr -8[RBP],017h 0x83,0x75,0xFC,0x17, // xor dword ptr -4[RBP],017h 0x81,0x75,0xFC,0x34,0x12,0x00,0x00, // xor dword ptr -4[RBP],01234h 0x30,0x7D,0xF8, // xor -8[RBP],BH 0x31,0x5D,0xFC, // xor -4[RBP],EBX 0x32,0x5D,0xF8, // xor BL,-8[RBP] 0x33,0x55,0xFC, // xor EDX,-4[RBP] ]; int i; int padding; byte rm8; int rm32; static int m32; asm { call L1 ; /* aaa ; aad ; aam ; aas ; arpl [SI],DI ; */ adc AL,5 ; adc EAX,20 ; adc rm8[RBP],23 ; adc rm32[RBP],23 ; adc rm32[RBP],0x1234 ; adc rm8[RBP],BH ; adc rm32[RBP],EBX ; adc BL,rm8[RBP] ; adc EDX,rm32[RBP] ; add AL,5 ; add EAX,20 ; add rm8[RBP],23 ; add rm32[RBP],23 ; add rm32[RBP],0x1234 ; add rm8[RBP],BH ; add rm32[RBP],EBX ; add BL,rm8[RBP] ; add EDX,rm32[RBP] ; and AL,5 ; and EAX,20 ; and rm8[RBP],23 ; and rm32[RBP],23 ; and rm32[RBP],0x1234 ; and rm8[RBP],BH ; and rm32[RBP],EBX ; and BL,rm8[RBP] ; and EDX,rm32[RBP] ; cmp AL,5 ; cmp EAX,20 ; cmp rm8[RBP],23 ; cmp rm32[RBP],23 ; cmp rm32[RBP],0x1234 ; cmp rm8[RBP],BH ; cmp rm32[RBP],EBX ; cmp BL,rm8[RBP] ; cmp EDX,rm32[RBP] ; or AL,5 ; or EAX,20 ; or rm8[RBP],23 ; or rm32[RBP],23 ; or rm32[RBP],0x1234 ; or rm8[RBP],BH ; or rm32[RBP],EBX ; or BL,rm8[RBP] ; or EDX,rm32[RBP] ; sbb AL,5 ; sbb EAX,20 ; sbb rm8[RBP],23 ; sbb rm32[RBP],23 ; sbb rm32[RBP],0x1234 ; sbb rm8[RBP],BH ; sbb rm32[RBP],EBX ; sbb BL,rm8[RBP] ; sbb EDX,rm32[RBP] ; sub AL,5 ; sub EAX,20 ; sub rm8[RBP],23 ; sub rm32[RBP],23 ; sub rm32[RBP],0x1234 ; sub rm8[RBP],BH ; sub rm32[RBP],EBX ; sub BL,rm8[RBP] ; sub EDX,rm32[RBP] ; test AL,5 ; test EAX,20 ; test rm8[RBP],23 ; test rm32[RBP],23 ; test rm32[RBP],0x1234 ; test rm8[RBP],BH ; test rm32[RBP],EBX ; xor AL,5 ; xor EAX,20 ; xor rm8[RBP],23 ; xor rm32[RBP],23 ; xor rm32[RBP],0x1234 ; xor rm8[RBP],BH ; xor rm32[RBP],EBX ; xor BL,rm8[RBP] ; xor EDX,rm32[RBP] ; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { //printf("p[%d] = x%02x, data = x%02x\n", i, p[i], data[i]); assert(p[i] == data[i]); } } /****************************************************/ void test13() { int m32; long m64; M128 m128; ubyte *p; static ubyte data[] = [ 0x0F,0x0B, // ud2 0x0F,0x05, // syscall 0x0F,0x34, // sysenter 0x0F,0x35, // sysexit 0x0F,0x07, // sysret 0x0F,0xAE,0xE8, // lfence 0x0F,0xAE,0xF0, // mfence 0x0F,0xAE,0xF8, // sfence 0x0F,0xAE,0x00, // fxsave [RAX] 0x0F,0xAE,0x08, // fxrstor [RAX] 0x0F,0xAE,0x10, // ldmxcsr [RAX] 0x0F,0xAE,0x18, // stmxcsr [RAX] 0x0F,0xAE,0x38, // clflush [RAX] 0x0F,0x58,0x08, // addps XMM1,[RAX] 0x0F,0x58,0xCA, // addps XMM1,XMM2 0x66, 0x0F,0x58,0x03, // addpd XMM0,[RBX] 0x66, 0x0F,0x58,0xD1, // addpd XMM2,XMM1 0xF2,0x0F,0x58,0x08, // addsd XMM1,[RAX] 0xF2,0x0F,0x58,0xCA, // addsd XMM1,XMM2 0xF3,0x0F,0x58,0x2E, // addss XMM5,[RSI] 0xF3,0x0F,0x58,0xF7, // addss XMM6,XMM7 0x0F,0x54,0x08, // andps XMM1,[RAX] 0x0F,0x54,0xCA, // andps XMM1,XMM2 0x66, 0x0F,0x54,0x03, // andpd XMM0,[RBX] 0x66, 0x0F,0x54,0xD1, // andpd XMM2,XMM1 0x0F,0x55,0x08, // andnps XMM1,[RAX] 0x0F,0x55,0xCA, // andnps XMM1,XMM2 0x66, 0x0F,0x55,0x03, // andnpd XMM0,[RBX] 0x66, 0x0F,0x55,0xD1, // andnpd XMM2,XMM1 0xA7, // cmpsd 0x0F,0xC2,0x08,0x01, // cmpps XMM1,[RAX],1 0x0F,0xC2,0xCA,0x02, // cmpps XMM1,XMM2,2 0x66, 0x0F,0xC2,0x03,0x03, // cmppd XMM0,[RBX],3 0x66, 0x0F,0xC2,0xD1,0x04, // cmppd XMM2,XMM1,4 0xF2,0x0F,0xC2,0x08,0x05, // cmpsd XMM1,[RAX],5 0xF2,0x0F,0xC2,0xCA,0x06, // cmpsd XMM1,XMM2,6 0xF3,0x0F,0xC2,0x2E,0x07, // cmpss XMM5,[RSI],7 0xF3,0x0F,0xC2,0xF7,0x00, // cmpss XMM6,XMM7,0 0x66, 0x0F,0x2F,0x08, // comisd XMM1,[RAX] 0x66, 0x0F,0x2F,0x4D,0xD8, // comisd XMM1,-028h[RBP] 0x66, 0x0F,0x2F,0xCA, // comisd XMM1,XMM2 0x0F,0x2F,0x2E, // comiss XMM5,[RSI] 0x0F,0x2F,0xF7, // comiss XMM6,XMM7 0xF3,0x0F,0xE6,0xDC, // cvtdq2pd XMM3,XMM4 0xF3,0x0F,0xE6,0x5D,0xD8, // cvtdq2pd XMM3,-028h[RBP] 0x0F,0x5B,0xDC, // cvtdq2ps XMM3,XMM4 0x0F,0x5B,0x5D,0xE0, // cvtdq2ps XMM3,-020h[RBP] 0xF2,0x0F,0xE6,0xDC, // cvtpd2dq XMM3,XMM4 0xF2,0x0F,0xE6,0x5D,0xE0, // cvtpd2dq XMM3,-020h[RBP] 0x66, 0x0F,0x2D,0xDC, // cvtpd2pi MM3,XMM4 0x66, 0x0F,0x2D,0x5D,0xE0, // cvtpd2pi MM3,-020h[RBP] 0x66, 0x0F,0x5A,0xDC, // cvtpd2ps XMM3,XMM4 0x66, 0x0F,0x5A,0x5D,0xE0, // cvtpd2ps XMM3,-020h[RBP] 0x66, 0x0F,0x2A,0xDC, // cvtpi2pd XMM3,MM4 0x66, 0x0F,0x2A,0x5D,0xD8, // cvtpi2pd XMM3,-028h[RBP] 0x0F,0x2A,0xDC, // cvtpi2ps XMM3,MM4 0x0F,0x2A,0x5D,0xD8, // cvtpi2ps XMM3,-028h[RBP] 0x66, 0x0F,0x5B,0xDC, // cvtps2dq XMM3,XMM4 0x66, 0x0F,0x5B,0x5D,0xE0, // cvtps2dq XMM3,-020h[RBP] 0x0F,0x5A,0xDC, // cvtps2pd XMM3,XMM4 0x0F,0x5A,0x5D,0xD8, // cvtps2pd XMM3,-028h[RBP] 0x0F,0x2D,0xDC, // cvtps2pi MM3,XMM4 0x0F,0x2D,0x5D,0xD8, // cvtps2pi MM3,-030h[RBP] 0xF2,0x0F,0x2D,0xCC, // cvtsd2si XMM1,XMM4 0xF2,0x0F,0x2D,0x55,0xD8, // cvtsd2si XMM2,-028h[RBP] 0xF2,0x0F,0x5A,0xDC, // cvtsd2ss XMM3,XMM4 0xF2,0x0F,0x5A,0x5D,0xD8, // cvtsd2ss XMM3,-028h[RBP] 0xF2,0x0F,0x2A,0xDA, // cvtsi2sd XMM3,EDX 0xF2,0x0F,0x2A,0x5D,0xD0, // cvtsi2sd XMM3,-030h[RBP] 0xF3,0x0F,0x2A,0xDA, // cvtsi2ss XMM3,EDX 0xF3,0x0F,0x2A,0x5D,0xD0, // cvtsi2ss XMM3,-030h[RBP] 0xF3,0x0F,0x5A,0xDC, // cvtss2sd XMM3,XMM4 0xF3,0x0F,0x5A,0x5D,0xD0, // cvtss2sd XMM3,-030h[RBP] 0xF3,0x0F,0x2D,0xFC, // cvtss2si XMM7,XMM4 0xF3,0x0F,0x2D,0x7D,0xD0, // cvtss2si XMM7,-030h[RBP] 0x66, 0x0F,0x2C,0xDC, // cvttpd2pi MM3,XMM4 0x66, 0x0F,0x2C,0x7D,0xE0, // cvttpd2pi MM7,-020h[RBP] 0x66, 0x0F,0xE6,0xDC, // cvttpd2dq XMM3,XMM4 0x66, 0x0F,0xE6,0x7D,0xE0, // cvttpd2dq XMM7,-020h[RBP] 0xF3,0x0F,0x5B,0xDC, // cvttps2dq XMM3,XMM4 0xF3,0x0F,0x5B,0x7D,0xE0, // cvttps2dq XMM7,-020h[RBP] 0x0F,0x2C,0xDC, // cvttps2pi MM3,XMM4 0x0F,0x2C,0x7D,0xD8, // cvttps2pi MM7,-028h[RBP] 0xF2,0x0F,0x2C,0xC4, // cvttsd2si EAX,XMM4 0xF2,0x0F,0x2C,0x4D,0xE0, // cvttsd2si ECX,-020h[RBP] 0xF3,0x0F,0x2C,0xC4, // cvttss2si EAX,XMM4 0xF3,0x0F,0x2C,0x4D,0xD0, // cvttss2si ECX,-030h[RBP] 0x66, 0x0F,0x5E,0xE8, // divpd XMM5,XMM0 0x66, 0x0F,0x5E,0x6D,0xE0, // divpd XMM5,-020h[RBP] 0x0F,0x5E,0xE8, // divps XMM5,XMM0 0x0F,0x5E,0x6D,0xE0, // divps XMM5,-020h[RBP] 0xF2,0x0F,0x5E,0xE8, // divsd XMM5,XMM0 0xF2,0x0F,0x5E,0x6D,0xD8, // divsd XMM5,-028h[RBP] 0xF3,0x0F,0x5E,0xE8, // divss XMM5,XMM0 0xF3,0x0F,0x5E,0x6D,0xD0, // divss XMM5,-030h[RBP] 0x66, 0x0F,0xF7,0xD1, // maskmovdqu XMM2,XMM1 0x0F,0xF7,0xE3, // maskmovq MM4,MM3 0x66, 0x0F,0x5F,0xC0, // maxpd XMM0,XMM0 0x66, 0x0F,0x5F,0x4D,0xE0, // maxpd XMM1,-020h[RBP] 0x0F,0x5F,0xD1, // maxps XMM2,XMM1 0x0F,0x5F,0x5D,0xE0, // maxps XMM3,-020h[RBP] 0xF2,0x0F,0x5F,0xE2, // maxsd XMM4,XMM2 0xF2,0x0F,0x5F,0x6D,0xD8, // maxsd XMM5,-028h[RBP] 0xF3,0x0F,0x5F,0xF3, // maxss XMM6,XMM3 0xF3,0x0F,0x5F,0x7D,0xD0, // maxss XMM7,-030h[RBP] 0x66, 0x0F,0x5D,0xC0, // minpd XMM0,XMM0 0x66, 0x0F,0x5D,0x4D,0xE0, // minpd XMM1,-020h[RBP] 0x0F,0x5D,0xD1, // minps XMM2,XMM1 0x0F,0x5D,0x5D,0xE0, // minps XMM3,-020h[RBP] 0xF2,0x0F,0x5D,0xE2, // minsd XMM4,XMM2 0xF2,0x0F,0x5D,0x6D,0xD8, // minsd XMM5,-028h[RBP] 0xF3,0x0F,0x5D,0xF3, // minss XMM6,XMM3 0xF3,0x0F,0x5D,0x7D,0xD0, // minss XMM7,-030h[RBP] 0x66, 0x0F,0x28,0xCA, // movapd XMM1,XMM2 0x66, 0x0F,0x28,0x5D,0xE0, // movapd XMM3,-020h[RBP] 0x66, 0x0F,0x29,0x65,0xE0, // movapd -020h[RBP],XMM4 0x0F,0x28,0xCA, // movaps XMM1,XMM2 0x0F,0x28,0x5D,0xE0, // movaps XMM3,-020h[RBP] 0x0F,0x29,0x65,0xE0, // movaps -020h[RBP],XMM4 0x0F,0x6E,0xCB, // movd MM1,EBX 0x0F,0x6E,0x55,0xD0, // movd MM2,-030h[RBP] 0x0F,0x7E,0xDB, // movd EBX,MM3 0x0F,0x7E,0x65,0xD0, // movd -030h[RBP],MM4 0x66, 0x0F,0x6E,0xCB, // movd XMM1,EBX 0x66, 0x0F,0x6E,0x55,0xD0, // movd XMM2,-030h[RBP] 0x66, 0x0F,0x7E,0xDB, // movd EBX,XMM3 0x66, 0x0F,0x7E,0x65,0xD0, // movd -030h[RBP],XMM4 0x66, 0x0F,0x6F,0xCA, // movdqa XMM1,XMM2 0x66, 0x0F,0x6F,0x55,0xE0, // movdqa XMM2,-020h[RBP] 0x66, 0x0F,0x7F,0x65,0xE0, // movdqa -020h[RBP],XMM4 0xF3,0x0F,0x6F,0xCA, // movdqu XMM1,XMM2 0xF3,0x0F,0x6F,0x55,0xE0, // movdqu XMM2,-020h[RBP] 0xF3,0x0F,0x7F,0x65,0xE0, // movdqu -020h[RBP],XMM4 0xF2,0x0F,0xD6,0xDC, // movdq2q MM4,XMM3 0x0F,0x12,0xDC, // movhlps XMM4,XMM3 0x66, 0x0F,0x16,0x55,0xD8, // movhpd XMM2,-028h[RBP] 0x66, 0x0F,0x17,0x7D,0xD8, // movhpd -028h[RBP],XMM7 0x0F,0x16,0x55,0xD8, // movhps XMM2,-028h[RBP] 0x0F,0x17,0x7D,0xD8, // movhps -028h[RBP],XMM7 0x0F,0x16,0xDC, // movlhps XMM4,XMM3 0x66, 0x0F,0x12,0x55,0xD8, // movlpd XMM2,-028h[RBP] 0x66, 0x0F,0x13,0x7D,0xD8, // movlpd -028h[RBP],XMM7 0x0F,0x12,0x55,0xD8, // movlps XMM2,-028h[RBP] 0x0F,0x13,0x7D,0xD8, // movlps -028h[RBP],XMM7 0x66, 0x0F,0x50,0xF3, // movmskpd ESI,XMM3 0x0F,0x50,0xF3, // movmskps ESI,XMM3 0x66, 0x0F,0x59,0xC0, // mulpd XMM0,XMM0 0x66, 0x0F,0x59,0x4D,0xE0, // mulpd XMM1,-020h[RBP] 0x0F,0x59,0xD1, // mulps XMM2,XMM1 0x0F,0x59,0x5D,0xE0, // mulps XMM3,-020h[RBP] 0xF2,0x0F,0x59,0xE2, // mulsd XMM4,XMM2 0xF2,0x0F,0x59,0x6D,0xD8, // mulsd XMM5,-028h[RBP] 0xF3,0x0F,0x59,0xF3, // mulss XMM6,XMM3 0xF3,0x0F,0x59,0x7D,0xD0, // mulss XMM7,-030h[RBP] 0x66, 0x0F,0x51,0xC4, // sqrtpd XMM0,XMM4 0x66, 0x0F,0x51,0x4D,0xE0, // sqrtpd XMM1,-020h[RBP] 0x0F,0x51,0xD5, // sqrtps XMM2,XMM5 0x0F,0x51,0x5D,0xE0, // sqrtps XMM3,-020h[RBP] 0xF2,0x0F,0x51,0xE6, // sqrtsd XMM4,XMM6 0xF2,0x0F,0x51,0x6D,0xD8, // sqrtsd XMM5,-028h[RBP] 0xF3,0x0F,0x51,0xF7, // sqrtss XMM6,XMM7 0xF3,0x0F,0x51,0x7D,0xD0, // sqrtss XMM7,-030h[RBP] 0x66, 0x0F,0x5C,0xC4, // subpd XMM0,XMM4 0x66, 0x0F,0x5C,0x4D,0xE0, // subpd XMM1,-020h[RBP] 0x0F,0x5C,0xD5, // subps XMM2,XMM5 0x0F,0x5C,0x5D,0xE0, // subps XMM3,-020h[RBP] 0xF2,0x0F,0x5C,0xE6, // subsd XMM4,XMM6 0xF2,0x0F,0x5C,0x6D,0xD8, // subsd XMM5,-028h[RBP] 0xF3,0x0F,0x5C,0xF7, // subss XMM6,XMM7 0xF3,0x0F,0x5C,0x7D,0xD0, // subss XMM7,-030h[RBP] 0x0F,0x01,0xE0, // smsw EAX ]; int i; asm { call L1 ; ud2 ; syscall ; sysenter ; sysexit ; sysret ; lfence ; mfence ; sfence ; fxsave [RAX] ; fxrstor [RAX] ; ldmxcsr [RAX] ; stmxcsr [RAX] ; clflush [RAX] ; addps XMM1,[RAX] ; addps XMM1,XMM2 ; addpd XMM0,[RBX] ; addpd XMM2,XMM1 ; addsd XMM1,[RAX] ; addsd XMM1,XMM2 ; addss XMM5,[RSI] ; addss XMM6,XMM7 ; andps XMM1,[RAX] ; andps XMM1,XMM2 ; andpd XMM0,[RBX] ; andpd XMM2,XMM1 ; andnps XMM1,[RAX] ; andnps XMM1,XMM2 ; andnpd XMM0,[RBX] ; andnpd XMM2,XMM1 ; cmpsd ; cmpps XMM1,[RAX],1 ; cmpps XMM1,XMM2,2 ; cmppd XMM0,[RBX],3 ; cmppd XMM2,XMM1,4 ; cmpsd XMM1,[RAX],5 ; cmpsd XMM1,XMM2,6 ; cmpss XMM5,[RSI],7 ; cmpss XMM6,XMM7,0 ; comisd XMM1,[RAX] ; comisd XMM1,m64[RBP] ; comisd XMM1,XMM2 ; comiss XMM5,[RSI] ; comiss XMM6,XMM7 ; cvtdq2pd XMM3,XMM4 ; cvtdq2pd XMM3,m64[RBP] ; cvtdq2ps XMM3,XMM4 ; cvtdq2ps XMM3,m128[RBP] ; cvtpd2dq XMM3,XMM4 ; cvtpd2dq XMM3,m128[RBP] ; cvtpd2pi MM3,XMM4 ; cvtpd2pi MM3,m128[RBP] ; cvtpd2ps XMM3,XMM4 ; cvtpd2ps XMM3,m128[RBP] ; cvtpi2pd XMM3,MM4 ; cvtpi2pd XMM3,m64[RBP] ; cvtpi2ps XMM3,MM4 ; cvtpi2ps XMM3,m64[RBP] ; cvtps2dq XMM3,XMM4 ; cvtps2dq XMM3,m128[RBP] ; cvtps2pd XMM3,XMM4 ; cvtps2pd XMM3,m64[RBP] ; cvtps2pi MM3,XMM4 ; cvtps2pi MM3,m64[RBP] ; cvtsd2si ECX,XMM4 ; cvtsd2si EDX,m64[RBP] ; cvtsd2ss XMM3,XMM4 ; cvtsd2ss XMM3,m64[RBP] ; cvtsi2sd XMM3,EDX ; cvtsi2sd XMM3,m32[RBP] ; cvtsi2ss XMM3,EDX ; cvtsi2ss XMM3,m32[RBP] ; cvtss2sd XMM3,XMM4 ; cvtss2sd XMM3,m32[RBP] ; cvtss2si EDI,XMM4 ; cvtss2si EDI,m32[RBP] ; cvttpd2pi MM3,XMM4 ; cvttpd2pi MM7,m128[RBP] ; cvttpd2dq XMM3,XMM4 ; cvttpd2dq XMM7,m128[RBP] ; cvttps2dq XMM3,XMM4 ; cvttps2dq XMM7,m128[RBP] ; cvttps2pi MM3,XMM4 ; cvttps2pi MM7,m64[RBP] ; cvttsd2si EAX,XMM4 ; cvttsd2si ECX,m128[RBP] ; cvttss2si EAX,XMM4 ; cvttss2si ECX,m32[RBP] ; divpd XMM5,XMM0 ; divpd XMM5,m128[RBP] ; divps XMM5,XMM0 ; divps XMM5,m128[RBP] ; divsd XMM5,XMM0 ; divsd XMM5,m64[RBP] ; divss XMM5,XMM0 ; divss XMM5,m32[RBP] ; maskmovdqu XMM1,XMM2 ; maskmovq MM3,MM4 ; maxpd XMM0,XMM0 ; maxpd XMM1,m128[RBP] ; maxps XMM2,XMM1 ; maxps XMM3,m128[RBP] ; maxsd XMM4,XMM2 ; maxsd XMM5,m64[RBP] ; maxss XMM6,XMM3 ; maxss XMM7,m32[RBP] ; minpd XMM0,XMM0 ; minpd XMM1,m128[RBP] ; minps XMM2,XMM1 ; minps XMM3,m128[RBP] ; minsd XMM4,XMM2 ; minsd XMM5,m64[RBP] ; minss XMM6,XMM3 ; minss XMM7,m32[RBP] ; movapd XMM1,XMM2 ; movapd XMM3,m128[RBP] ; movapd m128[RBP],XMM4 ; movaps XMM1,XMM2 ; movaps XMM3,m128[RBP] ; movaps m128[RBP],XMM4 ; movd MM1,EBX ; movd MM2,m32[RBP] ; movd EBX,MM3 ; movd m32[RBP],MM4 ; movd XMM1,EBX ; movd XMM2,m32[RBP] ; movd EBX,XMM3 ; movd m32[RBP],XMM4 ; movdqa XMM1,XMM2 ; movdqa XMM2,m128[RBP] ; movdqa m128[RBP],XMM4 ; movdqu XMM1,XMM2 ; movdqu XMM2,m128[RBP] ; movdqu m128[RBP],XMM4 ; movdq2q MM3,XMM4 ; movhlps XMM3,XMM4 ; movhpd XMM2,m64[RBP] ; movhpd m64[RBP],XMM7 ; movhps XMM2,m64[RBP] ; movhps m64[RBP],XMM7 ; movlhps XMM3,XMM4 ; movlpd XMM2,m64[RBP] ; movlpd m64[RBP],XMM7 ; movlps XMM2,m64[RBP] ; movlps m64[RBP],XMM7 ; movmskpd ESI,XMM3 ; movmskps ESI,XMM3 ; mulpd XMM0,XMM0 ; mulpd XMM1,m128[RBP] ; mulps XMM2,XMM1 ; mulps XMM3,m128[RBP] ; mulsd XMM4,XMM2 ; mulsd XMM5,m64[RBP] ; mulss XMM6,XMM3 ; mulss XMM7,m32[RBP] ; sqrtpd XMM0,XMM4 ; sqrtpd XMM1,m128[RBP] ; sqrtps XMM2,XMM5 ; sqrtps XMM3,m128[RBP] ; sqrtsd XMM4,XMM6 ; sqrtsd XMM5,m64[RBP] ; sqrtss XMM6,XMM7 ; sqrtss XMM7,m32[RBP] ; subpd XMM0,XMM4 ; subpd XMM1,m128[RBP] ; subps XMM2,XMM5 ; subps XMM3,m128[RBP] ; subsd XMM4,XMM6 ; subsd XMM5,m64[RBP] ; subss XMM6,XMM7 ; subss XMM7,m32[RBP] ; smsw EAX ; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { //printf("[%d] = %02x %02x\n", i, p[i], data[i]); assert(p[i] == data[i]); } } /****************************************************/ void test14() { byte m8; short m16; int m32; long m64; M128 m128; ubyte *p; static ubyte data[] = [ 0x66, 0x0F,0x50,0xF3, // movmskpd ESI,XMM3 0x0F,0x50,0xF3, // movmskps ESI,XMM3 0x66, 0x0F,0xE7,0x55,0xE0, // movntdq -020h[RBP],XMM2 0x0F,0xC3,0x4D,0xD4, // movnti -02Ch[RBP],ECX 0x66, 0x0F,0x2B,0x5D,0xE0, // movntpd -020h[RBP],XMM3 0x0F,0x2B,0x65,0xE0, // movntps -020h[RBP],XMM4 0x0F,0xE7,0x6D,0xD8, // movntq -028h[RBP],MM5 0x0F,0x6F,0xCA, // movq MM1,MM2 0x0F,0x6F,0x55,0xD8, // movq MM2,-028h[RBP] 0x0F,0x7F,0x5D,0xD8, // movq -028h[RBP],MM3 0xF3,0x0F,0x7E,0xCA, // movq XMM1,XMM2 0xF3,0x0F,0x7E,0x55,0xD8, // movq XMM2,-028h[RBP] 0x66, 0x0F,0xD6,0x5D,0xD8, // movq -028h[RBP],XMM3 0xF3,0x0F,0xD6,0xDA, // movq2dq XMM3,MM2 0xA5, // movsd 0xF2,0x0F,0x10,0xCA, // movsd XMM1,XMM2 0xF2,0x0F,0x10,0x5D,0xD8, // movsd XMM3,-028h[RBP] 0xF2,0x0F,0x11,0x65,0xD8, // movsd -028h[RBP],XMM4 0xF3,0x0F,0x10,0xCA, // movss XMM1,XMM2 0xF3,0x0F,0x10,0x5D,0xD4, // movss XMM3,-02Ch[RBP] 0xF3,0x0F,0x11,0x65,0xD4, // movss -02Ch[RBP],XMM4 0x66, 0x0F,0x10,0xCA, // movupd XMM1,XMM2 0x66, 0x0F,0x10,0x5D,0xE0, // movupd XMM3,-020h[RBP] 0x66, 0x0F,0x11,0x65,0xE0, // movupd -020h[RBP],XMM4 0x0F,0x10,0xCA, // movups XMM1,XMM2 0x0F,0x10,0x5D,0xE0, // movups XMM3,-020h[RBP] 0x0F,0x11,0x65,0xE0, // movups -020h[RBP],XMM4 0x66, 0x0F,0x56,0xCA, // orpd XMM1,XMM2 0x66, 0x0F,0x56,0x5D,0xE0, // orpd XMM3,-020h[RBP] 0x0F,0x56,0xCA, // orps XMM1,XMM2 0x0F,0x56,0x5D,0xE0, // orps XMM3,-020h[RBP] 0x0F,0x63,0xCA, // packsswb MM1,MM2 0x0F,0x63,0x5D,0xD8, // packsswb MM3,-028h[RBP] 0x66, 0x0F,0x63,0xCA, // packsswb XMM1,XMM2 0x66, 0x0F,0x63,0x5D,0xE0, // packsswb XMM3,-020h[RBP] 0x0F,0x6B,0xCA, // packssdw MM1,MM2 0x0F,0x6B,0x5D,0xD8, // packssdw MM3,-028h[RBP] 0x66, 0x0F,0x6B,0xCA, // packssdw XMM1,XMM2 0x66, 0x0F,0x6B,0x5D,0xE0, // packssdw XMM3,-020h[RBP] 0x0F,0x67,0xCA, // packuswb MM1,MM2 0x0F,0x67,0x5D,0xD8, // packuswb MM3,-028h[RBP] 0x66, 0x0F,0x67,0xCA, // packuswb XMM1,XMM2 0x66, 0x0F,0x67,0x5D,0xE0, // packuswb XMM3,-020h[RBP] 0x0F,0xFC,0xCA, // paddb MM1,MM2 0x0F,0xFC,0x5D,0xD8, // paddb MM3,-028h[RBP] 0x66, 0x0F,0xFC,0xCA, // paddb XMM1,XMM2 0x66, 0x0F,0xFC,0x5D,0xE0, // paddb XMM3,-020h[RBP] 0x0F,0xFD,0xCA, // paddw MM1,MM2 0x0F,0xFD,0x5D,0xD8, // paddw MM3,-028h[RBP] 0x66, 0x0F,0xFD,0xCA, // paddw XMM1,XMM2 0x66, 0x0F,0xFD,0x5D,0xE0, // paddw XMM3,-020h[RBP] 0x0F,0xFE,0xCA, // paddd MM1,MM2 0x0F,0xFE,0x5D,0xD8, // paddd MM3,-028h[RBP] 0x66, 0x0F,0xFE,0xCA, // paddd XMM1,XMM2 0x66, 0x0F,0xFE,0x5D,0xE0, // paddd XMM3,-020h[RBP] 0x0F,0xD4,0xCA, // paddq MM1,MM2 0x0F,0xD4,0x5D,0xD8, // paddq MM3,-028h[RBP] 0x66, 0x0F,0xD4,0xCA, // paddq XMM1,XMM2 0x66, 0x0F,0xD4,0x5D,0xE0, // paddq XMM3,-020h[RBP] 0x0F,0xEC,0xCA, // paddsb MM1,MM2 0x0F,0xEC,0x5D,0xD8, // paddsb MM3,-028h[RBP] 0x66, 0x0F,0xEC,0xCA, // paddsb XMM1,XMM2 0x66, 0x0F,0xEC,0x5D,0xE0, // paddsb XMM3,-020h[RBP] 0x0F,0xED,0xCA, // paddsw MM1,MM2 0x0F,0xED,0x5D,0xD8, // paddsw MM3,-028h[RBP] 0x66, 0x0F,0xED,0xCA, // paddsw XMM1,XMM2 0x66, 0x0F,0xED,0x5D,0xE0, // paddsw XMM3,-020h[RBP] 0x0F,0xDC,0xCA, // paddusb MM1,MM2 0x0F,0xDC,0x5D,0xD8, // paddusb MM3,-028h[RBP] 0x66, 0x0F,0xDC,0xCA, // paddusb XMM1,XMM2 0x66, 0x0F,0xDC,0x5D,0xE0, // paddusb XMM3,-020h[RBP] 0x0F,0xDD,0xCA, // paddusw MM1,MM2 0x0F,0xDD,0x5D,0xD8, // paddusw MM3,-028h[RBP] 0x66, 0x0F,0xDD,0xCA, // paddusw XMM1,XMM2 0x66, 0x0F,0xDD,0x5D,0xE0, // paddusw XMM3,-020h[RBP] 0x0F,0xDB,0xCA, // pand MM1,MM2 0x0F,0xDB,0x5D,0xD8, // pand MM3,-028h[RBP] 0x66, 0x0F,0xDB,0xCA, // pand XMM1,XMM2 0x66, 0x0F,0xDB,0x5D,0xE0, // pand XMM3,-020h[RBP] 0x0F,0xDF,0xCA, // pandn MM1,MM2 0x0F,0xDF,0x5D,0xD8, // pandn MM3,-028h[RBP] 0x66, 0x0F,0xDF,0xCA, // pandn XMM1,XMM2 0x66, 0x0F,0xDF,0x5D,0xE0, // pandn XMM3,-020h[RBP] 0x0F,0xE0,0xCA, // pavgb MM1,MM2 0x0F,0xE0,0x5D,0xD8, // pavgb MM3,-028h[RBP] 0x66, 0x0F,0xE0,0xCA, // pavgb XMM1,XMM2 0x66, 0x0F,0xE0,0x5D,0xE0, // pavgb XMM3,-020h[RBP] 0x0F,0xE3,0xCA, // pavgw MM1,MM2 0x0F,0xE3,0x5D,0xD8, // pavgw MM3,-028h[RBP] 0x66, 0x0F,0xE3,0xCA, // pavgw XMM1,XMM2 0x66, 0x0F,0xE3,0x5D,0xE0, // pavgw XMM3,-020h[RBP] 0x0F,0x74,0xCA, // pcmpeqb MM1,MM2 0x0F,0x74,0x5D,0xD8, // pcmpeqb MM3,-028h[RBP] 0x66, 0x0F,0x74,0xCA, // pcmpeqb XMM1,XMM2 0x66, 0x0F,0x74,0x5D,0xE0, // pcmpeqb XMM3,-020h[RBP] 0x0F,0x75,0xCA, // pcmpeqw MM1,MM2 0x0F,0x75,0x5D,0xD8, // pcmpeqw MM3,-028h[RBP] 0x66, 0x0F,0x75,0xCA, // pcmpeqw XMM1,XMM2 0x66, 0x0F,0x75,0x5D,0xE0, // pcmpeqw XMM3,-020h[RBP] 0x0F,0x76,0xCA, // pcmpeqd MM1,MM2 0x0F,0x76,0x5D,0xD8, // pcmpeqd MM3,-028h[RBP] 0x66, 0x0F,0x76,0xCA, // pcmpeqd XMM1,XMM2 0x66, 0x0F,0x76,0x5D,0xE0, // pcmpeqd XMM3,-020h[RBP] 0x0F,0x64,0xCA, // pcmpgtb MM1,MM2 0x0F,0x64,0x5D,0xD8, // pcmpgtb MM3,-028h[RBP] 0x66, 0x0F,0x64,0xCA, // pcmpgtb XMM1,XMM2 0x66, 0x0F,0x64,0x5D,0xE0, // pcmpgtb XMM3,-020h[RBP] 0x0F,0x65,0xCA, // pcmpgtw MM1,MM2 0x0F,0x65,0x5D,0xD8, // pcmpgtw MM3,-028h[RBP] 0x66, 0x0F,0x65,0xCA, // pcmpgtw XMM1,XMM2 0x66, 0x0F,0x65,0x5D,0xE0, // pcmpgtw XMM3,-020h[RBP] 0x0F,0x66,0xCA, // pcmpgtd MM1,MM2 0x0F,0x66,0x5D,0xD8, // pcmpgtd MM3,-028h[RBP] 0x66, 0x0F,0x66,0xCA, // pcmpgtd XMM1,XMM2 0x66, 0x0F,0x66,0x5D,0xE0, // pcmpgtd XMM3,-020h[RBP] 0x0F,0xC5,0xD6,0x07, // pextrw EDX,MM6,7 0x66, 0x0F,0xC5,0xD6,0x07, // pextrw EDX,XMM6,7 0x0F,0xC4,0xF2,0x07, // pinsrw MM6,EDX,7 0x0F,0xC4,0x75,0xD2,0x07, // pinsrw MM6,-02Eh[RBP],7 0x66, 0x0F,0xC4,0xF2,0x07, // pinsrw XMM6,EDX,7 0x66, 0x0F,0xC4,0x75,0xD2,0x07, // pinsrw XMM6,-02Eh[RBP],7 0x0F,0xF5,0xCA, // pmaddwd MM1,MM2 0x0F,0xF5,0x5D,0xD8, // pmaddwd MM3,-028h[RBP] 0x66, 0x0F,0xF5,0xCA, // pmaddwd XMM1,XMM2 0x66, 0x0F,0xF5,0x5D,0xE0, // pmaddwd XMM3,-020h[RBP] 0x0F,0xEE,0xCA, // pmaxsw MM1,XMM2 0x0F,0xEE,0x5D,0xD8, // pmaxsw MM3,-028h[RBP] 0x66, 0x0F,0xEE,0xCA, // pmaxsw XMM1,XMM2 0x66, 0x0F,0xEE,0x5D,0xE0, // pmaxsw XMM3,-020h[RBP] 0x0F,0xDE,0xCA, // pmaxub MM1,XMM2 0x0F,0xDE,0x5D,0xD8, // pmaxub MM3,-028h[RBP] 0x66, 0x0F,0xDE,0xCA, // pmaxub XMM1,XMM2 0x66, 0x0F,0xDE,0x5D,0xE0, // pmaxub XMM3,-020h[RBP] 0x0F,0xEA,0xCA, // pminsw MM1,MM2 0x0F,0xEA,0x5D,0xD8, // pminsw MM3,-028h[RBP] 0x66, 0x0F,0xEA,0xCA, // pminsw XMM1,XMM2 0x66, 0x0F,0xEA,0x5D,0xE0, // pminsw XMM3,-020h[RBP] 0x0F,0xDA,0xCA, // pminub MM1,MM2 0x0F,0xDA,0x5D,0xD8, // pminub MM3,-028h[RBP] 0x66, 0x0F,0xDA,0xCA, // pminub XMM1,XMM2 0x66, 0x0F,0xDA,0x5D,0xE0, // pminub XMM3,-020h[RBP] 0x0F,0xD7,0xC8, // pmovmskb ECX,MM0 0x66, 0x0F,0xD7,0xCE, // pmovmskb ECX,XMM6 0x0F,0xE4,0xCA, // pmulhuw MM1,MM2 0x0F,0xE4,0x5D,0xD8, // pmulhuw MM3,-028h[RBP] 0x66, 0x0F,0xE4,0xCA, // pmulhuw XMM1,XMM2 0x66, 0x0F,0xE4,0x5D,0xE0, // pmulhuw XMM3,-020h[RBP] 0x0F,0xE5,0xCA, // pmulhw MM1,MM2 0x0F,0xE5,0x5D,0xD8, // pmulhw MM3,-028h[RBP] 0x66, 0x0F,0xE5,0xCA, // pmulhw XMM1,XMM2 0x66, 0x0F,0xE5,0x5D,0xE0, // pmulhw XMM3,-020h[RBP] 0x0F,0xD5,0xCA, // pmullw MM1,MM2 0x0F,0xD5,0x5D,0xD8, // pmullw MM3,-028h[RBP] 0x66, 0x0F,0xD5,0xCA, // pmullw XMM1,XMM2 0x66, 0x0F,0xD5,0x5D,0xE0, // pmullw XMM3,-020h[RBP] 0x0F,0xF4,0xCA, // pmuludq MM1,MM2 0x0F,0xF4,0x5D,0xD8, // pmuludq MM3,-028h[RBP] 0x66, 0x0F,0xF4,0xCA, // pmuludq XMM1,XMM2 0x66, 0x0F,0xF4,0x5D,0xE0, // pmuludq XMM3,-020h[RBP] 0x0F,0xEB,0xCA, // por MM1,MM2 0x0F,0xEB,0x5D,0xD8, // por MM3,-028h[RBP] 0x66, 0x0F,0xEB,0xCA, // por XMM1,XMM2 0x66, 0x0F,0xEB,0x5D,0xE0, // por XMM3,-020h[RBP] 0x0F,0x18,0x4D,0xD0, // prefetcht0 -030h[RBP] 0x0F,0x18,0x55,0xD0, // prefetcht1 -030h[RBP] 0x0F,0x18,0x5D,0xD0, // prefetcht2 -030h[RBP] 0x0F,0x18,0x45,0xD0, // prefetchnta -030h[RBP] 0x0F,0xF6,0xCA, // psadbw MM1,MM2 0x0F,0xF6,0x5D,0xD8, // psadbw MM3,-028h[RBP] 0x66, 0x0F,0xF6,0xCA, // psadbw XMM1,XMM2 0x66, 0x0F,0xF6,0x5D,0xE0, // psadbw XMM3,-020h[RBP] 0x66, 0x0F,0x70,0xCA,0x03, // pshufd XMM1,XMM2,3 0x66, 0x0F,0x70,0x5D,0xE0,0x03, // pshufd XMM3,-020h[RBP],3 0xF3,0x0F,0x70,0xCA,0x03, // pshufhw XMM1,XMM2,3 0xF3,0x0F,0x70,0x5D,0xE0,0x03, // pshufhw XMM3,-020h[RBP],3 0xF2,0x0F,0x70,0xCA,0x03, // pshuflw XMM1,XMM2,3 0xF2,0x0F,0x70,0x5D,0xE0,0x03, // pshuflw XMM3,-020h[RBP],3 0x0F,0x70,0xCA,0x03, // pshufw MM1,MM2,3 0x0F,0x70,0x5D,0xD8,0x03, // pshufw MM3,-028h[RBP],3 0x66, 0x0F,0x73,0xF9,0x18, // pslldq XMM1,020h 0x0F,0xF1,0xCA, // psllw MM1,MM2 0x0F,0xF1,0x4D,0xD8, // psllw MM1,-028h[RBP] 0x66, 0x0F,0xF1,0xCA, // psllw XMM1,XMM2 0x66, 0x0F,0xF1,0x4D,0xE0, // psllw XMM1,-020h[RBP] 0x0F,0x71,0xF1,0x15, // psraw MM1,015h 0x66, 0x0F,0x71,0xF1,0x15, // psraw XMM1,015h 0x0F,0xF2,0xCA, // pslld MM1,MM2 0x0F,0xF2,0x4D,0xD8, // pslld MM1,-028h[RBP] 0x66, 0x0F,0xF2,0xCA, // pslld XMM1,XMM2 0x66, 0x0F,0xF2,0x4D,0xE0, // pslld XMM1,-020h[RBP] 0x0F,0x72,0xF1,0x15, // psrad MM1,015h 0x66, 0x0F,0x72,0xF1,0x15, // psrad XMM1,015h 0x0F,0xF3,0xCA, // psllq MM1,MM2 0x0F,0xF3,0x4D,0xD8, // psllq MM1,-028h[RBP] 0x66, 0x0F,0xF3,0xCA, // psllq XMM1,XMM2 0x66, 0x0F,0xF3,0x4D,0xE0, // psllq XMM1,-020h[RBP] 0x0F,0x73,0xF1,0x15, // psllq MM1,015h 0x66, 0x0F,0x73,0xF1,0x15, // psllq XMM1,015h 0x0F,0xE1,0xCA, // psraw MM1,MM2 0x0F,0xE1,0x4D,0xD8, // psraw MM1,-028h[RBP] 0x66, 0x0F,0xE1,0xCA, // psraw XMM1,XMM2 0x66, 0x0F,0xE1,0x4D,0xE0, // psraw XMM1,-020h[RBP] 0x0F,0x71,0xE1,0x15, // psraw MM1,015h 0x66, 0x0F,0x71,0xE1,0x15, // psraw XMM1,015h 0x0F,0xE2,0xCA, // psrad MM1,MM2 0x0F,0xE2,0x4D,0xD8, // psrad MM1,-028h[RBP] 0x66, 0x0F,0xE2,0xCA, // psrad XMM1,XMM2 0x66, 0x0F,0xE2,0x4D,0xE0, // psrad XMM1,-020h[RBP] 0x0F,0x72,0xE1,0x15, // psrad MM1,015h 0x66, 0x0F,0x72,0xE1,0x15, // psrad XMM1,015h 0x66, 0x0F,0x73,0xD9,0x18, // psrldq XMM1,020h 0x0F,0xD1,0xCA, // psrlw MM1,MM2 0x0F,0xD1,0x4D,0xD8, // psrlw MM1,-028h[RBP] 0x66, 0x0F,0xD1,0xCA, // psrlw XMM1,XMM2 0x66, 0x0F,0xD1,0x4D,0xE0, // psrlw XMM1,-020h[RBP] 0x0F,0x71,0xD1,0x15, // psrlw MM1,015h 0x66, 0x0F,0x71,0xD1,0x15, // psrlw XMM1,015h 0x0F,0xD2,0xCA, // psrld MM1,MM2 0x0F,0xD2,0x4D,0xD8, // psrld MM1,-028h[RBP] 0x66, 0x0F,0xD2,0xCA, // psrld XMM1,XMM2 0x66, 0x0F,0xD2,0x4D,0xE0, // psrld XMM1,-020h[RBP] 0x0F,0x72,0xD1,0x15, // psrld MM1,015h 0x66, 0x0F,0x72,0xD1,0x15, // psrld XMM1,015h 0x0F,0xD3,0xCA, // psrlq MM1,MM2 0x0F,0xD3,0x4D,0xD8, // psrlq MM1,-028h[RBP] 0x66, 0x0F,0xD3,0xCA, // psrlq XMM1,XMM2 0x66, 0x0F,0xD3,0x4D,0xE0, // psrlq XMM1,-020h[RBP] 0x0F,0x73,0xD1,0x15, // psrlq MM1,015h 0x66, 0x0F,0x73,0xD1,0x15, // psrlq XMM1,015h 0x0F,0xF8,0xCA, // psubb MM1,MM2 0x0F,0xF8,0x4D,0xD8, // psubb MM1,-028h[RBP] 0x66, 0x0F,0xF8,0xCA, // psubb XMM1,XMM2 0x66, 0x0F,0xF8,0x4D,0xE0, // psubb XMM1,-020h[RBP] 0x0F,0xF9,0xCA, // psubw MM1,MM2 0x0F,0xF9,0x4D,0xD8, // psubw MM1,-028h[RBP] 0x66, 0x0F,0xF9,0xCA, // psubw XMM1,XMM2 0x66, 0x0F,0xF9,0x4D,0xE0, // psubw XMM1,-020h[RBP] 0x0F,0xFA,0xCA, // psubd MM1,MM2 0x0F,0xFA,0x4D,0xD8, // psubd MM1,-028h[RBP] 0x66, 0x0F,0xFA,0xCA, // psubd XMM1,XMM2 0x66, 0x0F,0xFA,0x4D,0xE0, // psubd XMM1,-020h[RBP] 0x0F,0xFB,0xCA, // psubq MM1,MM2 0x0F,0xFB,0x4D,0xD8, // psubq MM1,-028h[RBP] 0x66, 0x0F,0xFB,0xCA, // psubq XMM1,XMM2 0x66, 0x0F,0xFB,0x4D,0xE0, // psubq XMM1,-020h[RBP] 0x0F,0xE8,0xCA, // psubsb MM1,MM2 0x0F,0xE8,0x4D,0xD8, // psubsb MM1,-028h[RBP] 0x66, 0x0F,0xE8,0xCA, // psubsb XMM1,XMM2 0x66, 0x0F,0xE8,0x4D,0xE0, // psubsb XMM1,-020h[RBP] 0x0F,0xE9,0xCA, // psubsw MM1,MM2 0x0F,0xE9,0x4D,0xD8, // psubsw MM1,-028h[RBP] 0x66, 0x0F,0xE9,0xCA, // psubsw XMM1,XMM2 0x66, 0x0F,0xE9,0x4D,0xE0, // psubsw XMM1,-020h[RBP] 0x0F,0xD8,0xCA, // psubusb MM1,MM2 0x0F,0xD8,0x4D,0xD8, // psubusb MM1,-028h[RBP] 0x66, 0x0F,0xD8,0xCA, // psubusb XMM1,XMM2 0x66, 0x0F,0xD8,0x4D,0xE0, // psubusb XMM1,-020h[RBP] 0x0F,0xD9,0xCA, // psubusw MM1,MM2 0x0F,0xD9,0x4D,0xD8, // psubusw MM1,-028h[RBP] 0x66, 0x0F,0xD9,0xCA, // psubusw XMM1,XMM2 0x66, 0x0F,0xD9,0x4D,0xE0, // psubusw XMM1,-020h[RBP] 0x0F,0x68,0xCA, // punpckhbw MM1,MM2 0x0F,0x68,0x4D,0xD8, // punpckhbw MM1,-028h[RBP] 0x66, 0x0F,0x68,0xCA, // punpckhbw XMM1,XMM2 0x66, 0x0F,0x68,0x4D,0xE0, // punpckhbw XMM1,-020h[RBP] 0x0F,0x69,0xCA, // punpckhwd MM1,MM2 0x0F,0x69,0x4D,0xD8, // punpckhwd MM1,-028h[RBP] 0x66, 0x0F,0x69,0xCA, // punpckhwd XMM1,XMM2 0x66, 0x0F,0x69,0x4D,0xE0, // punpckhwd XMM1,-020h[RBP] 0x0F,0x6A,0xCA, // punpckhdq MM1,MM2 0x0F,0x6A,0x4D,0xD8, // punpckhdq MM1,-028h[RBP] 0x66, 0x0F,0x6A,0xCA, // punpckhdq XMM1,XMM2 0x66, 0x0F,0x6A,0x4D,0xE0, // punpckhdq XMM1,-020h[RBP] 0x66, 0x0F,0x6D,0xCA, // punpckhqdq XMM1,XMM2 0x66, 0x0F,0x6D,0x4D,0xE0, // punpckhqdq XMM1,-020h[RBP] 0x0F,0x60,0xCA, // punpcklbw MM1,MM2 0x0F,0x60,0x4D,0xD8, // punpcklbw MM1,-028h[RBP] 0x66, 0x0F,0x60,0xCA, // punpcklbw XMM1,XMM2 0x66, 0x0F,0x60,0x4D,0xE0, // punpcklbw XMM1,-020h[RBP] 0x0F,0x61,0xCA, // punpcklwd MM1,MM2 0x0F,0x61,0x4D,0xD8, // punpcklwd MM1,-028h[RBP] 0x66, 0x0F,0x61,0xCA, // punpcklwd XMM1,XMM2 0x66, 0x0F,0x61,0x4D,0xE0, // punpcklwd XMM1,-020h[RBP] 0x0F,0x62,0xCA, // punpckldq MM1,MM2 0x0F,0x62,0x4D,0xD8, // punpckldq MM1,-028h[RBP] 0x66, 0x0F,0x62,0xCA, // punpckldq XMM1,XMM2 0x66, 0x0F,0x62,0x4D,0xE0, // punpckldq XMM1,-020h[RBP] 0x66, 0x0F,0x6C,0xCA, // punpcklqdq XMM1,XMM2 0x66, 0x0F,0x6C,0x4D,0xE0, // punpcklqdq XMM1,-020h[RBP] 0x0F,0xEF,0xCA, // pxor MM1,MM2 0x0F,0xEF,0x4D,0xD8, // pxor MM1,-028h[RBP] 0x66, 0x0F,0xEF,0xCA, // pxor XMM1,XMM2 0x66, 0x0F,0xEF,0x4D,0xE0, // pxor XMM1,-020h[RBP] 0x0F,0x53,0xCA, // rcpps XMM1,XMM2 0x0F,0x53,0x4D,0xE0, // rcpps XMM1,-020h[RBP] 0xF3,0x0F,0x53,0xCA, // rcpss XMM1,XMM2 0xF3,0x0F,0x53,0x4D,0xD4, // rcpss XMM1,-02Ch[RBP] 0x0F,0x52,0xCA, // rsqrtps XMM1,XMM2 0x0F,0x52,0x4D,0xE0, // rsqrtps XMM1,-020h[RBP] 0xF3,0x0F,0x52,0xCA, // rsqrtss XMM1,XMM2 0xF3,0x0F,0x52,0x4D,0xD4, // rsqrtss XMM1,-02Ch[RBP] 0x66, 0x0F,0xC6,0xCA,0x03, // shufpd XMM1,XMM2,3 0x66, 0x0F,0xC6,0x4D,0xE0,0x04, // shufpd XMM1,-020h[RBP],4 0x0F,0xC6,0xCA,0x03, // shufps XMM1,XMM2,3 0x0F,0xC6,0x4D,0xE0,0x04, // shufps XMM1,-020h[RBP],4 0x66, 0x0F,0x2E,0xE6, // ucimisd XMM4,XMM6 0x66, 0x0F,0x2E,0x6D,0xD8, // ucimisd XMM5,-028h[RBP] 0x0F,0x2E,0xF7, // ucomiss XMM6,XMM7 0x0F,0x2E,0x7D,0xD4, // ucomiss XMM7,-02Ch[RBP] 0x66, 0x0F,0x15,0xE6, // uppckhpd XMM4,XMM6 0x66, 0x0F,0x15,0x6D,0xE0, // uppckhpd XMM5,-020h[RBP] 0x0F,0x15,0xE6, // unpckhps XMM4,XMM6 0x0F,0x15,0x6D,0xE0, // unpckhps XMM5,-020h[RBP] 0x66, 0x0F,0x14,0xE6, // uppcklpd XMM4,XMM6 0x66, 0x0F,0x14,0x6D,0xE0, // uppcklpd XMM5,-020h[RBP] 0x0F,0x14,0xE6, // unpcklps XMM4,XMM6 0x0F,0x14,0x6D,0xE0, // unpcklps XMM5,-020h[RBP] 0x66, 0x0F,0x57,0xCA, // xorpd XMM1,XMM2 0x66, 0x0F,0x57,0x4D,0xE0, // xorpd XMM1,-020h[RBP] 0x0F,0x57,0xCA, // xorps XMM1,XMM2 0x0F,0x57,0x4D,0xE0, // xorps XMM1,-020h[RBP] ]; int i; asm { call L1 ; movmskpd ESI,XMM3 ; movmskps ESI,XMM3 ; movntdq m128[RBP],XMM2 ; movnti m32[RBP],ECX ; movntpd m128[RBP],XMM3 ; movntps m128[RBP],XMM4 ; movntq m64[RBP],MM5 ; movq MM1,MM2 ; movq MM2,m64[RBP] ; movq m64[RBP],MM3 ; movq XMM1,XMM2 ; movq XMM2,m64[RBP] ; movq m64[RBP],XMM3 ; movq2dq XMM3,MM2 ; movsd ; movsd XMM1,XMM2 ; movsd XMM3,m64[RBP] ; movsd m64[RBP],XMM4 ; movss XMM1,XMM2 ; movss XMM3,m32[RBP] ; movss m32[RBP],XMM4 ; movupd XMM1,XMM2 ; movupd XMM3,m128[RBP] ; movupd m128[RBP],XMM4 ; movups XMM1,XMM2 ; movups XMM3,m128[RBP] ; movups m128[RBP],XMM4 ; orpd XMM1,XMM2 ; orpd XMM3,m128[RBP] ; orps XMM1,XMM2 ; orps XMM3,m128[RBP] ; packsswb MM1,MM2 ; packsswb MM3,m64[RBP] ; packsswb XMM1,XMM2 ; packsswb XMM3,m128[RBP] ; packssdw MM1,MM2 ; packssdw MM3,m64[RBP] ; packssdw XMM1,XMM2 ; packssdw XMM3,m128[RBP] ; packuswb MM1,MM2 ; packuswb MM3,m64[RBP] ; packuswb XMM1,XMM2 ; packuswb XMM3,m128[RBP] ; paddb MM1,MM2 ; paddb MM3,m64[RBP] ; paddb XMM1,XMM2 ; paddb XMM3,m128[RBP] ; paddw MM1,MM2 ; paddw MM3,m64[RBP] ; paddw XMM1,XMM2 ; paddw XMM3,m128[RBP] ; paddd MM1,MM2 ; paddd MM3,m64[RBP] ; paddd XMM1,XMM2 ; paddd XMM3,m128[RBP] ; paddq MM1,MM2 ; paddq MM3,m64[RBP] ; paddq XMM1,XMM2 ; paddq XMM3,m128[RBP] ; paddsb MM1,MM2 ; paddsb MM3,m64[RBP] ; paddsb XMM1,XMM2 ; paddsb XMM3,m128[RBP] ; paddsw MM1,MM2 ; paddsw MM3,m64[RBP] ; paddsw XMM1,XMM2 ; paddsw XMM3,m128[RBP] ; paddusb MM1,MM2 ; paddusb MM3,m64[RBP] ; paddusb XMM1,XMM2 ; paddusb XMM3,m128[RBP] ; paddusw MM1,MM2 ; paddusw MM3,m64[RBP] ; paddusw XMM1,XMM2 ; paddusw XMM3,m128[RBP] ; pand MM1,MM2 ; pand MM3,m64[RBP] ; pand XMM1,XMM2 ; pand XMM3,m128[RBP] ; pandn MM1,MM2 ; pandn MM3,m64[RBP] ; pandn XMM1,XMM2 ; pandn XMM3,m128[RBP] ; pavgb MM1,MM2 ; pavgb MM3,m64[RBP] ; pavgb XMM1,XMM2 ; pavgb XMM3,m128[RBP] ; pavgw MM1,MM2 ; pavgw MM3,m64[RBP] ; pavgw XMM1,XMM2 ; pavgw XMM3,m128[RBP] ; pcmpeqb MM1,MM2 ; pcmpeqb MM3,m64[RBP] ; pcmpeqb XMM1,XMM2 ; pcmpeqb XMM3,m128[RBP] ; pcmpeqw MM1,MM2 ; pcmpeqw MM3,m64[RBP] ; pcmpeqw XMM1,XMM2 ; pcmpeqw XMM3,m128[RBP] ; pcmpeqd MM1,MM2 ; pcmpeqd MM3,m64[RBP] ; pcmpeqd XMM1,XMM2 ; pcmpeqd XMM3,m128[RBP] ; pcmpgtb MM1,MM2 ; pcmpgtb MM3,m64[RBP] ; pcmpgtb XMM1,XMM2 ; pcmpgtb XMM3,m128[RBP] ; pcmpgtw MM1,MM2 ; pcmpgtw MM3,m64[RBP] ; pcmpgtw XMM1,XMM2 ; pcmpgtw XMM3,m128[RBP] ; pcmpgtd MM1,MM2 ; pcmpgtd MM3,m64[RBP] ; pcmpgtd XMM1,XMM2 ; pcmpgtd XMM3,m128[RBP] ; pextrw EDX,MM6,7 ; pextrw EDX,XMM6,7 ; pinsrw MM6,EDX,7 ; pinsrw MM6,m16[RBP],7 ; pinsrw XMM6,EDX,7 ; pinsrw XMM6,m16[RBP],7 ; pmaddwd MM1,MM2 ; pmaddwd MM3,m64[RBP] ; pmaddwd XMM1,XMM2 ; pmaddwd XMM3,m128[RBP] ; pmaxsw MM1,MM2 ; pmaxsw MM3,m64[RBP] ; pmaxsw XMM1,XMM2 ; pmaxsw XMM3,m128[RBP] ; pmaxub MM1,MM2 ; pmaxub MM3,m64[RBP] ; pmaxub XMM1,XMM2 ; pmaxub XMM3,m128[RBP] ; pminsw MM1,MM2 ; pminsw MM3,m64[RBP] ; pminsw XMM1,XMM2 ; pminsw XMM3,m128[RBP] ; pminub MM1,MM2 ; pminub MM3,m64[RBP] ; pminub XMM1,XMM2 ; pminub XMM3,m128[RBP] ; pmovmskb ECX,MM0 ; pmovmskb ECX,XMM6 ; pmulhuw MM1,MM2 ; pmulhuw MM3,m64[RBP] ; pmulhuw XMM1,XMM2 ; pmulhuw XMM3,m128[RBP] ; pmulhw MM1,MM2 ; pmulhw MM3,m64[RBP] ; pmulhw XMM1,XMM2 ; pmulhw XMM3,m128[RBP] ; pmullw MM1,MM2 ; pmullw MM3,m64[RBP] ; pmullw XMM1,XMM2 ; pmullw XMM3,m128[RBP] ; pmuludq MM1,MM2 ; pmuludq MM3,m64[RBP] ; pmuludq XMM1,XMM2 ; pmuludq XMM3,m128[RBP] ; por MM1,MM2 ; por MM3,m64[RBP] ; por XMM1,XMM2 ; por XMM3,m128[RBP] ; prefetcht0 m8[RBP] ; prefetcht1 m8[RBP] ; prefetcht2 m8[RBP] ; prefetchnta m8[RBP] ; psadbw MM1,MM2 ; psadbw MM3,m64[RBP] ; psadbw XMM1,XMM2 ; psadbw XMM3,m128[RBP] ; pshufd XMM1,XMM2,3 ; pshufd XMM3,m128[RBP],3 ; pshufhw XMM1,XMM2,3 ; pshufhw XMM3,m128[RBP],3 ; pshuflw XMM1,XMM2,3 ; pshuflw XMM3,m128[RBP],3 ; pshufw MM1,MM2,3 ; pshufw MM3,m64[RBP],3 ; pslldq XMM1,0x18 ; psllw MM1,MM2 ; psllw MM1,m64[RBP] ; psllw XMM1,XMM2 ; psllw XMM1,m128[RBP] ; psllw MM1,0x15 ; psllw XMM1,0x15 ; pslld MM1,MM2 ; pslld MM1,m64[RBP] ; pslld XMM1,XMM2 ; pslld XMM1,m128[RBP] ; pslld MM1,0x15 ; pslld XMM1,0x15 ; psllq MM1,MM2 ; psllq MM1,m64[RBP] ; psllq XMM1,XMM2 ; psllq XMM1,m128[RBP] ; psllq MM1,0x15 ; psllq XMM1,0x15 ; psraw MM1,MM2 ; psraw MM1,m64[RBP] ; psraw XMM1,XMM2 ; psraw XMM1,m128[RBP] ; psraw MM1,0x15 ; psraw XMM1,0x15 ; psrad MM1,MM2 ; psrad MM1,m64[RBP] ; psrad XMM1,XMM2 ; psrad XMM1,m128[RBP] ; psrad MM1,0x15 ; psrad XMM1,0x15 ; psrldq XMM1,0x18 ; psrlw MM1,MM2 ; psrlw MM1,m64[RBP] ; psrlw XMM1,XMM2 ; psrlw XMM1,m128[RBP] ; psrlw MM1,0x15 ; psrlw XMM1,0x15 ; psrld MM1,MM2 ; psrld MM1,m64[RBP] ; psrld XMM1,XMM2 ; psrld XMM1,m128[RBP] ; psrld MM1,0x15 ; psrld XMM1,0x15 ; psrlq MM1,MM2 ; psrlq MM1,m64[RBP] ; psrlq XMM1,XMM2 ; psrlq XMM1,m128[RBP] ; psrlq MM1,0x15 ; psrlq XMM1,0x15 ; psubb MM1,MM2 ; psubb MM1,m64[RBP] ; psubb XMM1,XMM2 ; psubb XMM1,m128[RBP] ; psubw MM1,MM2 ; psubw MM1,m64[RBP] ; psubw XMM1,XMM2 ; psubw XMM1,m128[RBP] ; psubd MM1,MM2 ; psubd MM1,m64[RBP] ; psubd XMM1,XMM2 ; psubd XMM1,m128[RBP] ; psubq MM1,MM2 ; psubq MM1,m64[RBP] ; psubq XMM1,XMM2 ; psubq XMM1,m128[RBP] ; psubsb MM1,MM2 ; psubsb MM1,m64[RBP] ; psubsb XMM1,XMM2 ; psubsb XMM1,m128[RBP] ; psubsw MM1,MM2 ; psubsw MM1,m64[RBP] ; psubsw XMM1,XMM2 ; psubsw XMM1,m128[RBP] ; psubusb MM1,MM2 ; psubusb MM1,m64[RBP] ; psubusb XMM1,XMM2 ; psubusb XMM1,m128[RBP] ; psubusw MM1,MM2 ; psubusw MM1,m64[RBP] ; psubusw XMM1,XMM2 ; psubusw XMM1,m128[RBP] ; punpckhbw MM1,MM2 ; punpckhbw MM1,m64[RBP] ; punpckhbw XMM1,XMM2 ; punpckhbw XMM1,m128[RBP] ; punpckhwd MM1,MM2 ; punpckhwd MM1,m64[RBP] ; punpckhwd XMM1,XMM2 ; punpckhwd XMM1,m128[RBP] ; punpckhdq MM1,MM2 ; punpckhdq MM1,m64[RBP] ; punpckhdq XMM1,XMM2 ; punpckhdq XMM1,m128[RBP] ; punpckhqdq XMM1,XMM2 ; punpckhqdq XMM1,m128[RBP] ; punpcklbw MM1,MM2 ; punpcklbw MM1,m64[RBP] ; punpcklbw XMM1,XMM2 ; punpcklbw XMM1,m128[RBP] ; punpcklwd MM1,MM2 ; punpcklwd MM1,m64[RBP] ; punpcklwd XMM1,XMM2 ; punpcklwd XMM1,m128[RBP] ; punpckldq MM1,MM2 ; punpckldq MM1,m64[RBP] ; punpckldq XMM1,XMM2 ; punpckldq XMM1,m128[RBP] ; punpcklqdq XMM1,XMM2 ; punpcklqdq XMM1,m128[RBP] ; pxor MM1,MM2 ; pxor MM1,m64[RBP] ; pxor XMM1,XMM2 ; pxor XMM1,m128[RBP] ; rcpps XMM1,XMM2 ; rcpps XMM1,m128[RBP] ; rcpss XMM1,XMM2 ; rcpss XMM1,m32[RBP] ; rsqrtps XMM1,XMM2 ; rsqrtps XMM1,m128[RBP] ; rsqrtss XMM1,XMM2 ; rsqrtss XMM1,m32[RBP] ; shufpd XMM1,XMM2,3 ; shufpd XMM1,m128[RBP],4 ; shufps XMM1,XMM2,3 ; shufps XMM1,m128[RBP],4 ; ucomisd XMM4,XMM6 ; ucomisd XMM5,m64[RBP] ; ucomiss XMM6,XMM7 ; ucomiss XMM7,m32[RBP] ; unpckhpd XMM4,XMM6 ; unpckhpd XMM5,m128[RBP] ; unpckhps XMM4,XMM6 ; unpckhps XMM5,m128[RBP] ; unpcklpd XMM4,XMM6 ; unpcklpd XMM5,m128[RBP] ; unpcklps XMM4,XMM6 ; unpcklps XMM5,m128[RBP] ; xorpd XMM1,XMM2 ; xorpd XMM1,m128[RBP] ; xorps XMM1,XMM2 ; xorps XMM1,m128[RBP] ; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], data[i]); assert(p[i] == data[i]); } } /****************************************************/ void test15() { int m32; long m64; M128 m128; ubyte *p; static ubyte data[] = [ 0x0F,0x0F,0xDC,0xBF, // pavgusb MM3,MM4 0x0F,0x0F,0x5D,0xD8,0xBF, // pavgusb MM3,-028h[RBP] 0x0F,0x0F,0xDC,0x1D, // pf2id MM3,MM4 0x0F,0x0F,0x5D,0xD8,0x1D, // pf2id MM3,-028h[RBP] 0x0F,0x0F,0xDC,0xAE, // pfacc MM3,MM4 0x0F,0x0F,0x5D,0xD8,0xAE, // pfacc MM3,-028h[RBP] 0x0F,0x0F,0xDC,0x9E, // pfadd MM3,MM4 0x0F,0x0F,0x5D,0xD8,0x9E, // pfadd MM3,-028h[RBP] 0x0F,0x0F,0xDC,0xB0, // pfcmpeq MM3,MM4 0x0F,0x0F,0x5D,0xD8,0xB0, // pfcmpeq MM3,-028h[RBP] 0x0F,0x0F,0xDC,0x90, // pfcmpge MM3,MM4 0x0F,0x0F,0x5D,0xD8,0x90, // pfcmpge MM3,-028h[RBP] 0x0F,0x0F,0xDC,0xA0, // pfcmpgt MM3,MM4 0x0F,0x0F,0x5D,0xD8,0xA0, // pfcmpgt MM3,-028h[RBP] 0x0F,0x0F,0xDC,0xA4, // pfmax MM3,MM4 0x0F,0x0F,0x5D,0xD8,0x94, // pfmin MM3,-028h[RBP] 0x0F,0x0F,0xDC,0xB4, // pfmul MM3,MM4 0x0F,0x0F,0x5D,0xD8,0xB4, // pfmul MM3,-028h[RBP] 0x0F,0x0F,0xDC,0x8A, // pfnacc MM3,MM4 0x0F,0x0F,0x5D,0xD8,0x8E, // pfpnacc MM3,-028h[RBP] 0x0F,0x0F,0xDC,0x96, // pfrcp MM3,MM4 0x0F,0x0F,0x5D,0xD8,0x96, // pfrcp MM3,-028h[RBP] 0x0F,0x0F,0xDC,0xA6, // pfrcpit1 MM3,MM4 0x0F,0x0F,0x5D,0xD8,0xA6, // pfrcpit1 MM3,-028h[RBP] 0x0F,0x0F,0xDC,0xB6, // pfrcpit2 MM3,MM4 0x0F,0x0F,0x5D,0xD8,0xB6, // pfrcpit2 MM3,-028h[RBP] 0x0F,0x0F,0xDC,0x97, // pfrsqrt MM3,MM4 0x0F,0x0F,0x5D,0xD8,0xA7, // pfrsqit1 MM3,-028h[RBP] 0x0F,0x0F,0xDC,0x9A, // pfsub MM3,MM4 0x0F,0x0F,0x5D,0xD8,0x9A, // pfsub MM3,-028h[RBP] 0x0F,0x0F,0xDC,0xAA, // pfsubr MM3,MM4 0x0F,0x0F,0x5D,0xD8,0xAA, // pfsubr MM3,-028h[RBP] 0x0F,0x0F,0xDC,0x0D, // pi2fd MM3,MM4 0x0F,0x0F,0x5D,0xD8,0x0D, // pi2fd MM3,-028h[RBP] 0x0F,0x0F,0xDC,0xB7, // pmulhrw MM3,MM4 0x0F,0x0F,0x5D,0xD8,0xB7, // pmulhrw MM3,-028h[RBP] 0x0F,0x0F,0xDC,0xBB, // pswapd MM3,MM4 0x0F,0x0F,0x5D,0xD8,0xBB, // pswapd MM3,-028h[RBP] ]; int i; asm { call L1 ; pavgusb MM3,MM4 ; pavgusb MM3,m64[RBP] ; pf2id MM3,MM4 ; pf2id MM3,m64[RBP] ; pfacc MM3,MM4 ; pfacc MM3,m64[RBP] ; pfadd MM3,MM4 ; pfadd MM3,m64[RBP] ; pfcmpeq MM3,MM4 ; pfcmpeq MM3,m64[RBP] ; pfcmpge MM3,MM4 ; pfcmpge MM3,m64[RBP] ; pfcmpgt MM3,MM4 ; pfcmpgt MM3,m64[RBP] ; pfmax MM3,MM4 ; pfmin MM3,m64[RBP] ; pfmul MM3,MM4 ; pfmul MM3,m64[RBP] ; pfnacc MM3,MM4 ; pfpnacc MM3,m64[RBP] ; pfrcp MM3,MM4 ; pfrcp MM3,m64[RBP] ; pfrcpit1 MM3,MM4 ; pfrcpit1 MM3,m64[RBP] ; pfrcpit2 MM3,MM4 ; pfrcpit2 MM3,m64[RBP] ; pfrsqrt MM3,MM4 ; pfrsqit1 MM3,m64[RBP] ; pfsub MM3,MM4 ; pfsub MM3,m64[RBP] ; pfsubr MM3,MM4 ; pfsubr MM3,m64[RBP] ; pi2fd MM3,MM4 ; pi2fd MM3,m64[RBP] ; pmulhrw MM3,MM4 ; pmulhrw MM3,m64[RBP] ; pswapd MM3,MM4 ; pswapd MM3,m64[RBP] ; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ struct S17 { char x[6]; } __gshared S17 xx17; void test17() { ubyte *p; static ubyte data[] = [ 0x0F, 0x01, 0x10, // lgdt [EAX] 0x0F, 0x01, 0x18, // lidt [EAX] 0x0F, 0x01, 0x00, // sgdt [EAX] 0x0F, 0x01, 0x08, // sidt [EAX] ]; int i; asm { call L1 ; lgdt [RAX] ; lidt [RAX] ; sgdt [RAX] ; sidt [RAX] ; lgdt xx17 ; lidt xx17 ; sgdt xx17 ; sidt xx17 ; L1: pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test18() { ubyte *p; static ubyte data[] = [ 0xDB, 0xF1, // fcomi ST,ST(1) 0xDB, 0xF0, // fcomi ST,ST(0) 0xDB, 0xF2, // fcomi ST,ST(2) 0xDF, 0xF1, // fcomip ST,ST(1) 0xDF, 0xF0, // fcomip ST,ST(0) 0xDF, 0xF2, // fcomip ST,ST(2) 0xDB, 0xE9, // fucomi ST,ST(1) 0xDB, 0xE8, // fucomi ST,ST(0) 0xDB, 0xEB, // fucomi ST,ST(3) 0xDF, 0xE9, // fucomip ST,ST(1) 0xDF, 0xED, // fucomip ST,ST(5) 0xDF, 0xEC, // fucomip ST,ST(4) ]; int i; asm { call L1 ; fcomi ; fcomi ST(0) ; fcomi ST,ST(2) ; fcomip ; fcomip ST(0) ; fcomip ST,ST(2) ; fucomi ; fucomi ST(0) ; fucomi ST,ST(3) ; fucomip ; fucomip ST(5) ; fucomip ST,ST(4) ; L1: pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ extern (C) { void foo19() { } } void test19() { void function() fp; ulong x; ulong *p; asm { lea RAX, qword ptr [foo19]; mov fp, RAX; mov x, RAX; mov p, RAX; call fp; } (*fp)(); } /****************************************************/ /+ void test20() { ubyte *p; static ubyte data[] = [ 0x9B, 0xDB, 0xE0, // feni 0xDB, 0xE0, // fneni 0x9B, 0xDB, 0xE1, // fdisi 0xDB, 0xE1, // fndisi 0x9B, 0xDB, 0xE2, // fclex 0xDB, 0xE2, // fnclex 0x9B, 0xDB, 0xE3, // finit 0xDB, 0xE3, // fninit 0xDB, 0xE4, // fsetpm ]; int i; asm { call L1 ; feni ; fneni ; fdisi ; fndisi ; finit ; fninit ; fclex ; fnclex ; finit ; fninit ; fsetpm ; L1: pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } +/ /****************************************************/ void test21() { ubyte *p; static ubyte data[] = [ 0xE4, 0x06, // in AL,6 0x66, 0xE5, 0x07, // in AX,7 0xE5, 0x08, // in EAX,8 0xEC, // in AL,DX 0x66, 0xED, // in AX,DX 0xED, // in EAX,DX 0xE6, 0x06, // out 6,AL 0x66, 0xE7, 0x07, // out 7,AX 0xE7, 0x08, // out 8,EAX 0xEE, // out DX,AL 0x66, 0xEF, // out DX,AX 0xEF, // out DX,EAX ]; int i; asm { call L1 ; in AL,6 ; in AX,7 ; in EAX,8 ; in AL,DX ; in AX,DX ; in EAX,DX ; out 6,AL ; out 7,AX ; out 8,EAX ; out DX,AL ; out DX,AX ; out DX,EAX ; L1: pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test22() { ubyte *p; static ubyte data[] = [ 0x0F, 0xC7, 0x4D, 0xE0, // cmpxchg8b 0x48, 0x0F, 0xC7, 0x4D, 0xF0 // cmpxchg16b ]; int i; M64 m64; M128 m128; asm { call L1 ; cmpxchg8b m64 ; cmpxchg16b m128 ; L1: pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test23() { short m16; int m32; long m64; M128 m128; ubyte *p; static ubyte data[] = [ 0xD9, 0xC9, // fxch ST(1), ST(0) 0xDF, 0x5D, 0xD0, // fistp word ptr -030h[RBP] 0xDB, 0x5D, 0xD4, // fistp dword ptr -02Ch[RBP] 0xDF, 0x7D, 0xD8, // fistp long64 ptr -028h[RBP] 0xDF, 0x4D, 0xD0, // fisttp short ptr -030h[RBP] 0xDB, 0x4D, 0xD4, // fisttp word ptr -02Ch[RBP] 0xDD, 0x4D, 0xD8, // fisttp long64 ptr -028h[RBP] 0x0F, 0x01, 0xC8, // monitor 0x0F, 0x01, 0xC9, // mwait 0x0F, 0x01, 0xD0, // xgetbv 0x66, 0x0F, 0xD0, 0xCA, // addsubpd XMM1,XMM2 0x66, 0x0F, 0xD0, 0x4D, 0xE0, // addsubpd XMM1,-020h[RBP] 0xF2, 0x0F, 0xD0, 0xCA, // addsubps XMM1,XMM2 0xF2, 0x0F, 0xD0, 0x4D, 0xE0, // addsubps XMM1,-020h[RBP] 0x66, 0x0F, 0x7C, 0xCA, // haddpd XMM1,XMM2 0x66, 0x0F, 0x7C, 0x4D, 0xE0, // haddpd XMM1,-020h[RBP] 0xF2, 0x0F, 0x7C, 0xCA, // haddps XMM1,XMM2 0xF2, 0x0F, 0x7C, 0x4D, 0xE0, // haddps XMM1,-020h[RBP] 0x66, 0x0F, 0x7D, 0xCA, // hsubpd XMM1,XMM2 0x66, 0x0F, 0x7D, 0x4D, 0xE0, // hsubpd XMM1,-020h[RBP] 0xF2, 0x0F, 0x7D, 0xCA, // hsubps XMM1,XMM2 0xF2, 0x0F, 0x7D, 0x4D, 0xE0, // hsubps XMM1,-020h[RBP] 0xF2, 0x0F, 0xF0, 0x4D, 0xE0, // lddqu XMM1,-020h[RBP] 0xF2, 0x0F, 0x12, 0xCA, // movddup XMM1,XMM2 0xF2, 0x0F, 0x12, 0x4D, 0xD8, // movddup XMM1,-028h[RBP] 0xF3, 0x0F, 0x16, 0xCA, // movshdup XMM1,XMM2 0xF3, 0x0F, 0x16, 0x4D, 0xE0, // movshdup XMM1,-020h[RBP] 0xF3, 0x0F, 0x12, 0xCA, // movsldup XMM1,XMM2 0xF3, 0x0F, 0x12, 0x4D, 0xE0, // movsldup XMM1,-020h[RBP] ]; int i; asm { call L1 ; fxch ST(1), ST(0) ; fistp m16[RBP] ; fistp m32[RBP] ; fistp m64[RBP] ; fisttp m16[RBP] ; fisttp m32[RBP] ; fisttp m64[RBP] ; monitor ; mwait ; xgetbv ; addsubpd XMM1,XMM2 ; addsubpd XMM1,m128[RBP] ; addsubps XMM1,XMM2 ; addsubps XMM1,m128[RBP] ; haddpd XMM1,XMM2 ; haddpd XMM1,m128[RBP] ; haddps XMM1,XMM2 ; haddps XMM1,m128[RBP] ; hsubpd XMM1,XMM2 ; hsubpd XMM1,m128[RBP] ; hsubps XMM1,XMM2 ; hsubps XMM1,m128[RBP] ; lddqu XMM1,m128[RBP] ; movddup XMM1,XMM2 ; movddup XMM1,m64[RBP] ; movshdup XMM1,XMM2 ; movshdup XMM1,m128[RBP] ; movsldup XMM1,XMM2 ; movsldup XMM1,m128[RBP] ; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test24() { ushort i; asm { lea AX, i; mov i, AX; } assert(cast(ushort)&i == i); } /****************************************************/ void test25() { short m16; int m32; long m64; M128 m128; ubyte *p; static ubyte data[] = [ 0x66, 0x0F, 0x7E, 0xC1, // movd ECX,XMM0 0x66, 0x0F, 0x7E, 0xC9, // movd ECX,XMM1 0x66, 0x0F, 0x7E, 0xD1, // movd ECX,XMM2 0x66, 0x0F, 0x7E, 0xD9, // movd ECX,XMM3 0x66, 0x0F, 0x7E, 0xE1, // movd ECX,XMM4 0x66, 0x0F, 0x7E, 0xE9, // movd ECX,XMM5 0x66, 0x0F, 0x7E, 0xF1, // movd ECX,XMM6 0x66, 0x0F, 0x7E, 0xF9, // movd ECX,XMM7 0x0F, 0x7E, 0xC1, // movd ECX,MM0 0x0F, 0x7E, 0xC9, // movd ECX,MM1 0x0F, 0x7E, 0xD1, // movd ECX,MM2 0x0F, 0x7E, 0xD9, // movd ECX,MM3 0x0F, 0x7E, 0xE1, // movd ECX,MM4 0x0F, 0x7E, 0xE9, // movd ECX,MM5 0x0F, 0x7E, 0xF1, // movd ECX,MM6 0x0F, 0x7E, 0xF9, // movd ECX,MM7 0x66, 0x0F, 0x6E, 0xC1, // movd XMM0,ECX 0x66, 0x0F, 0x6E, 0xC9, // movd XMM1,ECX 0x66, 0x0F, 0x6E, 0xD1, // movd XMM2,ECX 0x66, 0x0F, 0x6E, 0xD9, // movd XMM3,ECX 0x66, 0x0F, 0x6E, 0xE1, // movd XMM4,ECX 0x66, 0x0F, 0x6E, 0xE9, // movd XMM5,ECX 0x66, 0x0F, 0x6E, 0xF1, // movd XMM6,ECX 0x66, 0x0F, 0x6E, 0xF9, // movd XMM7,ECX 0x0F, 0x6E, 0xC1, // movd MM0,ECX 0x0F, 0x6E, 0xC9, // movd MM1,ECX 0x0F, 0x6E, 0xD1, // movd MM2,ECX 0x0F, 0x6E, 0xD9, // movd MM3,ECX 0x0F, 0x6E, 0xE1, // movd MM4,ECX 0x0F, 0x6E, 0xE9, // movd MM5,ECX 0x0F, 0x6E, 0xF1, // movd MM6,ECX 0x0F, 0x6E, 0xF9, // movd MM7,ECX 0x66, 0x0F, 0x7E, 0xC8, // movd EAX,XMM1 0x66, 0x0F, 0x7E, 0xCB, // movd EBX,XMM1 0x66, 0x0F, 0x7E, 0xC9, // movd ECX,XMM1 0x66, 0x0F, 0x7E, 0xCA, // movd EDX,XMM1 0x66, 0x0F, 0x7E, 0xCE, // movd ESI,XMM1 0x66, 0x0F, 0x7E, 0xCF, // movd EDI,XMM1 0x66, 0x0F, 0x7E, 0xCD, // movd EBP,XMM1 0x66, 0x0F, 0x7E, 0xCC, // movd ESP,XMM1 0x0F, 0x7E, 0xC8, // movd EAX,MM1 0x0F, 0x7E, 0xCB, // movd EBX,MM1 0x0F, 0x7E, 0xC9, // movd ECX,MM1 0x0F, 0x7E, 0xCA, // movd EDX,MM1 0x0F, 0x7E, 0xCE, // movd ESI,MM1 0x0F, 0x7E, 0xCF, // movd EDI,MM1 0x0F, 0x7E, 0xCD, // movd EBP,MM1 0x0F, 0x7E, 0xCC, // movd ESP,MM1 0x66, 0x0F, 0x6E, 0xC8, // movd XMM1,EAX 0x66, 0x0F, 0x6E, 0xCB, // movd XMM1,EBX 0x66, 0x0F, 0x6E, 0xC9, // movd XMM1,ECX 0x66, 0x0F, 0x6E, 0xCA, // movd XMM1,EDX 0x66, 0x0F, 0x6E, 0xCE, // movd XMM1,ESI 0x66, 0x0F, 0x6E, 0xCF, // movd XMM1,EDI 0x66, 0x0F, 0x6E, 0xCD, // movd XMM1,EBP 0x66, 0x0F, 0x6E, 0xCC, // movd XMM1,ESP 0x0F, 0x6E, 0xC8, // movd MM1,EAX 0x0F, 0x6E, 0xCB, // movd MM1,EBX 0x0F, 0x6E, 0xC9, // movd MM1,ECX 0x0F, 0x6E, 0xCA, // movd MM1,EDX 0x0F, 0x6E, 0xCE, // movd MM1,ESI 0x0F, 0x6E, 0xCF, // movd MM1,EDI 0x0F, 0x6E, 0xCD, // movd MM1,EBP 0x0F, 0x6E, 0xCC, // movd MM1,ESP ]; int i; asm { call L1 ; movd ECX, XMM0; movd ECX, XMM1; movd ECX, XMM2; movd ECX, XMM3; movd ECX, XMM4; movd ECX, XMM5; movd ECX, XMM6; movd ECX, XMM7; movd ECX, MM0; movd ECX, MM1; movd ECX, MM2; movd ECX, MM3; movd ECX, MM4; movd ECX, MM5; movd ECX, MM6; movd ECX, MM7; movd XMM0, ECX; movd XMM1, ECX; movd XMM2, ECX; movd XMM3, ECX; movd XMM4, ECX; movd XMM5, ECX; movd XMM6, ECX; movd XMM7, ECX; movd MM0, ECX; movd MM1, ECX; movd MM2, ECX; movd MM3, ECX; movd MM4, ECX; movd MM5, ECX; movd MM6, ECX; movd MM7, ECX; movd EAX, XMM1; movd EBX, XMM1; movd ECX, XMM1; movd EDX, XMM1; movd ESI, XMM1; movd EDI, XMM1; movd EBP, XMM1; movd ESP, XMM1; movd EAX, MM1; movd EBX, MM1; movd ECX, MM1; movd EDX, MM1; movd ESI, MM1; movd EDI, MM1; movd EBP, MM1; movd ESP, MM1; movd XMM1, EAX; movd XMM1, EBX; movd XMM1, ECX; movd XMM1, EDX; movd XMM1, ESI; movd XMM1, EDI; movd XMM1, EBP; movd XMM1, ESP; movd MM1, EAX; movd MM1, EBX; movd MM1, ECX; movd MM1, EDX; movd MM1, ESI; movd MM1, EDI; movd MM1, EBP; movd MM1, ESP; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void fn26(ref byte val) { asm { mov RAX, val; inc byte ptr [RAX]; } } void test26() { byte b; //printf( "%i\n", b ); assert(b == 0); fn26(b); //printf( "%i\n", b ); assert(b == 1); } /****************************************************/ void test27() { static const ubyte[16] a = [0, 1, 2, 3, 4, 5, 6, 7, 8 ,9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF]; version (Windows) { asm { movdqu XMM0, a; pslldq XMM0, 2; } } } /****************************************************/ /* PASS: cfloat z; cfloat[1] z; double z; double[1] b; long z; long[1] z; FAIL: (bad type/size of operands 'movq') byte[8] z; char[8] z; dchar[2] z; float[2] z; int[2] z; short[4] z; wchar[4] z; XPASS: (too small, but accecpted by DMD) cfloat[0] z; double[0] z; long[0] z; */ void test28() { // version (Windows) // { cfloat[4] z = void; static const ubyte[8] A = [3, 4, 9, 0, 1, 3, 7, 2]; ubyte[8] b; asm{ movq MM0, z; movq MM0, A; movq b, MM0; } for(size_t i = 0; i < A.length; i++) { if(A[i] != b[i]) { assert(0); } } // } } /****************************************************/ /+ shared int[5] bar29 = [3, 4, 5, 6, 7]; void test29() { int* x; asm { push offsetof bar29; pop EAX; mov x, EAX; } assert(*x == 3); asm { mov EAX, offsetof bar29; mov x, EAX; } assert(*x == 3); } +/ /****************************************************/ const int CONST_OFFSET30 = 10; void foo30() { asm { mov EDX, 10; mov EAX, [RDX + CONST_OFFSET30]; } } void test30() { } /****************************************************/ void test31() { ubyte *p; static ubyte data[] = [ 0xF7, 0xD8, // neg EAX 0x74, 0x04, // je L8 0xF7, 0xD8, // neg EAX 0x75, 0xFC, // jne L4 0xFF, 0xC0, // inc EAX ]; int i; asm { call L1 ; neg EAX; je L2; L3: neg EAX; jne L3; L2: inc EAX; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void infiniteAsmLoops() { /* This crashes DMD 0.162: */ for (;;) asm { inc EAX; } /* It doesn't seem to matter what you use. These all crash: */ //for (;;) asm { mov EAX, EBX; } //for (;;) asm { xor EAX, EAX; } //for (;;) asm { push 0; pop RAX; } //for (;;) asm { jmp infiniteAsmLoops; } /* This is a workaround: */ for (bool a = true; a;) asm { hlt; } // compiles /* But this isn't: */ //for (const bool a = true; a;) asm{ hlt; } // crashes DMD /* It's not restricted to for-statements: */ //while(1) asm { hlt; } // crashes DMD /* This compiles: */ { bool a = true; while(a) asm { hlt; } } /* But again, this doesn't: */ /* { const bool a = true; // note the const while(a) asm { hlt; } } //*/ //do { asm { hlt; } } while (1); // crashes DMD /* This, of course, compiles: */ { bool a = true; do asm { hlt; } while (a); } /* But predicably, this doesn't: */ /* { const bool a = true; do asm { hlt; } while (a); } //**/ /* Not even hand-coding the loop works: */ /* { label: asm { hlt; } // commenting out this line to make it compile goto label; } //*/ /* Unless you go all the way: (i.e. this compiles) */ asm { L1: hlt; jmp L1; } /* or like this (also compiles): */ static void test() { asm { naked; hlt; jmp test; } } test(); /* Wait... it gets weirder: */ /* This also doesn't compile: */ /* for (;;) { printf("\n"); asm { hlt; } } //*/ /* But this does: */ //* for (;;) { asm { hlt; } printf("\n"); } //*/ /* The same loop that doesn't compile above * /does/ compile after previous one: */ //* for (;;) { printf("\n"); asm { hlt; } } //*/ /* Note: this one is at the end because it seems to also trigger the * "now it works" event of the loop above. */ /* There has to be /something/ in that asm block: */ for (;;) asm {} // compiles } void test32() { } /****************************************************/ void test33() { int x = 1; alias x y; asm { mov EAX, x; mov EAX, y; } } /****************************************************/ int test34() { asm{ jmp label; } return 0; label: return 1; } /****************************************************/ /+ void foo35() { printf("hello\n"); } void test35() { void function() p; ulong q; asm { mov ECX, foo35 ; mov q, ECX ; lea EDX, foo35 ; mov p, EDX ; } assert(p == &foo35); assert(q == *cast(ulong *)p); } /****************************************************/ void func36() { } int test36() { void* a = &func36; ulong* b = cast(ulong*) a; ulong f = *b; ulong g; asm{ mov RAX, func36; mov g, RAX; } if(f != g){ assert(0); } } +/ /****************************************************/ void a37(X...)(X expr) { alias expr[0] var1; asm { fld double ptr expr[0]; fstp double ptr var1; } } void test37() { a37(3.6); } /****************************************************/ int f38(X...)(X x) { asm { mov EAX, int ptr x[1]; } } int g38(X...)(X x) { asm { mov EAX, x[1]; } } void test38() { assert(456 == f38(123, 456)); assert(456 == g38(123, 456)); } /****************************************************/ void test39() { const byte z = 35; goto end; asm { db z; } end: ; } /****************************************************/ void test40() { printf(""); const string s = "abcdefghi"; asm { jmp L1; ds s; L1:; } end: ; } /****************************************************/ void test41() { ubyte *p; static ubyte data[] = [ 0x66,0x0F,0x28,0x0C,0x06, // movapd XMM1,[RAX][RSI] 0x66,0x0F,0x28,0x0C,0x06, // movapd XMM1,[RAX][RSI] 0x66,0x0F,0x28,0x0C,0x46, // movapd XMM1,[RAX*2][RSI] 0x66,0x0F,0x28,0x0C,0x86, // movapd XMM1,[RAX*4][RSI] 0x66,0x0F,0x28,0x0C,0xC6, // movapd XMM1,[RAX*8][RSI] ]; int i; asm { call L1 ; movapd XMM1, [RSI+RAX]; movapd XMM1, [RSI+1*RAX]; movapd XMM1, [RSI+2*RAX]; movapd XMM1, [RSI+4*RAX]; movapd XMM1, [RSI+8*RAX]; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ enum { enumeration42 = 1, } void test42() { asm { mov EAX, enumeration42; } } /****************************************************/ void foo43() { asm {lea EAX, [0*4+EAX]; } asm {lea EAX, [4*0+EAX]; } asm {lea EAX, [EAX+4*0]; } asm {lea EAX, [0+EAX]; } asm {lea EAX, [7*7+EAX]; } } void test43() { } /****************************************************/ enum n1 = 42; enum { n2 = 42 } uint retN1() { asm { mov EAX,n1; // No! - mov EAX,-4[EBP] } } uint retN2() { asm { mov EAX,n2; // OK - mov EAX,02Ah } } void test44() { assert(retN1() == 42); assert(retN2() == 42); } /****************************************************/ void test45() { ubyte *p; static ubyte data[] = [ 0xDA, 0xC0, // fcmovb ST(0) 0xDA, 0xC1, // fcmovb 0xDA, 0xCA, // fcmove ST(2) 0xDA, 0xD3, // fcmovbe ST(3) 0xDA, 0xDC, // fcmovu ST(4) 0xDB, 0xC5, // fcmovnb ST(5) 0xDB, 0xCE, // fcmovne ST(6) 0xDB, 0xD7, // fcmovnbe ST(7) 0xDB, 0xD9, // fcmovnu ]; int i; asm { call L1 ; fcmovb ST, ST(0); fcmovb ST, ST(1); fcmove ST, ST(2); fcmovbe ST, ST(3); fcmovu ST, ST(4); fcmovnb ST, ST(5); fcmovne ST, ST(6); fcmovnbe ST, ST(7); fcmovnu ST, ST(1); L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test46() { ubyte *p; static ubyte data[] = [ 0x66, 0x0F, 0x3A, 0x41, 0xCA, 0x08, // dppd XMM1,XMM2,8 0x66, 0x0F, 0x3A, 0x40, 0xDC, 0x07, // dpps XMM3,XMM4,7 0x66, 0x0F, 0x50, 0xF3, // movmskpd ESI,XMM3 0x66, 0x0F, 0x50, 0xC7, // movmskpd EAX,XMM7 0x0F, 0x50, 0xC7, // movmskps EAX,XMM7 0x0F, 0xD7, 0xC7, // pmovmskb EAX,MM7 0x66, 0x0F, 0xD7, 0xC7, // pmovmskb EAX,XMM7 ]; int i; asm { call L1 ; dppd XMM1,XMM2,8 ; dpps XMM3,XMM4,7 ; movmskpd ESI,XMM3 ; movmskpd EAX,XMM7 ; movmskps EAX,XMM7 ; pmovmskb EAX,MM7 ; pmovmskb EAX,XMM7 ; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ /+ struct Foo47 { float x,y; } void bar47(Foo47 f) { int i; asm { mov EAX, offsetof f; mov i, EAX; } printf("%d\n",i); assert(i == 8); } void test47() { Foo47 f; bar47(f); } +/ /****************************************************/ void func48(void delegate () callback) { callback(); } void test48() { func48(() { asm{ mov EAX,EAX; }; }); } /****************************************************/ void test49() { ubyte *p; static ubyte data[] = [ 0x00, 0xC0, // add AL,AL 0x00, 0xD8, // add AL,BL 0x00, 0xC8, // add AL,CL 0x00, 0xD0, // add AL,DL 0x00, 0xE0, // add AL,AH 0x00, 0xF8, // add AL,BH 0x00, 0xE8, // add AL,CH 0x00, 0xF0, // add AL,DH 0x00, 0xC4, // add AH,AL 0x00, 0xDC, // add AH,BL 0x00, 0xCC, // add AH,CL 0x00, 0xD4, // add AH,DL 0x00, 0xE4, // add AH,AH 0x00, 0xFC, // add AH,BH 0x00, 0xEC, // add AH,CH 0x00, 0xF4, // add AH,DH 0x00, 0xC3, // add BL,AL 0x00, 0xDB, // add BL,BL 0x00, 0xCB, // add BL,CL 0x00, 0xD3, // add BL,DL 0x00, 0xE3, // add BL,AH 0x00, 0xFB, // add BL,BH 0x00, 0xEB, // add BL,CH 0x00, 0xF3, // add BL,DH 0x00, 0xC7, // add BH,AL 0x00, 0xDF, // add BH,BL 0x00, 0xCF, // add BH,CL 0x00, 0xD7, // add BH,DL 0x00, 0xE7, // add BH,AH 0x00, 0xFF, // add BH,BH 0x00, 0xEF, // add BH,CH 0x00, 0xF7, // add BH,DH 0x00, 0xC1, // add CL,AL 0x00, 0xD9, // add CL,BL 0x00, 0xC9, // add CL,CL 0x00, 0xD1, // add CL,DL 0x00, 0xE1, // add CL,AH 0x00, 0xF9, // add CL,BH 0x00, 0xE9, // add CL,CH 0x00, 0xF1, // add CL,DH 0x00, 0xC5, // add CH,AL 0x00, 0xDD, // add CH,BL 0x00, 0xCD, // add CH,CL 0x00, 0xD5, // add CH,DL 0x00, 0xE5, // add CH,AH 0x00, 0xFD, // add CH,BH 0x00, 0xED, // add CH,CH 0x00, 0xF5, // add CH,DH 0x00, 0xC2, // add DL,AL 0x00, 0xDA, // add DL,BL 0x00, 0xCA, // add DL,CL 0x00, 0xD2, // add DL,DL 0x00, 0xE2, // add DL,AH 0x00, 0xFA, // add DL,BH 0x00, 0xEA, // add DL,CH 0x00, 0xF2, // add DL,DH 0x00, 0xC6, // add DH,AL 0x00, 0xDE, // add DH,BL 0x00, 0xCE, // add DH,CL 0x00, 0xD6, // add DH,DL 0x00, 0xE6, // add DH,AH 0x00, 0xFE, // add DH,BH 0x00, 0xEE, // add DH,CH 0x00, 0xF6, // add DH,DH 0x66, 0x01, 0xC0, // add AX,AX 0x66, 0x01, 0xD8, // add AX,BX 0x66, 0x01, 0xC8, // add AX,CX 0x66, 0x01, 0xD0, // add AX,DX 0x66, 0x01, 0xF0, // add AX,SI 0x66, 0x01, 0xF8, // add AX,DI 0x66, 0x01, 0xE8, // add AX,BP 0x66, 0x01, 0xE0, // add AX,SP 0x66, 0x01, 0xC3, // add BX,AX 0x66, 0x01, 0xDB, // add BX,BX 0x66, 0x01, 0xCB, // add BX,CX 0x66, 0x01, 0xD3, // add BX,DX 0x66, 0x01, 0xF3, // add BX,SI 0x66, 0x01, 0xFB, // add BX,DI 0x66, 0x01, 0xEB, // add BX,BP 0x66, 0x01, 0xE3, // add BX,SP 0x66, 0x01, 0xC1, // add CX,AX 0x66, 0x01, 0xD9, // add CX,BX 0x66, 0x01, 0xC9, // add CX,CX 0x66, 0x01, 0xD1, // add CX,DX 0x66, 0x01, 0xF1, // add CX,SI 0x66, 0x01, 0xF9, // add CX,DI 0x66, 0x01, 0xE9, // add CX,BP 0x66, 0x01, 0xE1, // add CX,SP 0x66, 0x01, 0xC2, // add DX,AX 0x66, 0x01, 0xDA, // add DX,BX 0x66, 0x01, 0xCA, // add DX,CX 0x66, 0x01, 0xD2, // add DX,DX 0x66, 0x01, 0xF2, // add DX,SI 0x66, 0x01, 0xFA, // add DX,DI 0x66, 0x01, 0xEA, // add DX,BP 0x66, 0x01, 0xE2, // add DX,SP 0x66, 0x01, 0xC6, // add SI,AX 0x66, 0x01, 0xDE, // add SI,BX 0x66, 0x01, 0xCE, // add SI,CX 0x66, 0x01, 0xD6, // add SI,DX 0x66, 0x01, 0xF6, // add SI,SI 0x66, 0x01, 0xFE, // add SI,DI 0x66, 0x01, 0xEE, // add SI,BP 0x66, 0x01, 0xE6, // add SI,SP 0x66, 0x01, 0xC7, // add DI,AX 0x66, 0x01, 0xDF, // add DI,BX 0x66, 0x01, 0xCF, // add DI,CX 0x66, 0x01, 0xD7, // add DI,DX 0x66, 0x01, 0xF7, // add DI,SI 0x66, 0x01, 0xFF, // add DI,DI 0x66, 0x01, 0xEF, // add DI,BP 0x66, 0x01, 0xE7, // add DI,SP 0x66, 0x01, 0xC5, // add BP,AX 0x66, 0x01, 0xDD, // add BP,BX 0x66, 0x01, 0xCD, // add BP,CX 0x66, 0x01, 0xD5, // add BP,DX 0x66, 0x01, 0xF5, // add BP,SI 0x66, 0x01, 0xFD, // add BP,DI 0x66, 0x01, 0xED, // add BP,BP 0x66, 0x01, 0xE5, // add BP,SP 0x66, 0x01, 0xC4, // add SP,AX 0x66, 0x01, 0xDC, // add SP,BX 0x66, 0x01, 0xCC, // add SP,CX 0x66, 0x01, 0xD4, // add SP,DX 0x66, 0x01, 0xF4, // add SP,SI 0x66, 0x01, 0xFC, // add SP,DI 0x66, 0x01, 0xEC, // add SP,BP 0x66, 0x01, 0xE4, // add SP,SP 0x01, 0xC0, // add EAX,EAX 0x01, 0xD8, // add EAX,EBX 0x01, 0xC8, // add EAX,ECX 0x01, 0xD0, // add EAX,EDX 0x01, 0xF0, // add EAX,ESI 0x01, 0xF8, // add EAX,EDI 0x01, 0xE8, // add EAX,EBP 0x01, 0xE0, // add EAX,ESP 0x01, 0xC3, // add EBX,EAX 0x01, 0xDB, // add EBX,EBX 0x01, 0xCB, // add EBX,ECX 0x01, 0xD3, // add EBX,EDX 0x01, 0xF3, // add EBX,ESI 0x01, 0xFB, // add EBX,EDI 0x01, 0xEB, // add EBX,EBP 0x01, 0xE3, // add EBX,ESP 0x01, 0xC1, // add ECX,EAX 0x01, 0xD9, // add ECX,EBX 0x01, 0xC9, // add ECX,ECX 0x01, 0xD1, // add ECX,EDX 0x01, 0xF1, // add ECX,ESI 0x01, 0xF9, // add ECX,EDI 0x01, 0xE9, // add ECX,EBP 0x01, 0xE1, // add ECX,ESP 0x01, 0xC2, // add EDX,EAX 0x01, 0xDA, // add EDX,EBX 0x01, 0xCA, // add EDX,ECX 0x01, 0xD2, // add EDX,EDX 0x01, 0xF2, // add EDX,ESI 0x01, 0xFA, // add EDX,EDI 0x01, 0xEA, // add EDX,EBP 0x01, 0xE2, // add EDX,ESP 0x01, 0xC6, // add ESI,EAX 0x01, 0xDE, // add ESI,EBX 0x01, 0xCE, // add ESI,ECX 0x01, 0xD6, // add ESI,EDX 0x01, 0xF6, // add ESI,ESI 0x01, 0xFE, // add ESI,EDI 0x01, 0xEE, // add ESI,EBP 0x01, 0xE6, // add ESI,ESP 0x01, 0xC7, // add EDI,EAX 0x01, 0xDF, // add EDI,EBX 0x01, 0xCF, // add EDI,ECX 0x01, 0xD7, // add EDI,EDX 0x01, 0xF7, // add EDI,ESI 0x01, 0xFF, // add EDI,EDI 0x01, 0xEF, // add EDI,EBP 0x01, 0xE7, // add EDI,ESP 0x01, 0xC5, // add EBP,EAX 0x01, 0xDD, // add EBP,EBX 0x01, 0xCD, // add EBP,ECX 0x01, 0xD5, // add EBP,EDX 0x01, 0xF5, // add EBP,ESI 0x01, 0xFD, // add EBP,EDI 0x01, 0xED, // add EBP,EBP 0x01, 0xE5, // add EBP,ESP 0x01, 0xC4, // add ESP,EAX 0x01, 0xDC, // add ESP,EBX 0x01, 0xCC, // add ESP,ECX 0x01, 0xD4, // add ESP,EDX 0x01, 0xF4, // add ESP,ESI 0x01, 0xFC, // add ESP,EDI 0x01, 0xEC, // add ESP,EBP 0x01, 0xE4, // add ESP,ESP ]; int i; asm { call L1 ; add AL,AL ; add AL,BL ; add AL,CL ; add AL,DL ; add AL,AH ; add AL,BH ; add AL,CH ; add AL,DH ; add AH,AL ; add AH,BL ; add AH,CL ; add AH,DL ; add AH,AH ; add AH,BH ; add AH,CH ; add AH,DH ; add BL,AL ; add BL,BL ; add BL,CL ; add BL,DL ; add BL,AH ; add BL,BH ; add BL,CH ; add BL,DH ; add BH,AL ; add BH,BL ; add BH,CL ; add BH,DL ; add BH,AH ; add BH,BH ; add BH,CH ; add BH,DH ; add CL,AL ; add CL,BL ; add CL,CL ; add CL,DL ; add CL,AH ; add CL,BH ; add CL,CH ; add CL,DH ; add CH,AL ; add CH,BL ; add CH,CL ; add CH,DL ; add CH,AH ; add CH,BH ; add CH,CH ; add CH,DH ; add DL,AL ; add DL,BL ; add DL,CL ; add DL,DL ; add DL,AH ; add DL,BH ; add DL,CH ; add DL,DH ; add DH,AL ; add DH,BL ; add DH,CL ; add DH,DL ; add DH,AH ; add DH,BH ; add DH,CH ; add DH,DH ; add AX,AX ; add AX,BX ; add AX,CX ; add AX,DX ; add AX,SI ; add AX,DI ; add AX,BP ; add AX,SP ; add BX,AX ; add BX,BX ; add BX,CX ; add BX,DX ; add BX,SI ; add BX,DI ; add BX,BP ; add BX,SP ; add CX,AX ; add CX,BX ; add CX,CX ; add CX,DX ; add CX,SI ; add CX,DI ; add CX,BP ; add CX,SP ; add DX,AX ; add DX,BX ; add DX,CX ; add DX,DX ; add DX,SI ; add DX,DI ; add DX,BP ; add DX,SP ; add SI,AX ; add SI,BX ; add SI,CX ; add SI,DX ; add SI,SI ; add SI,DI ; add SI,BP ; add SI,SP ; add DI,AX ; add DI,BX ; add DI,CX ; add DI,DX ; add DI,SI ; add DI,DI ; add DI,BP ; add DI,SP ; add BP,AX ; add BP,BX ; add BP,CX ; add BP,DX ; add BP,SI ; add BP,DI ; add BP,BP ; add BP,SP ; add SP,AX ; add SP,BX ; add SP,CX ; add SP,DX ; add SP,SI ; add SP,DI ; add SP,BP ; add SP,SP ; add EAX,EAX ; add EAX,EBX ; add EAX,ECX ; add EAX,EDX ; add EAX,ESI ; add EAX,EDI ; add EAX,EBP ; add EAX,ESP ; add EBX,EAX ; add EBX,EBX ; add EBX,ECX ; add EBX,EDX ; add EBX,ESI ; add EBX,EDI ; add EBX,EBP ; add EBX,ESP ; add ECX,EAX ; add ECX,EBX ; add ECX,ECX ; add ECX,EDX ; add ECX,ESI ; add ECX,EDI ; add ECX,EBP ; add ECX,ESP ; add EDX,EAX ; add EDX,EBX ; add EDX,ECX ; add EDX,EDX ; add EDX,ESI ; add EDX,EDI ; add EDX,EBP ; add EDX,ESP ; add ESI,EAX ; add ESI,EBX ; add ESI,ECX ; add ESI,EDX ; add ESI,ESI ; add ESI,EDI ; add ESI,EBP ; add ESI,ESP ; add EDI,EAX ; add EDI,EBX ; add EDI,ECX ; add EDI,EDX ; add EDI,ESI ; add EDI,EDI ; add EDI,EBP ; add EDI,ESP ; add EBP,EAX ; add EBP,EBX ; add EBP,ECX ; add EBP,EDX ; add EBP,ESI ; add EBP,EDI ; add EBP,EBP ; add EBP,ESP ; add ESP,EAX ; add ESP,EBX ; add ESP,ECX ; add ESP,EDX ; add ESP,ESI ; add ESP,EDI ; add ESP,EBP ; add ESP,ESP ; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test50() { ubyte *p; static ubyte data[] = [ 0x66, 0x98, // cbw 0xF8, // clc 0xFC, // cld 0xFA, // cli 0xF5, // cmc 0xA6, // cmpsb 0x66, 0xA7, // cmpsw 0xA7, // cmpsd 0x66, 0x99, // cwd // 0x27, // daa // 0x2F, // das 0xFF, 0xC8, // dec EAX 0xF6, 0xF1, // div CL 0x66, 0xF7, 0xF3, // div BX 0xF7, 0xF2, // div EDX 0xF4, // hlt 0xF6, 0xFB, // idiv BL 0x66, 0xF7, 0xFA, // idiv DX 0xF7, 0xFE, // idiv ESI 0xF6, 0xEB, // imul BL 0x66, 0xF7, 0xEA, // imul DX 0xF7, 0xEE, // imul ESI 0xEC, // in AL,DX 0x66, 0xED, // in AX,DX 0xFF, 0xC3, // inc EBX 0xCC, // int 3 0xCD, 0x67, // int 067h // 0xCE, // into 0x66, 0xCF, // iret 0x77, 0xFC, // ja L30 0x77, 0xFA, // ja L30 0x73, 0xF8, // jae L30 0x73, 0xF6, // jae L30 0x73, 0xF4, // jae L30 0x72, 0xF2, // jb L30 0x72, 0xF0, // jb L30 0x76, 0xEE, // jbe L30 0x76, 0xEC, // jbe L30 0x72, 0xEA, // jb L30 // 0x67, 0xE3, 0xE7, // jcxz L30 0x90, 0x90, 0x90, // nop;nop;nop 0x74, 0xE5, // je L30 0x74, 0xE3, // je L30 0x7F, 0xE1, // jg L30 0x7F, 0xDF, // jg L30 0x7D, 0xDD, // jge L30 0x7D, 0xDB, // jge L30 0x7C, 0xD9, // jl L30 0x7C, 0xD7, // jl L30 0x7E, 0xD5, // jle L30 0x7E, 0xD3, // jle L30 0xEB, 0xD1, // jmp short L30 0x75, 0xCF, // jne L30 0x75, 0xCD, // jne L30 0x71, 0xCB, // jno L30 0x79, 0xC9, // jns L30 0x7B, 0xC7, // jnp L30 0x7B, 0xC5, // jnp L30 0x70, 0xC3, // jo L30 0x7A, 0xC1, // jp L30 0x7A, 0xBF, // jp L30 0x78, 0xBD, // js L30 0x9F, // lahf // 0xC5, 0x30, // lds ESI,[EAX] 0x90, 0x90, // nop;nop 0x8B, 0xFB, // mov EDI,EBX // 0xC4, 0x29, // les EBP,[ECX] 0x90, 0x90, // nop;nop 0xF0, // lock 0xAC, // lodsb 0x66, 0xAD, // lodsw 0xAD, // lodsd 0xE2, 0xAF, // loop L30 0xE1, 0xAD, // loope L30 0xE1, 0xAB, // loope L30 0xE0, 0xA9, // loopne L30 0xE0, 0xA7, // loopne L30 0xA4, // movsb 0x66, 0xA5, // movsw 0xA5, // movsd 0xF6, 0xE4, // mul AH 0x66, 0xF7, 0xE1, // mul CX 0xF7, 0xE5, // mul EBP 0x90, // nop 0xF7, 0xD7, // not EDI 0x66, 0xE7, 0x44, // out 044h,AX 0xEE, // out DX,AL 0x66, 0x9D, // popf 0x66, 0x9C, // pushf 0xD1, 0xDB, // rcr EBX,1 0xF3, // rep 0xF3, // rep 0xF2, // repne 0xF3, // rep 0xF2, // repne 0xC3, // ret 0xC2, 0x04, 0x00, // ret 4 0xD1, 0xC1, // rol ECX,1 0xD1, 0xCA, // ror EDX,1 0x9E, // sahf 0xD1, 0xE5, // shl EBP,1 0xD1, 0xE4, // shl ESP,1 0xD1, 0xFF, // sar EDI,1 0xAE, // scasb 0x66, 0xAF, // scasw 0xAF, // scasd 0xD1, 0xEE, // shr ESI,1 0xFD, // std 0xF9, // stc 0xFB, // sti 0xAA, // stosb 0x66, 0xAB, // stosw 0xAB, // stosd 0x9B, // wait 0x91, // xchg EAX,ECX 0xD7, // xlat ]; int i; asm { call L1 ; cbw ; clc ; cld ; cli ; cmc ; cmpsb ; cmpsw ; cmpsd ; cwd ; //daa ; //das ; dec EAX ; div CL ; div BX ; div EDX ; hlt ; idiv BL ; idiv DX ; idiv ESI ; imul BL ; imul DX ; imul ESI ; in AL,DX ; in AX,DX ; inc EBX ; int 3 ; int 0x67 ; //into ; L10: iret ; ja L10 ; jnbe L10 ; jae L10 ; jnb L10 ; jnc L10 ; jb L10 ; jnae L10 ; jbe L10 ; jna L10 ; jc L10 ; nop;nop;nop; // jcxz L10; je L10 ; jz L10 ; jg L10 ; jnle L10 ; jge L10 ; jnl L10 ; jl L10 ; jnge L10 ; jle L10 ; jng L10 ; jmp short L10 ; jne L10 ; jnz L10 ; jno L10 ; jns L10 ; jnp L10 ; jpo L10 ; jo L10 ; jp L10 ; jpe L10 ; js L10 ; lahf ; nop;nop; //lds ESI,[EAX]; lea EDI,[EBX]; nop;nop; //les EBP,[ECX]; lock ; lodsb ; lodsw ; lodsd ; loop L10 ; loope L10 ; loopz L10 ; loopnz L10 ; loopne L10 ; movsb ; movsw ; movsd ; mul AH ; mul CX ; mul EBP ; nop ; not EDI ; out 0x44,AX ; out DX,AL ; popf ; pushf ; rcr EBX,1 ; rep ; repe ; repne ; repz ; repnz ; ret ; ret 4 ; rol ECX,1 ; ror EDX,1 ; sahf ; sal EBP,1 ; shl ESP,1 ; sar EDI,1 ; scasb ; scasw ; scasd ; shr ESI,1 ; std ; stc ; sti ; stosb ; stosw ; stosd ; wait ; xchg EAX,ECX ; xlat ; L1: ; pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ class Test51 { void test(int n) { asm { mov RAX, this; } } } /****************************************************/ void test52() { int x; ubyte* p; static ubyte data[] = [ 0xF6, 0xD8, // neg AL 0x66, 0xF7, 0xD8, // neg AX 0xF7, 0xD8, // neg EAX 0x48, 0xF7, 0xD8, // neg RAX 0xF6, 0xDC, // neg AH 0x41, 0xF6, 0xDC, // neg R12B 0x66, 0x41, 0xF7, 0xDC, // neg 12D 0x41, 0xF7, 0xDC, // neg R12D 0x49, 0xF7, 0xDB, // neg R11 // 0xF6, 0x1D, 0x00, 0x00, 0x00, 0x00, // neg byte ptr _D6iasm641bg@PC32[RIP] //0x66, 0xF7, 0x1D, 0x00, 0x00, 0x00, 0x00, // neg word ptr _D6iasm641ws@PC32[RIP] // 0xF7, 0x1D, 0x00, 0x00, 0x00, 0x00, // neg dword ptr _D6iasm641ii@PC32[RIP] // 0x48, 0xF7, 0x1D, 0x00, 0x00, 0x00, 0x00, // neg qword ptr _D6iasm641ll@PC32[RIP] 0xF7, 0x5D, 0xD0, // neg dword ptr -8[RBP] 0xF6, 0x1B, // neg byte ptr [RBX] 0xF6, 0x1B, // neg byte ptr [RBX] 0x49, 0xF7, 0xD8, // neg R8 ]; asm { call L1 ; neg AL ; neg AX ; neg EAX ; neg RAX ; neg AH ; neg R12B ; neg R12W ; neg R12D ; neg R11 ; // neg b ; // neg w ; // neg i ; // neg l ; neg x ; neg [EBX] ; neg [RBX] ; neg R8 ; L1: pop RAX ; mov p[RBP],RAX ; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ void test53() { int x; ubyte* p; static ubyte data[] = [ 0x48, 0x8D, 0x04, 0x00, // lea RAX,[RAX][RAX] 0x48, 0x8D, 0x04, 0x08, // lea RAX,[RCX][RAX] 0x48, 0x8D, 0x04, 0x10, // lea RAX,[RDX][RAX] 0x48, 0x8D, 0x04, 0x18, // lea RAX,[RBX][RAX] 0x48, 0x8D, 0x04, 0x28, // lea RAX,[RBP][RAX] 0x48, 0x8D, 0x04, 0x30, // lea RAX,[RSI][RAX] 0x48, 0x8D, 0x04, 0x38, // lea RAX,[RDI][RAX] 0x4A, 0x8D, 0x04, 0x00, // lea RAX,[R8][RAX] 0x4A, 0x8D, 0x04, 0x08, // lea RAX,[R9][RAX] 0x4A, 0x8D, 0x04, 0x10, // lea RAX,[R10][RAX] 0x4A, 0x8D, 0x04, 0x18, // lea RAX,[R11][RAX] 0x4A, 0x8D, 0x04, 0x20, // lea RAX,[R12][RAX] 0x4A, 0x8D, 0x04, 0x28, // lea RAX,[R13][RAX] 0x4A, 0x8D, 0x04, 0x30, // lea RAX,[R14][RAX] 0x4A, 0x8D, 0x04, 0x38, // lea RAX,[R15][RAX] 0x48, 0x8D, 0x04, 0x00, // lea RAX,[RAX][RAX] 0x48, 0x8D, 0x04, 0x01, // lea RAX,[RAX][RCX] 0x48, 0x8D, 0x04, 0x02, // lea RAX,[RAX][RDX] 0x48, 0x8D, 0x04, 0x03, // lea RAX,[RAX][RBX] 0x48, 0x8D, 0x04, 0x04, // lea RAX,[RAX][RSP] 0x48, 0x8D, 0x44, 0x05, 0x00, // lea RAX,0[RAX][RBP] 0x48, 0x8D, 0x04, 0x06, // lea RAX,[RAX][RSI] 0x48, 0x8D, 0x04, 0x07, // lea RAX,[RAX][RDI] 0x49, 0x8D, 0x04, 0x00, // lea RAX,[RAX][R8] 0x49, 0x8D, 0x04, 0x01, // lea RAX,[RAX][R9] 0x49, 0x8D, 0x04, 0x02, // lea RAX,[RAX][R10] 0x49, 0x8D, 0x04, 0x03, // lea RAX,[RAX][R11] 0x49, 0x8D, 0x04, 0x04, // lea RAX,[RAX][R12] 0x49, 0x8D, 0x44, 0x05, 0x00, // lea RAX,0[RAX][R13] 0x49, 0x8D, 0x04, 0x06, // lea RAX,[RAX][R14] 0x49, 0x8D, 0x04, 0x07, // lea RAX,[RAX][R15] 0x4B, 0x8D, 0x04, 0x24, // lea RAX,[R12][R12] 0x4B, 0x8D, 0x44, 0x25, 0x00, // lea RAX,0[R12][R13] 0x4B, 0x8D, 0x04, 0x26, // lea RAX,[R12][R14] 0x4B, 0x8D, 0x04, 0x2C, // lea RAX,[R13][R12] 0x4B, 0x8D, 0x44, 0x2D, 0x00, // lea RAX,0[R13][R13] 0x4B, 0x8D, 0x04, 0x2E, // lea RAX,[R13][R14] 0x4B, 0x8D, 0x04, 0x34, // lea RAX,[R14][R12] 0x4B, 0x8D, 0x44, 0x35, 0x00, // lea RAX,0[R14][R13] 0x4B, 0x8D, 0x04, 0x36, // lea RAX,[R14][R14] 0x48, 0x8D, 0x44, 0x01, 0x12, // lea RAX,012h[RAX][RCX] 0x48, 0x8D, 0x84, 0x01, 0x34, 0x12, 0x00, 0x00, // lea RAX,01234h[RAX][RCX] 0x48, 0x8D, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, // lea RAX,012345678h[RAX][RCX] 0x48, 0x8D, 0x44, 0x05, 0x12, // lea RAX,012h[RAX][RBP] 0x48, 0x8D, 0x84, 0x05, 0x34, 0x12, 0x00, 0x00, // lea RAX,01234h[RAX][RBP] 0x48, 0x8D, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, // lea RAX,012345678h[RAX][RBP] 0x49, 0x8D, 0x44, 0x05, 0x12, // lea RAX,012h[RAX][R13] 0x49, 0x8D, 0x84, 0x05, 0x34, 0x12, 0x00, 0x00, // lea RAX,01234h[RAX][R13] 0x49, 0x8D, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, // lea RAX,012345678h[RAX][R13] 0x48, 0x8D, 0x04, 0x24, // lea RAX,[RSP] 0x49, 0x8D, 0x04, 0x24, // lea RAX,[R12] ]; asm { call L1 ; // Right lea RAX, [RAX+RAX]; lea RAX, [RAX+RCX]; lea RAX, [RAX+RDX]; lea RAX, [RAX+RBX]; //lea RAX, [RAX+RSP]; RSP can't be on the right lea RAX, [RAX+RBP]; lea RAX, [RAX+RSI]; lea RAX, [RAX+RDI]; lea RAX, [RAX+R8]; lea RAX, [RAX+R9]; lea RAX, [RAX+R10]; lea RAX, [RAX+R11]; lea RAX, [RAX+R12]; lea RAX, [RAX+R13]; lea RAX, [RAX+R14]; lea RAX, [RAX+R15]; // Left lea RAX, [RAX+RAX]; lea RAX, [RCX+RAX]; lea RAX, [RDX+RAX]; lea RAX, [RBX+RAX]; lea RAX, [RSP+RAX]; lea RAX, [RBP+RAX]; // Good gets disp+8 correctly lea RAX, [RSI+RAX]; lea RAX, [RDI+RAX]; lea RAX, [R8+RAX]; lea RAX, [R9+RAX]; lea RAX, [R10+RAX]; lea RAX, [R11+RAX]; lea RAX, [R12+RAX]; lea RAX, [R13+RAX]; // Good disp+8 lea RAX, [R14+RAX]; lea RAX, [R15+RAX]; // Right and Left lea RAX, [R12+R12]; lea RAX, [R13+R12]; lea RAX, [R14+R12]; lea RAX, [R12+R13]; lea RAX, [R13+R13]; lea RAX, [R14+R13]; lea RAX, [R12+R14]; lea RAX, [R13+R14]; lea RAX, [R14+R14]; // Disp8/32 checks lea RAX, [RCX+RAX+0x12]; lea RAX, [RCX+RAX+0x1234]; lea RAX, [RCX+RAX+0x1234_5678]; lea RAX, [RBP+RAX+0x12]; lea RAX, [RBP+RAX+0x1234]; lea RAX, [RBP+RAX+0x1234_5678]; lea RAX, [R13+RAX+0x12]; lea RAX, [R13+RAX+0x1234]; lea RAX, [R13+RAX+0x1234_5678]; lea RAX, [RSP]; lea RAX, [R12]; L1: pop RAX ; mov p[RBP],RAX ; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ void test54() { int x; ubyte* p; static ubyte data[] = [ 0xFE, 0xC8, // dec AL 0xFE, 0xCC, // dec AH 0x66, 0xFF, 0xC8, // dec AX 0xFF, 0xC8, // dec EAX 0x48, 0xFF, 0xC8, // dec RAX 0x49, 0xFF, 0xCA, // dec R10 0xFE, 0xC0, // inc AL 0xFE, 0xC4, // inc AH 0x66, 0xFF, 0xC0, // inc AX 0xFF, 0xC0, // inc EAX 0x48, 0xFF, 0xC0, // inc RAX 0x49, 0xFF, 0xC2, // inc R10 0x66, 0x44, 0x0F, 0xA4, 0xC0, 0x04, // shld AX, R8W, 4 0x66, 0x44, 0x0F, 0xA5, 0xC0, // shld AX, R8W, CL 0x44, 0x0F, 0xA4, 0xC0, 0x04, // shld EAX, R8D, 4 0x44, 0x0F, 0xA5, 0xC0, // shld EAX, R8D, CL 0x4C, 0x0F, 0xA4, 0xC0, 0x04, // shld RAX, R8 , 4 0x4C, 0x0F, 0xA5, 0xC0, // shld RAX, R8 , CL 0x66, 0x44, 0x0F, 0xAC, 0xC0, 0x04, // shrd AX, R8W, 4 0x66, 0x44, 0x0F, 0xAD, 0xC0, // shrd AX, R8W, CL 0x44, 0x0F, 0xAC, 0xC0, 0x04, // shrd EAX, R8D, 4 0x44, 0x0F, 0xAD, 0xC0, // shrd EAX, R8D, CL 0x4C, 0x0F, 0xAC, 0xC0, 0x04, // shrd RAX, R8 , 4 0x4C, 0x0F, 0xAD, 0xC0 // shrd RAX, R8 , CL ]; asm { call L1; dec AL; dec AH; dec AX; dec EAX; dec RAX; dec R10; inc AL; inc AH; inc AX; inc EAX; inc RAX; inc R10; shld AX, R8W, 4; shld AX, R8W, CL; shld EAX, R8D, 4; shld EAX, R8D, CL; shld RAX, R8 , 4; shld RAX, R8 , CL; shrd AX, R8W, 4; shrd AX, R8W, CL; shrd EAX, R8D, 4; shrd EAX, R8D, CL; shrd RAX, R8 , 4; shrd RAX, R8 , CL; L1: pop RAX; mov p[RBP],RAX; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ void test55() { int x; ubyte* p; enum NOP = 0x9090_9090_9090_9090; static ubyte data[] = [ 0x0F, 0x87, 0xFF, 0xFF, 0, 0, // ja $ + 0xFFFF 0x72, 0x18, // jb Lb 0x0F, 0x82, 0x92, 0x00, 0, 0, // jc Lc 0x0F, 0x84, 0x0C, 0x01, 0, 0, // je Le 0xEB, 0x0A, // jmp Lb 0xE9, 0x85, 0x00, 0x00, 0, // jmp Lc 0xE9, 0x00, 0x01, 0x00, 0, // jmp Le ]; asm { call L1; ja $+0x0_FFFF; jb Lb; jc Lc; je Le; jmp Lb; jmp Lc; jmp Le; Lb: dq NOP,NOP,NOP,NOP; // 32 dq NOP,NOP,NOP,NOP; // 64 dq NOP,NOP,NOP,NOP; // 96 dq NOP,NOP,NOP,NOP; // 128 Lc: dq NOP,NOP,NOP,NOP; // 160 dq NOP,NOP,NOP,NOP; // 192 dq NOP,NOP,NOP,NOP; // 224 dq NOP,NOP,NOP,NOP; // 256 Le: nop; L1: pop RAX; mov p[RBP],RAX; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ void test56() { int x; x = foo56(); assert(x == 42); } int foo56() { asm { naked; xor EAX,EAX; jz bar56; ret; } } void bar56() { asm { naked; mov EAX, 42; ret; } } /****************************************************/ /* ======================= SSSE3 ======================= */ void test57() { ubyte* p; M64 m64; M128 m128; static ubyte data[] = [ 0x0F, 0x3A, 0x0F, 0xCA, 0x03, // palignr MM1, MM2, 3 0x66, 0x0F, 0x3A, 0x0F, 0xCA, 0x03, // palignr XMM1, XMM2, 3 0x0F, 0x3A, 0x0F, 0x5D, 0xC8, 0x03, // palignr MM3, -0x38[RBP], 3 0x66, 0x0F, 0x3A, 0x0F, 0x5D, 0xD0, 0x03, // palignr XMM3, -0x30[RBP], 3 0x0F, 0x38, 0x02, 0xCA, // phaddd MM1, MM2 0x66, 0x0F, 0x38, 0x02, 0xCA, // phaddd XMM1, XMM2 0x0F, 0x38, 0x02, 0x5D, 0xC8, // phaddd MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x02, 0x5D, 0xD0, // phaddd XMM3, -0x30[RBP] 0x0F, 0x38, 0x01, 0xCA, // phaddw MM1, MM2 0x66, 0x0F, 0x38, 0x01, 0xCA, // phaddw XMM1, XMM2 0x0F, 0x38, 0x01, 0x5D, 0xC8, // phaddw MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x01, 0x5D, 0xD0, // phaddw XMM3, -0x30[RBP] 0x0F, 0x38, 0x03, 0xCA, // phaddsw MM1, MM2 0x66, 0x0F, 0x38, 0x03, 0xCA, // phaddsw XMM1, XMM2 0x0F, 0x38, 0x03, 0x5D, 0xC8, // phaddsw MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x03, 0x5D, 0xD0, // phaddsw XMM3, -0x30[RBP] 0x0F, 0x38, 0x06, 0xCA, // phsubd MM1, MM2 0x66, 0x0F, 0x38, 0x06, 0xCA, // phsubd XMM1, XMM2 0x0F, 0x38, 0x06, 0x5D, 0xC8, // phsubd MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x06, 0x5D, 0xD0, // phsubd XMM3, -0x30[RBP] 0x0F, 0x38, 0x05, 0xCA, // phsubw MM1, MM2 0x66, 0x0F, 0x38, 0x05, 0xCA, // phsubw XMM1, XMM2 0x0F, 0x38, 0x05, 0x5D, 0xC8, // phsubw MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x05, 0x5D, 0xD0, // phsubw XMM3, -0x30[RBP] 0x0F, 0x38, 0x07, 0xCA, // phsubsw MM1, MM2 0x66, 0x0F, 0x38, 0x07, 0xCA, // phsubsw XMM1, XMM2 0x0F, 0x38, 0x07, 0x5D, 0xC8, // phsubsw MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x07, 0x5D, 0xD0, // phsubsw XMM3, -0x30[RBP] 0x0F, 0x38, 0x04, 0xCA, // pmaddubsw MM1, MM2 0x66, 0x0F, 0x38, 0x04, 0xCA, // pmaddubsw XMM1, XMM2 0x0F, 0x38, 0x04, 0x5D, 0xC8, // pmaddubsw MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x04, 0x5D, 0xD0, // pmaddubsw XMM3, -0x30[RBP] 0x0F, 0x38, 0x0B, 0xCA, // pmulhrsw MM1, MM2 0x66, 0x0F, 0x38, 0x0B, 0xCA, // pmulhrsw XMM1, XMM2 0x0F, 0x38, 0x0B, 0x5D, 0xC8, // pmulhrsw MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x0B, 0x5D, 0xD0, // pmulhrsw XMM3, -0x30[RBP] 0x0F, 0x38, 0x00, 0xCA, // pshufb MM1, MM2 0x66, 0x0F, 0x38, 0x00, 0xCA, // pshufb XMM1, XMM2 0x0F, 0x38, 0x00, 0x5D, 0xC8, // pshufb MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x00, 0x5D, 0xD0, // pshufb XMM3, -0x30[RBP] 0x0F, 0x38, 0x1C, 0xCA, // pabsb MM1, MM2 0x66, 0x0F, 0x38, 0x1C, 0xCA, // pabsb XMM1, XMM2 0x0F, 0x38, 0x1C, 0x5D, 0xC8, // pabsb MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x1C, 0x5D, 0xD0, // pabsb XMM3, -0x30[RBP] 0x0F, 0x38, 0x1E, 0xCA, // pabsd MM1, MM2 0x66, 0x0F, 0x38, 0x1E, 0xCA, // pabsd XMM1, XMM2 0x0F, 0x38, 0x1E, 0x5D, 0xC8, // pabsd MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x1E, 0x5D, 0xD0, // pabsd XMM3, -0x30[RBP] 0x0F, 0x38, 0x1D, 0xCA, // pabsw MM1, MM2 0x66, 0x0F, 0x38, 0x1D, 0xCA, // pabsw XMM1, XMM2 0x0F, 0x38, 0x1D, 0x5D, 0xC8, // pabsw MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x1D, 0x5D, 0xD0, // pabsw XMM3, -0x30[RBP] 0x0F, 0x38, 0x08, 0xCA, // psignb MM1, MM2 0x66, 0x0F, 0x38, 0x08, 0xCA, // psignb XMM1, XMM2 0x0F, 0x38, 0x08, 0x5D, 0xC8, // psignb MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x08, 0x5D, 0xD0, // psignb XMM3, -0x30[RBP] 0x0F, 0x38, 0x0A, 0xCA, // psignd MM1, MM2 0x66, 0x0F, 0x38, 0x0A, 0xCA, // psignd XMM1, XMM2 0x0F, 0x38, 0x0A, 0x5D, 0xC8, // psignd MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x0A, 0x5D, 0xD0, // psignd XMM3, -0x30[RBP] 0x0F, 0x38, 0x09, 0xCA, // psignw MM1, MM2 0x66, 0x0F, 0x38, 0x09, 0xCA, // psignw XMM1, XMM2 0x0F, 0x38, 0x09, 0x5D, 0xC8, // psignw MM3, -0x38[RBP] 0x66, 0x0F, 0x38, 0x09, 0x5D, 0xD0, // psignw XMM3, -0x30[RBP] ]; asm { call L1; palignr MM1, MM2, 3; palignr XMM1, XMM2, 3; palignr MM3, m64 , 3; palignr XMM3, m128, 3; phaddd MM1, MM2; phaddd XMM1, XMM2; phaddd MM3, m64; phaddd XMM3, m128; phaddw MM1, MM2; phaddw XMM1, XMM2; phaddw MM3, m64; phaddw XMM3, m128; phaddsw MM1, MM2; phaddsw XMM1, XMM2; phaddsw MM3, m64; phaddsw XMM3, m128; phsubd MM1, MM2; phsubd XMM1, XMM2; phsubd MM3, m64; phsubd XMM3, m128; phsubw MM1, MM2; phsubw XMM1, XMM2; phsubw MM3, m64; phsubw XMM3, m128; phsubsw MM1, MM2; phsubsw XMM1, XMM2; phsubsw MM3, m64; phsubsw XMM3, m128; pmaddubsw MM1, MM2; pmaddubsw XMM1, XMM2; pmaddubsw MM3, m64; pmaddubsw XMM3, m128; pmulhrsw MM1, MM2; pmulhrsw XMM1, XMM2; pmulhrsw MM3, m64; pmulhrsw XMM3, m128; pshufb MM1, MM2; pshufb XMM1, XMM2; pshufb MM3, m64; pshufb XMM3, m128; pabsb MM1, MM2; pabsb XMM1, XMM2; pabsb MM3, m64; pabsb XMM3, m128; pabsd MM1, MM2; pabsd XMM1, XMM2; pabsd MM3, m64; pabsd XMM3, m128; pabsw MM1, MM2; pabsw XMM1, XMM2; pabsw MM3, m64; pabsw XMM3, m128; psignb MM1, MM2; psignb XMM1, XMM2; psignb MM3, m64; psignb XMM3, m128; psignd MM1, MM2; psignd XMM1, XMM2; psignd MM3, m64; psignd XMM3, m128; psignw MM1, MM2; psignw XMM1, XMM2; psignw MM3, m64; psignw XMM3, m128; L1: pop RAX; mov p[RBP],RAX; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ /* ======================= SSE4.1 ======================= */ void test58() { ubyte* p; byte m8; short m16; int m32; M64 m64; M128 m128; static ubyte data[] = [ 0x66, 0x0F, 0x3A, 0x0D, 0xCA, 3,// blendpd XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x0D, 0x5D, 0xD0, 3,// blendpd XMM3,XMMWORD PTR [RBP-0x30],0x3 0x66, 0x0F, 0x3A, 0x0C, 0xCA, 3,// blendps XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x0C, 0x5D, 0xD0, 3,// blendps XMM3,XMMWORD PTR [RBP-0x30],0x3 0x66, 0x0F, 0x38, 0x15, 0xCA, // blendvpd XMM1,XMM2,XMM0 0x66, 0x0F, 0x38, 0x15, 0x5D, 0xD0, // blendvpd XMM3,XMMWORD PTR [RBP-0x30],XMM0 0x66, 0x0F, 0x38, 0x14, 0xCA, // blendvps XMM1,XMM2,XMM0 0x66, 0x0F, 0x38, 0x14, 0x5D, 0xD0, // blendvps XMM3,XMMWORD PTR [RBP-0x30],XMM0 0x66, 0x0F, 0x3A, 0x41, 0xCA, 3,// dppd XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x41, 0x5D, 0xD0, 3,// dppd XMM3,XMMWORD PTR [RBP-0x30],0x3 0x66, 0x0F, 0x3A, 0x40, 0xCA, 3,// dpps XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x40, 0x5D, 0xD0, 3,// dpps XMM3,XMMWORD PTR [RBP-0x30],0x3 0x66, 0x0F, 0x3A, 0x17, 0xD2, 3,// extractps EDX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x17, 0x55, 0xBC, 3,// extractps DWORD PTR [RBP-0x44],XMM2,0x3 0x66, 0x0F, 0x3A, 0x21, 0xCA, 3,// insertps XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x21, 0x5D, 0xBC, 3,// insertps XMM3,DWORD PTR [RBP-0x44],0x3 0x66, 0x0F, 0x38, 0x2A, 0x4D, 0xD0, // movntdqa XMM1,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x3A, 0x42, 0xCA, 3,// mpsadbw XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x42, 0x5D, 0xD0, 3,// mpsadbw XMM3,XMMWORD PTR [RBP-0x30],0x3 0x66, 0x0F, 0x38, 0x2B, 0xCA, // packusdw XMM1,XMM2 0x66, 0x0F, 0x38, 0x2B, 0x5D, 0xD0, // packusdw XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x10, 0xCA, // pblendvb XMM1,XMM2,XMM0 0x66, 0x0F, 0x38, 0x10, 0x5D, 0xD0, // pblendvb XMM3,XMMWORD PTR [RBP-0x30],XMM0 0x66, 0x0F, 0x3A, 0x0E, 0xCA, 3,// pblendw XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x0E, 0x5D, 0xD0, 3,// pblendw XMM3,XMMWORD PTR [RBP-0x30],0x3 0x66, 0x0F, 0x38, 0x29, 0xCA, // pcmpeqq XMM1,XMM2 0x66, 0x0F, 0x38, 0x29, 0x5D, 0xD0, // pcmpeqq XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x3A, 0x14, 0xD0, 3,// pextrb EAX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x14, 0xD3, 3,// pextrb EBX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x14, 0xD1, 3,// pextrb ECX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x14, 0xD2, 3,// pextrb EDX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x14, 0xD0, 3,// pextrb EAX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x14, 0xD3, 3,// pextrb EBX,XMM2,0x3 0x66, 0x41, 0x0F, 0x3A, 0x14, 0xD0, 3,// pextrb R8D,XMM2,0x3 0x66, 0x41, 0x0F, 0x3A, 0x14, 0xD2, 3,// pextrb R10D,XMM2,0x3 0x66, 0x0F, 0x3A, 0x14, 0x5D, 0xB8, 3,// pextrb BYTE PTR [RBP-0x48],XMM3,0x3 0x66, 0x0F, 0x3A, 0x16, 0xD0, 3,// pextrd EAX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x16, 0xD3, 3,// pextrd EBX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x16, 0xD1, 3,// pextrd ECX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x16, 0xD2, 3,// pextrd EDX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x16, 0x5D, 0xBC, 3,// pextrd DWORD PTR [RBP-0x44],XMM3,0x3 0x66, 0x48, 0x0F, 0x3A, 0x16, 0xD0, 3,// pextrq RAX,XMM2,0x3 0x66, 0x48, 0x0F, 0x3A, 0x16, 0xD3, 3,// pextrq RBX,XMM2,0x3 0x66, 0x48, 0x0F, 0x3A, 0x16, 0xD1, 3,// pextrq RCX,XMM2,0x3 0x66, 0x48, 0x0F, 0x3A, 0x16, 0xD2, 3,// pextrq RDX,XMM2,0x3 0x66, 0x48, 0x0F, 0x3A, 0x16, 0x5D, 0xC0, 3,// pextrq QWORD PTR [RBP-0x40],XMM3,0x3 0x66, 0x0F, 0xC5, 0xC2, 3,// pextrw EAX,XMM2,0x3 0x66, 0x0F, 0xC5, 0xDA, 3,// pextrw EBX,XMM2,0x3 0x66, 0x0F, 0xC5, 0xCA, 3,// pextrw ECX,XMM2,0x3 0x66, 0x0F, 0xC5, 0xD2, 3,// pextrw EDX,XMM2,0x3 0x66, 0x0F, 0xC5, 0xC2, 3,// pextrw EAX,XMM2,0x3 0x66, 0x0F, 0xC5, 0xDA, 3,// pextrw EBX,XMM2,0x3 0x66, 0x44, 0x0F, 0xC5, 0xC2, 3,// pextrw R8D,XMM2,0x3 0x66, 0x44, 0x0F, 0xC5, 0xD2, 3,// pextrw R10D,XMM2,0x3 0x66, 0x0F, 0x3A, 0x15, 0x5D, 0xBA, 3,// pextrw WORD PTR [RBP-0x46],XMM3,0x3 0x66, 0x0F, 0x38, 0x41, 0xCA, // phminposuw XMM1,XMM2 0x66, 0x0F, 0x38, 0x41, 0x5D, 0xD0, // phminposuw XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x3A, 0x20, 0xC8, 3,// pinsrb XMM1,EAX,0x3 0x66, 0x0F, 0x3A, 0x20, 0xCB, 3,// pinsrb XMM1,EBX,0x3 0x66, 0x0F, 0x3A, 0x20, 0xC9, 3,// pinsrb XMM1,ECX,0x3 0x66, 0x0F, 0x3A, 0x20, 0xCA, 3,// pinsrb XMM1,EDX,0x3 0x66, 0x0F, 0x3A, 0x20, 0x5D, 0xB8, 3,// pinsrb XMM3,BYTE PTR [RBP-0x48],0x3 0x66, 0x0F, 0x3A, 0x22, 0xC8, 3,// pinsrd XMM1,EAX,0x3 0x66, 0x0F, 0x3A, 0x22, 0xCB, 3,// pinsrd XMM1,EBX,0x3 0x66, 0x0F, 0x3A, 0x22, 0xC9, 3,// pinsrd XMM1,ECX,0x3 0x66, 0x0F, 0x3A, 0x22, 0xCA, 3,// pinsrd XMM1,EDX,0x3 0x66, 0x0F, 0x3A, 0x22, 0x5D, 0xBC, 3,// pinsrd XMM3,DWORD PTR [RBP-0x44],0x3 0x66, 0x48, 0x0F, 0x3A, 0x22, 0xC8, 3,// pinsrq XMM1,RAX,0x3 0x66, 0x48, 0x0F, 0x3A, 0x22, 0xCB, 3,// pinsrq XMM1,RBX,0x3 0x66, 0x48, 0x0F, 0x3A, 0x22, 0xC9, 3,// pinsrq XMM1,RCX,0x3 0x66, 0x48, 0x0F, 0x3A, 0x22, 0xCA, 3,// pinsrq XMM1,RDX,0x3 0x66, 0x48, 0x0F, 0x3A, 0x22, 0x5D, 0xC0, 3,// pinsrq XMM3,QWORD PTR [RBP-0x40],0x3 0x66, 0x0F, 0x38, 0x3C, 0xCA, // pmaxsb XMM1,XMM2 0x66, 0x0F, 0x38, 0x3C, 0x5D, 0xD0, // pmaxsb XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x3D, 0xCA, // pmaxsd XMM1,XMM2 0x66, 0x0F, 0x38, 0x3D, 0x5D, 0xD0, // pmaxsd XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x3F, 0xCA, // pmaxud XMM1,XMM2 0x66, 0x0F, 0x38, 0x3F, 0x5D, 0xD0, // pmaxud XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x3E, 0xCA, // pmaxuw XMM1,XMM2 0x66, 0x0F, 0x38, 0x3E, 0x5D, 0xD0, // pmaxuw XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x38, 0xCA, // pminsb XMM1,XMM2 0x66, 0x0F, 0x38, 0x38, 0x5D, 0xD0, // pminsb XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x39, 0xCA, // pminsd XMM1,XMM2 0x66, 0x0F, 0x38, 0x39, 0x5D, 0xD0, // pminsd XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x3B, 0xCA, // pminud XMM1,XMM2 0x66, 0x0F, 0x38, 0x3B, 0x5D, 0xD0, // pminud XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x3A, 0xCA, // pminuw XMM1,XMM2 0x66, 0x0F, 0x38, 0x3A, 0x5D, 0xD0, // pminuw XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x20, 0xCA, // pmovsxbw XMM1,XMM2 0x66, 0x0F, 0x38, 0x20, 0x5D, 0xC0, // pmovsxbw XMM3,QWORD PTR [RBP-0x40] 0x66, 0x0F, 0x38, 0x21, 0xCA, // pmovsxbd XMM1,XMM2 0x66, 0x0F, 0x38, 0x21, 0x5D, 0xBC, // pmovsxbd XMM3,DWORD PTR [RBP-0x44] 0x66, 0x0F, 0x38, 0x22, 0xCA, // pmovsxbq XMM1,XMM2 0x66, 0x0F, 0x38, 0x22, 0x5D, 0xBA, // pmovsxbq XMM3,WORD PTR [RBP-0x46] 0x66, 0x0F, 0x38, 0x23, 0xCA, // pmovsxwd XMM1,XMM2 0x66, 0x0F, 0x38, 0x23, 0x5D, 0xC0, // pmovsxwd XMM3,QWORD PTR [RBP-0x40] 0x66, 0x0F, 0x38, 0x24, 0xCA, // pmovsxwq XMM1,XMM2 0x66, 0x0F, 0x38, 0x24, 0x5D, 0xBC, // pmovsxwq XMM3,DWORD PTR [RBP-0x44] 0x66, 0x0F, 0x38, 0x25, 0xCA, // pmovsxdq XMM1,XMM2 0x66, 0x0F, 0x38, 0x25, 0x5D, 0xC0, // pmovsxdq XMM3,QWORD PTR [RBP-0x40] 0x66, 0x0F, 0x38, 0x30, 0xCA, // pmovzxbw XMM1,XMM2 0x66, 0x0F, 0x38, 0x30, 0x5D, 0xC0, // pmovzxbw XMM3,QWORD PTR [RBP-0x40] 0x66, 0x0F, 0x38, 0x31, 0xCA, // pmovzxbd XMM1,XMM2 0x66, 0x0F, 0x38, 0x31, 0x5D, 0xBC, // pmovzxbd XMM3,DWORD PTR [RBP-0x44] 0x66, 0x0F, 0x38, 0x32, 0xCA, // pmovzxbq XMM1,XMM2 0x66, 0x0F, 0x38, 0x32, 0x5D, 0xBA, // pmovzxbq XMM3,WORD PTR [RBP-0x46] 0x66, 0x0F, 0x38, 0x33, 0xCA, // pmovzxwd XMM1,XMM2 0x66, 0x0F, 0x38, 0x33, 0x5D, 0xC0, // pmovzxwd XMM3,QWORD PTR [RBP-0x40] 0x66, 0x0F, 0x38, 0x34, 0xCA, // pmovzxwq XMM1,XMM2 0x66, 0x0F, 0x38, 0x34, 0x5D, 0xBC, // pmovzxwq XMM3,DWORD PTR [RBP-0x44] 0x66, 0x0F, 0x38, 0x35, 0xCA, // pmovzxdq XMM1,XMM2 0x66, 0x0F, 0x38, 0x35, 0x5D, 0xC0, // pmovzxdq XMM3,QWORD PTR [RBP-0x40] 0x66, 0x0F, 0x38, 0x28, 0xCA, // pmuldq XMM1,XMM2 0x66, 0x0F, 0x38, 0x28, 0x5D, 0xD0, // pmuldq XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x40, 0xCA, // pmulld XMM1,XMM2 0x66, 0x0F, 0x38, 0x40, 0x5D, 0xD0, // pmulld XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x17, 0xCA, // ptest XMM1,XMM2 0x66, 0x0F, 0x38, 0x17, 0x5D, 0xD0, // ptest XMM3,XMMWORD PTR [RBP-0x30] 0x66, 0x0F, 0x3A, 0x09, 0xCA, 3,// roundpd XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x09, 0x5D, 0xD0, 3,// roundpd XMM3,XMMWORD PTR [RBP-0x30],0x3 0x66, 0x0F, 0x3A, 0x08, 0xCA, 3,// roundps XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x08, 0x5D, 0xD0, 3,// roundps XMM3,XMMWORD PTR [RBP-0x30],0x3 0x66, 0x0F, 0x3A, 0x0B, 0xCA, 3,// roundsd XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x0B, 0x5D, 0xC0, 3,// roundsd XMM3,QWORD PTR [RBP-0x40],0x3 0x66, 0x0F, 0x3A, 0x0A, 0xCA, 3,// roundss XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x0A, 0x4D, 0xBC, 3,// roundss xmm1,dword ptr [rbp-0x44],0x3 ]; asm { call L1; blendpd XMM1, XMM2, 3; blendpd XMM3, m128, 3; blendps XMM1, XMM2, 3; blendps XMM3, m128, 3; blendvpd XMM1, XMM2, XMM0; blendvpd XMM3, m128, XMM0; blendvps XMM1, XMM2, XMM0; blendvps XMM3, m128, XMM0; dppd XMM1, XMM2, 3; dppd XMM3, m128, 3; dpps XMM1, XMM2, 3; dpps XMM3, m128, 3; extractps EDX, XMM2, 3; extractps m32, XMM2, 3; insertps XMM1, XMM2, 3; insertps XMM3, m32, 3; movntdqa XMM1, m128; mpsadbw XMM1, XMM2, 3; mpsadbw XMM3, m128, 3; packusdw XMM1, XMM2; packusdw XMM3, m128; pblendvb XMM1, XMM2, XMM0; pblendvb XMM3, m128, XMM0; pblendw XMM1, XMM2, 3; pblendw XMM3, m128, 3; pcmpeqq XMM1, XMM2; pcmpeqq XMM3, m128; pextrb EAX, XMM2, 3; pextrb EBX, XMM2, 3; pextrb ECX, XMM2, 3; pextrb EDX, XMM2, 3; pextrb RAX, XMM2, 3; pextrb RBX, XMM2, 3; pextrb R8 , XMM2, 3; pextrb R10, XMM2, 3; pextrb m8, XMM3, 3; pextrd EAX, XMM2, 3; pextrd EBX, XMM2, 3; pextrd ECX, XMM2, 3; pextrd EDX, XMM2, 3; pextrd m32, XMM3, 3; pextrq RAX, XMM2, 3; pextrq RBX, XMM2, 3; pextrq RCX, XMM2, 3; pextrq RDX, XMM2, 3; pextrq m64, XMM3, 3; pextrw EAX, XMM2, 3; pextrw EBX, XMM2, 3; pextrw ECX, XMM2, 3; pextrw EDX, XMM2, 3; pextrw RAX, XMM2, 3; pextrw RBX, XMM2, 3; pextrw R8 , XMM2, 3; pextrw R10, XMM2, 3; pextrw m16, XMM3, 3; phminposuw XMM1, XMM2; phminposuw XMM3, m128; pinsrb XMM1, EAX, 3; pinsrb XMM1, EBX, 3; pinsrb XMM1, ECX, 3; pinsrb XMM1, EDX, 3; pinsrb XMM3, m8, 3; pinsrd XMM1, EAX, 3; pinsrd XMM1, EBX, 3; pinsrd XMM1, ECX, 3; pinsrd XMM1, EDX, 3; pinsrd XMM3, m32, 3; pinsrq XMM1, RAX, 3; pinsrq XMM1, RBX, 3; pinsrq XMM1, RCX, 3; pinsrq XMM1, RDX, 3; pinsrq XMM3, m64, 3; pmaxsb XMM1, XMM2; pmaxsb XMM3, m128; pmaxsd XMM1, XMM2; pmaxsd XMM3, m128; pmaxud XMM1, XMM2; pmaxud XMM3, m128; pmaxuw XMM1, XMM2; pmaxuw XMM3, m128; pminsb XMM1, XMM2; pminsb XMM3, m128; pminsd XMM1, XMM2; pminsd XMM3, m128; pminud XMM1, XMM2; pminud XMM3, m128; pminuw XMM1, XMM2; pminuw XMM3, m128; pmovsxbw XMM1, XMM2; pmovsxbw XMM3, m64; pmovsxbd XMM1, XMM2; pmovsxbd XMM3, m32; pmovsxbq XMM1, XMM2; pmovsxbq XMM3, m16; pmovsxwd XMM1, XMM2; pmovsxwd XMM3, m64; pmovsxwq XMM1, XMM2; pmovsxwq XMM3, m32; pmovsxdq XMM1, XMM2; pmovsxdq XMM3, m64; pmovzxbw XMM1, XMM2; pmovzxbw XMM3, m64; pmovzxbd XMM1, XMM2; pmovzxbd XMM3, m32; pmovzxbq XMM1, XMM2; pmovzxbq XMM3, m16; pmovzxwd XMM1, XMM2; pmovzxwd XMM3, m64; pmovzxwq XMM1, XMM2; pmovzxwq XMM3, m32; pmovzxdq XMM1, XMM2; pmovzxdq XMM3, m64; pmuldq XMM1, XMM2; pmuldq XMM3, m128; pmulld XMM1, XMM2; pmulld XMM3, m128; ptest XMM1, XMM2; ptest XMM3, m128; roundpd XMM1, XMM2, 3; roundpd XMM3, m128, 3; roundps XMM1, XMM2, 3; roundps XMM3, m128, 3; roundsd XMM1, XMM2, 3; roundsd XMM3, m64, 3; roundss XMM1, XMM2, 3; roundss XMM1, m32, 3; L1: pop RAX; mov p[RBP],RAX; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ /* ======================= SSE4.2 ======================= */ void test59() { ubyte* p; byte m8; short m16; int m32; M64 m64; M128 m128; static ubyte data[] = [ 0xF2, 0x0F, 0x38, 0xF0, 0xC1, // crc32 EAX, CL 0x66, 0xF2, 0x0F, 0x38, 0xF1, 0xC1, // crc32 EAX, CX 0xF2, 0x0F, 0x38, 0xF1, 0xC1, // crc32 EAX, ECX 0xF2, 0x48, 0x0F, 0x38, 0xF0, 0xC1, // crc32 RAX, CL 0xF2, 0x48, 0x0F, 0x38, 0xF1, 0xC1, // crc32 RAX, RCX 0xF2, 0x0F, 0x38, 0xF0, 0x55, 0xB8, // crc32 EDX, byte ptr [RBP-0x48] 0x66, 0xF2, 0x0F, 0x38, 0xF1, 0x55, 0xBA, // crc32 EDX, word ptr [RBP-0x46] 0xF2, 0x0F, 0x38, 0xF1, 0x55, 0xBC, // crc32 EDX,dword ptr [RBP-0x44] 0xF2, 0x48, 0x0F, 0x38, 0xF0, 0x55, 0xB8, // crc32 RDX, byte ptr [RBP-0x48] 0xF2, 0x48, 0x0F, 0x38, 0xF1, 0x55, 0xC0, // crc32 RDX,qword ptr [RBP-0x40] 0x66, 0x0F, 0x3A, 0x61, 0xCA, 2, // pcmpestri XMM1,XMM2, 2 0x66, 0x0F, 0x3A, 0x61, 0x5D, 0xD0, 2, // pcmpestri XMM3,xmmword ptr [RBP-0x30], 2 0x66, 0x0F, 0x3A, 0x60, 0xCA, 2, // pcmpestrm XMM1,XMM2, 2 0x66, 0x0F, 0x3A, 0x60, 0x5D, 0xD0, 2, // pcmpestrm XMM3,xmmword ptr [RBP-0x30], 2 0x66, 0x0F, 0x3A, 0x63, 0xCA, 2, // pcmpistri XMM1,XMM2, 2 0x66, 0x0F, 0x3A, 0x63, 0x5D, 0xD0, 2, // pcmpistri XMM3,xmmword ptr [RBP-0x30], 2 0x66, 0x0F, 0x3A, 0x62, 0xCA, 2, // pcmpistrm XMM1,XMM2, 2 0x66, 0x0F, 0x3A, 0x62, 0x5D, 0xD0, 2, // pcmpistrm XMM3,xmmword ptr [RBP-0x30], 2 0x66, 0x0F, 0x38, 0x37, 0xCA, // pcmpgtq XMM1,XMM2 0x66, 0x0F, 0x38, 0x37, 0x5D, 0xD0, // pcmpgtq XMM3,xmmword ptr [RBP-0x30] 0x66, 0xF3, 0x0F, 0xB8, 0xC1, // popcnt AX, CX 0xF3, 0x0F, 0xB8, 0xC1, // popcnt EAX, ECX 0xF3, 0x48, 0x0F, 0xB8, 0xC1, // popcnt RAX, RCX 0x66, 0xF3, 0x0F, 0xB8, 0x55, 0xBA, // popcnt DX, word ptr [RBP-0x46] 0xF3, 0x0F, 0xB8, 0x55, 0xBC, // popcnt EDX,dword ptr [RBP-0x44] 0xF3, 0x48, 0x0F, 0xB8, 0x55, 0xC0 // popcnt RDX,qword ptr [RBP-0x40] ]; asm { call L1; crc32 EAX, CL; crc32 EAX, CX; crc32 EAX, ECX; crc32 RAX, CL; crc32 RAX, RCX; crc32 EDX, m8; crc32 EDX, m16; crc32 EDX, m32; crc32 RDX, m8; crc32 RDX, m64; pcmpestri XMM1, XMM2, 2; pcmpestri XMM3, m128, 2; pcmpestrm XMM1, XMM2, 2; pcmpestrm XMM3, m128, 2; pcmpistri XMM1, XMM2, 2; pcmpistri XMM3, m128, 2; pcmpistrm XMM1, XMM2, 2; pcmpistrm XMM3, m128, 2; pcmpgtq XMM1, XMM2; pcmpgtq XMM3, m128; popcnt AX, CX; popcnt EAX, ECX; popcnt RAX, RCX; popcnt DX, m16; popcnt EDX, m32; popcnt RDX, m64; L1: pop RAX; mov p[RBP],RAX; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } void test60() { ubyte *p; static ubyte data[] = [ 0x49, 0x8B, 0x00, // mov RAX, [R8] 0x4D, 0x8B, 0x00, // mov R8, [R8] 0x49, 0x89, 0x00, // mov [R8], RAX 0x4D, 0x89, 0x00, // mov [R8], R8 0x41, 0x0F, 0x10, 0x00, // movups XMM0, [R8] 0x45, 0x0F, 0x10, 0x00, // movups XMM8, [R8] ]; asm { call L1; mov RAX, [R8]; mov R8, [R8]; mov [R8], RAX; mov [R8], R8; movups XMM0, [R8]; movups XMM8, [R8]; L1: pop RAX; mov p[RBP], RAX; } foreach (ref i, b; data) { assert(p[i] == b); } } /* ======================= AVX ======================= */ void test61() { ubyte* p; static ubyte data[] = [ 0x0F, 0x01, 0xD0, // xgetbv 0x0F, 0x01, 0xD1, // xsetbv 0x0F, 0xAE, 0x28, // xrstor [RAX] 0x48, 0x0F, 0xAE, 0x28, // xrstor64 [RAX] 0x0F, 0xAE, 0x20, // xsave [RAX] 0x48, 0x0F, 0xAE, 0x20, // xsave64 [RAX] 0x0F, 0xAE, 0x30, // xsaveopt [RAX] 0x48, 0x0F, 0xAE, 0x30, // xsaveopt64 [RAX] 0xC5, 0xF8, 0xAE, 0x10, // vldmxcsr [RAX] 0xC5, 0xF8, 0xAE, 0x18, // vstmxcsr [RAX] 0xC5, 0xF2, 0x58, 0xC2, // vaddss XMM0, XMM1, XMM2; 0xC5, 0x83, 0x58, 0x00, // vaddsd XMM0, XMM15, [RAX]; 0xC5, 0x78, 0x58, 0xE0, // vaddps XMM12, XMM0, XMM0; 0xC4, 0x41, 0x39, 0x58, 0xC0, // vaddpd XMM8, XMM8, XMM8; 0xC5, 0xF2, 0x5C, 0xC2, // vsubss XMM0, XMM1, XMM2; 0xC5, 0x83, 0x5C, 0x00, // vsubsd XMM0, XMM1, [RAX]; 0xC5, 0x78, 0x5C, 0xE0, // vsubps XMM12, XMM0, XMM0; 0xC4, 0x41, 0x39, 0x5C, 0xC0, // vsubpd XMM8, XMM8, XMM8; 0xC5, 0xF3, 0xD0, 0xC2, // vaddsubps XMM0, XMM1, XMM2; 0xC5, 0xF7, 0xD0, 0xC2, // vaddsubps YMM0, YMM1, YMM2; 0xC5, 0x75, 0xD0, 0xC2, // vaddsubpd YMM8, YMM1, YMM2; 0xC5, 0x05, 0xD0, 0x78, 0x40, // vaddsubpd YMM15, YMM15, 64[RAX]; 0xC4, 0xE3, 0x7D, 0x40, 0xC0, 0x00, // vdpps YMM0, YMM0, YMM0, 0 0xC4, 0xE3, 0x79, 0x41, 0xC0, 0x88, // vdppd XMM0, XMM0, XMM0, 0x88 0xC5, 0xBD, 0x7C, 0x07, // vhaddpd YMM0, YMM8, [RDI]; 0xC5, 0xBB, 0x7C, 0xC1, // vhaddps XMM0, XMM8, XMM1; 0xC5, 0xFD, 0x5F, 0xC1, // vmaxpd YMM0, YMM0, YMM1; 0xC5, 0xF9, 0x5F, 0x00, // vmaxpd XMM0, XMM0, [RAX]; 0xC5, 0xFC, 0x5F, 0xC1, // vmaxps YMM0, YMM0, YMM1; 0xC5, 0xF8, 0x5F, 0x00, // vmaxps XMM0, XMM0, [RAX]; 0xC5, 0xFB, 0x5F, 0x00, // vmaxsd XMM0, XMM0, [RAX]; 0xC5, 0xFA, 0x5F, 0x00, // vmaxss XMM0, XMM0, [RAX]; 0xC5, 0xFD, 0x5D, 0xC1, // vminpd YMM0, YMM0, YMM1; 0xC5, 0xF9, 0x5D, 0x00, // vminpd XMM0, XMM0, [RAX]; 0xC5, 0xFC, 0x5D, 0xC1, // vminps YMM0, YMM0, YMM1; 0xC5, 0xF8, 0x5D, 0x00, // vminps XMM0, XMM0, [RAX]; 0xC5, 0xFB, 0x5D, 0x00, // vminsd XMM0, XMM0, [RAX]; 0xC5, 0xFA, 0x5D, 0x00, // vminss XMM0, XMM0, [RAX]; 0xC5, 0xF9, 0x50, 0xC0, // vmovmskpd EAX, XMM0; 0xC5, 0xFD, 0x50, 0xF8, // vmovmskpd EDI, YMM0; 0xC4, 0xC1, 0x7C, 0x50, 0xC7, // vmovmskps EAX, YMM15; 0xC5, 0x7C, 0x50, 0xC0, // vmovmskps R8D, YMM0; 0xC5, 0xF9, 0xD7, 0xC0, // vpmovmskb EAX, XMM0; 0xC4, 0xE3, 0x71, 0x42, 0xC2, 0x00, // vmpsadbw XMM0, XMM1, XMM2, 0x00; 0xC4, 0x43, 0x31, 0x42, 0xC2, 0xFF, // vmpsadbw XMM8, XMM9, XMM10, 0xFF; 0xC4, 0xE2, 0x79, 0x1C, 0x00, // vpabsb XMM0, [RAX]; 0xC4, 0xC2, 0x79, 0x1D, 0xCF, // vpabsw XMM1, XMM15; 0xC4, 0xE2, 0x79, 0x1E, 0x0B, // vpabsd XMM1, [RBX]; 0xC5, 0xF9, 0xFC, 0x00, // vpaddb XMM0, XMM0, [RAX]; 0xC4, 0x41, 0x39, 0xFD, 0xC7, // vpaddw XMM8, XMM8, XMM15; 0xC5, 0x39, 0xFE, 0x03, // vpaddd XMM8, XMM8, [RBX]; 0xC5, 0xF9, 0xD4, 0xC0, // vpaddq XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xF8, 0x00, // vpsubb XMM0, XMM0, [RAX]; 0xC4, 0x41, 0x39, 0xF9, 0xC7, // vpsubw XMM8, XMM8, XMM15; 0xC5, 0x39, 0xFA, 0x03, // vpsubd XMM8, XMM8, [RBX]; 0xC5, 0xF9, 0xFB, 0xC0, // vpsubq XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xEC, 0xC0, // vpaddsb XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xED, 0xC0, // vpaddsw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xDC, 0xC0, // vpaddusb XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xDD, 0xC0, // vpaddusw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xE8, 0xC0, // vpsubsb XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xE9, 0xC0, // vpsubsw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xD8, 0xC0, // vpsubusb XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xD9, 0xC0, // vpsubusw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xE0, 0xC0, // vpavgb XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xE3, 0xC0, // vpavgw XMM0, XMM0, XMM0; 0xC4, 0xE3, 0x79, 0x44, 0x44, 0x88, 0x40, 0x00, // vpclmulqdq XMM0, XMM0, 64[RAX + 4 * RCX], 0; 0xC4, 0xE2, 0x79, 0x01, 0xC0, // vphaddw XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x02, 0xC0, // vphaddd XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x05, 0xC0, // vphsubw XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x06, 0xC0, // vphsubd XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x03, 0xC0, // vphaddsw XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x07, 0xC0, // vphsubsw XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x41, 0xC0, // vphminposuw XMM0, XMM0; 0xC5, 0xF9, 0xF5, 0xC0, // vpmaddwd XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x04, 0xC0, // vpmaddubsw XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x3C, 0xC0, // vpmaxsb XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x3D, 0xC0, // vpmaxsd XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xEE, 0xC0, // vpmaxsw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xDE, 0xC0, // vpmaxub XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x3F, 0xC0, // vpmaxud XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x3E, 0xC0, // vpmaxuw XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x38, 0xC0, // vpminsb XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x39, 0xC0, // vpminsd XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xEA, 0xC0, // vpminsw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xDA, 0xC0, // vpminub XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x3B, 0xC0, // vpminud XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x3A, 0xC0, // vpminuw XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x0B, 0xC0, // vpmulhrsw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xE4, 0xC0, // vpmulhuw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xE5, 0xC0, // vpmulhw XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x40, 0xC0, // vpmulld XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xD5, 0xC0, // vpmullw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xF4, 0xC0, // vpmuludq XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x28, 0xC0, // vpmuldq XMM0, XMM0, XMM0; 0xC5, 0xF9, 0xF6, 0xC0, // vpsadbw XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x08, 0xC0, // vpsignb XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x09, 0xC0, // vpsignw XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x0A, 0xC0, // vpsignd XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x73, 0xF8, 0x00, // vpslldq XMM0, XMM0, 0; 0xC5, 0xF9, 0x71, 0xF0, 0x00, // vpsllw XMM0, XMM0, 0; 0xC5, 0xF9, 0xF1, 0xC0, // vpsllw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x72, 0xF0, 0x00, // vpslld XMM0, XMM0, 0; 0xC5, 0xF9, 0xF2, 0xC0, // vpslld XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x73, 0xF0, 0x00, // vpsllq XMM0, XMM0, 0; 0xC5, 0xF9, 0xF3, 0xC0, // vpsllq XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x71, 0xE0, 0x00, // vpsraw XMM0, XMM0, 0; 0xC5, 0xF9, 0xE1, 0xC0, // vpsraw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x72, 0xE0, 0x00, // vpsrad XMM0, XMM0, 0; 0xC5, 0xF9, 0xE2, 0xC0, // vpsrad XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x73, 0xD8, 0x00, // vpsrldq XMM0, XMM0, 0; 0xC5, 0xF9, 0x71, 0xD0, 0x00, // vpsrlw XMM0, XMM0, 0; 0xC5, 0xF9, 0xD1, 0xC0, // vpsrlw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x72, 0xD0, 0x00, // vpsrld XMM0, XMM0, 0; 0xC5, 0xF9, 0xD2, 0xC0, // vpsrld XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x73, 0xD0, 0x00, // vpsrlq XMM0, XMM0, 0; 0xC5, 0xF9, 0xD3, 0xC0, // vpsrlq XMM0, XMM0, XMM0; 0xC5, 0xF8, 0x53, 0xC1, // vrcpps XMM0, XMM1; 0xC5, 0xFC, 0x53, 0xC1, // vrcpps YMM0, YMM1; 0xC5, 0xFA, 0x53, 0xC1, // vrcpss XMM0, XMM0, XMM1; 0xC4, 0xE3, 0x79, 0x09, 0xC0, 0x00, // vroundpd XMM0, XMM0, 0; 0xC4, 0xE3, 0x7D, 0x09, 0xC0, 0x00, // vroundpd YMM0, YMM0, 0; 0xC4, 0xE3, 0x79, 0x08, 0xC0, 0x00, // vroundps XMM0, XMM0, 0; 0xC4, 0xE3, 0x7D, 0x08, 0xC0, 0x00, // vroundps YMM0, YMM0, 0; 0xC4, 0xE3, 0x79, 0x0B, 0xC0, 0x00, // vroundsd XMM0, XMM0, XMM0, 0; 0xC4, 0xE3, 0x79, 0x0A, 0xC0, 0x00, // vroundss XMM0, XMM0, XMM0, 0; 0xC5, 0xF9, 0x51, 0xC0, // vsqrtpd XMM0, XMM0; 0xC5, 0xFD, 0x51, 0xC0, // vsqrtpd YMM0, YMM0; 0xC5, 0xF8, 0x51, 0xC0, // vsqrtps XMM0, XMM0; 0xC5, 0xFC, 0x51, 0xC0, // vsqrtps YMM0, YMM0; 0xC5, 0xFB, 0x51, 0xC0, // vsqrtsd XMM0, XMM0, XMM0; 0xC5, 0xFA, 0x51, 0xC0, // vsqrtss XMM0, XMM0, XMM0; 0xC5, 0xFC, 0x77, // vzeroall 0xC5, 0xF8, 0x77, // vzeroupper 0xC5, 0xF9, 0xC2, 0xC0, 0x00, // vcmppd XMM0, XMM0, XMM0, 0; 0xC5, 0xFD, 0xC2, 0xC0, 0x00, // vcmppd YMM0, YMM0, YMM0, 0; 0xC5, 0xF8, 0xC2, 0xC0, 0x00, // vcmpps XMM0, XMM0, XMM0, 0; 0xC5, 0xFC, 0xC2, 0xC0, 0x00, // vcmpps YMM0, YMM0, YMM0, 0; 0xC5, 0xFB, 0xC2, 0xC0, 0x00, // vcmpsd XMM0, XMM0, XMM0, 0; 0xC5, 0xFA, 0xC2, 0xC0, 0x00, // vcmpss XMM0, XMM0, XMM0, 0; 0xC5, 0xF9, 0x2F, 0xC0, // vcomisd XMM0, XMM0; 0xC5, 0xF8, 0x2F, 0xC0, // vcomiss XMM0, XMM0; 0xC5, 0xF9, 0x74, 0xC0, // vpcmpeqb XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x75, 0xC0, // vpcmpeqw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x76, 0xC0, // vpcmpeqd XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x29, 0xC0, // vpcmpeqq XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x64, 0xC0, // vpcmpgtb XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x65, 0xC0, // vpcmpgtw XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x66, 0xC0, // vpcmpgtd XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x37, 0xC0, // vpcmpgtq XMM0, XMM0, XMM0; 0xC4, 0xE3, 0x79, 0x61, 0xC0, 0x00, // vpcmpestri XMM0, XMM0, 0; 0xC4, 0xE3, 0x79, 0x60, 0xC0, 0x00, // vpcmpestrm XMM0, XMM0, 0; 0xC4, 0xE3, 0x79, 0x63, 0xC0, 0x00, // vpcmpistri XMM0, XMM0, 0; 0xC4, 0xE3, 0x79, 0x62, 0xC0, 0x00, // vpcmpistrm XMM0, XMM0, 0; 0xC5, 0xFA, 0xE6, 0xC0, // vcvtdq2pd XMM0, XMM0; 0xC5, 0xFE, 0xE6, 0xC0, // vcvtdq2pd YMM0, XMM0; 0xC5, 0xFE, 0xE6, 0x00, // vcvtdq2pd YMM0, [RAX]; 0xC5, 0xF8, 0x5B, 0xC0, // vcvtdq2ps XMM0, XMM0; 0xC5, 0xFC, 0x5B, 0xC0, // vcvtdq2ps YMM0, YMM0; 0xC5, 0xFC, 0x5B, 0x00, // vcvtdq2ps YMM0, [RAX]; 0xC5, 0xFB, 0xE6, 0xC0, // vcvtpd2dq XMM0, XMM0; 0xC5, 0xFF, 0xE6, 0xC0, // vcvtpd2dq XMM0, YMM0; 0xC5, 0xFB, 0xE6, 0x00, // vcvtpd2dq XMM0, [RAX]; 0xC5, 0xF9, 0x5A, 0xC0, // vcvtpd2ps XMM0, XMM0; 0xC5, 0xFD, 0x5A, 0xC0, // vcvtpd2ps XMM0, YMM0; 0xC5, 0xF9, 0x5A, 0x00, // vcvtpd2ps XMM0, [RAX]; 0xC5, 0xF9, 0x5B, 0xC0, // vcvtps2dq XMM0, XMM0; 0xC5, 0xFD, 0x5B, 0xC0, // vcvtps2dq YMM0, YMM0; 0xC5, 0xFD, 0x5B, 0x00, // vcvtps2dq YMM0, [RAX]; 0xC5, 0xF8, 0x5A, 0xC0, // vcvtps2pd XMM0, XMM0; 0xC5, 0xFC, 0x5A, 0xC0, // vcvtps2pd YMM0, XMM0; 0xC5, 0xFC, 0x5A, 0x00, // vcvtps2pd YMM0, [RAX]; 0xC5, 0xFB, 0x2D, 0xC0, // vcvtsd2si EAX, XMM0; 0xC4, 0xE1, 0xFB, 0x2D, 0xC0, // vcvtsd2si RAX, XMM0; 0xC4, 0xE1, 0xFB, 0x2D, 0x00, // vcvtsd2si RAX, [RAX]; 0xC5, 0xFB, 0x5A, 0xC0, // vcvtsd2ss XMM0, XMM0, XMM0; 0xC5, 0xFB, 0x5A, 0x00, // vcvtsd2ss XMM0, XMM0, [RAX]; 0xC5, 0xFB, 0x2A, 0xC0, // vcvtsi2sd XMM0, XMM0, EAX; 0xC4, 0xE1, 0xFB, 0x2A, 0xC0, // vcvtsi2sd XMM0, XMM0, RAX; 0xC5, 0xFB, 0x2A, 0x00, // vcvtsi2sd XMM0, XMM0, [RAX]; 0xC5, 0xFA, 0x2A, 0xC0, // vcvtsi2ss XMM0, XMM0, EAX; 0xC4, 0xE1, 0xFA, 0x2A, 0xC0, // vcvtsi2ss XMM0, XMM0, RAX; 0xC5, 0xFA, 0x2A, 0x00, // vcvtsi2ss XMM0, XMM0, [RAX]; 0xC5, 0xFB, 0x2A, 0xC0, // vcvtsi2sd XMM0, XMM0, EAX; 0xC4, 0xE1, 0xFB, 0x2A, 0xC0, // vcvtsi2sd XMM0, XMM0, RAX; 0xC5, 0xFB, 0x2A, 0x00, // vcvtsi2sd XMM0, XMM0, [RAX]; 0xC5, 0xFA, 0x2D, 0xC0, // vcvtss2si EAX, XMM0; 0xC4, 0xE1, 0xFA, 0x2D, 0xC0, // vcvtss2si RAX, XMM0; 0xC4, 0xE1, 0xFA, 0x2D, 0x00, // vcvtss2si RAX, [RAX]; 0xC5, 0xF9, 0xE6, 0xC0, // vcvttpd2dq XMM0, XMM0; 0xC5, 0xFD, 0xE6, 0xC0, // vcvttpd2dq XMM0, YMM0; 0xC5, 0xF9, 0xE6, 0x00, // vcvttpd2dq XMM0, [RAX]; 0xC5, 0xFA, 0x5B, 0xC0, // vcvttps2dq XMM0, XMM0; 0xC5, 0xFE, 0x5B, 0xC0, // vcvttps2dq YMM0, YMM0; 0xC5, 0xFE, 0x5B, 0x00, // vcvttps2dq YMM0, [RAX]; 0xC5, 0xFB, 0x2C, 0xC0, // vcvttsd2si EAX, XMM0; 0xC4, 0xE1, 0xFB, 0x2C, 0xC0, // vcvttsd2si RAX, XMM0; 0xC4, 0xE1, 0xFB, 0x2C, 0x00, // vcvttsd2si RAX, [RAX]; 0xC5, 0xFA, 0x2C, 0xC0, // vcvttss2si EAX, XMM0; 0xC4, 0xE1, 0xFA, 0x2C, 0xC0, // vcvttss2si RAX, XMM0; 0xC4, 0xE1, 0xFA, 0x2C, 0x00, // vcvttss2si RAX, [RAX]; 0xC4, 0xE2, 0x79, 0x18, 0x00, // vbroadcastss XMM0, [RAX]; 0xC4, 0xE2, 0x7D, 0x18, 0x00, // vbroadcastss YMM0, [RAX]; 0xC4, 0xE2, 0x7D, 0x19, 0x00, // vbroadcastsd YMM0, [RAX]; 0xC4, 0xE2, 0x7D, 0x1A, 0x00, // vbroadcastf128 YMM0, [RAX]; 0xC4, 0xE3, 0x7D, 0x19, 0xC0, 0x00, // vextractf128 XMM0, YMM0, 0; 0xC4, 0xE3, 0x7D, 0x19, 0x00, 0x00, // vextractf128 [RAX], YMM0, 0; 0xC4, 0xE3, 0x79, 0x17, 0xC0, 0x00, // vextractps EAX, XMM0, 0; 0xC4, 0xE3, 0x79, 0x17, 0x00, 0x00, // vextractps [RAX], XMM0, 0; 0xC4, 0xE3, 0x7D, 0x18, 0xC0, 0x00, // vinsertf128 YMM0, YMM0, XMM0, 0; 0xC4, 0xE3, 0x7D, 0x18, 0x00, 0x00, // vinsertf128 YMM0, YMM0, [RAX], 0; 0xC4, 0xE3, 0x79, 0x21, 0xC0, 0x00, // vinsertps XMM0, XMM0, XMM0, 0; 0xC4, 0xE3, 0x79, 0x21, 0x00, 0x00, // vinsertps XMM0, XMM0, [RAX], 0; 0xC4, 0xE3, 0x79, 0x20, 0xC0, 0x00, // vpinsrb XMM0, XMM0, EAX, 0; 0xC4, 0xE3, 0x79, 0x20, 0x00, 0x00, // vpinsrb XMM0, XMM0, [RAX], 0; 0xC5, 0xF9, 0xC4, 0xC0, 0x00, // vpinsrw XMM0, XMM0, EAX, 0; 0xC5, 0xF9, 0xC4, 0x00, 0x00, // vpinsrw XMM0, XMM0, [RAX], 0; 0xC4, 0xE3, 0x79, 0x22, 0xC0, 0x00, // vpinsrd XMM0, XMM0, EAX, 0; 0xC4, 0xE3, 0x79, 0x22, 0x00, 0x00, // vpinsrd XMM0, XMM0, [RAX], 0; 0xC4, 0xE3, 0xF9, 0x22, 0xC0, 0x00, // vpinsrq XMM0, XMM0, RAX, 0; 0xC4, 0xE3, 0xF9, 0x22, 0x00, 0x00, // vpinsrq XMM0, XMM0, [RAX], 0; 0xC5, 0xFB, 0xF0, 0x00, // vlddqu XMM0, [RAX]; 0xC5, 0xFF, 0xF0, 0x00, // vlddqu YMM0, [RAX]; 0xC5, 0xF9, 0xF7, 0xC0, // vmaskmovdqu XMM0, XMM0; 0xC4, 0xE2, 0x79, 0x2C, 0x00, // vmaskmovps XMM0, XMM0, [RAX]; 0xC4, 0xE2, 0x79, 0x2E, 0x00, // vmaskmovps [RAX], XMM0, XMM0; 0xC4, 0xE2, 0x7D, 0x2C, 0x00, // vmaskmovps YMM0, YMM0, [RAX]; 0xC4, 0xE2, 0x7D, 0x2E, 0x00, // vmaskmovps [RAX], YMM0, YMM0; 0xC4, 0xE2, 0x79, 0x2D, 0x00, // vmaskmovpd XMM0, XMM0, [RAX]; 0xC4, 0xE2, 0x79, 0x2F, 0x00, // vmaskmovpd [RAX], XMM0, XMM0; 0xC4, 0xE2, 0x7D, 0x2D, 0x00, // vmaskmovpd YMM0, YMM0, [RAX]; 0xC4, 0xE2, 0x7D, 0x2F, 0x00, // vmaskmovpd [RAX], YMM0, YMM0; 0xC5, 0xFD, 0x28, 0x00, // vmovapd YMM0, [RAX]; 0xC5, 0x7D, 0x28, 0x00, // vmovapd YMM8, [RAX]; 0xC5, 0x7D, 0x28, 0x47, 0x40, // vmovapd YMM8, 64[RDI]; 0xC5, 0xFD, 0x29, 0x00, // vmovapd [RAX], YMM0; 0xC5, 0x7D, 0x29, 0x00, // vmovapd [RAX], YMM8; 0xC5, 0x7D, 0x29, 0x47, 0x40, // vmovapd 64[RDI], YMM8; 0xC5, 0xFC, 0x28, 0x00, // vmovaps YMM0, [RAX]; 0xC5, 0x7C, 0x28, 0x00, // vmovaps YMM8, [RAX]; 0xC5, 0x7C, 0x28, 0x47, 0x40, // vmovaps YMM8, 64[RDI]; 0xC5, 0xFC, 0x29, 0x00, // vmovaps [RAX], YMM0; 0xC5, 0x7C, 0x29, 0x00, // vmovaps [RAX], YMM8; 0xC5, 0x7C, 0x29, 0x47, 0x40, // vmovaps 64[RDI], YMM8; 0xC5, 0xFD, 0x10, 0x00, // vmovupd YMM0, [RAX]; 0xC5, 0x7D, 0x10, 0x00, // vmovupd YMM8, [RAX]; 0xC5, 0x7D, 0x10, 0x47, 0x40, // vmovupd YMM8, 64[RDI]; 0xC5, 0xFD, 0x11, 0x00, // vmovupd [RAX], YMM0; 0xC5, 0x7D, 0x11, 0x00, // vmovupd [RAX], YMM8; 0xC5, 0x7D, 0x11, 0x47, 0x40, // vmovupd 64[RDI], YMM8; 0xC5, 0xFC, 0x10, 0x00, // vmovups YMM0, [RAX]; 0xC5, 0x7C, 0x10, 0x00, // vmovups YMM8, [RAX]; 0xC5, 0x7C, 0x10, 0x47, 0x40, // vmovups YMM8, 64[RDI]; 0xC5, 0xFC, 0x11, 0x00, // vmovups [RAX], YMM0; 0xC5, 0x7C, 0x11, 0x00, // vmovups [RAX], YMM8; 0xC5, 0x7C, 0x11, 0x47, 0x40, // vmovups 64[RDI], YMM8; 0xC5, 0xF9, 0x6E, 0xC0, // vmovd XMM0, EAX; 0xC5, 0xF9, 0x6E, 0x00, // vmovd XMM0, [RAX]; 0xC5, 0xF9, 0x7E, 0xC0, // vmovd EAX, XMM0; 0xC5, 0xF9, 0x7E, 0x00, // vmovd [RAX], XMM0; 0xC4, 0xE1, 0xF9, 0x6E, 0xC0, // vmovq XMM0, RAX; 0xC4, 0xE1, 0xF9, 0x6E, 0x00, // vmovq XMM0, [RAX]; 0xC4, 0xE1, 0xF9, 0x7E, 0xC0, // vmovq RAX, XMM0; 0xC4, 0xE1, 0xF9, 0x7E, 0x00, // vmovq [RAX], XMM0; 0xC5, 0xF9, 0x6F, 0xC0, // vmovdqa XMM0, XMM0; 0xC5, 0xF9, 0x6F, 0x00, // vmovdqa XMM0, [RAX]; 0xC5, 0xFD, 0x6F, 0xC0, // vmovdqa YMM0, YMM0; 0xC5, 0xFD, 0x6F, 0x00, // vmovdqa YMM0, [RAX]; 0xC5, 0xF9, 0x6F, 0xC0, // vmovdqa XMM0, XMM0; 0xC5, 0xF9, 0x7F, 0x00, // vmovdqa [RAX], XMM0; 0xC5, 0xFD, 0x6F, 0xC0, // vmovdqa YMM0, YMM0; 0xC5, 0xFD, 0x7F, 0x00, // vmovdqa [RAX],YMM0; 0xC5, 0xFA, 0x6F, 0xC0, // vmovdqu XMM0, XMM0; 0xC5, 0xFA, 0x6F, 0x00, // vmovdqu XMM0, [RAX]; 0xC5, 0xFE, 0x6F, 0xC0, // vmovdqu YMM0, YMM0; 0xC5, 0xFE, 0x6F, 0x00, // vmovdqu YMM0, [RAX]; 0xC5, 0xFA, 0x6F, 0xC0, // vmovdqu XMM0, XMM0; 0xC5, 0xFA, 0x7F, 0x00, // vmovdqu [RAX], XMM0; 0xC5, 0xFE, 0x6F, 0xC0, // vmovdqu YMM0, YMM0; 0xC5, 0xFE, 0x7F, 0x00, // vmovdqu [RAX],YMM0; 0xC5, 0xF8, 0x12, 0xC0, // vmovlhps XMM0, XMM0, XMM0; 0xC5, 0xF8, 0x16, 0xC0, // vmovhlps XMM0, XMM0, XMM0; 0xC5, 0xF9, 0x16, 0x00, // vmovhpd XMM0, XMM0, [RAX]; 0xC5, 0xF9, 0x17, 0x00, // vmovhpd [RAX], XMM0; 0xC5, 0xF8, 0x16, 0x00, // vmovhps XMM0, XMM0, [RAX]; 0xC5, 0xF8, 0x17, 0x00, // vmovhps [RAX], XMM0; 0xC5, 0xF9, 0x12, 0x00, // vmovlpd XMM0, XMM0, [RAX]; 0xC5, 0xF9, 0x13, 0x00, // vmovlpd [RAX], XMM0; 0xC5, 0xF8, 0x12, 0x00, // vmovlps XMM0, XMM0, [RAX]; 0xC5, 0xF8, 0x13, 0x00, // vmovlps [RAX], XMM0; 0xC5, 0xF9, 0xE7, 0x00, // vmovntdq [RAX], XMM0; 0xC5, 0x7D, 0xE7, 0x00, // vmovntdq [RAX], YMM8; 0xC5, 0xF9, 0x2B, 0x00, // vmovntpd [RAX], XMM0; 0xC5, 0x7D, 0x2B, 0x00, // vmovntpd [RAX], YMM8; 0xC5, 0xF8, 0x2B, 0x00, // vmovntps [RAX], XMM0; 0xC5, 0x7C, 0x2B, 0x00, // vmovntps [RAX], YMM8; 0xC4, 0xE2, 0x79, 0x2A, 0x00, // vmovntdqa XMM0, [RAX]; 0xC5, 0xFB, 0x10, 0xC0, // vmovsd XMM0, XMM0, XMM0; 0xC4, 0x41, 0x3B, 0x10, 0xC0, // vmovsd XMM8, XMM8, XMM8; 0xC5, 0xFB, 0x11, 0x00, // vmovsd [RAX], XMM0; 0xC4, 0x41, 0x7B, 0x11, 0x00, // vmovsd [R8], XMM8; 0xC5, 0xFA, 0x10, 0xC0, // vmovss XMM0, XMM0, XMM0; 0xC4, 0x41, 0x3A, 0x10, 0xC0, // vmovss XMM8, XMM8, XMM8; 0xC5, 0xFA, 0x11, 0x00, // vmovss [RAX], XMM0; 0xC4, 0x41, 0x7A, 0x11, 0x00, // vmovss [R8], XMM8; 0xC5, 0x7A, 0x16, 0xC1, // vmovshdup XMM8, XMM1; 0xC4, 0xC1, 0x7E, 0x16, 0xC0, // vmovshdup YMM0, YMM8; 0xC5, 0xFE, 0x16, 0x00, // vmovshdup YMM0, [RAX]; 0xC5, 0x7A, 0x12, 0xC1, // vmovsldup XMM8, XMM1; 0xC4, 0xC1, 0x7E, 0x12, 0xC0, // vmovsldup YMM0, YMM8; 0xC5, 0xFE, 0x12, 0x00, // vmovsldup YMM0, [RAX]; 0xC5, 0xF1, 0x67, 0xC2, // vpackuswb XMM0, XMM1, XMM2; 0xC5, 0xB9, 0x67, 0x00, // vpackuswb XMM0, XMM8, [RAX]; 0xC4, 0xE2, 0x71, 0x2B, 0xC2, // vpackusdw XMM0, XMM1, XMM2; 0xC4, 0xE2, 0x39, 0x2B, 0x00, // vpackusdw XMM0, XMM8, [RAX]; 0xC5, 0xF1, 0x63, 0xC2, // vpacksswb XMM0, XMM1, XMM2; 0xC5, 0xB9, 0x63, 0x00, // vpacksswb XMM0, XMM8, [RAX]; 0xC5, 0xF1, 0x6B, 0xC2, // vpackssdw XMM0, XMM1, XMM2; 0xC5, 0xB9, 0x6B, 0x00, // vpackssdw XMM0, XMM8, [RAX]; 0xC4, 0xE3, 0x71, 0x0F, 0xC2, 0xFF, // vpalignr XMM0, XMM1, XMM2, 0xFF; 0xC4, 0x63, 0x39, 0x0F, 0x08, 0x10, // vpalignr XMM9, XMM8, [RAX], 0x10; 0xC4, 0xE3, 0x79, 0x14, 0xC0, 0x00, // vpextrb EAX, XMM0, 0x0; 0xC4, 0x43, 0x79, 0x14, 0xCA, 0x0F, // vpextrb R10, XMM9, 0xF; 0xC4, 0x43, 0x79, 0x14, 0x0A, 0x0F, // vpextrb [R10], XMM9, 0xF; 0xC4, 0xE3, 0x79, 0x16, 0xC0, 0x00, // vpextrd EAX, XMM0, 0x0; 0xC4, 0x43, 0x79, 0x16, 0xC8, 0x0F, // vpextrd R8D, XMM9, 0xF; 0xC4, 0x43, 0x79, 0x16, 0x0A, 0x0F, // vpextrd [R10], XMM9, 0xF; 0xC4, 0xE3, 0xF9, 0x16, 0xC0, 0x00, // vpextrq RAX, XMM0, 0x0; 0xC4, 0x43, 0xF9, 0x16, 0xCA, 0x0F, // vpextrq R10, XMM9, 0xF; 0xC4, 0x43, 0xF9, 0x16, 0x0A, 0x0F, // vpextrq [R10], XMM9, 0xF; 0xC5, 0xF9, 0xC5, 0xC0, 0x00, // vpextrw EAX, XMM0, 0x0; 0xC4, 0x41, 0x79, 0xC5, 0xD1, 0x0F, // vpextrw R10, XMM9, 0xF; 0xC4, 0x43, 0x79, 0x15, 0x0A, 0x0F, // vpextrw [R10], XMM9, 0xF; 0xC4, 0xE2, 0x79, 0x20, 0xC0, // vpmovsxbw XMM0, XMM0; 0xC4, 0x42, 0x79, 0x20, 0x00, // vpmovsxbw XMM8, [R8]; 0xC4, 0xE2, 0x79, 0x21, 0xC0, // vpmovsxbd XMM0, XMM0; 0xC4, 0x42, 0x79, 0x21, 0x00, // vpmovsxbd XMM8, [R8]; 0xC4, 0xE2, 0x79, 0x22, 0xC0, // vpmovsxbq XMM0, XMM0; 0xC4, 0x42, 0x79, 0x22, 0x00, // vpmovsxbq XMM8, [R8]; 0xC4, 0xE2, 0x79, 0x23, 0xC0, // vpmovsxwd XMM0, XMM0; 0xC4, 0x42, 0x79, 0x23, 0x00, // vpmovsxwd XMM8, [R8]; 0xC4, 0xE2, 0x79, 0x24, 0xC0, // vpmovsxwq XMM0, XMM0; 0xC4, 0x42, 0x79, 0x24, 0x00, // vpmovsxwq XMM8, [R8]; 0xC4, 0xE2, 0x79, 0x25, 0xC0, // vpmovsxdq XMM0, XMM0; 0xC4, 0x42, 0x79, 0x25, 0x00, // vpmovsxdq XMM8, [R8]; 0xC4, 0xE2, 0x79, 0x30, 0xC0, // vpmovzxbw XMM0, XMM0; 0xC4, 0x42, 0x79, 0x30, 0x00, // vpmovzxbw XMM8, [R8]; 0xC4, 0xE2, 0x79, 0x31, 0xC0, // vpmovzxbd XMM0, XMM0; 0xC4, 0x42, 0x79, 0x31, 0x00, // vpmovzxbd XMM8, [R8]; 0xC4, 0xE2, 0x79, 0x32, 0xC0, // vpmovzxbq XMM0, XMM0; 0xC4, 0x42, 0x79, 0x32, 0x00, // vpmovzxbq XMM8, [R8]; 0xC4, 0xE2, 0x79, 0x33, 0xC0, // vpmovzxwd XMM0, XMM0; 0xC4, 0x42, 0x79, 0x33, 0x00, // vpmovzxwd XMM8, [R8]; 0xC4, 0xE2, 0x79, 0x34, 0xC0, // vpmovzxwq XMM0, XMM0; 0xC4, 0x42, 0x79, 0x34, 0x00, // vpmovzxwq XMM8, [R8]; 0xC4, 0xE2, 0x79, 0x35, 0xC0, // vpmovzxdq XMM0, XMM0; 0xC4, 0x42, 0x79, 0x35, 0x00, // vpmovzxdq XMM8, [R8]; 0xC5, 0xF9, 0x54, 0xC0, // vandpd XMM0, XMM0, XMM0; 0xC4, 0x41, 0x39, 0x54, 0x08, // vandpd XMM9, XMM8, [R8]; 0xC5, 0xF8, 0x54, 0xC0, // vandps XMM0, XMM0, XMM0; 0xC4, 0x41, 0x38, 0x54, 0x08, // vandps XMM9, XMM8, [R8]; 0xC5, 0xF9, 0x55, 0xC0, // vandnpd XMM0, XMM0, XMM0; 0xC4, 0x41, 0x39, 0x55, 0x08, // vandnpd XMM9, XMM8, [R8]; 0xC5, 0xF8, 0x55, 0xC0, // vandnps XMM0, XMM0, XMM0; 0xC4, 0x41, 0x38, 0x55, 0x08, // vandnps XMM9, XMM8, [R8]; 0xC5, 0xF9, 0x56, 0xC0, // vorpd XMM0, XMM0, XMM0; 0xC4, 0x41, 0x39, 0x56, 0x08, // vorpd XMM9, XMM8, [R8]; 0xC5, 0xF8, 0x56, 0xC0, // vorps XMM0, XMM0, XMM0; 0xC4, 0x41, 0x38, 0x56, 0x08, // vorps XMM9, XMM8, [R8]; 0xC5, 0xF9, 0xDB, 0xC0, // vpand XMM0, XMM0, XMM0; 0xC4, 0x41, 0x39, 0xDB, 0x08, // vpand XMM9, XMM8, [R8]; 0xC5, 0xF9, 0xDF, 0xC0, // vpandn XMM0, XMM0, XMM0; 0xC4, 0x41, 0x39, 0xDF, 0x08, // vpandn XMM9, XMM8, [R8]; 0xC5, 0xF9, 0xEB, 0xC0, // vpor XMM0, XMM0, XMM0; 0xC4, 0x41, 0x39, 0xEB, 0x0A, // vpor XMM9, XMM8, [R10]; 0xC5, 0xF9, 0xEF, 0xC0, // vpxor XMM0, XMM0, XMM0; 0xC4, 0x41, 0x39, 0xEF, 0x0A, // vpxor XMM9, XMM8, [R10]; 0xC4, 0xE2, 0x79, 0x17, 0xC0, // vptest XMM0, XMM0; 0xC4, 0x62, 0x79, 0x17, 0x00, // vptest XMM8, [RAX]; 0xC4, 0x42, 0x7D, 0x17, 0xC0, // vptest YMM8, YMM8; 0xC4, 0xC2, 0x7D, 0x17, 0x00, // vptest YMM0, [R8]; 0xC5, 0xF9, 0x2E, 0xC0, // vucomisd XMM0, XMM0; 0xC5, 0x79, 0x2E, 0x00, // vucomisd XMM8, [RAX] 0xC5, 0xF8, 0x2E, 0xC0, // vucomiss YMM8, YMM8; 0xC5, 0x78, 0x2E, 0x00, // vucomiss YMM0, [R8]; 0xC5, 0xB9, 0x57, 0xC0, // vxorpd XMM0, XMM8, XMM0; 0xC5, 0x79, 0x57, 0x00, // vxorpd XMM8, XMM0, [RAX]; 0xC5, 0xBD, 0x57, 0xC0, // vxorpd YMM0, YMM8, YMM0; 0xC5, 0x7D, 0x57, 0x00, // vxorpd YMM8, YMM0, [RAX]; 0xC5, 0xB8, 0x57, 0xC0, // vxorps XMM0, XMM8, XMM0; 0xC5, 0x78, 0x57, 0x00, // vxorps XMM8, XMM0, [RAX]; 0xC5, 0xBC, 0x57, 0xC0, // vxorps YMM0, YMM8, YMM0; 0xC5, 0x7C, 0x57, 0x00, // vxorps YMM8, YMM0, [RAX]; 0xC4, 0xE3, 0x71, 0x0D, 0xC2, 0x00, // vblendpd XMM0, XMM1, XMM2, 0x00; 0xC4, 0x63, 0x39, 0x0D, 0x08, 0xFF, // vblendpd XMM9, XMM8, [RAX], 0xFF; 0xC4, 0xE3, 0x75, 0x0D, 0xC2, 0x00, // vblendpd YMM0, YMM1, YMM2, 0x00; 0xC4, 0x63, 0x3D, 0x0D, 0x08, 0xFF, // vblendpd YMM9, YMM8, [RAX], 0xFF; 0xC4, 0xE3, 0x71, 0x0C, 0xC2, 0x00, // vblendps XMM0, XMM1, XMM2, 0x00; 0xC4, 0x63, 0x39, 0x0C, 0x08, 0xFF, // vblendps XMM9, XMM8, [RAX], 0xFF; 0xC4, 0xE3, 0x75, 0x0C, 0xC2, 0x00, // vblendps YMM0, YMM1, YMM2, 0x00; 0xC4, 0x63, 0x3D, 0x0C, 0x08, 0xFF, // vblendps YMM9, YMM8, [RAX], 0xFF; 0xC4, 0xE3, 0x71, 0x4B, 0xC2, 0x00, // vblendvpd XMM0, XMM1, XMM2, 0x00; 0xC4, 0x63, 0x39, 0x4B, 0x08, 0xff, // vblendvpd XMM9, XMM8, [RAX], 0xFF; 0xC4, 0xE3, 0x75, 0x4B, 0xC2, 0x00, // vblendvpd YMM0, YMM1, YMM2, 0x00; 0xC4, 0x63, 0x3D, 0x4B, 0x08, 0xff, // vblendvpd YMM9, YMM8, [RAX], 0xFF; 0xC4, 0xE3, 0x71, 0x4A, 0xC2, 0x00, // vblendvps XMM0, XMM1, XMM2, 0x00; 0xC4, 0x63, 0x39, 0x4A, 0x08, 0xff, // vblendvps XMM9, XMM8, [RAX], 0xFF; 0xC4, 0xE3, 0x75, 0x4A, 0xC2, 0x00, // vblendvps YMM0, YMM1, YMM2, 0x00; 0xC4, 0x63, 0x3D, 0x4A, 0x08, 0xff, // vblendvps YMM9, YMM8, [RAX], 0xFF; 0xC5, 0x7B, 0x12, 0xC0, // vmovddup XMM8, XMM0; 0xC5, 0xFB, 0x12, 0x00, // vmovddup XMM0, [RAX]; 0xC4, 0xC1, 0x7F, 0x12, 0xC0, // vmovddup YMM0, YMM8; 0xC4, 0xC1, 0x7F, 0x12, 0x02, // vmovddup YMM0, [R10]; 0xC4, 0xE3, 0x39, 0x4C, 0xC0, 0x00, // vpblendvb XMM0, XMM8, XMM0, 0x00; 0xC4, 0x63, 0x79, 0x4C, 0x00, 0x00, // vpblendvb XMM8, XMM0, [RAX], 0x00; 0xC4, 0x43, 0x79, 0x4C, 0x02, 0x00, // vpblendvb XMM8, XMM0, [R10], 0x00; 0xC4, 0xE3, 0x39, 0x0E, 0xC0, 0x00, // vpblendw XMM0, XMM8, XMM0, 0x00; 0xC4, 0x63, 0x79, 0x0E, 0x00, 0x00, // vpblendw XMM8, XMM0, [RAX], 0x00; 0xC4, 0x43, 0x79, 0x0E, 0x02, 0x00, // vpblendw XMM8, XMM0, [R10], 0x00; 0xC4, 0xE2, 0x71, 0x0D, 0xC2, // vpermilpd XMM0, XMM1, XMM2; 0xC4, 0xE2, 0x71, 0x0D, 0x00, // vpermilpd XMM0, XMM1, [RAX]; 0xC4, 0xE3, 0x79, 0x05, 0xC1, 0x00, // vpermilpd XMM0, XMM1, 0x00; 0xC4, 0xE3, 0x79, 0x05, 0x00, 0x00, // vpermilpd XMM0, [RAX], 0x00; 0xC4, 0xE2, 0x71, 0x0C, 0xC2, // vpermilps XMM0, XMM1, XMM2; 0xC4, 0xE2, 0x71, 0x0C, 0x00, // vpermilps XMM0, XMM1, [RAX]; 0xC4, 0xE3, 0x79, 0x04, 0xC1, 0x00, // vpermilps XMM0, XMM1, 0x00; 0xC4, 0xE3, 0x79, 0x04, 0x00, 0x00, // vpermilps XMM0, [RAX], 0x00; 0xC4, 0xE3, 0x75, 0x06, 0xC2, 0x00, // vperm2f128 YMM0, YMM1, YMM2, 0x00; 0xC4, 0xE3, 0x75, 0x06, 0x00, 0x00, // vperm2f128 YMM0, YMM1, [RAX], 0x00; 0xC4, 0x43, 0x35, 0x06, 0x02, 0x00, // vperm2f128 YMM8, YMM9, [R10], 0x00; 0xC4, 0xE2, 0x79, 0x00, 0xC0, // vpshufb XMM0, XMM0, XMM0; 0xC4, 0x42, 0x39, 0x00, 0x08, // vpshufb XMM9, XMM8, [R8]; 0xC5, 0xF9, 0x70, 0xC0, 0x00, // vpshufd XMM0, XMM0, 0x0; 0xC4, 0x41, 0x79, 0x70, 0x00, 0x00, // vpshufd XMM8, [R8], 0x0; 0xC5, 0xFA, 0x70, 0xC0, 0x00, // vpshufhw XMM0, XMM0, 0x0; 0xC4, 0x41, 0x7A, 0x70, 0x00, 0x00, // vpshufhw XMM8, [R8], 0x0; 0xC5, 0xFB, 0x70, 0xC0, 0x00, // vpshuflw XMM0, XMM0, 0x0; 0xC4, 0x41, 0x7B, 0x70, 0x00, 0x00, // vpshuflw XMM8, [R8], 0x0; 0xC5, 0xF1, 0x68, 0xC2, // vpunpckhbw XMM0, XMM1, XMM2; 0xC4, 0x41, 0x39, 0x68, 0x00, // vpunpckhbw XMM8, XMM8, [R8]; 0xC5, 0xF1, 0x69, 0xC2, // vpunpckhwd XMM0, XMM1, XMM2; 0xC4, 0x41, 0x39, 0x69, 0x00, // vpunpckhwd XMM8, XMM8, [R8]; 0xC5, 0xF1, 0x6A, 0xC2, // vpunpckhdq XMM0, XMM1, XMM2; 0xC4, 0x41, 0x39, 0x6A, 0x00, // vpunpckhdq XMM8, XMM8, [R8]; 0xC5, 0xF1, 0x6D, 0xC2, // vpunpckhqdq XMM0, XMM1, XMM2; 0xC4, 0x41, 0x39, 0x6D, 0x00, // vpunpckhqdq XMM8, XMM8, [R8]; 0xC5, 0xF1, 0x60, 0xC2, // vpunpcklbw XMM0, XMM1, XMM2; 0xC4, 0x41, 0x39, 0x60, 0x00, // vpunpcklbw XMM8, XMM8, [R8]; 0xC5, 0xF1, 0x61, 0xC2, // vpunpcklwd XMM0, XMM1, XMM2; 0xC4, 0x41, 0x39, 0x61, 0x00, // vpunpcklwd XMM8, XMM8, [R8]; 0xC5, 0xF1, 0x62, 0xC2, // vpunpckldq XMM0, XMM1, XMM2; 0xC4, 0x41, 0x39, 0x62, 0x00, // vpunpckldq XMM8, XMM8, [R8]; 0xC5, 0xF1, 0x6C, 0xC2, // vpunpcklqdq XMM0, XMM1, XMM2; 0xC4, 0x41, 0x39, 0x6C, 0x00, // vpunpcklqdq XMM8, XMM8, [R8]; 0xC5, 0xF9, 0xC6, 0xC0, 0x00, // vshufpd XMM0, XMM0, XMM0, 0x00; 0xC4, 0xC1, 0x39, 0xC6, 0x00, 0x00, // vshufpd XMM0, XMM8, [R8], 0x00; 0xC4, 0x41, 0x7D, 0xC6, 0xC0, 0x00, // vshufpd YMM8, YMM0, YMM8, 0x00; 0xC5, 0x7D, 0xC6, 0x00, 0x00, // vshufpd YMM8, YMM0, [RAX], 0x00; 0xC5, 0xF8, 0xC6, 0xC0, 0x00, // vshufps XMM0, XMM0, XMM0, 0x00; 0xC4, 0xC1, 0x38, 0xC6, 0x00, 0x00, // vshufps XMM0, XMM8, [R8], 0x00; 0xC4, 0x41, 0x7C, 0xC6, 0xC0, 0x00, // vshufps YMM8, YMM0, YMM8, 0x00; 0xC5, 0x7C, 0xC6, 0x00, 0x00, // vshufps YMM8, YMM0, [RAX], 0x00; 0xC5, 0xF9, 0x15, 0xC0, // vunpckhpd XMM0, XMM0, XMM0; 0xC5, 0x39, 0x15, 0x00, // vunpckhpd XMM8, XMM8, [RAX]; 0xC4, 0x41, 0x7D, 0x15, 0x00, // vunpckhpd YMM8, YMM0, [R8]; 0xC4, 0xC1, 0x3D, 0x15, 0x00, // vunpckhpd YMM0, YMM8, [R8]; 0xC5, 0xF8, 0x15, 0xC0, // vunpckhps XMM0, XMM0, XMM0; 0xC5, 0x38, 0x15, 0x00, // vunpckhps XMM8, XMM8, [RAX]; 0xC4, 0x41, 0x7C, 0x15, 0x00, // vunpckhps YMM8, YMM0, [R8]; 0xC4, 0xC1, 0x3C, 0x15, 0x00, // vunpckhps YMM0, YMM8, [R8]; 0xC5, 0xF9, 0x14, 0xC0, // vunpcklpd XMM0, XMM0, XMM0; 0xC5, 0x39, 0x14, 0x00, // vunpcklpd XMM8, XMM8, [RAX]; 0xC4, 0x41, 0x7D, 0x14, 0x00, // vunpcklpd YMM8, YMM0, [R8]; 0xC4, 0xC1, 0x3D, 0x14, 0x00, // vunpcklpd YMM0, YMM8, [R8]; 0xC5, 0xF8, 0x14, 0xC0, // vunpcklps XMM0, XMM0, XMM0; 0xC5, 0x38, 0x14, 0x00, // vunpcklps XMM8, XMM8, [RAX]; 0xC4, 0x41, 0x7C, 0x14, 0x00, // vunpcklps YMM8, YMM0, [R8]; 0xC4, 0xC1, 0x3C, 0x14, 0x00, // vunpcklps YMM0, YMM8, [R8]; /* AES */ 0x66, 0x0F, 0x38, 0xDC, 0xC0, // aesenc XMM0, XMM0; 0x66, 0x0F, 0x38, 0xDC, 0x00, // aesenc XMM0, [RAX]; 0xC4, 0xE2, 0x79, 0xDC, 0xC0, // vaesenc XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0xDC, 0x00, // vaesenc XMM0, XMM0, [RAX]; 0x66, 0x0F, 0x38, 0xDD, 0xC0, // aesenclast XMM0, XMM0; 0x66, 0x0F, 0x38, 0xDD, 0x00, // aesenclast XMM0, [RAX]; 0xC4, 0xE2, 0x79, 0xDD, 0xC0, // vaesenclast XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0xDD, 0x00, // vaesenclast XMM0, XMM0, [RAX]; 0x66, 0x0F, 0x38, 0xDE, 0xC0, // aesdec XMM0, XMM0; 0x66, 0x0F, 0x38, 0xDE, 0x00, // aesdec XMM0, [RAX]; 0xC4, 0xE2, 0x79, 0xDE, 0xC0, // vaesdec XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0xDE, 0x00, // vaesdec XMM0, XMM0, [RAX]; 0x66, 0x0F, 0x38, 0xDF, 0xC0, // aesdeclast XMM0, XMM0; 0x66, 0x0F, 0x38, 0xDF, 0x00, // aesdeclast XMM0, [RAX]; 0xC4, 0xE2, 0x79, 0xDF, 0xC0, // vaesdeclast XMM0, XMM0, XMM0; 0xC4, 0xE2, 0x79, 0xDF, 0x00, // vaesdeclast XMM0, XMM0, [RAX]; 0x66, 0x0F, 0x38, 0xDB, 0xC0, // aesimc XMM0, XMM0; 0x66, 0x0F, 0x38, 0xDB, 0x00, // aesimc XMM0, [RAX]; 0xC4, 0xE2, 0x79, 0xDB, 0xC0, // vaesimc XMM0, XMM0; 0xC4, 0xE2, 0x79, 0xDB, 0x00, // vaesimc XMM0, [RAX]; 0x66, 0x0F, 0x3A, 0xDF, 0xC0, 0x00, // aeskeygenassist XMM0, XMM0, 0x0; 0x66, 0x0F, 0x3A, 0xDF, 0x00, 0x00, // aeskeygenassist XMM0, [RAX], 0x0; 0xC4, 0xE3, 0x79, 0xDF, 0xC0, 0x00, // vaeskeygenassist XMM0, XMM0, 0x0; 0xC4, 0xE3, 0x79, 0xDF, 0x00, 0x00, // vaeskeygenassist XMM0, [RAX], 0x0; /* FSGSBASE */ 0xf3, 0x48, 0x0f, 0xae, 0xc0, // rdfsbase RAX; 0xf3, 0x49, 0x0f, 0xae, 0xc7, // rdfsbase R15; 0xf3, 0x48, 0x0f, 0xae, 0xc8, // rdgsbase RAX; 0xf3, 0x49, 0x0f, 0xae, 0xcf, // rdgsbase R15; 0xf3, 0x48, 0x0f, 0xae, 0xd0, // wrfsbase RAX; 0xf3, 0x49, 0x0f, 0xae, 0xd7, // wrfsbase R15; 0xf3, 0x48, 0x0f, 0xae, 0xd8, // wrgsbase RAX; 0xf3, 0x49, 0x0f, 0xae, 0xdf, // wrgsbase R15; /* RDRAND */ 0x66, 0x0f, 0xc7, 0xf0, // rdrand AX; 0x0f, 0xc7, 0xf0, // rdrand EAX; 0x48, 0x0f, 0xc7, 0xf0, // rdrand RAX; 0x66, 0x41, 0x0f, 0xc7, 0xf7, // rdrand R15W; 0x41, 0x0f, 0xc7, 0xf7, // rdrand R15D; 0x49, 0x0f, 0xc7, 0xf7, // rdrand R15; /* FP16C */ 0xc4, 0xe2, 0x79, 0x13, 0xc0, // vcvtph2ps XMM0, XMM0; 0xc4, 0xe2, 0x79, 0x13, 0x00, // vcvtph2ps XMM0, [RAX]; 0xc4, 0xe2, 0x7d, 0x13, 0xc0, // vcvtph2ps YMM0, XMM0; 0xc4, 0x42, 0x7d, 0x13, 0x00, // vcvtph2ps YMM8, [R8]; 0xc4, 0xe3, 0x79, 0x13, 0xc0, 0x00, // vcvtps2ph XMM0, XMM0, 0x0; 0xc4, 0xe3, 0x79, 0x13, 0x00, 0x00, // vcvtps2ph [RAX], XMM0, 0x0; 0xc4, 0xe3, 0x7d, 0x13, 0xc0, 0x00, // vcvtps2ph XMM0, YMM0, 0x0; 0xc4, 0x43, 0x7d, 0x13, 0x00, 0x00, // vcvtps2ph [R8], YMM8, 0x0; /* FMA */ 0xc4, 0xe2, 0xf9, 0x98, 0xc0, // vfmadd132pd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0x98, 0x00, // vfmadd132pd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xfd, 0x98, 0xc0, // vfmadd132pd YMM0, YMM0, YMM0; 0xc4, 0x42, 0xbd, 0x98, 0x00, // vfmadd132pd YMM8, YMM8, [R8]; 0xc4, 0xe2, 0x79, 0x98, 0xc0, // vfmadd132ps XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0x98, 0x00, // vfmadd132ps XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x7d, 0x98, 0xc0, // vfmadd132ps YMM0, YMM0, YMM0; 0xc4, 0x42, 0x3d, 0x98, 0x00, // vfmadd132ps YMM8, YMM8, [R8]; 0xc4, 0xe2, 0xf9, 0x99, 0xc0, // vfmadd132sd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0x99, 0x00, // vfmadd132sd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x79, 0x99, 0xc0, // vfmadd132ss XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0x99, 0x00, // vfmadd132ss XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xf9, 0xA8, 0xc0, // vfmadd213pd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0xA8, 0x00, // vfmadd213pd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xfd, 0xA8, 0xc0, // vfmadd213pd YMM0, YMM0, YMM0; 0xc4, 0x42, 0xbd, 0xA8, 0x00, // vfmadd213pd YMM8, YMM8, [R8]; 0xc4, 0xe2, 0x79, 0xA8, 0xc0, // vfmadd213ps XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0xA8, 0x00, // vfmadd213ps XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x7d, 0xA8, 0xc0, // vfmadd213ps YMM0, YMM0, YMM0; 0xc4, 0x42, 0x3d, 0xA8, 0x00, // vfmadd213ps YMM8, YMM8, [R8]; 0xc4, 0xe2, 0xf9, 0xA9, 0xc0, // vfmadd213sd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0xA9, 0x00, // vfmadd213sd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x79, 0xA9, 0xc0, // vfmadd213ss XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0xA9, 0x00, // vfmadd213ss XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xf9, 0xB8, 0xc0, // vfmadd231pd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0xB8, 0x00, // vfmadd231pd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xfd, 0xB8, 0xc0, // vfmadd231pd YMM0, YMM0, YMM0; 0xc4, 0x42, 0xbd, 0xB8, 0x00, // vfmadd231pd YMM8, YMM8, [R8]; 0xc4, 0xe2, 0x79, 0xB8, 0xc0, // vfmadd231ps XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0xB8, 0x00, // vfmadd231ps XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x7d, 0xB8, 0xc0, // vfmadd231ps YMM0, YMM0, YMM0; 0xc4, 0x42, 0x3d, 0xB8, 0x00, // vfmadd231ps YMM8, YMM8, [R8]; 0xc4, 0xe2, 0xf9, 0xB9, 0xc0, // vfmadd231sd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0xB9, 0x00, // vfmadd231sd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x79, 0xB9, 0xc0, // vfmadd231ss XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0xB9, 0x00, // vfmadd231ss XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xf9, 0x96, 0xc0, // vfmaddsub132pd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0x96, 0x00, // vfmaddsub132pd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xfd, 0x96, 0xc0, // vfmaddsub132pd YMM0, YMM0, YMM0; 0xc4, 0x42, 0xbd, 0x96, 0x00, // vfmaddsub132pd YMM8, YMM8, [R8]; 0xc4, 0xe2, 0x79, 0x96, 0xc0, // vfmaddsub132ps XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0x96, 0x00, // vfmaddsub132ps XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x7d, 0x96, 0xc0, // vfmaddsub132ps YMM0, YMM0, YMM0; 0xc4, 0x42, 0x3d, 0x96, 0x00, // vfmaddsub132ps YMM8, YMM8, [R8]; 0xc4, 0xe2, 0xf9, 0xA6, 0xc0, // vfmaddsub213pd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0xA6, 0x00, // vfmaddsub213pd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xfd, 0xA6, 0xc0, // vfmaddsub213pd YMM0, YMM0, YMM0; 0xc4, 0x42, 0xbd, 0xA6, 0x00, // vfmaddsub213pd YMM8, YMM8, [R8]; 0xc4, 0xe2, 0x79, 0xA6, 0xc0, // vfmaddsub213ps XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0xA6, 0x00, // vfmaddsub213ps XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x7d, 0xA6, 0xc0, // vfmaddsub213ps YMM0, YMM0, YMM0; 0xc4, 0x42, 0x3d, 0xA6, 0x00, // vfmaddsub213ps YMM8, YMM8, [R8]; 0xc4, 0xe2, 0xf9, 0xB6, 0xc0, // vfmaddsub231pd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0xB6, 0x00, // vfmaddsub231pd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xfd, 0xB6, 0xc0, // vfmaddsub231pd YMM0, YMM0, YMM0; 0xc4, 0x42, 0xbd, 0xB6, 0x00, // vfmaddsub231pd YMM8, YMM8, [R8]; 0xc4, 0xe2, 0x79, 0xB6, 0xc0, // vfmaddsub231ps XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0xB6, 0x00, // vfmaddsub231ps XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x7d, 0xB6, 0xc0, // vfmaddsub231ps YMM0, YMM0, YMM0; 0xc4, 0x42, 0x3d, 0xB6, 0x00, // vfmaddsub231ps YMM8, YMM8, [R8]; 0xc4, 0xe2, 0xf9, 0x97, 0xc0, // vfmsubadd132pd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0x97, 0x00, // vfmsubadd132pd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xfd, 0x97, 0xc0, // vfmsubadd132pd YMM0, YMM0, YMM0; 0xc4, 0x42, 0xbd, 0x97, 0x00, // vfmsubadd132pd YMM8, YMM8, [R8]; 0xc4, 0xe2, 0x79, 0x97, 0xc0, // vfmsubadd132ps XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0x97, 0x00, // vfmsubadd132ps XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x7d, 0x97, 0xc0, // vfmsubadd132ps YMM0, YMM0, YMM0; 0xc4, 0x42, 0x3d, 0x97, 0x00, // vfmsubadd132ps YMM8, YMM8, [R8]; 0xc4, 0xe2, 0xf9, 0xA7, 0xc0, // vfmsubadd213pd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0xA7, 0x00, // vfmsubadd213pd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xfd, 0xA7, 0xc0, // vfmsubadd213pd YMM0, YMM0, YMM0; 0xc4, 0x42, 0xbd, 0xA7, 0x00, // vfmsubadd213pd YMM8, YMM8, [R8]; 0xc4, 0xe2, 0x79, 0xA7, 0xc0, // vfmsubadd213ps XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0xA7, 0x00, // vfmsubadd213ps XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x7d, 0xA7, 0xc0, // vfmsubadd213ps YMM0, YMM0, YMM0; 0xc4, 0x42, 0x3d, 0xA7, 0x00, // vfmsubadd213ps YMM8, YMM8, [R8]; 0xc4, 0xe2, 0xf9, 0xB7, 0xc0, // vfmsubadd231pd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0xB7, 0x00, // vfmsubadd231pd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xfd, 0xB7, 0xc0, // vfmsubadd231pd YMM0, YMM0, YMM0; 0xc4, 0x42, 0xbd, 0xB7, 0x00, // vfmsubadd231pd YMM8, YMM8, [R8]; 0xc4, 0xe2, 0x79, 0xB7, 0xc0, // vfmsubadd231ps XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0xB7, 0x00, // vfmsubadd231ps XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x7d, 0xB7, 0xc0, // vfmsubadd231ps YMM0, YMM0, YMM0; 0xc4, 0x42, 0x3d, 0xB7, 0x00, // vfmsubadd231ps YMM8, YMM8, [R8]; 0xc4, 0xe2, 0xf9, 0x9A, 0xc0, // vfmsub132pd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0x9A, 0x00, // vfmsub132pd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xfd, 0x9A, 0xc0, // vfmsub132pd YMM0, YMM0, YMM0; 0xc4, 0x42, 0xbd, 0x9A, 0x00, // vfmsub132pd YMM8, YMM8, [R8]; 0xc4, 0xe2, 0x79, 0x9A, 0xc0, // vfmsub132ps XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0x9A, 0x00, // vfmsub132ps XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x7d, 0x9A, 0xc0, // vfmsub132ps YMM0, YMM0, YMM0; 0xc4, 0x42, 0x3d, 0x9A, 0x00, // vfmsub132ps YMM8, YMM8, [R8]; 0xc4, 0xe2, 0xf9, 0x9B, 0xc0, // vfmsub132sd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0x9B, 0x00, // vfmsub132sd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x79, 0x9B, 0xc0, // vfmsub132ss XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0x9B, 0x00, // vfmsub132ss XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xf9, 0xAA, 0xc0, // vfmsub213pd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0xAA, 0x00, // vfmsub213pd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xfd, 0xAA, 0xc0, // vfmsub213pd YMM0, YMM0, YMM0; 0xc4, 0x42, 0xbd, 0xAA, 0x00, // vfmsub213pd YMM8, YMM8, [R8]; 0xc4, 0xe2, 0x79, 0xAA, 0xc0, // vfmsub213ps XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0xAA, 0x00, // vfmsub213ps XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x7d, 0xAA, 0xc0, // vfmsub213ps YMM0, YMM0, YMM0; 0xc4, 0x42, 0x3d, 0xAA, 0x00, // vfmsub213ps YMM8, YMM8, [R8]; 0xc4, 0xe2, 0xf9, 0xAB, 0xc0, // vfmsub213sd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0xAB, 0x00, // vfmsub213sd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x79, 0xAB, 0xc0, // vfmsub213ss XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0xAB, 0x00, // vfmsub213ss XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xf9, 0xBA, 0xc0, // vfmsub231pd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0xBA, 0x00, // vfmsub231pd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0xfd, 0xBA, 0xc0, // vfmsub231pd YMM0, YMM0, YMM0; 0xc4, 0x42, 0xbd, 0xBA, 0x00, // vfmsub231pd YMM8, YMM8, [R8]; 0xc4, 0xe2, 0x79, 0xBA, 0xc0, // vfmsub231ps XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0xBA, 0x00, // vfmsub231ps XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x7d, 0xBA, 0xc0, // vfmsub231ps YMM0, YMM0, YMM0; 0xc4, 0x42, 0x3d, 0xBA, 0x00, // vfmsub231ps YMM8, YMM8, [R8]; 0xc4, 0xe2, 0xf9, 0xBB, 0xc0, // vfmsub231sd XMM0, XMM0, XMM0; 0xc4, 0xe2, 0xf9, 0xBB, 0x00, // vfmsub231sd XMM0, XMM0, [RAX]; 0xc4, 0xe2, 0x79, 0xBB, 0xc0, // vfmsub231ss XMM0, XMM0, XMM0; 0xc4, 0xe2, 0x79, 0xBB, 0x00, // vfmsub231ss XMM0, XMM0, [RAX]; // 0x58, // pop RAX ]; asm { call L1; xgetbv; xsetbv; xrstor [RAX]; xrstor64 [RAX]; xsave [RAX]; xsave64 [RAX]; xsaveopt [RAX]; xsaveopt64 [RAX]; vldmxcsr [RAX]; vstmxcsr [RAX]; vaddss XMM0, XMM1, XMM2; vaddsd XMM0, XMM15, [RAX]; vaddps XMM12, XMM0, XMM0; vaddpd XMM8, XMM8, XMM8; vsubss XMM0, XMM1, XMM2; vsubsd XMM0, XMM15, [RAX]; vsubps XMM12, XMM0, XMM0; vsubpd XMM8, XMM8, XMM8; vaddsubps XMM0, XMM1, XMM2; vaddsubps YMM0, YMM1, YMM2; vaddsubpd YMM8, YMM1, YMM2; vaddsubpd YMM15, YMM15, 64[RAX]; vdpps YMM0, YMM0, YMM0, 0; vdppd XMM0, XMM0, XMM0, 0x88; vhaddpd YMM0, YMM8, [RDI]; vhaddps XMM0, XMM8, XMM1; vmaxpd YMM0, YMM0, YMM1; vmaxpd XMM0, XMM0, [RAX]; vmaxps YMM0, YMM0, YMM1; vmaxps XMM0, XMM0, [RAX]; vmaxsd XMM0, XMM0, [RAX]; vmaxss XMM0, XMM0, [RAX]; vminpd YMM0, YMM0, YMM1; vminpd XMM0, XMM0, [RAX]; vminps YMM0, YMM0, YMM1; vminps XMM0, XMM0, [RAX]; vminsd XMM0, XMM0, [RAX]; vminss XMM0, XMM0, [RAX]; vmovmskpd EAX, XMM0; vmovmskpd EDI, YMM0; vmovmskps EAX, YMM15; vmovmskps R8D, YMM0; vpmovmskb EAX, XMM0; vmpsadbw XMM0, XMM1, XMM2, 0x00; vmpsadbw XMM8, XMM9, XMM10, 0xFF; vpabsb XMM0, [RAX]; vpabsw XMM1, XMM15; vpabsd XMM1, [RBX]; vpaddb XMM0, XMM0, [RAX]; vpaddw XMM8, XMM8, XMM15; vpaddd XMM8, XMM8, [RBX]; vpaddq XMM0, XMM0, XMM0; vpsubb XMM0, XMM0, [RAX]; vpsubw XMM8, XMM8, XMM15; vpsubd XMM8, XMM8, [RBX]; vpsubq XMM0, XMM0, XMM0; vpaddsb XMM0, XMM0, XMM0; vpaddsw XMM0, XMM0, XMM0; vpaddusb XMM0, XMM0, XMM0; vpaddusw XMM0, XMM0, XMM0; vpsubsb XMM0, XMM0, XMM0; vpsubsw XMM0, XMM0, XMM0; vpsubusb XMM0, XMM0, XMM0; vpsubusw XMM0, XMM0, XMM0; vpavgb XMM0, XMM0, XMM0; vpavgw XMM0, XMM0, XMM0; vpclmulqdq XMM0, XMM0, 64[RAX + 4 * RCX], 0; vphaddw XMM0, XMM0, XMM0; vphaddd XMM0, XMM0, XMM0; vphsubw XMM0, XMM0, XMM0; vphsubd XMM0, XMM0, XMM0; vphaddsw XMM0, XMM0, XMM0; vphsubsw XMM0, XMM0, XMM0; vphminposuw XMM0, XMM0; vpmaddwd XMM0, XMM0, XMM0; vpmaddubsw XMM0, XMM0, XMM0; vpmaxsb XMM0, XMM0, XMM0; vpmaxsd XMM0, XMM0, XMM0; vpmaxsw XMM0, XMM0, XMM0; vpmaxub XMM0, XMM0, XMM0; vpmaxud XMM0, XMM0, XMM0; vpmaxuw XMM0, XMM0, XMM0; vpminsb XMM0, XMM0, XMM0; vpminsd XMM0, XMM0, XMM0; vpminsw XMM0, XMM0, XMM0; vpminub XMM0, XMM0, XMM0; vpminud XMM0, XMM0, XMM0; vpminuw XMM0, XMM0, XMM0; vpmulhrsw XMM0, XMM0, XMM0; vpmulhuw XMM0, XMM0, XMM0; vpmulhw XMM0, XMM0, XMM0; vpmulld XMM0, XMM0, XMM0; vpmullw XMM0, XMM0, XMM0; vpmuludq XMM0, XMM0, XMM0; vpmuldq XMM0, XMM0, XMM0; vpsadbw XMM0, XMM0, XMM0; vpsignb XMM0, XMM0, XMM0; vpsignw XMM0, XMM0, XMM0; vpsignd XMM0, XMM0, XMM0; vpslldq XMM0, XMM0, 0; vpsllw XMM0, XMM0, 0; vpsllw XMM0, XMM0, XMM0; vpslld XMM0, XMM0, 0; vpslld XMM0, XMM0, XMM0; vpsllq XMM0, XMM0, 0; vpsllq XMM0, XMM0, XMM0; vpsraw XMM0, XMM0, 0; vpsraw XMM0, XMM0, XMM0; vpsrad XMM0, XMM0, 0; vpsrad XMM0, XMM0, XMM0; vpsrldq XMM0, XMM0, 0; vpsrlw XMM0, XMM0, 0; vpsrlw XMM0, XMM0, XMM0; vpsrld XMM0, XMM0, 0; vpsrld XMM0, XMM0, XMM0; vpsrlq XMM0, XMM0, 0; vpsrlq XMM0, XMM0, XMM0; vrcpps XMM0, XMM1; vrcpps YMM0, YMM1; vrcpss XMM0, XMM0, XMM1; vroundpd XMM0, XMM0, 0; vroundpd YMM0, YMM0, 0; vroundps XMM0, XMM0, 0; vroundps YMM0, YMM0, 0; vroundsd XMM0, XMM0, XMM0, 0; vroundss XMM0, XMM0, XMM0, 0; vsqrtpd XMM0, XMM0; vsqrtpd YMM0, YMM0; vsqrtps XMM0, XMM0; vsqrtps YMM0, YMM0; vsqrtsd XMM0, XMM0, XMM0; vsqrtss XMM0, XMM0, XMM0; vzeroall; vzeroupper; vcmppd XMM0, XMM0, XMM0, 0; vcmppd YMM0, YMM0, YMM0, 0; vcmpps XMM0, XMM0, XMM0, 0; vcmpps YMM0, YMM0, YMM0, 0; vcmpsd XMM0, XMM0, XMM0, 0; vcmpss XMM0, XMM0, XMM0, 0; vcomisd XMM0, XMM0; vcomiss XMM0, XMM0; vpcmpeqb XMM0, XMM0, XMM0; vpcmpeqw XMM0, XMM0, XMM0; vpcmpeqd XMM0, XMM0, XMM0; vpcmpeqq XMM0, XMM0, XMM0; vpcmpgtb XMM0, XMM0, XMM0; vpcmpgtw XMM0, XMM0, XMM0; vpcmpgtd XMM0, XMM0, XMM0; vpcmpgtq XMM0, XMM0, XMM0; vpcmpestri XMM0, XMM0, 0; vpcmpestrm XMM0, XMM0, 0; vpcmpistri XMM0, XMM0, 0; vpcmpistrm XMM0, XMM0, 0; vcvtdq2pd XMM0, XMM0; vcvtdq2pd YMM0, XMM0; vcvtdq2pd YMM0, [RAX]; vcvtdq2ps XMM0, XMM0; vcvtdq2ps YMM0, YMM0; vcvtdq2ps YMM0, [RAX]; vcvtpd2dq XMM0, XMM0; vcvtpd2dq XMM0, YMM0; vcvtpd2dq XMM0, [RAX]; vcvtpd2ps XMM0, XMM0; vcvtpd2ps XMM0, YMM0; vcvtpd2ps XMM0, [RAX]; vcvtps2dq XMM0, XMM0; vcvtps2dq YMM0, YMM0; vcvtps2dq YMM0, [RAX]; vcvtps2pd XMM0, XMM0; vcvtps2pd YMM0, XMM0; vcvtps2pd YMM0, [RAX]; vcvtsd2si EAX, XMM0; vcvtsd2si RAX, XMM0; vcvtsd2si RAX, [RAX]; vcvtsd2ss XMM0, XMM0, XMM0; vcvtsd2ss XMM0, XMM0, [RAX]; vcvtsi2sd XMM0, XMM0, EAX; vcvtsi2sd XMM0, XMM0, RAX; vcvtsi2sd XMM0, XMM0, [RAX]; vcvtsi2ss XMM0, XMM0, EAX; vcvtsi2ss XMM0, XMM0, RAX; vcvtsi2ss XMM0, XMM0, [RAX]; vcvtsi2sd XMM0, XMM0, EAX; vcvtsi2sd XMM0, XMM0, RAX; vcvtsi2sd XMM0, XMM0, [RAX]; vcvtss2si EAX, XMM0; vcvtss2si RAX, XMM0; vcvtss2si RAX, [RAX]; vcvttpd2dq XMM0, XMM0; vcvttpd2dq XMM0, YMM0; vcvttpd2dq XMM0, [RAX]; vcvttps2dq XMM0, XMM0; vcvttps2dq YMM0, YMM0; vcvttps2dq YMM0, [RAX]; vcvttsd2si EAX, XMM0; vcvttsd2si RAX, XMM0; vcvttsd2si RAX, [RAX]; vcvttss2si EAX, XMM0; vcvttss2si RAX, XMM0; vcvttss2si RAX, [RAX]; vbroadcastss XMM0, [RAX]; vbroadcastss YMM0, [RAX]; vbroadcastsd YMM0, [RAX]; vbroadcastf128 YMM0, [RAX]; vextractf128 XMM0, YMM0, 0; vextractf128 [RAX], YMM0, 0; vextractps EAX, XMM0, 0; vextractps [RAX], XMM0, 0; vinsertf128 YMM0, YMM0, XMM0, 0; vinsertf128 YMM0, YMM0, [RAX], 0; vinsertps XMM0, XMM0, XMM0, 0; vinsertps XMM0, XMM0, [RAX], 0; vpinsrb XMM0, XMM0, EAX, 0; vpinsrb XMM0, XMM0, [RAX], 0; vpinsrw XMM0, XMM0, EAX, 0; vpinsrw XMM0, XMM0, [RAX], 0; vpinsrd XMM0, XMM0, EAX, 0; vpinsrd XMM0, XMM0, [RAX], 0; vpinsrq XMM0, XMM0, RAX, 0; vpinsrq XMM0, XMM0, [RAX], 0; vlddqu XMM0, [RAX]; vlddqu YMM0, [RAX]; vmaskmovdqu XMM0, XMM0; vmaskmovps XMM0, XMM0, [RAX]; vmaskmovps [RAX], XMM0, XMM0; vmaskmovps YMM0, YMM0, [RAX]; vmaskmovps [RAX], YMM0, YMM0; vmaskmovpd XMM0, XMM0, [RAX]; vmaskmovpd [RAX], XMM0, XMM0; vmaskmovpd YMM0, YMM0, [RAX]; vmaskmovpd [RAX], YMM0, YMM0; vmovapd YMM0, [RAX]; vmovapd YMM8, [RAX]; vmovapd YMM8, 64[RDI]; vmovapd [RAX], YMM0; vmovapd [RAX], YMM8; vmovapd 64[RDI], YMM8; vmovaps YMM0, [RAX]; vmovaps YMM8, [RAX]; vmovaps YMM8, 64[RDI]; vmovaps [RAX], YMM0; vmovaps [RAX], YMM8; vmovaps 64[RDI], YMM8; vmovupd YMM0, [RAX]; vmovupd YMM8, [RAX]; vmovupd YMM8, 64[RDI]; vmovupd [RAX], YMM0; vmovupd [RAX], YMM8; vmovupd 64[RDI], YMM8; vmovups YMM0, [RAX]; vmovups YMM8, [RAX]; vmovups YMM8, 64[RDI]; vmovups [RAX], YMM0; vmovups [RAX], YMM8; vmovups 64[RDI], YMM8; vmovd XMM0, EAX; vmovd XMM0, [RAX]; vmovd EAX, XMM0; vmovd [RAX], XMM0; vmovq XMM0, RAX; vmovq XMM0, [RAX]; vmovq RAX, XMM0; vmovq [RAX], XMM0; vmovdqa XMM0, XMM0; vmovdqa XMM0, [RAX]; vmovdqa YMM0, YMM0; vmovdqa YMM0, [RAX]; vmovdqa XMM0, XMM0; vmovdqa [RAX], XMM0; vmovdqa YMM0, YMM0; vmovdqa [RAX],YMM0; vmovdqu XMM0, XMM0; vmovdqu XMM0, [RAX]; vmovdqu YMM0, YMM0; vmovdqu YMM0, [RAX]; vmovdqu XMM0, XMM0; vmovdqu [RAX], XMM0; vmovdqu YMM0, YMM0; vmovdqu [RAX],YMM0; vmovlhps XMM0, XMM0, XMM0; vmovhlps XMM0, XMM0, XMM0; vmovhpd XMM0, XMM0, [RAX]; vmovhpd [RAX], XMM0; vmovhps XMM0, XMM0, [RAX]; vmovhps [RAX], XMM0; vmovlpd XMM0, XMM0, [RAX]; vmovlpd [RAX], XMM0; vmovlps XMM0, XMM0, [RAX]; vmovlps [RAX], XMM0; vmovntdq [RAX], XMM0; vmovntdq [RAX], YMM8; vmovntpd [RAX], XMM0; vmovntpd [RAX], YMM8; vmovntps [RAX], XMM0; vmovntps [RAX], YMM8; vmovntdqa XMM0, [RAX]; vmovsd XMM0, XMM0, XMM0; vmovsd XMM8, XMM8, XMM8; vmovsd [RAX], XMM0; vmovsd [R8], XMM8; vmovss XMM0, XMM0, XMM0; vmovss XMM8, XMM8, XMM8; vmovss [RAX], XMM0; vmovss [R8], XMM8; vmovshdup XMM8, XMM1; vmovshdup YMM0, YMM8; vmovshdup YMM0, [RAX]; vmovsldup XMM8, XMM1; vmovsldup YMM0, YMM8; vmovsldup YMM0, [RAX]; vpackuswb XMM0, XMM1, XMM2; vpackuswb XMM0, XMM8, [RAX]; vpackusdw XMM0, XMM1, XMM2; vpackusdw XMM0, XMM8, [RAX]; vpacksswb XMM0, XMM1, XMM2; vpacksswb XMM0, XMM8, [RAX]; vpackssdw XMM0, XMM1, XMM2; vpackssdw XMM0, XMM8, [RAX]; vpalignr XMM0, XMM1, XMM2, 0xFF; vpalignr XMM9, XMM8, [RAX], 0x10; vpextrb EAX, XMM0, 0x0; vpextrb R10, XMM9, 0xF; vpextrb [R10], XMM9, 0xF; vpextrd EAX, XMM0, 0x0; vpextrd R8D, XMM9, 0xF; vpextrd [R10], XMM9, 0xF; vpextrq RAX, XMM0, 0x0; vpextrq R10, XMM9, 0xF; vpextrq [R10], XMM9, 0xF; vpextrw EAX, XMM0, 0x0; vpextrw R10, XMM9, 0xF; vpextrw [R10], XMM9, 0xF; vpmovsxbw XMM0, XMM0; vpmovsxbw XMM8, [R8]; vpmovsxbd XMM0, XMM0; vpmovsxbd XMM8, [R8]; vpmovsxbq XMM0, XMM0; vpmovsxbq XMM8, [R8]; vpmovsxwd XMM0, XMM0; vpmovsxwd XMM8, [R8]; vpmovsxwq XMM0, XMM0; vpmovsxwq XMM8, [R8]; vpmovsxdq XMM0, XMM0; vpmovsxdq XMM8, [R8]; vpmovzxbw XMM0, XMM0; vpmovzxbw XMM8, [R8]; vpmovzxbd XMM0, XMM0; vpmovzxbd XMM8, [R8]; vpmovzxbq XMM0, XMM0; vpmovzxbq XMM8, [R8]; vpmovzxwd XMM0, XMM0; vpmovzxwd XMM8, [R8]; vpmovzxwq XMM0, XMM0; vpmovzxwq XMM8, [R8]; vpmovzxdq XMM0, XMM0; vpmovzxdq XMM8, [R8]; vandpd XMM0, XMM0, XMM0; vandpd XMM9, XMM8, [R8]; vandps XMM0, XMM0, XMM0; vandps XMM9, XMM8, [R8]; vandnpd XMM0, XMM0, XMM0; vandnpd XMM9, XMM8, [R8]; vandnps XMM0, XMM0, XMM0; vandnps XMM9, XMM8, [R8]; vorpd XMM0, XMM0, XMM0; vorpd XMM9, XMM8, [R8]; vorps XMM0, XMM0, XMM0; vorps XMM9, XMM8, [R8]; vpand XMM0, XMM0, XMM0; vpand XMM9, XMM8, [R8]; vpandn XMM0, XMM0, XMM0; vpandn XMM9, XMM8, [R8]; vpor XMM0, XMM0, XMM0; vpor XMM9, XMM8, [R10]; vpxor XMM0, XMM0, XMM0; vpxor XMM9, XMM8, [R10]; vptest XMM0, XMM0; vptest XMM8, [RAX]; vptest YMM8, YMM8; vptest YMM0, [R8]; vucomisd XMM0, XMM0; vucomisd XMM8, [RAX]; vucomiss XMM0, XMM0; vucomiss XMM8, [RAX]; vxorpd XMM0, XMM8, XMM0; vxorpd XMM8, XMM0, [RAX]; vxorpd YMM0, YMM8, YMM0; vxorpd YMM8, YMM0, [RAX]; vxorps XMM0, XMM8, XMM0; vxorps XMM8, XMM0, [RAX]; vxorps YMM0, YMM8, YMM0; vxorps YMM8, YMM0, [RAX]; vblendpd XMM0, XMM1, XMM2, 0x00; vblendpd XMM9, XMM8, [RAX], 0xFF; vblendpd YMM0, YMM1, YMM2, 0x00; vblendpd YMM9, YMM8, [RAX], 0xFF; vblendps XMM0, XMM1, XMM2, 0x00; vblendps XMM9, XMM8, [RAX], 0xFF; vblendps YMM0, YMM1, YMM2, 0x00; vblendps YMM9, YMM8, [RAX], 0xFF; vblendvpd XMM0, XMM1, XMM2, 0x00; vblendvpd XMM9, XMM8, [RAX], 0xFF; vblendvpd YMM0, YMM1, YMM2, 0x00; vblendvpd YMM9, YMM8, [RAX], 0xFF; vblendvps XMM0, XMM1, XMM2, 0x00; vblendvps XMM9, XMM8, [RAX], 0xFF; vblendvps YMM0, YMM1, YMM2, 0x00; vblendvps YMM9, YMM8, [RAX], 0xFF; vmovddup XMM8, XMM0; vmovddup XMM0, [RAX]; vmovddup YMM0, YMM8; vmovddup YMM0, [R10]; vpblendvb XMM0, XMM8, XMM0, 0x00; vpblendvb XMM8, XMM0, [RAX], 0x00; vpblendvb XMM8, XMM0, [R10], 0x00; vpblendw XMM0, XMM8, XMM0, 0x00; vpblendw XMM8, XMM0, [RAX], 0x00; vpblendw XMM8, XMM0, [R10], 0x00; vpermilpd XMM0, XMM1, XMM2; vpermilpd XMM0, XMM1, [RAX]; vpermilpd XMM0, XMM1, 0x00; vpermilpd XMM0, [RAX], 0x00; vpermilps XMM0, XMM1, XMM2; vpermilps XMM0, XMM1, [RAX]; vpermilps XMM0, XMM1, 0x00; vpermilps XMM0, [RAX], 0x00; vperm2f128 YMM0, YMM1, YMM2, 0x00; vperm2f128 YMM0, YMM1, [RAX], 0x00; vperm2f128 YMM8, YMM9, [R10], 0x00; vpshufb XMM0, XMM0, XMM0; vpshufb XMM9, XMM8, [R8]; vpshufd XMM0, XMM0, 0x0; vpshufd XMM8, [R8], 0x0; vpshufhw XMM0, XMM0, 0x0; vpshufhw XMM8, [R8], 0x0; vpshuflw XMM0, XMM0, 0x0; vpshuflw XMM8, [R8], 0x0; vpunpckhbw XMM0, XMM1, XMM2; vpunpckhbw XMM8, XMM8, [R8]; vpunpckhwd XMM0, XMM1, XMM2; vpunpckhwd XMM8, XMM8, [R8]; vpunpckhdq XMM0, XMM1, XMM2; vpunpckhdq XMM8, XMM8, [R8]; vpunpckhqdq XMM0, XMM1, XMM2; vpunpckhqdq XMM8, XMM8, [R8]; vpunpcklbw XMM0, XMM1, XMM2; vpunpcklbw XMM8, XMM8, [R8]; vpunpcklwd XMM0, XMM1, XMM2; vpunpcklwd XMM8, XMM8, [R8]; vpunpckldq XMM0, XMM1, XMM2; vpunpckldq XMM8, XMM8, [R8]; vpunpcklqdq XMM0, XMM1, XMM2; vpunpcklqdq XMM8, XMM8, [R8]; vshufpd XMM0, XMM0, XMM0, 0x00; vshufpd XMM0, XMM8, [R8], 0x00; vshufpd YMM8, YMM0, YMM8, 0x00; vshufpd YMM8, YMM0, [RAX], 0x00; vshufps XMM0, XMM0, XMM0, 0x00; vshufps XMM0, XMM8, [R8], 0x00; vshufps YMM8, YMM0, YMM8, 0x00; vshufps YMM8, YMM0, [RAX], 0x00; vunpckhpd XMM0, XMM0, XMM0; vunpckhpd XMM8, XMM8, [RAX]; vunpckhpd YMM8, YMM0, [R8]; vunpckhpd YMM0, YMM8, [R8]; vunpckhps XMM0, XMM0, XMM0; vunpckhps XMM8, XMM8, [RAX]; vunpckhps YMM8, YMM0, [R8]; vunpckhps YMM0, YMM8, [R8]; vunpcklpd XMM0, XMM0, XMM0; vunpcklpd XMM8, XMM8, [RAX]; vunpcklpd YMM8, YMM0, [R8]; vunpcklpd YMM0, YMM8, [R8]; vunpcklps XMM0, XMM0, XMM0; vunpcklps XMM8, XMM8, [RAX]; vunpcklps YMM8, YMM0, [R8]; vunpcklps YMM0, YMM8, [R8]; /* AES */ aesenc XMM0, XMM0; aesenc XMM0, [RAX]; vaesenc XMM0, XMM0, XMM0; vaesenc XMM0, XMM0, [RAX]; aesenclast XMM0, XMM0; aesenclast XMM0, [RAX]; vaesenclast XMM0, XMM0, XMM0; vaesenclast XMM0, XMM0, [RAX]; aesdec XMM0, XMM0; aesdec XMM0, [RAX]; vaesdec XMM0, XMM0, XMM0; vaesdec XMM0, XMM0, [RAX]; aesdeclast XMM0, XMM0; aesdeclast XMM0, [RAX]; vaesdeclast XMM0, XMM0, XMM0; vaesdeclast XMM0, XMM0, [RAX]; aesimc XMM0, XMM0; aesimc XMM0, [RAX]; vaesimc XMM0, XMM0; vaesimc XMM0, [RAX]; aeskeygenassist XMM0, XMM0, 0x0; aeskeygenassist XMM0, [RAX], 0x0; vaeskeygenassist XMM0, XMM0, 0x0; vaeskeygenassist XMM0, [RAX], 0x0; /* FSGSBASE */ rdfsbase RAX; rdfsbase R15; rdgsbase RAX; rdgsbase R15; wrfsbase RAX; wrfsbase R15; wrgsbase RAX; wrgsbase R15; /* RDRAND */ rdrand AX; rdrand EAX; rdrand RAX; rdrand R15W; rdrand R15D; rdrand R15; /* FP16C */ vcvtph2ps XMM0, XMM0; vcvtph2ps XMM0, [RAX]; vcvtph2ps YMM0, XMM0; vcvtph2ps YMM8, [R8]; vcvtps2ph XMM0, XMM0, 0x0; vcvtps2ph [RAX], XMM0, 0x0; vcvtps2ph XMM0, YMM0, 0x0; vcvtps2ph [R8], YMM8, 0x0; /* FMA */ vfmadd132pd XMM0, XMM0, XMM0; vfmadd132pd XMM0, XMM0, [RAX]; vfmadd132pd YMM0, YMM0, YMM0; vfmadd132pd YMM8, YMM8, [R8]; vfmadd132ps XMM0, XMM0, XMM0; vfmadd132ps XMM0, XMM0, [RAX]; vfmadd132ps YMM0, YMM0, YMM0; vfmadd132ps YMM8, YMM8, [R8]; vfmadd132sd XMM0, XMM0, XMM0; vfmadd132sd XMM0, XMM0, [RAX]; vfmadd132ss XMM0, XMM0, XMM0; vfmadd132ss XMM0, XMM0, [RAX]; vfmadd213pd XMM0, XMM0, XMM0; vfmadd213pd XMM0, XMM0, [RAX]; vfmadd213pd YMM0, YMM0, YMM0; vfmadd213pd YMM8, YMM8, [R8]; vfmadd213ps XMM0, XMM0, XMM0; vfmadd213ps XMM0, XMM0, [RAX]; vfmadd213ps YMM0, YMM0, YMM0; vfmadd213ps YMM8, YMM8, [R8]; vfmadd213sd XMM0, XMM0, XMM0; vfmadd213sd XMM0, XMM0, [RAX]; vfmadd213ss XMM0, XMM0, XMM0; vfmadd213ss XMM0, XMM0, [RAX]; vfmadd231pd XMM0, XMM0, XMM0; vfmadd231pd XMM0, XMM0, [RAX]; vfmadd231pd YMM0, YMM0, YMM0; vfmadd231pd YMM8, YMM8, [R8]; vfmadd231ps XMM0, XMM0, XMM0; vfmadd231ps XMM0, XMM0, [RAX]; vfmadd231ps YMM0, YMM0, YMM0; vfmadd231ps YMM8, YMM8, [R8]; vfmadd231sd XMM0, XMM0, XMM0; vfmadd231sd XMM0, XMM0, [RAX]; vfmadd231ss XMM0, XMM0, XMM0; vfmadd231ss XMM0, XMM0, [RAX]; vfmaddsub132pd XMM0, XMM0, XMM0; vfmaddsub132pd XMM0, XMM0, [RAX]; vfmaddsub132pd YMM0, YMM0, YMM0; vfmaddsub132pd YMM8, YMM8, [R8]; vfmaddsub132ps XMM0, XMM0, XMM0; vfmaddsub132ps XMM0, XMM0, [RAX]; vfmaddsub132ps YMM0, YMM0, YMM0; vfmaddsub132ps YMM8, YMM8, [R8]; vfmaddsub213pd XMM0, XMM0, XMM0; vfmaddsub213pd XMM0, XMM0, [RAX]; vfmaddsub213pd YMM0, YMM0, YMM0; vfmaddsub213pd YMM8, YMM8, [R8]; vfmaddsub213ps XMM0, XMM0, XMM0; vfmaddsub213ps XMM0, XMM0, [RAX]; vfmaddsub213ps YMM0, YMM0, YMM0; vfmaddsub213ps YMM8, YMM8, [R8]; vfmaddsub231pd XMM0, XMM0, XMM0; vfmaddsub231pd XMM0, XMM0, [RAX]; vfmaddsub231pd YMM0, YMM0, YMM0; vfmaddsub231pd YMM8, YMM8, [R8]; vfmaddsub231ps XMM0, XMM0, XMM0; vfmaddsub231ps XMM0, XMM0, [RAX]; vfmaddsub231ps YMM0, YMM0, YMM0; vfmaddsub231ps YMM8, YMM8, [R8]; vfmsubadd132pd XMM0, XMM0, XMM0; vfmsubadd132pd XMM0, XMM0, [RAX]; vfmsubadd132pd YMM0, YMM0, YMM0; vfmsubadd132pd YMM8, YMM8, [R8]; vfmsubadd132ps XMM0, XMM0, XMM0; vfmsubadd132ps XMM0, XMM0, [RAX]; vfmsubadd132ps YMM0, YMM0, YMM0; vfmsubadd132ps YMM8, YMM8, [R8]; vfmsubadd213pd XMM0, XMM0, XMM0; vfmsubadd213pd XMM0, XMM0, [RAX]; vfmsubadd213pd YMM0, YMM0, YMM0; vfmsubadd213pd YMM8, YMM8, [R8]; vfmsubadd213ps XMM0, XMM0, XMM0; vfmsubadd213ps XMM0, XMM0, [RAX]; vfmsubadd213ps YMM0, YMM0, YMM0; vfmsubadd213ps YMM8, YMM8, [R8]; vfmsubadd231pd XMM0, XMM0, XMM0; vfmsubadd231pd XMM0, XMM0, [RAX]; vfmsubadd231pd YMM0, YMM0, YMM0; vfmsubadd231pd YMM8, YMM8, [R8]; vfmsubadd231ps XMM0, XMM0, XMM0; vfmsubadd231ps XMM0, XMM0, [RAX]; vfmsubadd231ps YMM0, YMM0, YMM0; vfmsubadd231ps YMM8, YMM8, [R8]; vfmsub132pd XMM0, XMM0, XMM0; vfmsub132pd XMM0, XMM0, [RAX]; vfmsub132pd YMM0, YMM0, YMM0; vfmsub132pd YMM8, YMM8, [R8]; vfmsub132ps XMM0, XMM0, XMM0; vfmsub132ps XMM0, XMM0, [RAX]; vfmsub132ps YMM0, YMM0, YMM0; vfmsub132ps YMM8, YMM8, [R8]; vfmsub132sd XMM0, XMM0, XMM0; vfmsub132sd XMM0, XMM0, [RAX]; vfmsub132ss XMM0, XMM0, XMM0; vfmsub132ss XMM0, XMM0, [RAX]; vfmsub213pd XMM0, XMM0, XMM0; vfmsub213pd XMM0, XMM0, [RAX]; vfmsub213pd YMM0, YMM0, YMM0; vfmsub213pd YMM8, YMM8, [R8]; vfmsub213ps XMM0, XMM0, XMM0; vfmsub213ps XMM0, XMM0, [RAX]; vfmsub213ps YMM0, YMM0, YMM0; vfmsub213ps YMM8, YMM8, [R8]; vfmsub213sd XMM0, XMM0, XMM0; vfmsub213sd XMM0, XMM0, [RAX]; vfmsub213ss XMM0, XMM0, XMM0; vfmsub213ss XMM0, XMM0, [RAX]; vfmsub231pd XMM0, XMM0, XMM0; vfmsub231pd XMM0, XMM0, [RAX]; vfmsub231pd YMM0, YMM0, YMM0; vfmsub231pd YMM8, YMM8, [R8]; vfmsub231ps XMM0, XMM0, XMM0; vfmsub231ps XMM0, XMM0, [RAX]; vfmsub231ps YMM0, YMM0, YMM0; vfmsub231ps YMM8, YMM8, [R8]; vfmsub231sd XMM0, XMM0, XMM0; vfmsub231sd XMM0, XMM0, [RAX]; vfmsub231ss XMM0, XMM0, XMM0; vfmsub231ss XMM0, XMM0, [RAX]; L1: pop RAX; mov p[RBP],RAX; } foreach (ref i, b; data) { // printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } assert(p[data.length] == 0x58); // pop RAX } /* ======================= SHA ========================== */ void test62() { ubyte* p; byte m8; short m16; int m32; M64 m64; M128 m128; static ubyte data[] = [ 0x0F, 0x3A, 0xCC, 0xD1, 0x01, // sha1rnds4 XMM2, XMM1, 1; 0x0F, 0x3A, 0xCC, 0x10, 0x01, // sha1rnds4 XMM2, [RAX], 1; 0x0F, 0x38, 0xC8, 0xD1, // sha1nexte XMM2, XMM1; 0x0F, 0x38, 0xC8, 0x10, // sha1nexte XMM2, [RAX]; 0x0F, 0x38, 0xC9, 0xD1, // sha1msg1 XMM2, XMM1; 0x0F, 0x38, 0xC9, 0x10, // sha1msg1 XMM2, [RAX]; 0x0F, 0x38, 0xCA, 0xD1, // sha1msg2 XMM2, XMM1; 0x0F, 0x38, 0xCA, 0x10, // sha1msg2 XMM2, [RAX]; 0x0F, 0x38, 0xCB, 0xD1, // sha256rnds2 XMM2, XMM1; 0x0F, 0x38, 0xCB, 0x10, // sha256rnds2 XMM2, [RAX]; 0x0F, 0x38, 0xCC, 0xD1, // sha256msg1 XMM2, XMM1; 0x0F, 0x38, 0xCC, 0x10, // sha256msg1 XMM2, [RAX]; 0x0F, 0x38, 0xCD, 0xD1, // sha256msg2 XMM2, XMM1; 0x0F, 0x38, 0xCD, 0x10, // sha256msg2 XMM2, [RAX]; ]; asm { call L1; sha1rnds4 XMM2, XMM1, 1; sha1rnds4 XMM2, [RAX], 1; sha1nexte XMM2, XMM1; sha1nexte XMM2, [RAX]; sha1msg1 XMM2, XMM1; sha1msg1 XMM2, [RAX]; sha1msg2 XMM2, XMM1; sha1msg2 XMM2, [RAX]; sha256rnds2 XMM2, XMM1; sha256rnds2 XMM2, [RAX]; sha256msg1 XMM2, XMM1; sha256msg1 XMM2, [RAX]; sha256msg2 XMM2, XMM1; sha256msg2 XMM2, [RAX]; L1: pop RAX; mov p[RBP],RAX; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } void test2941() { ubyte *p; static ubyte data[] = [ 0x9B, 0xDF, 0xE0, // fstsw AX; ]; int i; asm { call L1 ; fstsw AX; L1: pop RBX ; mov p[RBP],RBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } void test9866() { ubyte* p; static ubyte data[] = [ 0x48, 0x0f, 0xbe, 0xc0, // movsx RAX, AL 0x48, 0x0f, 0xbe, 0x00, // movsx RAX, byte ptr [RAX] 0x48, 0x0f, 0xbf, 0xc0, // movsx RAX, AX 0x48, 0x0f, 0xbf, 0x00, // movsx RAX, word ptr [RAX] 0x48, 0x63, 0xc0, // movsxd RAX, EAX 0x48, 0x63, 0x00, // movsxd RAX, dword ptr [RAX] ]; asm { call L1; movsx RAX, AL; movsx RAX, byte ptr [RAX]; movsx RAX, AX; movsx RAX, word ptr [RAX]; movsxd RAX, EAX; movsxd RAX, dword ptr [RAX]; L1: pop RAX; mov p[RBP],RAX; } foreach (ref i, b; data) { // printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } assert(p[data.length] == 0x58); // pop RAX } /****************************************************/ void testxadd() { int x; ubyte* p; static ubyte data[] = [ 0x0F, 0xC0, 0x10, 0x66, 0x0F, 0xC1, 0x10, 0x0F, 0xC1, 0x10, 0x48, 0x0F, 0xC1, 0x10, ]; asm { call L1 ; xadd byte ptr [RAX],DL; xadd word ptr [RAX],DX; xadd dword ptr [RAX],EDX; xadd qword ptr [RAX],RDX; L1: pop RAX; mov p[RBP],RAX; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ void testconst() { ulong result; asm { mov RAX, 0xFFFF_FFFFu; mov result, RAX; } assert (result == 0xFFFF_FFFFu); } /****************************************************/ void test9965() { ubyte* p; static ubyte data[] = [ 0xB7, 0x01, // mov BH,1 0x40, 0xB6, 0x01, // mov SIL,1 0x40, 0xB7, 0x01, // mov DIL,1 0x40, 0xB5, 0x01, // mov BPL,1 0x40, 0xB4, 0x01, // mov SPL,1 0x41, 0xB0, 0x01, // mov R8B,1 0x40, 0x80, 0xE6, 0x01, // and SIL,1 (issue 12971) ]; asm { call L1; mov BH, 1; mov SIL, 1; mov DIL, 1; mov BPL, 1; mov SPL, 1; mov R8B, 1; and SIL, 1; L1: pop RAX; mov p[RBP],RAX; } foreach (ref i, b; data) { // printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } assert(p[data.length] == 0x58); // pop RAX } /****************************************************/ void test12849() { ulong a = 0xff00ff00ff00ff00L; ulong result; ulong expected = 0b10101010; asm { pxor XMM0, XMM0; movq XMM0, a; pmovmskb RAX, XMM0; mov result, RAX; } assert (result == expected); } /****************************************************/ void test12968() { int x; ubyte* p; static ubyte data[] = [ 0x48, 0x89, 0xF8, 0x4C, 0x87, 0xC2, 0xC3 ]; asm { call L1 ; mov RAX, RDI; xchg RDX, R8; ret; L1: pop RAX; mov p[RBP],RAX; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ int main() { printf("Testing iasm64.d\n"); test1(); test2(); test3(); test4(); test5(); test6(); //test7(); TODO 16bit seg test8(); //test9(); Fails //test10(); Fails test11(); test12(); test13(); test14(); test15(); //test16(); // add this one from \cbx\test\iasm.c ? test17(); test18(); test19(); //test20(); 8087 test21(); test22(); test23(); test24(); test25(); test26(); test27(); test28(); //test29(); offsetof? test30(); test31(); test32(); test33(); test34(); //test35(); RIP addressing? //test36(); RIP addressing? test37(); test38(); test39(); test40(); test41(); test42(); test43(); test44(); test45(); test46(); //test47(); RIP addressing? test48(); test49(); test50(); //Test51 test52(); test53(); test54(); test55(); test56(); test57(); test58(); test59(); test60(); test61(); test62(); test2941(); test9866(); testxadd(); test9965(); test12849(); test12968(); testconst(); printf("Success\n"); return 0; } } else { int main() { return 0; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test11447c.d0000644000175000017500000000033113200164642023274 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/c11447.d // PERMUTE_ARGS: -allinst -w -debug -gc import imports.c11447; void main() { auto a = new A(); TemplateInstancier().instanciateFromResolvedArgs(a); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testscope.d0000644000175000017500000001174313200164642023573 0ustar matthiasmatthias// PERMUTE_ARGS: extern(C) int printf(const char*, ...); class Eh : Exception { this() { super("Eh thrown"); } } /********************************************/ class Foo { static int x; this() { assert(x == 0); x++; printf("Foo.this()\n"); throw new Eh(); assert(0); } ~this() { printf("Foo.~this()\n"); } } void test1() { try { scope Foo f = new Foo(); assert(0); } catch (Eh) { assert(Foo.x == 1); Foo.x++; } finally { assert(Foo.x == 2); Foo.x++; } assert(Foo.x == 3); } /********************************************/ void test2() { int x; { scope (exit) { printf("test1\n"); assert(x == 3); x = 4; } scope (exit) { printf("test2\n"); assert(x == 2); x = 3; } scope (exit) { printf("test3\n"); assert(x == 1); x = 2; } printf("test4\n"); assert(x == 0); x = 1; } assert(x == 4); } /********************************************/ void test3() { int x; { scope (success) { printf("test1\n"); assert(x == 3); x = 4; } scope (success) { printf("test2\n"); assert(x == 2); x = 3; } scope (success) { printf("test3\n"); assert(x == 1); x = 2; } printf("test4\n"); assert(x == 0); x = 1; } assert(x == 4); } /********************************************/ void test4() { int x; try { scope (exit) { printf("test1\n"); assert(x == 3); x = 4; } scope (exit) { printf("test2\n"); assert(x == 2); x = 3; } x = 2; throw new Eh; scope (exit) { printf("test3\n"); assert(x == 1); x = 2; } printf("test4\n"); assert(x == 0); x = 1; } catch (Eh e) { } assert(x == 4); } /********************************************/ void test5() { int x; try { scope (success) { printf("test1\n"); assert(x == 3); x = 4; } scope (success) { printf("test2\n"); assert(x == 2); x = 3; } x = 2; throw new Eh; scope (success) { printf("test3\n"); assert(x == 1); x = 2; } printf("test4\n"); assert(x == 0); x = 1; } catch (Eh e) { } assert(x == 2); } /********************************************/ void test6() { int x; scope (failure) { assert(0); } try { scope (failure) { printf("test1\n"); assert(x == 3); x = 4; } scope (failure) { printf("test2\n"); assert(x == 2); x = 3; } x = 2; throw new Eh; scope (failure) { printf("test3\n"); assert(x == 1); x = 2; } printf("test4\n"); assert(x == 0); x = 1; } catch (Eh e) { } assert(x == 4); } /********************************************/ void test7() { int i; int x; void foo() { scope (success) { assert(x == 1); x = 2; } i = 2; if (i == 2) return; } i = 1; x = 1; foo(); assert(x == 2); } /********************************************/ void test8() { int i; { version (all) { scope (exit) i += 2; } assert(i == 0); i += 1; printf("betty\n"); } assert(i == 3); } /********************************************/ char[] r9; int scp( int n ) { if( n==0 ) return 0; scope(exit) { printf("%d",n); r9 ~= cast(char)(n + '0'); } return scp(n-1); } void test9() { scp(5); assert(r9 == "12345"); } /********************************************/ alias real T; T readMessageBegin() { return 3.0; } T bar10() { return 8.0; } T foo10() { // Send RPC request, etc. readMessageBegin(); scope (exit) readMessageEnd(); T result = bar10(); // Read message off the wire. return result; } void test10() { if (foo10() != 8.0) assert(0); } T readMessageEnd() { static T d; d = 4.0; d = (((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d)))))/((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d)))))+((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d)))))/((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))))*(((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d)))))/((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d)))))+((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d)))))/((((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d))))+(((d-(2*d))+(d-(2*d)))*((d-(2*d))+(d-(2*d)))))); return 4.0; } /********************************************/ void test7435() { scope(failure) debug printf("error\n"); printf("do something\n"); } /********************************************/ void test7049() @safe { int count = 0; @safe void foo() { scope (failure) { count++; } scope (failure) { count++; } throw new Exception("failed"); } try { foo(); } catch(Exception e) { } assert(count == 2); } /********************************************/ void main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test7435(); test7049(); printf("Success\n"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testappend.d0000644000175000017500000000167013200164642023727 0ustar matthiasmatthias// PERMUTE_ARGS: import core.stdc.stdio; import core.stdc.math : isnan; void test12826() { string s, t; t = t ~ "1234567"; s = s ~ "1234567"; s ~= s; assert(s == "12345671234567", s); assert(t == "1234567", t); } int main() { int[] a; for (int i = 0; i < 1000; i++) { a.length = a.length + 100; } foreach (v; a) { assert(v == 0); } float[] b; for (int i = 0; i < 2000; i++) { b.length = b.length + 100; } foreach (v; b) { assert(isnan(v)); } delete a; delete b; a = null; for (int i = 0; i < 100000; i++) { a ~= i; } foreach (k, v; a) { assert(v == k); } b = null; for (int i = 0; i < 200000; i++) { b ~= i; } foreach (k, v; b) { assert(v == k); } delete a; delete b; test12826(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_556.d0000644000175000017500000000041413200164642024256 0ustar matthiasmatthiasvoid main() { union TestUnion { ubyte[20] small; ubyte[28] large; } struct Container { TestUnion u; byte b; } Container c; c.b = 123; assert(*((cast(ubyte*)cast(void*)&c) + Container.b.offsetof) == 123); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testbitarray.d0000644000175000017500000000043513200164642024273 0ustar matthiasmatthias// PERMUTE_ARGS: import std.bitmanip; void main() { BitArray a; a.length = 5; foreach (ref bool b; a) { assert (b == 0); b = 1; } foreach (bool b; a) assert (b == 1); // FAILS, they're all 0 } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_420.d0000644000175000017500000000021313200164642024241 0ustar matthiasmatthiasimport core.simd : double2; struct Foo { double2 x; this(uint) { x = [0.0, 0.0]; } } void main() { Foo y = Foo(); }ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test19.d0000644000175000017500000001600213200164642022704 0ustar matthiasmatthias// REQUIRED_ARGS: -unittest import std.algorithm: cmp; extern(C) int printf(const char*, ...); /* ================================ */ class Foo { int foo(int x) { return x + 3; } } class Bar : Foo { override int foo(int y) { return y + 4; } } void test1() { Bar e; assert(e is null); e = new Bar(); assert(e.foo(5) == 9); } /* ================================ */ class Foo2 { int foo(int x) { return x + 3; } } class Bar2 : Foo2 { override int foo(int y) { assert(Foo2.foo(2) == 5); return y + 4; } } void test2() { Bar2 e; assert(e is null); e = new Bar2(); assert(e.foo(5) == 9); assert(e.Foo2.foo(10) == 13); } /* ================================ */ void test3() { debug printf("debug\n"); debug(1) printf("debug(1)\n"); debug(2) printf("debug(2)\n"); debug(3) printf("debug(3)\n"); debug(bar) printf("debug(bar)\n"); debug(10) assert(0); debug(1) { int d1 = 3; printf("debug(1) { }\n"); } debug(2) { printf("debug(2): d1 = %d\n", d1); } } /* ================================ */ int x1; int x2; class Foo4 { static this() { x1 = 3; printf("Foo4 ctor()\n"); } static ~this() { x1 = 4; printf("Foo4 dtor()\n"); } } static this() { x2 = 5; printf("ctor()\n"); } static ~this() { x2 = 6; printf("dtor()\n"); } void test4() { printf("x1 = %d, x2 = %d\n", x1, x2); assert(x1 == 3); assert(x2 == 5); } /* ================================ */ void test5() { version (D_Bits) { printf("test5()\n"); static uint foo; static uint x = 3; static uint len = 32; bool[] bools; bools = (cast(bool *)&foo)[0..len]; bools[6] = true; assert(foo == (1 << 6)); } } /* ================================ */ int[] test6_1(int[] a) { a.length = 6; return a; } void test6() { printf("test6()\n"); int b[3]; int a[]; b[0] = 0; b[1] = 1; b[2] = 2; assert(b.length == 3); a = test6_1(b); a[2] = 2; assert(a.length == 6); } /* ================================ */ class OutBuffer7 { char data[]; uint offset; void write(const(char) *p, uint nbytes) { data[offset .. offset + nbytes] = (cast(char *)p)[0 .. nbytes]; } } void test7() { printf("test7()\n"); int i; OutBuffer7 ob = new OutBuffer7; ob.data = new char[10]; printf("ob.data.length = %d\n", ob.data.length); assert(ob.data.length == 10); for (i = 0; i < 10; i++) assert(ob.data[i] == char.init); printf("test7.1()\n"); ob.data[] = '-'; printf("test7.2()\n"); printf("ob.data[] = '%.*s'\n", ob.data.length, ob.data.ptr); for (i = 0; i < 10; i++) assert(ob.data[i] == '-'); ob.offset = 3; ob.write("foo", 3); printf("ob.data.length = %d\n", ob.data.length); printf("ob.data[] = '%.*s'\n", ob.data.length, ob.data.ptr); for (i = 0; i < 10; i++) { if (i < 3 || i >= 6) assert(ob.data[i] == '-'); } assert(ob.data[3] == 'f'); assert(ob.data[4] == 'o'); assert(ob.data[5] == 'o'); } /* ================================ */ class A8 { enum { bar = 8, baz } int foo; } void test8() { printf("test8()\n"); A8 a; a = new A8(); a.foo = A8.bar; assert(a.foo == 8); } /* ================================ */ int z9; unittest { printf("module unittest 9\n"); z9 = 3; } void test9() { assert(z9 == 3); } /* ================================ */ void test10() { printf("test10()\n"); const int i = 8000; assert(i == 8000); static int j = 78; assert(j == 78); } /* ================================ */ Object test11_a() { return null; } void test11() { assert(test11_a() is null); } /* ================================ */ class A12 { } class B12 { } int testx(A12 a) { return 1; } int testx(B12 b) { return 2; } void test12() { A12 a = new A12(); B12 b = new B12(); assert(testx(a) == 1); assert(testx(b) == 2); } /* ================================ */ char[] tolower13(ref char[] s) { int i; for (i = 0; i < s.length; i++) { char c = s[i]; if ('A' <= c && c <= 'Z') s[i] = cast(char)(c + (cast(char)'a' - 'A')); } return s; } void test13() { char[] s1 = "FoL".dup; char[] s2; s1 = s1.dup; s2 = tolower13(s1); assert(cmp(s2, "fol") == 0); assert(s2 == s1); } /* ================================ */ alias ABC14* LPABC14; class ABC14 { } alias DEF14* LPDEF14; DEF14[3] foo; struct DEF14 { int x; } void test14() { assert(foo.sizeof == int.sizeof * 3); } /* ================================ */ class bools15 { bool a = true, b = true, c = true; void dump() { printf("%d %d %d\n", a, b, c); } } void test15() { bools15 k = new bools15; k.a = true; k.dump(); k.b = true; k.dump(); k.c = true; k.dump(); assert(k.a == true); assert(k.b == true); assert(k.c == true); } /* ================================ */ align(4) struct foo16 { short s; int i; } void test16() { assert(foo16.sizeof == 8); } /* ================================ */ enum Color { red, blue, green }; int[Color.max+1] colors1 = [ Color.blue:6, Color.green:2, Color.red:5 ]; enum { red, blue, green }; int[3] colors2 = [ blue:6, green:2, red:5 ]; void test17() { assert(colors1.length == 3); assert(colors1[0] == 5); assert(colors1[1] == 6); assert(colors1[2] == 2); assert(colors2[0] == 5); assert(colors2[1] == 6); assert(colors2[2] == 2); } /* ================================ */ alias void* HANDLE18; HANDLE18 testx18() { return null; } void test18() { assert(testx18() is null); } /* ================================ */ class Test19 { struct { int a, b, c; } } void test19() { Test19 t = new Test19(); t.a = 3; assert(t.a == 3); } /* ================================ */ bool tested20; struct S20 { unittest { assert(!tested20); tested20 = true; } } void test20() { assert(tested20); } /* ================================ */ // 7848 @safe pure nothrow void func7848() {} @safe pure nothrow unittest { func7848(); } /* ================================ */ // 8128 int flag8128 = 0; interface I8128 { unittest { printf("utest, flag8128 = %d\n", flag8128); flag8128 = 1; } } void test8128() { printf("main, flag8128 = %d\n", flag8128); assert(flag8128 == 1); } /* ================================ */ class C8635{ int x; this(int x) { this.x = x; } } void test8635() { assert(new C8635(2).x==2); assert(new C8635(3).x==3); } /* ================================ */ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test8128(); test8635(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link13394.d0000644000175000017500000000026313200164642023116 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/link13394a.d module link13394; import imports.link13394a; void main() { auto b = new B(); auto s = S(); s.func(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test36.d0000644000175000017500000000174313200164642022711 0ustar matthiasmatthias// PERMUTE_ARGS: import std.stdio; interface IUnknown{ extern(Windows): void func(); } class ComObject :IUnknown { extern (Windows): void func() {writefln(`comobject`); } } interface IDataObject: IUnknown { extern(Windows): void method(); } package class invarianttest:ComObject, IDataObject { invariant() { writefln(`hello invariant`); } extern (Windows): override void func() { int esp; asm{ mov esp,ESP; } printf("\n%d",esp); printf(`func`); } void method() { writefln(`method`); } } int main() { auto inst= new invarianttest; int esp; asm{ mov esp,ESP; } inst.func(); inst.method(); writefln("\n%d",esp); asm{ mov esp,ESP; } writefln("\n%d",esp); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test24.d0000644000175000017500000000030013200164642022672 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test24a.d imports/test24b.d // PERMUTE_ARGS: // REQUIRED_ARGS: import imports.test24a, imports.test24b; void main() { string hi = std.string.format("%s", 3); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test14901.d0000644000175000017500000000062213200164642023132 0ustar matthiasmatthias// REQUIRED_ARGS: // PERMUTE_ARGS: -unittest // EXTRA_SOURCES: imports/test14901a.d imports/test14901b.d imports/test14901c.d imports/test14901d.d // COMPILE_SEPARATELY module test14901; import imports.test14901c; import imports.test14901d; extern(C) __gshared static int initCount; extern(C) int printf(const char*, ...); void main() { caller1(); caller2(); assert(initCount == 1); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testarray.d0000644000175000017500000000560513200164642023600 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: import core.memory; // see http://forum.dlang.org/thread/4BB6296E.6050506@digitalmars.com for more info // failure case for bug fixed by druntime rev 282 // how it works: // The erroneous code used the first element in the LRU cache to determine the // length of the block, instead of looking at the current blocks blockinfo. So // we need a somewhat alignment of moons to get this to fail. First, we create // the perfect storm: 1) a long blockinfo at the beginning (size = 32), 2) the // second blockinfo is smaller (16 bytes) and 3) a block of memory that is // exactly 16 bytes past the element in the 2nd block. While this seems kind // of unlikely, in code that uses a lot of appending, it can easily happen. // // The bug causes the array appender to think that a pointer in the 16 bytes // past the second blockinfo is actually in the second blockinfo. This is // because it uses the length from the first blockinfo for checking (which is // 32, so since the pointer is only 16 bytes into the block, it is considered // inside). // On top of all this, the third block must be marked as containing pointers, // and the second block not containing pointers. The reason is because, it's // impossible for the runtime to append in place, since the outside pointer // can't possibly match the array length in the block. But because the runtime // copies the blockinfo's attributes when reallocating, it copies the // attributes from the *wrong* block. The only way to make this cause a // problem would be to then collect memory, which should incorrectly deallocate // data that the array containing pointers points to, and then use those // pointers. However, for our purposes, we know this is possible, but we can // deterministically check the attributes of the array after appending and // verify that they are wrong. // void main() { // fill up the cache to make it wrap, The block info cache has 8 elements, // and the first element is not the first one filled, so we want to wrap to // that first element we want to fill in for(int i = 0; i < 7; i++) { auto n = new int[1]; n ~= 1; } // this will allocate a 32-byte block, and appending will insert it into // the cache at the beginning. auto y = new int[4]; y ~= 1; // now, allocate a 16 byte block with pointers, this will be our block that // gets corrupted. The current GC allocates down, so we allocate this one // first. auto x = new char[][1]; // this block contains no pointers, and appending will insert it into the // second element of the cache y = new int[1]; y ~= 1; // verify the noscan flag is 0 on the pointer-containing blocks assert((GC.getAttr(x.ptr) & GC.BlkAttr.NO_SCAN) == 0); x ~= "hello".dup; // this should leave the attributes alone assert((GC.getAttr(x.ptr) & GC.BlkAttr.NO_SCAN) == 0); // fails on 2.042 } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test32.d0000644000175000017500000000023213200164642022675 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test32a.d // PERMUTE_ARGS: import imports.test32a; void main() { assert(S.sizeof == int.sizeof); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_enum.d0000644000175000017500000000067113200164642023346 0ustar matthiasmatthiasmodule ldc_enum; enum EF : float { a = 1.1, b = 1, c = 2 } enum ED : double { a = 1.2, b, c } auto test1_a() { auto t = typeid(EF); assert(t.name == "ldc_enum.EF"); auto init = *cast(float*)t.init.ptr; assert(init == 1.1f); } auto test1_b() { auto t = typeid(ED); assert(t.name == "ldc_enum.ED"); auto init = *cast(double*)t.init.ptr; assert(init == 1.2); } void main() { test1_a(); test1_b(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link13043.d0000644000175000017500000000014113200164642023100 0ustar matthiasmatthias// PERMUTE_ARGS: -g -inline -version=bug -release -O import imports.link13043a; void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testmodule.d0000644000175000017500000000056413200164642023746 0ustar matthiasmatthias// PERMUTE_ARGS: // $HeadURL$ // $Date$ // $Author$ // @author@ Anders F Björklund // @date@ 2005-01-25 // @uri@ news:ct428n$2qoe$1@digitaldaemon.com // @url@ nntp://news.digitalmars.com/D.gnu/983 module dstress.run.unicode_06_哪里; int 哪里(int ö){ return ö+2; } int main(){ assert(dstress.run.unicode_06_哪里.哪里(2)==4); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extern1.d0000644000175000017500000000031013200164642023134 0ustar matthiasmatthias// note: not actually imported, just built and linked against // EXTRA_SOURCES: imports/extern1a.d // PERMUTE_ARGS: extern (C) { extern int x; } int main() { assert(x == 3); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_no_gc.d0000644000175000017500000000106613200164642023466 0ustar matthiasmatthias// REQUIRED_ARGS: -nogc // None of the below array literals should be allocated on the GC heap. void arrayLiterals() { int[3] x = [1, 2, 3]; if (x[2] != 3) assert(0); auto a = 4; int[3] y = [1, 2, a]; if (y[2] != 4) assert(0); immutable int[] z = [1, 2, 3]; if (z[2] != 3) assert(0); } // Enums shouldn't actually be emitted as variable declarations (see GitHub // issue #762). void noEmitEnum() { foreach (i; 0 .. 10000) { enum sortedIDs = [2, 4, 1, 5, 7]; } } void main() { arrayLiterals(); noEmitEnum(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link14541.d0000644000175000017500000000377613200164642023125 0ustar matthiasmatthiasimport imports.link14541traits; void main() { Tuple!(int, int) result; alias T = typeof(result); static assert(hasElaborateAssign!T); // hasElaborateAssign!(Tuple(int, int)): // 1. instantiates Tuple!(int, int).opAssign!(Tuple!(int, int)) [auto ref = Rvalue] // 2. instantiates swap!(Tuple!(int, int)) // 3. instantiates hasElaborateAssign!(Tuple!(int, int)) // --> forward reference error // --> swap!(Tuple!(int, int)) fails to instantiate // --> Tuple!(int, int).opAssign!(Tuple!(int, int)) [auto ref = rvalue] fails to instantiate // 4. instantiates Tuple!(int, int).opAssign!(Tuple!(int, int)) [auto ref = Lvalue] // --> succeeds // hasElaborateAssign!(Tuple(int, int)) succeeds to instantiate (result is 'true') // Instantiates Tuple!(int, int).opAssign!(Tuple!(int, int)) [auto ref = Rvalue], but // it's already done in gagged context, so this is made an error reproduction instantiation. // But, the forward reference of hasElaborateAssign!(Tuple(int, int)) is already resolved, so // the instantiation will succeeds. result = Tuple!(int, int)(0, 0); // --> 1st error reproduction instantiation result = Tuple!(int, int)(0, 0); // --> 2nd error reproduction instantiation // The two error reproduction instantiations generate the function: // Tuple!(int, int).opAssign!(Tuple!(int, int)) [auto ref = Rvalue] // twice, then it will cause duplicate COMDAT error in Win64 platform. } /+ The point is, if instantiated contexts are different, two instantiations may cause different result. - The 1st Tuple.opAssign instantiation is invoked from hasElaborateAssign template with gagging. So it has failed, because of the circular reference of hasElaborateAssign template.. - The 2nd Tuple.opAssign instantiation is invoked from main() without gagging. It does not have circular reference, so the instantiation should succeed. Therefore, the gagged failure should be overridden by the ungagged success. +/ ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test16.d0000644000175000017500000001241713200164642022707 0ustar matthiasmatthias// REQUIRED_ARGS: extern(C) int printf(const char*, ...); /************************************************/ // These seem to be the original tests for $ (originally 'length'). int x; int[] bar(int[] a) { x++; return a[0 .. $ - 1]; } void test1() { { int[4] foo; foo[$ - 2] = 4; assert(foo[0] == 0); assert(foo[1] == 0); assert(foo[2] == 4); assert(foo[3] == 0); foo[3] = 5; assert(foo[$ - 1] == 5); x = 0; bar(foo)[$ - 3] = 6; assert(x == 1); assert(foo[0] == 6); assert(bar(foo)[$ * 2 - 1 - $] == 4); assert(x == 2); foo[0 .. $] = 1; assert(foo[0] == 1); assert(foo[1] == 1); assert(foo[2] == 1); assert(foo[3] == 1); x = 0; bar(foo)[1 .. $ * 3 - $ - $] = 2; assert(x == 1); assert(foo[0] == 1); assert(foo[1] == 2); assert(foo[2] == 2); assert(foo[3] == 1); int[] a = new int[3]; a[0..$] = foo[0..$-1]; assert(a[0] == 1); assert(a[1] == 2); assert(a[2] == 2); a[] = 4; a[0..$] = bar(foo)[0..$]; assert(x == 2); assert(a[0] == 1); assert(a[1] == 2); assert(a[2] == 2); } { int[4] f; int[] foo = f; foo[$ - 2] = 4; assert(foo[0] == 0); assert(foo[1] == 0); assert(foo[2] == 4); assert(foo[3] == 0); foo[3] = 5; assert(foo[$ - 1] == 5); x = 0; bar(foo)[$ - 3] = 6; assert(x == 1); assert(foo[0] == 6); assert(bar(foo)[$ * 2 - 1 - $] == 4); assert(x == 2); foo[0 .. $] = 1; assert(foo[0] == 1); assert(foo[1] == 1); assert(foo[2] == 1); assert(foo[3] == 1); x = 0; bar(foo)[1 .. $ * 3 - $ - $] = 2; assert(x == 1); assert(foo[0] == 1); assert(foo[1] == 2); assert(foo[2] == 2); assert(foo[3] == 1); int[] a = new int[3]; a[0..$] = foo[0..$-1]; assert(a[0] == 1); assert(a[1] == 2); assert(a[2] == 2); a[] = 4; a[0..$] = bar(foo)[0..$]; assert(x == 2); assert(a[0] == 1); assert(a[1] == 2); assert(a[2] == 2); } } /************************************************/ struct ICONINFO { bool fIcon; } void test2() { ICONINFO info; info.fIcon = true; assert(info.fIcon == true); } /************************************************/ class A3 { void foo() { printf("A.foo \n" ); } } class B3 : A3 { } class C3 : B3 { override void foo() { printf("C.foo \n" ); super.foo(); } } void test3() { C3 c = new C3(); c.foo(); } /************************************************/ void test4() { int function (int i) x = function int (int i) { return i * 2; }; int function (int i) y = function int (int i) { return i / 2; }; int k; k = x(2); assert(k == 4); k = y(3); assert(k == 1); } /************************************************/ class Parser { void next(ref int test) { void work (int input) { printf("work(%d, %d)\n", input, test); test = 2; } test = 3; work(4); } } void test5() { Parser parser = new Parser(); int test; parser.next (test); printf("test %d\n", test); assert(test == 2); } /************************************************/ void foo6(out int bar) { } void test6() { int bar = 3; foo6(bar); printf("%d", bar ); assert(bar == 0); // return 0; } /************************************************/ void test7() { char ch = ' '; char[] u; u.length = 3; int i = 2; printf("a\n"); u[0..2] = ch; printf("b\n"); u[0..i] = ch; printf("c\n"); assert(u[0] == 0x20); assert(u[1] == 0x20); } /************************************************/ struct X8 { bool flag; } void test8() { X8 x; x.flag = 0 != 0; } /************************************************/ void foo9(float x) { assert(x == 0.0f); } void len9(float x, float y, float z, float t) { foo9(x*x+y*y+z*z); } void test9() { float[4] a; a[0] = a[1] = a[2] = a[3] = 0.0f; for (int y = 0; y < 7; ++y) { len9(a[0], a[1], a[2], a[3]); float justOne() { return 1.0f; } float dot = justOne(); if (dot < 0.0f) dot = 0.0f; } } /************************************************/ ubyte[4] arr10; void foo10() { *cast(float*)(&arr10[0]) = 3.25; } uint bar10() { uint result = *cast(uint*)&arr10[0]; return result; } float baz10() { uint result = bar10(); return *cast(float*)&result; } void test10() { foo10(); float x = baz10(); assert(x == 3.25); } /************************************************/ interface I11 { void M (); } interface J11 : I11 { void N (); } class A11 : I11 { void M () { printf("A.M()\n"); } } class B11 : A11, J11 { void N () { printf("B.N()\n"); } } void test11() { I11 f = new B11 (); f.M(); } /************************************************/ int x12; void test12() { static class S { static this() { printf ("static constructor\n"); x12 += 1; } this() { printf ("class constructor\n"); x12 += 10; } } assert(x12 == 1); new S; assert(x12 == 11); } /************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/traits.d0000644000175000017500000013763213200164642023076 0ustar matthiasmatthias// PERMUTE_ARGS: module traits; import std.stdio; alias int myint; struct S { void bar() { } int x = 4; static int z = 5; } class C { void bar() { } final void foo() { } static void abc() { } } abstract class AC { } class AC2 { abstract void foo(); } class AC3 : AC2 { } final class FC { void foo() { } } enum E { EMEM } /********************************************************/ void test1() { auto t = __traits(isArithmetic, int); writeln(t); assert(t == true); assert(__traits(isArithmetic) == false); assert(__traits(isArithmetic, myint) == true); assert(__traits(isArithmetic, S) == false); assert(__traits(isArithmetic, C) == false); assert(__traits(isArithmetic, E) == true); assert(__traits(isArithmetic, void*) == false); assert(__traits(isArithmetic, void[]) == false); assert(__traits(isArithmetic, void[3]) == false); assert(__traits(isArithmetic, int[char]) == false); assert(__traits(isArithmetic, int, int) == true); assert(__traits(isArithmetic, int, S) == false); assert(__traits(isArithmetic, void) == false); assert(__traits(isArithmetic, byte) == true); assert(__traits(isArithmetic, ubyte) == true); assert(__traits(isArithmetic, short) == true); assert(__traits(isArithmetic, ushort) == true); assert(__traits(isArithmetic, int) == true); assert(__traits(isArithmetic, uint) == true); assert(__traits(isArithmetic, long) == true); assert(__traits(isArithmetic, ulong) == true); assert(__traits(isArithmetic, float) == true); assert(__traits(isArithmetic, double) == true); assert(__traits(isArithmetic, real) == true); assert(__traits(isArithmetic, ifloat) == true); assert(__traits(isArithmetic, idouble) == true); assert(__traits(isArithmetic, ireal) == true); assert(__traits(isArithmetic, cfloat) == true); assert(__traits(isArithmetic, cdouble) == true); assert(__traits(isArithmetic, creal) == true); assert(__traits(isArithmetic, char) == true); assert(__traits(isArithmetic, wchar) == true); assert(__traits(isArithmetic, dchar) == true); int i; assert(__traits(isArithmetic, i, i+1, int) == true); assert(__traits(isArithmetic) == false); } /********************************************************/ void test2() { auto t = __traits(isScalar, int); writeln(t); assert(t == true); assert(__traits(isScalar) == false); assert(__traits(isScalar, myint) == true); assert(__traits(isScalar, S) == false); assert(__traits(isScalar, C) == false); assert(__traits(isScalar, E) == true); assert(__traits(isScalar, void*) == true); assert(__traits(isScalar, void[]) == false); assert(__traits(isScalar, void[3]) == false); assert(__traits(isScalar, int[char]) == false); assert(__traits(isScalar, int, int) == true); assert(__traits(isScalar, int, S) == false); assert(__traits(isScalar, void) == false); assert(__traits(isScalar, byte) == true); assert(__traits(isScalar, ubyte) == true); assert(__traits(isScalar, short) == true); assert(__traits(isScalar, ushort) == true); assert(__traits(isScalar, int) == true); assert(__traits(isScalar, uint) == true); assert(__traits(isScalar, long) == true); assert(__traits(isScalar, ulong) == true); assert(__traits(isScalar, float) == true); assert(__traits(isScalar, double) == true); assert(__traits(isScalar, real) == true); assert(__traits(isScalar, ifloat) == true); assert(__traits(isScalar, idouble) == true); assert(__traits(isScalar, ireal) == true); assert(__traits(isScalar, cfloat) == true); assert(__traits(isScalar, cdouble) == true); assert(__traits(isScalar, creal) == true); assert(__traits(isScalar, char) == true); assert(__traits(isScalar, wchar) == true); assert(__traits(isScalar, dchar) == true); } /********************************************************/ void test3() { assert(__traits(isIntegral) == false); assert(__traits(isIntegral, myint) == true); assert(__traits(isIntegral, S) == false); assert(__traits(isIntegral, C) == false); assert(__traits(isIntegral, E) == true); assert(__traits(isIntegral, void*) == false); assert(__traits(isIntegral, void[]) == false); assert(__traits(isIntegral, void[3]) == false); assert(__traits(isIntegral, int[char]) == false); assert(__traits(isIntegral, int, int) == true); assert(__traits(isIntegral, int, S) == false); assert(__traits(isIntegral, void) == false); assert(__traits(isIntegral, byte) == true); assert(__traits(isIntegral, ubyte) == true); assert(__traits(isIntegral, short) == true); assert(__traits(isIntegral, ushort) == true); assert(__traits(isIntegral, int) == true); assert(__traits(isIntegral, uint) == true); assert(__traits(isIntegral, long) == true); assert(__traits(isIntegral, ulong) == true); assert(__traits(isIntegral, float) == false); assert(__traits(isIntegral, double) == false); assert(__traits(isIntegral, real) == false); assert(__traits(isIntegral, ifloat) == false); assert(__traits(isIntegral, idouble) == false); assert(__traits(isIntegral, ireal) == false); assert(__traits(isIntegral, cfloat) == false); assert(__traits(isIntegral, cdouble) == false); assert(__traits(isIntegral, creal) == false); assert(__traits(isIntegral, char) == true); assert(__traits(isIntegral, wchar) == true); assert(__traits(isIntegral, dchar) == true); } /********************************************************/ void test4() { assert(__traits(isFloating) == false); assert(__traits(isFloating, S) == false); assert(__traits(isFloating, C) == false); assert(__traits(isFloating, E) == false); assert(__traits(isFloating, void*) == false); assert(__traits(isFloating, void[]) == false); assert(__traits(isFloating, void[3]) == false); assert(__traits(isFloating, int[char]) == false); assert(__traits(isFloating, float, float) == true); assert(__traits(isFloating, float, S) == false); assert(__traits(isFloating, void) == false); assert(__traits(isFloating, byte) == false); assert(__traits(isFloating, ubyte) == false); assert(__traits(isFloating, short) == false); assert(__traits(isFloating, ushort) == false); assert(__traits(isFloating, int) == false); assert(__traits(isFloating, uint) == false); assert(__traits(isFloating, long) == false); assert(__traits(isFloating, ulong) == false); assert(__traits(isFloating, float) == true); assert(__traits(isFloating, double) == true); assert(__traits(isFloating, real) == true); assert(__traits(isFloating, ifloat) == true); assert(__traits(isFloating, idouble) == true); assert(__traits(isFloating, ireal) == true); assert(__traits(isFloating, cfloat) == true); assert(__traits(isFloating, cdouble) == true); assert(__traits(isFloating, creal) == true); assert(__traits(isFloating, char) == false); assert(__traits(isFloating, wchar) == false); assert(__traits(isFloating, dchar) == false); } /********************************************************/ void test5() { assert(__traits(isUnsigned) == false); assert(__traits(isUnsigned, S) == false); assert(__traits(isUnsigned, C) == false); assert(__traits(isUnsigned, E) == false); assert(__traits(isUnsigned, void*) == false); assert(__traits(isUnsigned, void[]) == false); assert(__traits(isUnsigned, void[3]) == false); assert(__traits(isUnsigned, int[char]) == false); assert(__traits(isUnsigned, float, float) == false); assert(__traits(isUnsigned, float, S) == false); assert(__traits(isUnsigned, void) == false); assert(__traits(isUnsigned, byte) == false); assert(__traits(isUnsigned, ubyte) == true); assert(__traits(isUnsigned, short) == false); assert(__traits(isUnsigned, ushort) == true); assert(__traits(isUnsigned, int) == false); assert(__traits(isUnsigned, uint) == true); assert(__traits(isUnsigned, long) == false); assert(__traits(isUnsigned, ulong) == true); assert(__traits(isUnsigned, float) == false); assert(__traits(isUnsigned, double) == false); assert(__traits(isUnsigned, real) == false); assert(__traits(isUnsigned, ifloat) == false); assert(__traits(isUnsigned, idouble) == false); assert(__traits(isUnsigned, ireal) == false); assert(__traits(isUnsigned, cfloat) == false); assert(__traits(isUnsigned, cdouble) == false); assert(__traits(isUnsigned, creal) == false); assert(__traits(isUnsigned, char) == true); assert(__traits(isUnsigned, wchar) == true); assert(__traits(isUnsigned, dchar) == true); } /********************************************************/ void test6() { assert(__traits(isAssociativeArray) == false); assert(__traits(isAssociativeArray, S) == false); assert(__traits(isAssociativeArray, C) == false); assert(__traits(isAssociativeArray, E) == false); assert(__traits(isAssociativeArray, void*) == false); assert(__traits(isAssociativeArray, void[]) == false); assert(__traits(isAssociativeArray, void[3]) == false); assert(__traits(isAssociativeArray, int[char]) == true); assert(__traits(isAssociativeArray, float, float) == false); assert(__traits(isAssociativeArray, float, S) == false); assert(__traits(isAssociativeArray, void) == false); assert(__traits(isAssociativeArray, byte) == false); assert(__traits(isAssociativeArray, ubyte) == false); assert(__traits(isAssociativeArray, short) == false); assert(__traits(isAssociativeArray, ushort) == false); assert(__traits(isAssociativeArray, int) == false); assert(__traits(isAssociativeArray, uint) == false); assert(__traits(isAssociativeArray, long) == false); assert(__traits(isAssociativeArray, ulong) == false); assert(__traits(isAssociativeArray, float) == false); assert(__traits(isAssociativeArray, double) == false); assert(__traits(isAssociativeArray, real) == false); assert(__traits(isAssociativeArray, ifloat) == false); assert(__traits(isAssociativeArray, idouble) == false); assert(__traits(isAssociativeArray, ireal) == false); assert(__traits(isAssociativeArray, cfloat) == false); assert(__traits(isAssociativeArray, cdouble) == false); assert(__traits(isAssociativeArray, creal) == false); assert(__traits(isAssociativeArray, char) == false); assert(__traits(isAssociativeArray, wchar) == false); assert(__traits(isAssociativeArray, dchar) == false); } /********************************************************/ void test7() { assert(__traits(isStaticArray) == false); assert(__traits(isStaticArray, S) == false); assert(__traits(isStaticArray, C) == false); assert(__traits(isStaticArray, E) == false); assert(__traits(isStaticArray, void*) == false); assert(__traits(isStaticArray, void[]) == false); assert(__traits(isStaticArray, void[3]) == true); assert(__traits(isStaticArray, int[char]) == false); assert(__traits(isStaticArray, float, float) == false); assert(__traits(isStaticArray, float, S) == false); assert(__traits(isStaticArray, void) == false); assert(__traits(isStaticArray, byte) == false); assert(__traits(isStaticArray, ubyte) == false); assert(__traits(isStaticArray, short) == false); assert(__traits(isStaticArray, ushort) == false); assert(__traits(isStaticArray, int) == false); assert(__traits(isStaticArray, uint) == false); assert(__traits(isStaticArray, long) == false); assert(__traits(isStaticArray, ulong) == false); assert(__traits(isStaticArray, float) == false); assert(__traits(isStaticArray, double) == false); assert(__traits(isStaticArray, real) == false); assert(__traits(isStaticArray, ifloat) == false); assert(__traits(isStaticArray, idouble) == false); assert(__traits(isStaticArray, ireal) == false); assert(__traits(isStaticArray, cfloat) == false); assert(__traits(isStaticArray, cdouble) == false); assert(__traits(isStaticArray, creal) == false); assert(__traits(isStaticArray, char) == false); assert(__traits(isStaticArray, wchar) == false); assert(__traits(isStaticArray, dchar) == false); } /********************************************************/ void test8() { assert(__traits(isAbstractClass) == false); assert(__traits(isAbstractClass, S) == false); assert(__traits(isAbstractClass, C) == false); assert(__traits(isAbstractClass, AC) == true); assert(__traits(isAbstractClass, E) == false); assert(__traits(isAbstractClass, void*) == false); assert(__traits(isAbstractClass, void[]) == false); assert(__traits(isAbstractClass, void[3]) == false); assert(__traits(isAbstractClass, int[char]) == false); assert(__traits(isAbstractClass, float, float) == false); assert(__traits(isAbstractClass, float, S) == false); assert(__traits(isAbstractClass, void) == false); assert(__traits(isAbstractClass, byte) == false); assert(__traits(isAbstractClass, ubyte) == false); assert(__traits(isAbstractClass, short) == false); assert(__traits(isAbstractClass, ushort) == false); assert(__traits(isAbstractClass, int) == false); assert(__traits(isAbstractClass, uint) == false); assert(__traits(isAbstractClass, long) == false); assert(__traits(isAbstractClass, ulong) == false); assert(__traits(isAbstractClass, float) == false); assert(__traits(isAbstractClass, double) == false); assert(__traits(isAbstractClass, real) == false); assert(__traits(isAbstractClass, ifloat) == false); assert(__traits(isAbstractClass, idouble) == false); assert(__traits(isAbstractClass, ireal) == false); assert(__traits(isAbstractClass, cfloat) == false); assert(__traits(isAbstractClass, cdouble) == false); assert(__traits(isAbstractClass, creal) == false); assert(__traits(isAbstractClass, char) == false); assert(__traits(isAbstractClass, wchar) == false); assert(__traits(isAbstractClass, dchar) == false); assert(__traits(isAbstractClass, AC2) == true); assert(__traits(isAbstractClass, AC3) == true); } /********************************************************/ void test9() { assert(__traits(isFinalClass) == false); assert(__traits(isFinalClass, C) == false); assert(__traits(isFinalClass, FC) == true); } /********************************************************/ void test10() { assert(__traits(isVirtualFunction, C.bar) == true); assert(__traits(isVirtualFunction, S.bar) == false); } /********************************************************/ void test11() { assert(__traits(isAbstractFunction, C.bar) == false); assert(__traits(isAbstractFunction, S.bar) == false); assert(__traits(isAbstractFunction, AC2.foo) == true); } /********************************************************/ void test12() { assert(__traits(isFinalFunction, C.bar) == false); assert(__traits(isFinalFunction, S.bar) == false); assert(__traits(isFinalFunction, AC2.foo) == false); assert(__traits(isFinalFunction, FC.foo) == true); assert(__traits(isFinalFunction, C.foo) == true); } /********************************************************/ void test13() { S s; __traits(getMember, s, "x") = 7; auto i = __traits(getMember, s, "x"); assert(i == 7); auto j = __traits(getMember, S, "z"); assert(j == 5); writeln(__traits(hasMember, s, "x")); assert(__traits(hasMember, s, "x") == true); assert(__traits(hasMember, S, "z") == true); assert(__traits(hasMember, S, "aaa") == false); auto k = __traits(classInstanceSize, C); writeln(k); assert(k == C.classinfo.init.length); } /********************************************************/ // 7123 private struct DelegateFaker7123(F) { template GeneratingPolicy() {} enum WITH_BASE_CLASS = __traits(hasMember, GeneratingPolicy!(), "x"); } auto toDelegate7123(F)(F fp) { alias DelegateFaker7123!F Faker; } void test7123() { static assert(is(typeof(toDelegate7123(&main)))); } /********************************************************/ class D14 { this() { } ~this() { } void foo() { } int foo(int) { return 0; } } void test14() { auto a = [__traits(derivedMembers, D14)]; writeln(a); assert(a == ["__ctor","__dtor","foo", "__xdtor"]); } /********************************************************/ class D15 { this() { } ~this() { } void foo() { } int foo(int) { return 2; } } void test15() { D15 d = new D15(); foreach (t; __traits(getVirtualFunctions, D15, "foo")) writeln(typeid(typeof(t))); alias typeof(__traits(getVirtualFunctions, D15, "foo")) b; foreach (t; b) writeln(typeid(t)); auto i = __traits(getVirtualFunctions, d, "foo")[1](1); assert(i == 2); } /********************************************************/ struct S16 { } int foo16(); int bar16(); void test16() { assert(__traits(isSame, foo16, foo16) == true); assert(__traits(isSame, foo16, bar16) == false); assert(__traits(isSame, foo16, S16) == false); assert(__traits(isSame, S16, S16) == true); assert(__traits(isSame, std, S16) == false); assert(__traits(isSame, std, std) == true); } /********************************************************/ struct S17 { static int s1; int s2; } int foo17(); void test17() { assert(__traits(compiles) == false); assert(__traits(compiles, foo17) == true); assert(__traits(compiles, foo17 + 1) == true); assert(__traits(compiles, &foo17 + 1) == false); assert(__traits(compiles, typeof(1)) == true); assert(__traits(compiles, S17.s1) == true); assert(__traits(compiles, S17.s3) == false); assert(__traits(compiles, 1,2,3,int,long,std) == true); assert(__traits(compiles, 3[1]) == false); assert(__traits(compiles, 1,2,3,int,long,3[1]) == false); } /********************************************************/ interface D18 { extern(Windows): void foo(); int foo(int); } void test18() { auto a = __traits(allMembers, D18); writeln(a); assert(a.length == 1); } /********************************************************/ class C19 { void mutating_method(){} const void const_method(){} void bastard_method(){} const void bastard_method(int){} } void test19() { auto a = __traits(allMembers, C19); writeln(a); assert(a.length == 9); foreach( m; __traits(allMembers, C19) ) writeln(m); } /********************************************************/ void test20() { void fooref(ref int x) { static assert(__traits(isRef, x)); static assert(!__traits(isOut, x)); static assert(!__traits(isLazy, x)); } void fooout(out int x) { static assert(!__traits(isRef, x)); static assert(__traits(isOut, x)); static assert(!__traits(isLazy, x)); } void foolazy(lazy int x) { static assert(!__traits(isRef, x)); static assert(!__traits(isOut, x)); static assert(__traits(isLazy, x)); } } /********************************************************/ void test21() { assert(__traits(isStaticFunction, C.bar) == false); assert(__traits(isStaticFunction, C.abc) == true); assert(__traits(isStaticFunction, S.bar) == false); } /********************************************************/ class D22 { this() { } ~this() { } void foo() { } int foo(int) { return 2; } } void test22() { D22 d = new D22(); foreach (t; __traits(getOverloads, D22, "foo")) writeln(typeid(typeof(t))); alias typeof(__traits(getOverloads, D22, "foo")) b; foreach (t; b) writeln(typeid(t)); auto i = __traits(getOverloads, d, "foo")[1](1); assert(i == 2); } /********************************************************/ string toString23(E)(E value) if (is(E == enum)) { foreach (s; __traits(allMembers, E)) { if (value == mixin("E." ~ s)) return s; } return null; } enum OddWord { acini, alembicated, prolegomena, aprosexia } void test23() { auto w = OddWord.alembicated; assert(toString23(w) == "alembicated"); } /********************************************************/ struct Test24 { public void test24(int){} private void test24(int, int){} } static assert(__traits(getProtection, __traits(getOverloads, Test24, "test24")[1]) == "private"); /********************************************************/ // 1369 void test1369() { class C1 { static int count; void func() { count++; } } // variable symbol C1 c1 = new C1; __traits(getMember, c1, "func")(); // TypeIdentifier -> VarExp __traits(getMember, mixin("c1"), "func")(); // Expression -> VarExp assert(C1.count == 2); // nested function symbol @property C1 get() { return c1; } __traits(getMember, get, "func")(); __traits(getMember, mixin("get"), "func")(); assert(C1.count == 4); class C2 { C1 c1; this() { c1 = new C1; } void test() { // variable symbol (this.outer.c1) __traits(getMember, c1, "func")(); // TypeIdentifier -> VarExp -> DotVarExp __traits(getMember, mixin("c1"), "func")(); // Expression -> VarExp -> DotVarExp assert(C1.count == 6); // nested function symbol (this.outer.get) __traits(getMember, get, "func")(); __traits(getMember, mixin("get"), "func")(); assert(C1.count == 8); } } C2 c2 = new C2; c2.test(); } /********************************************************/ template Foo2234(){ int x; } struct S2234a{ mixin Foo2234; } struct S2234b{ mixin Foo2234; mixin Foo2234; } struct S2234c{ alias Foo2234!() foo; } static assert([__traits(allMembers, S2234a)] == ["x"]); static assert([__traits(allMembers, S2234b)] == ["x"]); static assert([__traits(allMembers, S2234c)] == ["foo"]); /********************************************************/ // 5878 template J5878(A) { static if (is(A P == super)) alias P J5878; } alias J5878!(A5878) Z5878; class X5878 {} class A5878 : X5878 {} /********************************************************/ mixin template Members6674() { static int i1; static int i2; static int i3; //comment out to make func2 visible static int i4; //comment out to make func1 visible } class Test6674 { mixin Members6674; alias void function() func1; alias bool function() func2; } static assert([__traits(allMembers,Test6674)] == [ "i1","i2","i3","i4", "func1","func2", "toString","toHash","opCmp","opEquals","Monitor","factory"]); /********************************************************/ // 6073 struct S6073 {} template T6073(M...) { //alias int T; } alias T6073!traits V6073; // ok alias T6073!(__traits(parent, S6073)) U6073; // error static assert(__traits(isSame, V6073, U6073)); // same instantiation == same arguemnts /********************************************************/ // 7027 struct Foo7027 { int a; } static assert(!__traits(compiles, { return Foo7027.a; })); /********************************************************/ // 9213 class Foo9213 { int a; } static assert(!__traits(compiles, { return Foo9213.a; })); /********************************************************/ interface AA { int YYY(); } class CC : AA { final int YYY() { return 4; } } static assert(__traits(isVirtualMethod, CC.YYY)); static assert(__traits(getVirtualMethods, CC, "YYY").length == 1); class DD { final int YYY() { return 4; } } static assert(__traits(isVirtualMethod, DD.YYY) == false); static assert(__traits(getVirtualMethods, DD, "YYY").length == 0); class EE { int YYY() { return 0; } } class FF : EE { final override int YYY() { return 4; } } static assert(__traits(isVirtualMethod, FF.YYY)); static assert(__traits(getVirtualMethods, FF, "YYY").length == 1); /********************************************************/ // 7608 struct S7608a(bool T) { static if (T) { int x; } int y; } struct S7608b { version(none) { int x; } int y; } template TypeTuple7608(T...){ alias T TypeTuple7608; } void test7608() { alias TypeTuple7608!(__traits(allMembers, S7608a!false)) MembersA; static assert(MembersA.length == 1); static assert(MembersA[0] == "y"); alias TypeTuple7608!(__traits(allMembers, S7608b)) MembersB; static assert(MembersB.length == 1); static assert(MembersB[0] == "y"); } /********************************************************/ // 7858 void test7858() { class C { final void ffunc(){} final void ffunc(int){} void vfunc(){} void vfunc(int){} abstract void afunc(); abstract void afunc(int); static void sfunc(){} static void sfunc(int){} } static assert(__traits(isFinalFunction, C.ffunc) == __traits(isFinalFunction, __traits(getOverloads, C, "ffunc")[0])); // NG static assert(__traits(isVirtualFunction, C.vfunc) == __traits(isVirtualFunction, __traits(getOverloads, C, "vfunc")[0])); // NG static assert(__traits(isVirtualMethod, C.vfunc) == __traits(isVirtualMethod, __traits(getOverloads, C, "vfunc")[0])); // NG static assert(__traits(isAbstractFunction, C.afunc) == __traits(isAbstractFunction, __traits(getOverloads, C, "afunc")[0])); // OK static assert(__traits(isStaticFunction, C.sfunc) == __traits(isStaticFunction, __traits(getOverloads, C, "sfunc")[0])); // OK static assert(__traits(isSame, C.ffunc, __traits(getOverloads, C, "ffunc")[0])); // NG static assert(__traits(isSame, C.vfunc, __traits(getOverloads, C, "vfunc")[0])); // NG static assert(__traits(isSame, C.afunc, __traits(getOverloads, C, "afunc")[0])); // NG static assert(__traits(isSame, C.sfunc, __traits(getOverloads, C, "sfunc")[0])); // NG } /********************************************************/ // 8971 template Tuple8971(TL...){ alias TL Tuple8971; } class A8971 { void bar() {} void connect() { alias Tuple8971!(__traits(getOverloads, typeof(this), "bar")) overloads; static assert(__traits(isSame, overloads[0], bar)); } } /********************************************************/ // 8972 struct A8972 { void foo() {} void connect() { alias Tuple8971!(__traits(getOverloads, typeof(this), "foo")) overloads; static assert(__traits(isSame, overloads[0], foo)); } } /********************************************************/ private struct TestProt1 {} package struct TestProt2 {} protected struct TestProt3 {} public struct TestProt4 {} export struct TestProt5 {} void getProtection() { class Test { private { int va; void fa(){} } package { int vb; void fb(){} } protected { int vc; void fc(){} } public { int vd; void fd(){} } export { int ve; void fe(){} } } Test t; // TOKvar and VarDeclaration static assert(__traits(getProtection, Test.va) == "private"); static assert(__traits(getProtection, Test.vb) == "package"); static assert(__traits(getProtection, Test.vc) == "protected"); static assert(__traits(getProtection, Test.vd) == "public"); static assert(__traits(getProtection, Test.ve) == "export"); // TOKdotvar and VarDeclaration static assert(__traits(getProtection, t.va) == "private"); static assert(__traits(getProtection, t.vb) == "package"); static assert(__traits(getProtection, t.vc) == "protected"); static assert(__traits(getProtection, t.vd) == "public"); static assert(__traits(getProtection, t.ve) == "export"); // TOKvar and FuncDeclaration static assert(__traits(getProtection, Test.fa) == "private"); static assert(__traits(getProtection, Test.fb) == "package"); static assert(__traits(getProtection, Test.fc) == "protected"); static assert(__traits(getProtection, Test.fd) == "public"); static assert(__traits(getProtection, Test.fe) == "export"); // TOKdotvar and FuncDeclaration static assert(__traits(getProtection, t.fa) == "private"); static assert(__traits(getProtection, t.fb) == "package"); static assert(__traits(getProtection, t.fc) == "protected"); static assert(__traits(getProtection, t.fd) == "public"); static assert(__traits(getProtection, t.fe) == "export"); // TOKtype static assert(__traits(getProtection, TestProt1) == "private"); static assert(__traits(getProtection, TestProt2) == "package"); static assert(__traits(getProtection, TestProt3) == "protected"); static assert(__traits(getProtection, TestProt4) == "public"); static assert(__traits(getProtection, TestProt5) == "export"); // This specific pattern is important to ensure it always works // through reflection, however that becomes implemented static assert(__traits(getProtection, __traits(getMember, t, "va")) == "private"); static assert(__traits(getProtection, __traits(getMember, t, "vb")) == "package"); static assert(__traits(getProtection, __traits(getMember, t, "vc")) == "protected"); static assert(__traits(getProtection, __traits(getMember, t, "vd")) == "public"); static assert(__traits(getProtection, __traits(getMember, t, "ve")) == "export"); static assert(__traits(getProtection, __traits(getMember, t, "fa")) == "private"); static assert(__traits(getProtection, __traits(getMember, t, "fb")) == "package"); static assert(__traits(getProtection, __traits(getMember, t, "fc")) == "protected"); static assert(__traits(getProtection, __traits(getMember, t, "fd")) == "public"); static assert(__traits(getProtection, __traits(getMember, t, "fe")) == "export"); } /********************************************************/ // 9546 void test9546() { import imports.a9546; S s; static assert(__traits(getProtection, s.privA) == "private"); static assert(__traits(getProtection, s.protA) == "protected"); static assert(__traits(getProtection, s.packA) == "package"); static assert(__traits(getProtection, S.privA) == "private"); static assert(__traits(getProtection, S.protA) == "protected"); static assert(__traits(getProtection, S.packA) == "package"); static assert(__traits(getProtection, mixin("s.privA")) == "private"); static assert(__traits(getProtection, mixin("s.protA")) == "protected"); static assert(__traits(getProtection, mixin("s.packA")) == "package"); static assert(__traits(getProtection, mixin("S.privA")) == "private"); static assert(__traits(getProtection, mixin("S.protA")) == "protected"); static assert(__traits(getProtection, mixin("S.packA")) == "package"); static assert(__traits(getProtection, __traits(getMember, s, "privA")) == "private"); static assert(__traits(getProtection, __traits(getMember, s, "protA")) == "protected"); static assert(__traits(getProtection, __traits(getMember, s, "packA")) == "package"); static assert(__traits(getProtection, __traits(getMember, S, "privA")) == "private"); static assert(__traits(getProtection, __traits(getMember, S, "protA")) == "protected"); static assert(__traits(getProtection, __traits(getMember, S, "packA")) == "package"); static assert(__traits(getProtection, s.privF) == "private"); static assert(__traits(getProtection, s.protF) == "protected"); static assert(__traits(getProtection, s.packF) == "package"); static assert(__traits(getProtection, S.privF) == "private"); static assert(__traits(getProtection, S.protF) == "protected"); static assert(__traits(getProtection, S.packF) == "package"); static assert(__traits(getProtection, mixin("s.privF")) == "private"); static assert(__traits(getProtection, mixin("s.protF")) == "protected"); static assert(__traits(getProtection, mixin("s.packF")) == "package"); static assert(__traits(getProtection, mixin("S.privF")) == "private"); static assert(__traits(getProtection, mixin("S.protF")) == "protected"); static assert(__traits(getProtection, mixin("S.packF")) == "package"); static assert(__traits(getProtection, __traits(getMember, s, "privF")) == "private"); static assert(__traits(getProtection, __traits(getMember, s, "protF")) == "protected"); static assert(__traits(getProtection, __traits(getMember, s, "packF")) == "package"); static assert(__traits(getProtection, __traits(getMember, S, "privF")) == "private"); static assert(__traits(getProtection, __traits(getMember, S, "protF")) == "protected"); static assert(__traits(getProtection, __traits(getMember, S, "packF")) == "package"); } /********************************************************/ // 9091 template isVariable9091(X...) if (X.length == 1) { enum isVariable9091 = true; } class C9091 { int x; // some class members void func(int n){ this.x = n; } void test() { alias T = C9091; enum is_x = isVariable9091!(__traits(getMember, T, "x")); foreach (i, m; __traits(allMembers, T)) { enum x = isVariable9091!(__traits(getMember, T, m)); static if (i == 0) // x { __traits(getMember, T, m) = 10; assert(this.x == 10); } static if (i == 1) // func { __traits(getMember, T, m)(20); assert(this.x == 20); } } } } struct S9091 { int x; // some struct members void func(int n){ this.x = n; } void test() { alias T = S9091; enum is_x = isVariable9091!(__traits(getMember, T, "x")); foreach (i, m; __traits(allMembers, T)) { enum x = isVariable9091!(__traits(getMember, T, m)); static if (i == 0) // x { __traits(getMember, T, m) = 10; assert(this.x == 10); } static if (i == 1) // func { __traits(getMember, T, m)(20); assert(this.x == 20); } } } } void test9091() { auto c = new C9091(); c.test(); auto s = S9091(); s.test(); } /********************************************************/ struct CtorS_9237 { this(int x) { } } // ctor -> POD struct DtorS_9237 { ~this() { } } // dtor -> nonPOD struct PostblitS_9237 { this(this) { } } // cpctor -> nonPOD struct NonPOD1_9237 { DtorS_9237 field; // nonPOD -> ng } struct NonPOD2_9237 { DtorS_9237[2] field; // static array of nonPOD -> ng } struct POD1_9237 { DtorS_9237* field; // pointer to nonPOD -> ok } struct POD2_9237 { DtorS_9237[] field; // dynamic array of nonPOD -> ok } struct POD3_9237 { int x = 123; } class C_9273 { } void test9237() { int x; struct NS_9237 // acceses .outer -> nested { void foo() { x++; } } struct NonNS_9237 { } // doesn't access .outer -> non-nested static struct StatNS_9237 { } // can't access .outer -> non-nested static assert(!__traits(isPOD, NS_9237)); static assert(__traits(isPOD, NonNS_9237)); static assert(__traits(isPOD, StatNS_9237)); static assert(__traits(isPOD, CtorS_9237)); static assert(!__traits(isPOD, DtorS_9237)); static assert(!__traits(isPOD, PostblitS_9237)); static assert(!__traits(isPOD, NonPOD1_9237)); static assert(!__traits(isPOD, NonPOD2_9237)); static assert(__traits(isPOD, POD1_9237)); static assert(__traits(isPOD, POD2_9237)); static assert(__traits(isPOD, POD3_9237)); // static array of POD/non-POD types static assert(!__traits(isPOD, NS_9237[2])); static assert(__traits(isPOD, NonNS_9237[2])); static assert(__traits(isPOD, StatNS_9237[2])); static assert(__traits(isPOD, CtorS_9237[2])); static assert(!__traits(isPOD, DtorS_9237[2])); static assert(!__traits(isPOD, PostblitS_9237[2])); static assert(!__traits(isPOD, NonPOD1_9237[2])); static assert(!__traits(isPOD, NonPOD2_9237[2])); static assert(__traits(isPOD, POD1_9237[2])); static assert(__traits(isPOD, POD2_9237[2])); static assert(__traits(isPOD, POD3_9237[2])); // non-structs are POD types static assert(__traits(isPOD, C_9273)); static assert(__traits(isPOD, int)); static assert(__traits(isPOD, int*)); static assert(__traits(isPOD, int[])); static assert(!__traits(compiles, __traits(isPOD, 123) )); } /*************************************************************/ // 5978 void test5978() { () { int x; pragma(msg, __traits(identifier, __traits(parent, x))); } (); } /*************************************************************/ template T7408() { } void test7408() { auto x = T7408!().stringof; auto y = T7408!().mangleof; static assert(__traits(compiles, T7408!().stringof)); static assert(__traits(compiles, T7408!().mangleof)); static assert(!__traits(compiles, T7408!().init)); static assert(!__traits(compiles, T7408!().offsetof)); } /*************************************************************/ // 9552 class C9552 { int f() { return 10; } int f(int n) { return n * 2; } } void test9552() { auto c = new C9552; auto dg1 = &(__traits(getOverloads, c, "f")[0]); // DMD crashes assert(dg1() == 10); auto dg2 = &(__traits(getOverloads, c, "f")[1]); assert(dg2(10) == 20); } /*************************************************************/ void test9136() { int x; struct S1 { void f() { x++; } } struct U1 { void f() { x++; } } static struct S2 { } static struct S3 { S1 s; } static struct U2 { } void f1() { x++; } static void f2() { } static assert(__traits(isNested, S1)); static assert(__traits(isNested, U1)); static assert(!__traits(isNested, S2)); static assert(!__traits(isNested, S3)); static assert(!__traits(isNested, U2)); static assert(!__traits(compiles, __traits(isNested, int) )); static assert(!__traits(compiles, __traits(isNested, f1, f2) )); static assert(__traits(isNested, f1)); static assert(!__traits(isNested, f2)); static class A { static class SC { } class NC { } } static assert(!__traits(isNested, A)); static assert(!__traits(isNested, A.SC)); static assert(__traits(isNested, A.NC)); } /********************************************************/ // 9939 struct Test9939 { int f; enum /*Anonymous enum*/ { A, B } enum NamedEnum { C, D } } static assert([__traits(allMembers, Test9939)] == ["f", "A", "B", "NamedEnum"]); /********************************************************/ // 10043 void test10043() { struct X {} X d1; static assert(!__traits(compiles, d1.structuralCast!Refleshable)); } /********************************************************/ // 10096 struct S10096X { string str; invariant() {} invariant() {} unittest {} this(int) {} this(this) {} ~this() {} } static assert( [__traits(allMembers, S10096X)] == ["str", "__ctor", "__postblit", "__dtor", "__xdtor", "__xpostblit", "opAssign"]); // -------- string foo10096(alias var, T = typeof(var))() { foreach (idx, member; __traits(allMembers, T)) { auto x = var.tupleof[idx]; } return ""; } string foo10096(T)(T var) { return ""; } struct S10096 { int i; string s; } void test10096() { S10096 s = S10096(1, ""); auto x = foo10096!s; } /********************************************************/ unittest { } struct GetUnitTests { unittest { } } void test_getUnitTests () { // Always returns empty tuple if the -unittest flag isn't used static assert(__traits(getUnitTests, mixin(__MODULE__)).length == 0); static assert(__traits(getUnitTests, GetUnitTests).length == 0); } /********************************************************/ void test_getFunctionAttributes() { alias tuple(T...) = T; struct S { int noF() { return 0; } int constF() const { return 0; } int immutableF() immutable { return 0; } int inoutF() inout { return 0; } int sharedF() shared { return 0; } int x; ref int refF() { return x; } int propertyF() @property { return 0; } int nothrowF() nothrow { return 0; } int nogcF() @nogc { return 0; } int systemF() @system { return 0; } int trustedF() @trusted { return 0; } int safeF() @safe { return 0; } int pureF() pure { return 0; } } static assert(__traits(getFunctionAttributes, S.noF) == tuple!("@system")); static assert(__traits(getFunctionAttributes, typeof(S.noF)) == tuple!("@system")); static assert(__traits(getFunctionAttributes, S.constF) == tuple!("const", "@system")); static assert(__traits(getFunctionAttributes, typeof(S.constF)) == tuple!("const", "@system")); static assert(__traits(getFunctionAttributes, S.immutableF) == tuple!("immutable", "@system")); static assert(__traits(getFunctionAttributes, typeof(S.immutableF)) == tuple!("immutable", "@system")); static assert(__traits(getFunctionAttributes, S.inoutF) == tuple!("inout", "@system")); static assert(__traits(getFunctionAttributes, typeof(S.inoutF)) == tuple!("inout", "@system")); static assert(__traits(getFunctionAttributes, S.sharedF) == tuple!("shared", "@system")); static assert(__traits(getFunctionAttributes, typeof(S.sharedF)) == tuple!("shared", "@system")); static assert(__traits(getFunctionAttributes, S.refF) == tuple!("ref", "@system")); static assert(__traits(getFunctionAttributes, typeof(S.refF)) == tuple!("ref", "@system")); static assert(__traits(getFunctionAttributes, S.propertyF) == tuple!("@property", "@system")); static assert(__traits(getFunctionAttributes, typeof(&S.propertyF)) == tuple!("@property", "@system")); static assert(__traits(getFunctionAttributes, S.nothrowF) == tuple!("nothrow", "@system")); static assert(__traits(getFunctionAttributes, typeof(S.nothrowF)) == tuple!("nothrow", "@system")); static assert(__traits(getFunctionAttributes, S.nogcF) == tuple!("@nogc", "@system")); static assert(__traits(getFunctionAttributes, typeof(S.nogcF)) == tuple!("@nogc", "@system")); static assert(__traits(getFunctionAttributes, S.systemF) == tuple!("@system")); static assert(__traits(getFunctionAttributes, typeof(S.systemF)) == tuple!("@system")); static assert(__traits(getFunctionAttributes, S.trustedF) == tuple!("@trusted")); static assert(__traits(getFunctionAttributes, typeof(S.trustedF)) == tuple!("@trusted")); static assert(__traits(getFunctionAttributes, S.safeF) == tuple!("@safe")); static assert(__traits(getFunctionAttributes, typeof(S.safeF)) == tuple!("@safe")); static assert(__traits(getFunctionAttributes, S.pureF) == tuple!("pure", "@system")); static assert(__traits(getFunctionAttributes, typeof(S.pureF)) == tuple!("pure", "@system")); int pure_nothrow() nothrow pure { return 0; } static ref int static_ref_property() @property { return *(new int); } ref int ref_property() @property { return *(new int); } void safe_nothrow() @safe nothrow { } static assert(__traits(getFunctionAttributes, pure_nothrow) == tuple!("pure", "nothrow", "@system")); static assert(__traits(getFunctionAttributes, typeof(pure_nothrow)) == tuple!("pure", "nothrow", "@system")); static assert(__traits(getFunctionAttributes, static_ref_property) == tuple!("@property", "ref", "@system")); static assert(__traits(getFunctionAttributes, typeof(&static_ref_property)) == tuple!("@property", "ref", "@system")); static assert(__traits(getFunctionAttributes, ref_property) == tuple!("@property", "ref", "@system")); static assert(__traits(getFunctionAttributes, typeof(&ref_property)) == tuple!("@property", "ref", "@system")); static assert(__traits(getFunctionAttributes, safe_nothrow) == tuple!("nothrow", "@safe")); static assert(__traits(getFunctionAttributes, typeof(safe_nothrow)) == tuple!("nothrow", "@safe")); struct S2 { int pure_const() const pure { return 0; } int pure_sharedconst() const shared pure { return 0; } } static assert(__traits(getFunctionAttributes, S2.pure_const) == tuple!("const", "pure", "@system")); static assert(__traits(getFunctionAttributes, typeof(S2.pure_const)) == tuple!("const", "pure", "@system")); static assert(__traits(getFunctionAttributes, S2.pure_sharedconst) == tuple!("const", "shared", "pure", "@system")); static assert(__traits(getFunctionAttributes, typeof(S2.pure_sharedconst)) == tuple!("const", "shared", "pure", "@system")); static assert(__traits(getFunctionAttributes, (int a) { }) == tuple!("pure", "nothrow", "@nogc", "@safe")); static assert(__traits(getFunctionAttributes, typeof((int a) { })) == tuple!("pure", "nothrow", "@nogc", "@safe")); auto safeDel = delegate() @safe { }; static assert(__traits(getFunctionAttributes, safeDel) == tuple!("pure", "nothrow", "@nogc", "@safe")); static assert(__traits(getFunctionAttributes, typeof(safeDel)) == tuple!("pure", "nothrow", "@nogc", "@safe")); auto trustedDel = delegate() @trusted { }; static assert(__traits(getFunctionAttributes, trustedDel) == tuple!("pure", "nothrow", "@nogc", "@trusted")); static assert(__traits(getFunctionAttributes, typeof(trustedDel)) == tuple!("pure", "nothrow", "@nogc", "@trusted")); auto systemDel = delegate() @system { }; static assert(__traits(getFunctionAttributes, systemDel) == tuple!("pure", "nothrow", "@nogc", "@system")); static assert(__traits(getFunctionAttributes, typeof(systemDel)) == tuple!("pure", "nothrow", "@nogc", "@system")); } /********************************************************/ class TestIsOverrideFunctionBase { void bar () {} } class TestIsOverrideFunctionPass : TestIsOverrideFunctionBase { override void bar () {} } void test_isOverrideFunction () { assert(__traits(isOverrideFunction, TestIsOverrideFunctionPass.bar) == true); assert(__traits(isOverrideFunction, TestIsOverrideFunctionBase.bar) == false); } /********************************************************/ // 11711 - Add __traits(getAliasThis) alias TypeTuple(T...) = T; void test11711() { struct S1 { string var; alias var this; } static assert(__traits(getAliasThis, S1) == TypeTuple!("var")); static assert(is(typeof(__traits(getMember, S1.init, __traits(getAliasThis, S1)[0])) == string)); struct S2 { TypeTuple!(int, string) var; alias var this; } static assert(__traits(getAliasThis, S2) == TypeTuple!("var")); static assert(is(typeof(__traits(getMember, S2.init, __traits(getAliasThis, S2)[0])) == TypeTuple!(int, string))); } /********************************************************/ // Issue 12278 class Foo12278 { InPlace12278!Bar12278 inside; } class Bar12278 { } struct InPlace12278(T) { static assert(__traits(classInstanceSize, T) != 0); } /********************************************************/ // 12571 mixin template getScopeName12571() { enum string scopeName = __traits(identifier, __traits(parent, scopeName)); } void test12571() { mixin getScopeName12571; static assert(scopeName == "test12571"); } /********************************************************/ // 12237 auto f12237(T)(T a) { static if (is(typeof(a) == int)) return f12237(""); else return 10; } void test12237() { assert(f12237(1) == 10); assert((a){ static if (is(typeof(a) == int)) { int x; return __traits(parent, x)(""); } else return 10; }(1) == 10); } /********************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test7123(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test1369(); test7608(); test7858(); test9091(); test5978(); test7408(); test9552(); test9136(); test10096(); test_getUnitTests(); test_getFunctionAttributes(); test_isOverrideFunction(); test12237(); writeln("Success"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/template2962.d0000644000175000017500000000066013200164642023714 0ustar matthiasmatthias// EXTRA_SOURCES: imports/template2962a.d // comment 29 void foo(T)(T p) { void inner(U)() { auto p2 = p; } inner!int(); } // comment 20 void funcD(alias x)() { assert(x==1.0); } void funcC(T)(double a){ // Case 1: ICE(glue.c) funcD!(a)(); // Case 2: wrong code double b = 1.0; funcD!(b)(); } void bug2962comment36()(int p) { int inner()() { return p; } alias inner!() finner; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/helloUTF8.d0000644000175000017500000000020513200164642023323 0ustar matthiasmatthias// PERMUTE_ARGS: extern(C) int printf(const char *, ...); int main(char[][] args) { printf("hello world\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test9495.d0000644000175000017500000000061713200164642023072 0ustar matthiasmatthias// PERMUTE_ARGS: import core.vararg; int func1(int a, ...) { auto result = va_arg!int(_argptr); return result; } void test9495a() { assert(func1(5, 12345678) == 12345678); } int func2(const(char)[] a, ...) { auto result = va_arg!int(_argptr); return result; } void test9495b() { assert(func2("5", 12345678) == 12345678); } void main(string[] args) { test9495a(); test9495b(); }ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_1058.d0000644000175000017500000000052013200164642024332 0ustar matthiasmatthiasalign(1) struct vec3 { float x, y, z; } interface I { abstract void interfaceFun(); } class A : I { override void interfaceFun() { } bool b; vec3 v; } pragma(msg, A.v.offsetof); void main(string[]args) { I a = new A(); a.interfaceFun(); // crash in a's invariant here, cannot find the TypeInfo } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/opover3.d0000644000175000017500000001041313200164642023150 0ustar matthiasmatthias void test1() { static struct Foo1 { } Foo1 foo1; Foo1 foo1_2 = Foo1(); // literal syntax static assert(!__traits(compiles, foo1())); } /**************************************/ void test2() { static struct Foo2 { this(int n){} } Foo2 foo2; Foo2 foo2_2 = Foo2(1); // user ctor call Foo2 foo2_3 = Foo2(); // literal syntax static assert(!__traits(compiles, foo2(1))); static assert(!__traits(compiles, foo2())); } /**************************************/ void test2a() { static struct Foo2a // alternation of Foo2 { static Foo2a opCall(int n){ Foo2a foo2a; return foo2a; } } Foo2a foo2a; Foo2a foo2a_3 = Foo2a(1); // static opCall static assert(!__traits(compiles, Foo2a())); // static opCall hides literal syntax. foo2a(1); // static opCall from instance static assert(!__traits(compiles, foo2a())); } /**************************************/ void test2c() { static struct Foo2c // conflict version { this(int n){} static Foo2c opCall(int n, int m){ Foo2c foo2c; return foo2c; } } Foo2c foo2c; Foo2c foo2c_2 = Foo2c(1); // user ctor call static assert(!__traits(compiles, Foo2c(1,2))); // user ctor hides static opCall. Foo2c foo2c_3 = Foo2c(); // literal syntax static assert(!__traits(compiles, foo2c(1))); foo2c(1,2); // static opCall from instance static assert(!__traits(compiles, foo2c())); } /**************************************/ void test3() { static struct Foo3 { this(int n){} int opCall(int n){ return 0; } } Foo3 foo3; Foo3 foo3_2 = Foo3(); // literal syntax (default construction) Foo3 foo3_3 = Foo3(1); // user ctor call assert(foo3(1) == 0); // instance opCall static assert(!__traits(compiles, foo3())); } /**************************************/ void test3c() { static struct Foo3c { this(int n){} static Foo3c opCall(int n, int m){ Foo3c foo3c; return foo3c; } int opCall(int n){ return 0; } } Foo3c foo3c; Foo3c foo3c_2 = Foo3c(); // literal syntax (default construction) Foo3c foo3c_3 = Foo3c(1); // user ctor call static assert(!__traits(compiles, Foo3c(1,2))); // user ctor hides static opCall assert(foo3c(1,2) == Foo3c.init); // static opCall from instance assert(foo3c(1) == 0); // instance opCall static assert(!__traits(compiles, foo3c())); } /**************************************/ void test4() { static struct Foo4 { static Foo4 opCall(int n, int m){ Foo4 foo4; return foo4; } int opCall(int n){ return 0; } } Foo4 foo4; Foo4 foo4_4 = Foo4(1,2); // static opCall static assert(!__traits(compiles, Foo4(1))); static assert(!__traits(compiles, Foo4())); // static opCall without constructor hides literal syntax assert(foo4(1,2) == Foo4.init); // static opCall from instance assert(foo4(1) == 0); // instance opCall static assert(!__traits(compiles, foo4())); } /**************************************/ // 12070 void test12070() { static string result; struct S { this(T...)(T) { result ~= "c" ~ cast(char)('0' + T.length); } void opCall(A...)(A) { result ~= "x" ~ cast(char)('0' + A.length); } } auto s0 = S(); s0(); s0(1); s0(1, 2); assert(result == "x0x1x2"); result = null; auto s1 = S(1); s1(); s1('a'); s1('a', 'b'); assert(result == "c1x0x1x2"); } /**************************************/ // 12124 struct S12124 { this(int) {} S12124 opCall()() { static assert(0); } // speculative opCall instantiation for diagnostic message should not cause false errors } /**************************************/ void main() { test1(); test2(); test2a(); test2c(); test3(); test3c(); test4(); test12070(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/eh2.d0000644000175000017500000000221113200164642022226 0ustar matthiasmatthias// PERMUTE_ARGS: -fPIC extern(C) int printf(const char*, ...); class Abc : Throwable { this() pure { super(""); } static int x; int a,b,c; synchronized void test() { printf("test 1\n"); x |= 1; foo(); printf("test 2\n"); x |= 2; } shared void foo() { printf("foo 1\n"); x |= 4; throw this; printf("foo 2\n"); x |= 8; } } struct RefCounted { void *p; ~this() { p = null; } } struct S { RefCounted _data; int get() @property { throw new Exception(""); } } void b9438() { try { S s; S().get; } catch (Exception e){ } } int main() { printf("hello world\n"); auto a = new shared(Abc)(); printf("hello 2\n"); Abc.x |= 0x10; try { Abc.x |= 0x20; a.test(); Abc.x |= 0x40; } catch (shared(Abc) b) { Abc.x |= 0x80; printf("Caught %p, x = x%x\n", b, Abc.x); assert(a is b); assert(Abc.x == 0xB5); } printf("Success!\n"); b9438(); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test11447b.d0000644000175000017500000000022113200164642023271 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/b11447.d // PERMUTE_ARGS: -allinst import imports.b11447; void main() { A a; aaa(a); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test13117.d0000644000175000017500000000040313200164642023125 0ustar matthiasmatthias// PERMUTE_ARGS: -O -release -g import std.file, std.stdio; int main() { auto size = thisExePath.getSize(); writeln(size); version (D_LP64) enum limit = 1195096; else enum limit = 1042973; return size > limit * 11 / 10; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/bench1.d0000644000175000017500000000123513200164642022715 0ustar matthiasmatthias// REQUIRED_ARGS: // EXECUTE_ARGS: 10000 extern(C) int printf(const char *, ...); extern(C) int atoi(const char *); int main (string[] argv) { string s = ""; int count, loop; count = atoi((argv[1] ~ '\0').ptr); if (count == 0) count = 1; printf("count = %u\n", count); for (loop = 0; loop < count; loop ++) s ~= "hello\n"; for (loop = 0; loop < count; loop ++) s ~= "h"; printf ("%d\n", s.length); //printf("%.*s\n", s[0..100]); assert(s.length == count * (6 + 1)); s.length = 3; s.length = 10; s.length = 0; s.length = 1000; return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testfile.d0000644000175000017500000000052613200164642023376 0ustar matthiasmatthias// PERMUTE_ARGS: import std.file; import std.stdio; /***********************************************/ void test1() { auto p = std.file.getcwd(); writefln("%s '%s'\n", p.length, p); assert(p[$ - 1] != 0); } /***********************************************/ int main() { test1(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/property2.d0000644000175000017500000004150513200164642023527 0ustar matthiasmatthias// PERMUTE_ARGS: -property extern (C) int printf(const char* fmt, ...); // Is -property option specified? enum enforceProperty = !__traits(compiles, { int prop(){ return 1; } int n = prop; }); /*******************************************/ template select(alias v1, alias v2) { static if (enforceProperty) enum select = v1; else enum select = v2; } struct Test(int N) { int value; int getset; static if (N == 0) { ref foo(){ getset = 1; return value; } enum result = select!(0, 1); // -property test.d(xx): Error: not a property foo // (no option) prints "getter" } static if (N == 1) { ref foo(int x){ getset = 2; value = x; return value; } enum result = select!(0, 2); // -property test.d(xx): Error: not a property foo // (no option) prints "setter" } static if (N == 2) { @property ref foo(){ getset = 1; return value; } enum result = select!(1, 1); // -property prints "getter" // (no option) prints "getter" } static if (N == 3) { @property ref foo(int x){ getset = 2; value = x; return value; } enum result = select!(2, 2); // -property prints "setter" // (no option) prints "setter" } static if (N == 4) { ref foo() { getset = 1; return value; } ref foo(int x){ getset = 2; value = x; return value; } enum result = select!(0, 2); // -property test.d(xx): Error: not a property foo // (no option) prints "setter" } static if (N == 5) { @property ref foo() { getset = 1; return value; } ref foo(int x){ getset = 2; value = x; return value; } enum result = select!(0, 0); // -property test.d(xx): Error: cannot overload both property and non-property functions // (no option) test.d(xx): Error: cannot overload both property and non-property functions } static if (N == 6) { ref foo() { getset = 1; return value; } @property ref foo(int x){ getset = 2; value = x; return value; } enum result = select!(0, 0); // -property test.d(xx): Error: cannot overload both property and non-property functions // (no option) test.d(xx): Error: cannot overload both property and non-property functions } static if (N == 7) { @property ref foo() { getset = 1; return value; } @property ref foo(int x){ getset = 2; value = x; return value; } enum result = select!(2, 2); // -property prints "setter" // (no option) prints "setter" } } template seq(T...) { alias T seq; } template iota(int begin, int end) if (begin <= end) { static if (begin == end) alias seq!() iota; else alias seq!(begin, iota!(begin+1, end)) iota; } void test1() { foreach (N; iota!(0, 8)) { printf("%d: ", N); Test!N s; static if (Test!N.result == 0) { static assert(!is(typeof({ s.foo = 1; }))); printf("compile error\n"); } else { s.foo = 1; if (s.getset == 1) printf("getter\n"); else printf("setter\n"); assert(s.getset == Test!N.result); } } } /*******************************************/ // 7722 class Foo7722 {} void spam7722(Foo7722 f) {} void test7722() { auto f = new Foo7722; static if (enforceProperty) static assert(!__traits(compiles, f.spam7722)); else f.spam7722; } /*******************************************/ @property void check(alias v1, alias v2, alias dg)() { void checkImpl(alias v)() { static if (v == 0) static assert(!__traits(compiles, dg(0))); else assert(dg(0) == v); } static if (enforceProperty) checkImpl!(v1)(); else checkImpl!(v2)(); } struct S {} int foo(int n) { return 1; } int foo(int n, int m) { return 2; } int goo(int[] a) { return 1; } int goo(int[] a, int m) { return 2; } int bar(S s) { return 1; } int bar(S s, int n) { return 2; } int baz(X)(X x) { return 1; } int baz(X)(X x, int n) { return 2; } int temp; ref int boo(int n) { return temp; } ref int coo(int[] a) { return temp; } ref int mar(S s) { return temp; } ref int maz(X)(X x) { return temp; } void test7722a() { int n; int[] a; S s; check!(1, 1, x => foo(4) ); check!(1, 1, x => baz(4) ); check!(1, 1, x => 4.foo() ); check!(1, 1, x => 4.baz() ); check!(0, 1, x => 4.foo ); check!(0, 1, x => 4.baz ); check!(2, 2, x => foo(4, 2) ); check!(2, 2, x => baz(4, 2) ); check!(2, 2, x => 4.foo(2) ); check!(2, 2, x => 4.baz(2) ); check!(0, 2, x => (4.foo = 2) ); check!(0, 2, x => (4.baz = 2) ); check!(1, 1, x => goo(a) ); check!(1, 1, x => baz(a) ); check!(1, 1, x => a.goo() ); check!(1, 1, x => a.baz() ); check!(0, 1, x => a.goo ); check!(0, 1, x => a.baz ); check!(2, 2, x => goo(a, 2) ); check!(2, 2, x => baz(a, 2) ); check!(2, 2, x => a.goo(2) ); check!(2, 2, x => a.baz(2) ); check!(0, 2, x => (a.goo = 2) ); check!(0, 2, x => (a.baz = 2) ); check!(1, 1, x => bar(s) ); check!(1, 1, x => baz(s) ); check!(1, 1, x => s.bar() ); check!(1, 1, x => s.baz() ); check!(0, 1, x => s.bar ); check!(0, 1, x => s.baz ); check!(2, 2, x => bar(s, 2) ); check!(2, 2, x => baz(s, 2) ); check!(2, 2, x => s.bar(2) ); check!(2, 2, x => s.baz(2) ); check!(0, 2, x => (s.bar = 2) ); check!(0, 2, x => (s.baz = 2) ); check!(2, 2, x => ( boo(4) = 2)); check!(2, 2, x => ( maz(4) = 2)); check!(0, 2, x => (4.boo = 2)); check!(0, 2, x => (4.maz = 2)); check!(2, 2, x => ( coo(a) = 2)); check!(2, 2, x => ( maz(a) = 2)); check!(0, 2, x => (a.coo = 2)); check!(0, 2, x => (a.maz = 2)); check!(2, 2, x => ( mar(s) = 2)); check!(2, 2, x => ( maz(s) = 2)); check!(0, 2, x => (s.mar = 2)); check!(0, 2, x => (s.maz = 2)); } int hoo(T)(int n) { return 1; } int hoo(T)(int n, int m) { return 2; } int koo(T)(int[] a) { return 1; } int koo(T)(int[] a, int m) { return 2; } int var(T)(S s) { return 1; } int var(T)(S s, int n) { return 2; } int vaz(T, X)(X x) { return 1; } int vaz(T, X)(X x, int n) { return 2; } //int temp; ref int voo(T)(int n) { return temp; } ref int woo(T)(int[] a) { return temp; } ref int nar(T)(S s) { return temp; } ref int naz(T, X)(X x) { return temp; } void test7722b() { int n; int[] a; S s; check!(1, 1, x => hoo!int(4) ); check!(1, 1, x => vaz!int(4) ); check!(1, 1, x => 4.hoo!int() ); check!(1, 1, x => 4.vaz!int() ); check!(0, 1, x => 4.hoo!int ); check!(0, 1, x => 4.vaz!int ); check!(2, 2, x => hoo!int(4, 2) ); check!(2, 2, x => vaz!int(4, 2) ); check!(2, 2, x => 4.hoo!int(2) ); check!(2, 2, x => 4.vaz!int(2) ); check!(0, 2, x => (4.hoo!int = 2) ); check!(0, 2, x => (4.vaz!int = 2) ); check!(1, 1, x => koo!int(a) ); check!(1, 1, x => vaz!int(a) ); check!(1, 1, x => a.koo!int() ); check!(1, 1, x => a.vaz!int() ); check!(0, 1, x => a.koo!int ); check!(0, 1, x => a.vaz!int ); check!(2, 2, x => koo!int(a, 2) ); check!(2, 2, x => vaz!int(a, 2) ); check!(2, 2, x => a.koo!int(2) ); check!(2, 2, x => a.vaz!int(2) ); check!(0, 2, x => (a.koo!int = 2) ); check!(0, 2, x => (a.vaz!int = 2) ); check!(1, 1, x => var!int(s) ); check!(1, 1, x => vaz!int(s) ); check!(1, 1, x => s.var!int() ); check!(1, 1, x => s.vaz!int() ); check!(0, 1, x => s.var!int ); check!(0, 1, x => s.vaz!int ); check!(2, 2, x => var!int(s, 2) ); check!(2, 2, x => vaz!int(s, 2) ); check!(2, 2, x => s.var!int(2) ); check!(2, 2, x => s.vaz!int(2) ); check!(0, 2, x => (s.var!int = 2) ); check!(0, 2, x => (s.vaz!int = 2) ); check!(2, 2, x => ( voo!int(4) = 2)); check!(2, 2, x => ( naz!int(4) = 2)); check!(0, 2, x => (4.voo!int = 2)); check!(0, 2, x => (4.naz!int = 2)); check!(2, 2, x => ( woo!int(a) = 2)); check!(2, 2, x => ( naz!int(a) = 2)); check!(0, 2, x => (a.woo!int = 2)); check!(0, 2, x => (a.naz!int = 2)); check!(2, 2, x => ( nar!int(s) = 2)); check!(2, 2, x => ( naz!int(s) = 2)); check!(0, 2, x => (s.nar!int = 2)); check!(0, 2, x => (s.naz!int = 2)); } /*******************************************/ // 7174 void test7174() { @property bool foo7174() { return true; } static if (foo7174) {} } /***************************************************/ // 7274 @property foo7274(){ return "test"; } @property bar7274(){ return "kernel32.lib"; } pragma(msg, "decl: ", foo7274); // print "decl: foo", not "decl: test" version(Windows) pragma(lib, bar7274); // Error: pragma lib string expected for library name, not 'bar' void test7274() { pragma(msg, "stmt: ", foo7274); // print "stmt: foo", not "stmt: test" //pragma(lib, bar); // Error: pragma(lib) not allowed as statement } /***************************************************/ // 7275 void test7275() { @property int bar1() { return 0; } @property int bar2() { return 1; } @property int bar3() { return 2; } switch (0){ case bar1: break; case bar2: .. case bar3: break; default: break; } } /*****************************************/ // 7538 void test7538() { struct P { @property long pr() { return 1; } @property void pr(int) {} @property long a1()() { return 1; } @property void a1()(int) {} template a2() { @property long a2() { return 1; } } template a2() { @property void a2(int) {} } template a3() { long a3() @property { return 1; } } template a3() { void a3(int) @property {} } static { @property long b1()() { return 1; } @property void b1()(int) {} template b2() { @property long b2() { return 1; } } template b2() { @property void b2(int) {} } template b3() { long b3() @property { return 1; } } template b3() { void b3(int) @property {} } } @property long c1(T)() { return 1; } @property long c1(T)(int) { return 1; } template c2(T) { @property long c2() { return 1; } } template c2(T) { @property void c2(int) {} } template c3(T) { long c3() @property { return 1; } } template c3(T) { void c3(int) @property {} } static { @property long d1(T)() { return 1; } @property void d1(T)(int) {} template d2(T) { @property long d2() { return 1; } } template d2(T) { @property void d2(int) {} } template d3(T) { long d3() @property { return 1; } } template d3(T) { void d3(int) @property {} } } void test() { // TOKvar static assert(is(typeof(pr) == long)); // TOKtemplate static assert(is(typeof(b1) == long)); static assert(is(typeof(b2) == long)); static assert(is(typeof(b3) == long)); // TOKimport static assert(is(typeof(d1!int) == long)); static assert(is(typeof(d2!int) == long)); static assert(is(typeof(d3!int) == long)); } } P p; { // TOKdotvar static assert(is(typeof(p.pr) == long)); // TOKdottd static assert(is(typeof(p.a1) == long)); static assert(is(typeof(p.a2) == long)); static assert(is(typeof(p.a3) == long)); // TOKimport static assert(is(typeof(P.b1) == long)); static assert(is(typeof(P.b2) == long)); static assert(is(typeof(P.b3) == long)); // TOKdotti; static assert(is(typeof(p.c1!int) == long)); static assert(is(typeof(p.c2!int) == long)); static assert(is(typeof(p.c3!int) == long)); } struct F { long fn() { return 1; } void fn(int) {} long a1()() { return 1; } void a1()(int) {} template a2() { long a2() { return 1; } } template a2() { void a2(int) {} } static { long b1()() { return 1; } void b1()(int) {} template b2() { long b2() { return 1; } } template b2() { void b2(int) {} } } long c1(T)() { return 1; } long c1(T)(int) { return 1; } template c2(T) { long c2() { return 1; } } template c2(T) { void c2(int) {} } static { long d1(T)() { return 1; } void d1(T)(int) {} template d2(T) { long d2() { return 1; } } template d2(T) { void d2(int) {} } } void test() { // TOKvar static assert( is(typeof(fn) == function)); // TOKtemplate static assert(!is(typeof(b1) == long)); static assert(!is(typeof(b2) == long)); // TOKimport static assert(!is(typeof(d1!int) == long)); static assert(!is(typeof(d2!int) == long)); } } F f; { // TOKdotvar static assert(is( typeof(f.fn) == function)); // TOKdottd static assert(!is(typeof(f.a1) == long)); static assert(!is(typeof(f.a2) == long)); // TOKimport static assert(!is(typeof(F.b1) == long)); static assert(!is(typeof(F.b2) == long)); // TOKdotti; static assert(!is(typeof(f.c1!int) == long)); static assert(!is(typeof(f.c2!int) == long)); } } /*****************************************/ // 8251 struct S8251 { static @property int min() { return 123; } } @property int T8251_Min() { return 456; } template T8251a (int v) { int T8251a = v; } template T8251b1(int v = S8251.min) { int T8251b1 = v; } template T8251b2(int v = T8251_Min) { int T8251b2 = v; } template T8251c1(int v : S8251.min) { int T8251c1 = v; } template T8251c2(int v : T8251_Min) { int T8251c2 = v; } void test8251() { static assert(S8251.min == 123); // OK static assert(T8251_Min == 456); // OK int a0 = T8251a!(S8251.min()); // OK int b0 = T8251a!(T8251_Min()); // OK // TemplateValueParameter int a1 = T8251a!(S8251.min); // NG int b1 = T8251a!(T8251_Min); // NG // TemplateValueParameterDefault int a2 = T8251b1!(); // NG int b2 = T8251b2!(); // NG // TemplateValueParameterSpecialization int a3 = T8251c1!(123); // NG int b3 = T8251c2!(456); // NG } /*****************************************/ // 9063 @property bool foo9063(){ return true; } static assert(foo9063); /*****************************************/ // 9234 class Fizz9234 { void bar() {} Foo9234!bar foobar; } struct Foo9234(alias F) {} struct Foo9234(string thunk) {} /*****************************************/ // 10103 mixin template Getter10103() { @property auto foo() { return v; } @property auto bar()() { return v; } @property auto baz(T)() { return v; } static @property auto goo() { return 1; } } mixin template Setter10103() { @property void foo(int x) { v = x; } @property void bar()(int x) { v = x; } @property void baz(T)(int x) { v = x; } static @property void goo(int x) {} } struct Foo10103 { int v; mixin Getter10103!(); mixin Setter10103!(); } void test10103() { auto f = Foo10103(4); f.foo; f.foo = 3; f.bar; f.bar = 3; f.baz!int; f.baz!int = 3; Foo10103.goo = 3; } /*****************************************/ // 10197 template OriginalType10197(T) { static if (is(T U == enum)) alias OriginalType10197 = U; else static assert(0); } void test10197() { enum E : int { F = -20 } struct S { int val; @trusted @property T as(T)() if (is(T == int) && !is(T == enum)) { return cast(T)(val); } @trusted @property T as(T)() if (is(T == enum)) { return cast(T)as!(OriginalType10197!T); } } S val = S(-20); assert(val.as!int == -20); assert(val.as!E == E.F); } /*****************************************/ int main() { test1(); test7722(); test7722a(); test7722b(); test7174(); test7274(); test7275(); test7538(); test8251(); test10103(); test10197(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/warning1.d0000644000175000017500000000534513200164642023311 0ustar matthiasmatthias// REQUIRED_ARGS: -w // PERMUTE_ARGS: extern(C) int printf(const char*, ...); /******************************************/ class F { } int foo() { scope F f = new F(); // comment out and warning goes away return 0; } /******************************************/ int foo2() { try { return 0; } finally { } } /******************************************/ private int getNthInt(A...)(uint index, A args) { foreach (i, arg; args) { static if (is(typeof(arg) : long) || is(typeof(arg) : ulong)) { if (i != index) continue; return cast(int)(arg); } else { if (i == index) break; } } throw new Error("int expected"); } /******************************************/ class Foo2 { int foo() { synchronized(this){ return 8; } } } /******************************************/ void mainX() { int i=0; printf("This number is zero: "); goto inloop; for(; i<10; i++) { // this is line 7 printf("This number is nonzero: "); inloop: printf("%d\n", i); } } /******************************************/ string foo3(int bar) { switch (bar) { case 1: return "1"; case 2: return "2"; default: return "3"; } } /******************************************/ int foo4() { int i; for (;; ++i) { if (i == 10) return 0; } } /******************************************/ int foo5() { do { if (false) return 1; } while (true); } /******************************************/ nothrow int foo6() { int x = 2; try { } catch(Exception e) { x = 4; throw new Exception("xxx"); } return x; } /******************************************/ // 6518 template TypeTuple(T...) { alias T TypeTuple; } void test6518() { switch(2) { foreach(v; TypeTuple!(1, 2, 3)) case v: break; default: assert(0); } } /******************************************/ // 7232 bool test7232() { scope(failure) return false; return true; } /***************************************************/ struct S9332 { this(S9332) { // while (1) { } assert(0, "unreachable?"); } } /******************************************/ // 13201 class C13201 { void foo() { synchronized(this) { assert(0); } } } void test13201a() { auto c = new C13201(); synchronized(c) { assert(0); } } void test13201b() { struct S { ~this() {} } S s; assert(0); } /******************************************/ void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/objc_self_test.d0000644000175000017500000000023713200164642024543 0ustar matthiasmatthias// EXTRA_OBJC_SOURCES: objc_self_test.m // REQUIRED_ARGS: -L-framework -LFoundation extern (C) int getValue(); void main () { assert(getValue() == 3); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testaa.d0000644000175000017500000006151413200164642023044 0ustar matthiasmatthias// PERMUTE_ARGS: -fPIC /* Test associative arrays */ extern(C) int printf(const char*, ...); extern(C) int memcmp(const void *s1, const void *s2, size_t n); import core.memory; // for GC.collect import std.random; // for uniform random numbers /************************************************/ int nametable[char[]]; void insert(string name, int value) { nametable[name] = value; } int retrieve(string name) { return nametable[name]; } void test1() { int v; printf("test1.a\n"); insert("hello", 1); printf("test1.b\n"); insert("world", 2); printf("test1.c\n"); v = retrieve("hello"); assert(v == 1); v = retrieve("world"); assert(v == 2); v = retrieve("world"); assert(v == 2); nametable.rehash; v = retrieve("world"); assert(v == 2); } /************************************************/ void test2() { int[string] aa; string[] keys; int[] values; printf("test2()\n"); /*************/ assert(aa == null); assert(aa.length == 0); keys = aa.keys; assert(keys.length == 0); values = aa.values; assert(values.length == 0); aa.rehash; assert(aa.length == 0); /*************/ aa["hello"] = 3; assert(aa["hello"] == 3); aa["hello"]++; assert(aa["hello"] == 4); assert(aa.length == 1); keys = aa.keys; assert(keys.length == 1); assert(memcmp(keys[0].ptr, cast(char*)"hello", 5) == 0); values = aa.values; assert(values.length == 1); assert(values[0] == 4); aa.rehash; assert(aa.length == 1); assert(aa["hello"] == 4); } /************************************************/ void test4() { int[const(ubyte)[]] b; const(ubyte)[] x; b[x] = 3; assert(b[x] == 3); } /************************************************/ void test5() { int[immutable(short)[]] b; immutable(short)[] x; b[x] = 3; assert(b[x] == 3); } /************************************************/ void test6() { int[const(int)[]] b; const(int)[] x; b[x] = 3; assert(b[x] == 3); } /************************************************/ void test7() { int[immutable(uint)[]] b; immutable(uint)[] x; b[x] = 3; assert(b[x] == 3); } /************************************************/ void test8() { int[immutable(long)[]] b; immutable(long)[] x; b[x] = 3; assert(b[x] == 3); } /************************************************/ void test9() { int[immutable(ulong)[]] b; immutable(ulong)[] x; b[x] = 3; assert(b[x] == 3); } /************************************************/ class A10 {} int[immutable(A10)[]] foo10; void test10() { auto key = new immutable(A10)[2]; cast()(key[0]) = new A10(); foo10[key] = 0; assert(key in foo10); assert(!(key !in foo10)); } /************************************************/ struct Value { uint x,y,z,t; } struct Key { int a,b,c,d; static int hash, cmp, equals; size_t toHash() const { hash = 1; return a + b + c + d; } int opCmp(ref const Key s) const { cmp = 1; int x; x = a - s.a; if (x == 0) { x = b - s.b; if (x == 0) { x = c - s.c; if (x == 0) x = d - s.d; } } return x; } bool opEquals(ref const Key s) const { printf("opEquals()\n"); equals = 1; return (a == s.a && b == s.b && c == s.c && d == s.d); } } void test11() { Value[Key] table; Value* p; Value v; Value r; Key k; v.x = 7; v.y = 8; v.z = 9; v.t = 10; k.a = 1; k.b = 2; k.c = 3; k.d = 4; p = k in table; assert(!p); table[k] = v; p = k in table; assert(p); table.rehash; p = k in table; assert(p); r = table[k]; assert(v == r); table.remove(k); assert(!(k in table)); printf("Key.hash = %d\n", Key.hash); assert(Key.hash == 1); printf("Key.cmp = %d\n", Key.cmp); printf("Key.equals = %d\n", Key.equals); assert(Key.cmp == 1 && !Key.equals || !Key.cmp && Key.equals == 1); } /************************************************/ struct S12 { byte number; char[] description; char[] font_face; byte font_size; ushort flags; int colour_back; int colour_fore; byte charset; } void test12() { S12[] x; printf("size %d\n",S12.sizeof); printf("align %d\n",S12.alignof); printf("offset %d\n",S12.description.offsetof); for (int i=0;i<3;i++) { S12 s; s.font_face="font face".dup; x ~= s; } /* works fine S12 s; s.font_face="font face".dup; x ~= s; s.font_face="font face".dup; x ~= s; s.font_face="font face".dup; x ~= s; s.font_face="font face".dup; x ~= s; */ GC.collect(); printf("%.*s\n",x[0].font_face.length,x[0].font_face.ptr); printf("%.*s\n",x[1].font_face.length,x[1].font_face.ptr); } /************************************************/ void test13() { int[string] array; array["eins"]=1; array["zwei"]=2; array["drei"]=3; assert(array.length==3); int[string] rehashed=array.rehash; assert(rehashed is array); string[] key = array.keys; assert(key.length==3); bool have[3]; assert(!have[0]); assert(!have[1]); assert(!have[2]); foreach(string value; key){ switch(value){ case "eins":{ have[0]=true; break; }case "zwei":{ have[1]=true; break; }case "drei":{ have[2]=true; break; }default:{ assert(0); } } } assert(have[0]); assert(have[1]); assert(have[2]); } /************************************************/ void test14() { int[char[]] aa; aa["hello"] = 3; assert(aa["hello"] == 3); assert("hello" in aa); //delete aa["hello"]; aa.remove("hello"); assert(!("hello" in aa)); } /************************************************/ class SomeClass { this(char value) { printf("class created\n"); _value = value; } ~this() { printf("class killed (%d)\n", _value); } char value() { return _value; } private { char _value; } } char[] allChars = [ 'a', 'b', 'c', 'e', 'z', 'q', 'x' ]; SomeClass[char] _chars; void _realLoad() { printf("Loading...\n"); foreach(char ch; allChars) { _chars[ch] = new SomeClass(ch); } } void test15() { _realLoad(); int j; for (int i = 0; i < 10000; i++) { foreach(char ch; allChars) { SomeClass obj = _chars[ch]; j += obj.value; } GC.collect(); } printf("j = %d\n", j); assert(j == 7500000); } /************************************************/ void test16() { int[int] aa; Random gen; for (int i = 0; i < 50000; i++) { int key = uniform(0, int.max, gen); int value = uniform(0, int.max, gen); aa[key] = value; } int[] keys = aa.keys; assert(keys.length == aa.length); int j; foreach (k; keys) { assert(k in aa); j += aa[k]; } printf("test16 = %d\n", j); int m; foreach (k, v; aa) { assert(k in aa); assert(aa[k] == v); m += v; } assert(j == m); m = 0; foreach (v; aa) { m += v; } assert(j == m); int[] values = aa.values; assert(values.length == aa.length); foreach(k; keys) { aa.remove(k); } assert(aa.length == 0); for (int i = 0; i < 1000; i++) { int key2 = uniform(0, int.max, gen); int value2 = uniform(0, int.max, gen); aa[key2] = value2; } foreach(k; aa) { if (k < 1000) break; } foreach(k, v; aa) { if (k < 1000) break; } } /************************************************/ void dummy17() { } int bb17[string]; int foo17() { foreach(string s, int i; bb17) { dummy17(); } bb17["a"] = 1; foreach(int b; bb17) { try{ throw new Error("foo"); }catch(Error e){ assert(e); return 0; }catch{ assert(0); } assert(0); } assert(0); } void test17() { int i = foo17(); printf("foo17 = %d\n", i); assert(i == 0); } /************************************************/ void test18() { int[uint] aa; aa[1236448822] = 0; aa[2716102924] = 1; aa[ 315901071] = 2; aa.remove(1236448822); printf("%d\n", aa[2716102924]); assert(aa[2716102924] == 1); } /************************************************/ void test19() { immutable(char[5])[int] aa = ([3:"hello", 4:"betty"]); assert(aa[3] == "hello"); assert(aa[4] == "betty"); auto keys = aa.keys; printf("%d\n", keys[0]); printf("%d\n", keys[1]); auto vs = aa.values; printf("%.*s\n", vs[0].length, vs[0].ptr); printf("%.*s\n", vs[1].length, vs[1].ptr); string aavalue_typeid = typeid(typeof(aa.values)).toString(); printf("%.*s\n", aavalue_typeid.length, aavalue_typeid.ptr); printf("%.*s\n", aa[3].length, aa[3].ptr); printf("%.*s\n", aa[4].length, aa[4].ptr); } /************************************************/ void test20() { string[int] aa = ([3:"hello", 4:"betty"]); assert(aa[3] == "hello"); assert(aa[4] == "betty"); auto keys = aa.keys; printf("%d\n", keys[0]); printf("%d\n", keys[1]); auto values = aa.values; printf("%.*s\n", values[0].length, values[0].ptr); printf("%.*s\n", values[1].length, values[1].ptr); string aavalue_typeid = typeid(typeof(aa.values)).toString(); printf("%.*s\n", aavalue_typeid.length, aavalue_typeid.ptr); printf("%.*s\n", aa[3].length, aa[3].ptr); printf("%.*s\n", aa[4].length, aa[4].ptr); } /************************************************/ void test21() { ushort[20] key = 23; int[ushort[20]] aa; aa[key] = 42; auto x = aa[key]; assert(x == 42); printf("foo\n"); } /************************************************/ void test22() { int[string] stopWords = [ "abc"[]:1 ]; assert("abc"[] in stopWords); } /************************************************/ void test23() { uint[char[]][] fractal; fractal.length = 10; } /************************************************/ void test24() { int[string] x; char[] y; if (y in x) { int z = x[y]; } } /************************************************/ void test25() { string[string] aa; foreach (k,v; aa) { } } /************************************************/ class Tag { string[string] attr; } void foo26(const(Tag) tag_) { foreach(k,v;tag_.attr) { } } void test26() { } /************************************************/ void test27() { int[int] s; s = s.init; } /************************************************/ void test28() { auto a1 = [ 1:10.0, 2:20, 3:15 ]; auto a2 = [ 1:10.0, 2:20, 3:15 ]; assert(a1 !is a2); assert(a1 == a2); a2[7] = 23; assert(a1 != a2); a2.remove(7); assert(a1 == a2); a1.rehash; assert(a1 == a2); a2[2] = 18; assert(a1 != a2); } /************************************************/ void test29() { auto gammaFunc = [-1.5:2.363, -0.5:-3.545, 0.5:1.772]; // write all keys foreach (k; gammaFunc.byKey()) { printf("%f\n", k); } // write all values foreach (v; gammaFunc.byValue()) { printf("%f\n", v); } } /************************************************/ string toString(int value) { char[] result = new char[12]; uint ndigits = 0; do { const c = cast(char) ((value % 10) + '0'); value /= 10; ndigits++; result[$ - ndigits] = c; } while (value); return cast(string) result[$ - ndigits .. $]; } void test30() { int[string] aa; for(int i = 0; i < 100000; i++) { string s = toString(i); aa[s] = i; } } /************************************************/ void test31() { int[int] test; test[0] = 0; test[1] = 1; test[2] = 2; bool flag = false; foreach( k, v; test){ //printf("loop: %d %d\n", k, v); assert(!flag); flag = true; break; } } /************************************************/ void test32() { uint[ushort] aa; aa[1] = 1; aa[2] = 2; aa[3] = 3; aa[4] = 4; aa[5] = 5; foreach(v; aa) { printf("%x\n", v); assert(v >= 1 && v <= 5); } } /************************************************/ template ICE3996(T : V[K], K, V) {} struct Bug3996 {} static assert(!is( ICE3996!(Bug3996) )); /************************************************/ void bug4826c(T)(int[int] value, T x) {} void test4826c() { AssociativeArray!(int, int) z; bug4826c(z,1); } /************************************************/ // 5131 struct ICE5131 { this(int n) {} ICE5131 opAssign(int x) { return this; } } void test5131() { ICE5131[string] a; a["ICE?"] = 1; // call ctor a["ICE?"] = 1; // call opAssign } /************************************************/ // 6178 bool test6178a() { // AA value setting through identity opAssign int assign = 0; struct S { int value = 10; void opAssign(S rhs) { ++assign; assert(value == 10); } } int count = 0; int makeKey() { return ++count; } S[int] aa; assert(aa.length == 0); aa[makeKey()] = S(); assert(assign == 0); assert(aa.length == 1 && 1 in aa); aa[1] = S(); assert(assign == 1); assert(aa.length == 1 && 1 in aa); return true; } bool test6178b() { // AA value setting through implicit ctor call + non-identity opAssign int ctor = 0; int assign = 0; struct S { int value = 10; @disable this(); this(int n) { ++ctor; assert(value == 10); value = 20; } void opAssign(int rhs) { ++assign; assert(value == 20); assert(rhs == 30); value = rhs; } } int count = 0; int makeKey() { return ++count; } S[int] aa; assert(aa.length == 0); aa[makeKey()] = 20; assert(assign == 0 && ctor == 1 && count == 1); assert(aa.length == 1 && (1 in aa)); aa[1] = 30; assert(assign == 1 && ctor == 1); assert(aa.length == 1 && 1 in aa); return true; } bool test6178c() { // AA value setting through non-identity opAssign struct S { //this(int) {} // not possible to perform implicit ctor call void opAssign(int) {} } S[int] aa; assert(aa.length == 0); if (!__ctfe) { // currently CTFE does not support throwing RangeError import core.exception : RangeError; try { aa[1] = 1; assert(0); } catch (RangeError) {} // The above line is exactly same as: try { aa[1].opAssign(1); assert(0); } catch (RangeError) {} } assert(aa.length == 0); aa[1] = S(); aa[1] = 1; assert(aa.length == 1); return true; } bool test6178d() { // AA value setting through implicit ctor call + alias this int ctor; struct S { this(int n) { ++ctor; value = n; } int value; alias value this; } S[int] aa; assert(ctor == 0); assert(aa.length == 0); aa[1] = 0; // implicit ctor call + blit assign assert(aa[1].value == 0 && ctor == 1); assert(aa.length == 1); aa[1] = 1; // set through alias this assert(aa[1].value == 1 && ctor == 1); assert(aa.length == 1); return true; } bool test6178e() { // AA value setting through alias this struct S { int value; alias value this; } S[int] aa; assert(aa.length == 0); if (!__ctfe) { // currently CTFE does not support throwing RangeError import core.exception : RangeError; try { aa[1] = 1; assert(0); } catch (RangeError) {} // The above line is exactly same as: try { aa[1].value = 1; assert(0); } catch (RangeError) {} } assert(aa.length == 0); aa[1] = S(0); // construct + blit assign assert(aa[1].value == 0 && aa.length == 1); aa[1] = 1; // set through alias this assert(aa[1].value == 1 && aa.length == 1); return true; } void test6178() { static assert(test6178a()); // ctfe check test6178a(); // runtime test static assert(test6178b()); test6178b(); static assert(test6178c()); test6178c(); static assert(test6178d()); test6178d(); static assert(test6178e()); test6178e(); } void test6178x() { return; // depends on AA implementation static int ctor, cpctor, dtor; static struct S { this(int) { ++ctor; printf("ctor\n"); } this(this) { ++cpctor; printf("cpctor\n"); } ~this() { ++dtor; printf("dtor\n"); } } static struct X { this(int) {} void opAssign(int) {} } X[S] aa1; S[int] aa2; { auto value = S(1); assert(ctor==1 && cpctor==0 && dtor==0); ref getRef(ref S s = value) { return s; } auto getVal() { return value; } aa1[value] = 10; assert(ctor==1 && cpctor==1 && dtor==0); //call copy ctor when we putting 'value' to aa1 aa1[getRef()] = 20; assert(ctor==1 && cpctor==1 && dtor==0); //copy ctor wasn't called because we didn't create a new entry in aa, using an existing key aa1[getVal()] = 20; assert(ctor==1 && cpctor==2 && dtor==1); //call copy ctor and dtor, because we pass key by value aa2[1] = value; assert(ctor==1 && cpctor==3 && dtor==1); //call copy ctor when we putting `value` to aa2[1] aa2[2] = getRef(); assert(ctor==1 && cpctor==4 && dtor==1); //call copy ctor when we putting `value` to aa2[2] } assert(ctor==1 && cpctor==4 && dtor==2); //We've got 3 "S" instances that aren't destroyed yet: the key in aa1, aa2[1], aa2[2]. assert(ctor + cpctor - aa2.length - aa1.length == dtor); } /************************************************/ // 10595 struct S10595 { bool b = true; bool test() { if (!b) // note: must be a check, not 'return b;' return false; return true; } } struct Wrap10595 { int i; alias i this; S10595 s; } void test10595() { { Wrap10595[int] wrap; wrap[0] = Wrap10595(); wrap[0].i = 0; assert(wrap[0].s.test()); // ok } { Wrap10595[int] wrap; wrap[0] = Wrap10595(); wrap[0] = 0; // note: using 'alias this' to assign assert(wrap[0].s.test()); // failure } } /************************************************/ // 10970 struct RefCounted10970(T) //if (!is(T == class)) { struct RefCountedStore { } RefCountedStore _refCounted; this(this) {} ~this() {} } struct Array10970(T) if (!is(T : const(bool))) { struct Payload { } RefCounted10970!Payload _data; } class C10970 { this(string name) { m[name] = Arr(); } alias Array10970!C10970 Arr; Arr[string] m; } void test10970() { C10970 c = new C10970("test"); } /************************************************/ // 6433 void test6433() { int[int] aa; static assert(aa.sizeof != 0); static assert(aa.alignof != 0); static assert(is(typeof(aa.init) == int[int])); static assert(typeof(aa).mangleof == "Hii"); static assert(typeof(aa).stringof == "int[int]"); static struct AA { int[int] aa; } static assert(AA.aa.offsetof == 0); aa = aa.init; aa[0] = 1; assert(aa.length == 1 && aa[0] == 1); } /************************************************/ // 6612 void test6612() { auto aa1 = [1: 2]; // OK auto aa2 = [4: 5]; // OK int[int[int]] aa3 = [aa1:3, aa2:6]; // OK int[int[int]] aa4 = [[1:2]:3, [4:5]:6]; // error int[int[string]] aa5 = [["a":1]:2, ["b":3]:4]; } /************************************************/ // 7365 struct TickDuration { bool opEquals(ref const TickDuration rhs) const { return true; } } void test7365() { TickDuration[Object] aa; aa.keys; } /************************************************/ enum aa5520 = [5 : "hello"]; void test5520() { auto a = aa5520.values; } /************************************************/ enum size_t N6655 = 1; int[bar6655.length] foo6655; int[N6655] bar6655; /************************************************/ struct ChunkLoc {} ChunkLoc Get() { return ChunkLoc(); } void test6799() { int[ChunkLoc] aa; aa.remove(Get()); } /************************************************/ // 11359 void test11359() { class Bar {} static Bar[string] aa; static ref fun() { return aa; } string key = "test"; fun[key] = new Bar; assert(aa.length == 1); Bar bar = fun[key]; } /************************************************/ // 11730 struct SysTime11730 { ref SysTime11730 opAssign(SysTime11730 rhs) { assert(0); } } struct Nullable11730(T) { T _value; void opAssign()(T value) { assert(0); } @property ref inout(T) get() inout { assert(0); } alias get this; } void test11730() { Nullable11730!SysTime11730[string] map; map["foo"] = Nullable11730!SysTime11730(); } /************************************************/ // 14089 struct S14089 { int num; S14089 opAssign(S14089 val) { return this; } } void test14089() { S14089[int] aa; S14089 b = aa[1] = S14089(0); assert(aa[1].num == 0); assert(b.num == 0); } /************************************************/ // 14144 struct JSON14144 { union { double _floating; } this(typeof(null)) { } @trusted pure nothrow typeof(null) opAssign(typeof(null) nothing) { return null; } } void test14144() { JSON14144[string] x; x["wat"] = null; assert(x.length == 1); assert("wat" in x); } /************************************************/ // 14321 void test14321() { struct Foo { static char[8] buf; static char[] op; this(int id) { buf[op.length] = 'c'; op = buf[0..op.length + 1]; } this(this) { buf[op.length] = 'p'; op = buf[0..op.length + 1]; } ~this() { buf[op.length] = 'd'; op = buf[0..op.length + 1]; } } Foo[string] foos; assert(Foo.op == ""); foos["test"] = Foo(42); // initialization assert(Foo.op == "c"); foos["test"] = Foo(42); // assignment assert(Foo.op == "ccd"); struct Bar { static char[8] buf; static char[] op; int id; //this(int id) { op ~= "c"; } this(this) { buf[op.length] = 'p'; op = buf[0..op.length + 1]; } ~this() { buf[op.length] = 'd'; op = buf[0..op.length + 1]; } } Bar[string] bars; assert(Bar.op == ""); bars["test"] = Bar(42); // initialization assert(Bar.op == ""); bars["test"] = Bar(42); // assignment assert(Bar.op == "d"); } /************************************************/ int main() { printf("before test 1\n"); test1(); printf("before test 2\n"); test2(); printf("before test 4\n"); test4(); printf("before test 5\n"); test5(); printf("before test 6\n"); test6(); printf("before test 7\n"); test7(); printf("before test 8\n"); test8(); printf("before test 9\n"); test9(); printf("before test 10\n"); test10(); printf("before test 11\n"); test11(); printf("before test 12\n"); test12(); printf("before test 13\n"); test13(); printf("before test 14\n"); test14(); printf("before test 15\n"); test15(); printf("before test 16\n"); test16(); printf("before test 17\n"); test17(); printf("before test 18\n"); test18(); printf("before test 19\n"); test19(); printf("before test 20\n"); test20(); printf("before test 21\n"); test21(); printf("before test 22\n"); test22(); printf("before test 23\n"); test23(); printf("before test 24\n"); test24(); printf("before test 25\n"); test25(); printf("before test 26\n"); test26(); printf("before test 27\n"); test27(); printf("before test 28\n"); test28(); printf("before test 29\n"); test29(); printf("before test 30\n"); test30(); printf("before test 31\n"); test31(); printf("before test 32\n"); test32(); test4826c(); test5131(); test6178(); test6178x(); test10595(); test10970(); test6433(); test6612(); test7365(); test5520(); test6799(); test11359(); test11730(); test14089(); test14321(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testbounds_off.d0000644000175000017500000000117713200164642024606 0ustar matthiasmatthias// REQUIRED_ARGS: -boundscheck=off // PERMUTE_ARGS: -inline -g -O import core.exception : RangeError; // Check for RangeError is thrown bool thrown(T)(lazy T cond) { import core.exception; bool f = false; try { cond(); } catch (RangeError e) { f = true; } return f; } @safe int safeIndex (int[] arr) { return arr[2]; } @trusted int trustedIndex(int[] arr) { return arr[2]; } @system int systemIndex (int[] arr) { return arr[2]; } void main() { int[3] data = [1,2,3]; int[] arr = data[0..2]; assert(arr. safeIndex() == 3); assert(arr.trustedIndex() == 3); assert(arr. systemIndex() == 3); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/foreach4.d0000644000175000017500000004115013200164642023250 0ustar matthiasmatthias import core.stdc.stdio; import std.stdio; alias bool bit; /************************************************/ class Foo { uint array[2]; int opApply(int delegate(ref uint) dg) { int result; for (int i = 0; i < array.length; i++) { result = dg(array[i]); if (result) break; } return result; } } /**************************************************/ void test1() { Foo a = new Foo(); int i; a.array[0] = 73; a.array[1] = 82; foreach (uint u; a) { i++; u++; } assert(i == 2); assert(a.array[0] == 73); assert(a.array[1] == 82); } /**************************************************/ void test2() { Foo a = new Foo(); int i; a.array[0] = 73; a.array[1] = 82; foreach (ref uint u; a) { i++; u++; } assert(i == 2); assert(a.array[0] == 74); assert(a.array[1] == 83); } /**************************************************/ void test3() { Foo a = new Foo(); int i; a.array[0] = 73; a.array[1] = 82; foreach (ref uint u; a) { i++; if (i) break; u++; } assert(i == 1); assert(a.array[0] == 73); assert(a.array[1] == 82); } /**************************************************/ void test4() { Foo a = new Foo(); int i; a.array[0] = 73; a.array[1] = 82; foreach (ref uint u; a) { i++; if (i == 1) continue; u++; } assert(i == 2); assert(a.array[0] == 73 && a.array[1] == 83); } /**************************************************/ void test5() { Foo a = new Foo(); int i; a.array[0] = 73; a.array[1] = 82; Loop: while (1) { foreach (ref uint u; a) { i++; if (i) break Loop; u++; } } assert(i == 1); assert(a.array[0] == 73); assert(a.array[1] == 82); } /**************************************************/ void test6() { Foo a = new Foo(); int i; a.array[0] = 73; a.array[1] = 82; Loop: while (1) { foreach (ref uint u; a) { i++; if (i == 1) continue Loop; u++; } break; } assert(i == 3); assert(a.array[0] == 74); assert(a.array[1] == 83); } /**************************************************/ void test7() { Foo a = new Foo(); int i; a.array[0] = 73; a.array[1] = 82; foreach (ref uint u; a) { i++; if (i) goto Label; u++; } assert(0); Label: assert(i == 1); assert(a.array[0] == 73); assert(a.array[1] == 82); } /**************************************************/ void test8_x(Foo a) { int i; foreach (ref uint u; a) { i++; if (i) return; u++; } } void test8() { Foo a = new Foo(); int i; a.array[0] = 73; a.array[1] = 82; test8_x(a); assert(i == 0); assert(a.array[0] == 73); assert(a.array[1] == 82); } /**************************************************/ int test9_x(Foo a) { int i; foreach (ref uint u; a) { i++; if (i) return 67; u++; } return 23; } void test9() { Foo a = new Foo(); int i; a.array[0] = 73; a.array[1] = 82; i = test9_x(a); assert(i == 67); assert(a.array[0] == 73); assert(a.array[1] == 82); } /**************************************************/ int test10_x(Foo a) { int i; foreach (ref uint u; a) { i++; if (i) return i; u++; } return 23; } void test10() { Foo a = new Foo(); int i; a.array[0] = 73; a.array[1] = 82; i = test10_x(a); assert(i == 1); assert(a.array[0] == 73); assert(a.array[1] == 82); } /**************************************************/ /+ the expected output: 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 0 +/ void test11() { bit[25] data; int j; for (int i = 0; i < 25; i += 5) { data[i+0] = data[i+1] = true; } for (int i = 0; i < 25; i++) { printf("%d ", data[i]); if ((i % 5) < 2) assert(data[i] == true); else assert(data[i] == false); } printf("\n%d\n", data[22] = true); j = data[22] = true; assert(j == true); for (int i = 0; i < 25; i += 5) { data[i+1] = data[i+3] = true; j = i % 5; if (j == 0 || j == 1 || j == 3) assert(data[i] == true); else assert(data[i] == false); } for (int i = 0; i < 25; i++) { printf("%d ", data[i]); } printf("\n"); int k; foreach (bit b; data) { printf("%d ", b); j = k % 5; if (j == 0 || j == 1 || j == 3 || k == 22) assert(data[k] == true); else assert(data[k] == false); k++; } printf("\n"); foreach (int l, bit b; data) { printf("%d ", b); j = l % 5; if (j == 0 || j == 1 || j == 3 || l == 22) assert(data[l] == true); else assert(data[l] == false); } printf("\n"); } /**************************************************/ void test12() { int j; j = 0; foreach (dchar d; "hello") { printf("d = x%x\n", d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); if (j == 3) assert(d == 'l'); if (j == 4) assert(d == 'o'); j++; } assert(j == 5); j = 0; foreach (size_t i, dchar d; "hello") { printf("i = %d, d = x%x\n", i, d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); if (j == 3) assert(d == 'l'); if (j == 4) assert(d == 'o'); assert(i == j); j++; } assert(j == 5); } /**************************************************/ void test13() { int j; j = 0; foreach (wchar d; "hello") { printf("d = x%x\n", d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); if (j == 3) assert(d == 'l'); if (j == 4) assert(d == 'o'); j++; } assert(j == 5); j = 0; foreach (size_t i, wchar d; "hello") { printf("i = %d, d = x%x\n", i, d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); if (j == 3) assert(d == 'l'); if (j == 4) assert(d == 'o'); assert(i == j); j++; } assert(j == 5); } /**************************************************/ void test14() { int j; j = 0; foreach (char d; cast(wstring)"hello") { printf("d = x%x\n", d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); if (j == 3) assert(d == 'l'); if (j == 4) assert(d == 'o'); j++; } assert(j == 5); j = 0; foreach (size_t i, char d; cast(wstring)"hello") { printf("i = %d, d = x%x\n", i, d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); if (j == 3) assert(d == 'l'); if (j == 4) assert(d == 'o'); assert(i == j); j++; } assert(j == 5); } /**************************************************/ void test15() { int j; j = 0; foreach (dchar d; cast(wstring)"hello") { printf("d = x%x\n", d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); if (j == 3) assert(d == 'l'); if (j == 4) assert(d == 'o'); j++; } assert(j == 5); j = 0; foreach (size_t i, dchar d; cast(wstring)"hello") { printf("i = %d, d = x%x\n", i, d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); if (j == 3) assert(d == 'l'); if (j == 4) assert(d == 'o'); assert(i == j); j++; } assert(j == 5); } /**************************************************/ void test16() { int j; j = 0; foreach (char d; cast(dstring)"hello") { printf("d = x%x\n", d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); if (j == 3) assert(d == 'l'); if (j == 4) assert(d == 'o'); j++; } assert(j == 5); j = 0; foreach (size_t i, char d; cast(dstring)"hello") { printf("i = %d, d = x%x\n", i, d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); if (j == 3) assert(d == 'l'); if (j == 4) assert(d == 'o'); assert(i == j); j++; } assert(j == 5); } /**************************************************/ void test17() { int j; j = 0; foreach (wchar d; cast(dstring)"hello") { printf("d = x%x\n", d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); if (j == 3) assert(d == 'l'); if (j == 4) assert(d == 'o'); j++; } assert(j == 5); j = 0; foreach (size_t i, wchar d; cast(dstring)"hello") { printf("i = %d, d = x%x\n", i, d); if (j == 0) assert(d == 'h'); if (j == 1) assert(d == 'e'); if (j == 2) assert(d == 'l'); if (j == 3) assert(d == 'l'); if (j == 4) assert(d == 'o'); assert(i == j); j++; } assert(j == 5); } /**************************************************/ void test18() { string a = "\xE2\x89\xA0"; // \u2260 encoded as 3 UTF-8 bytes foreach (dchar c; a) { printf("a[] = %x\n", c); // prints 'a[] = 2260' assert(c == 0x2260); } dstring b = "\u2260"; int i; foreach (char c; b) { printf("%x, ", c); // prints e2, 89, a0 if (i == 0) assert(c == 0xE2); else if (i == 1) assert(c == 0x89); else if (i == 2) assert(c == 0xA0); else assert(0); i++; } printf("\n"); } /**************************************************/ void test19() { string string = x"F0 9D 83 93"; int count=0; dchar tmp; foreach(dchar value ; string){ tmp=value; count++; } assert(count==1); assert(tmp==0x01D0D3); } /**************************************************/ struct S20 { int opApply(int delegate(ref int i) dg) { return 0; } } S20 foo20; void test20() { label: foreach(int i; foo20) { continue label; } } /**************************************************/ void foo21(string[] args) { printf("args.length = %d\n", args.length); assert(args.length == 3); foreach (i, arg; args) { assert(typeid(typeof(i)) == typeid(size_t)); assert(typeid(typeof(arg)) == typeid(string)); writefln("args[%d] = '%s'", i, arg); } foreach (arg; args) { assert(typeid(typeof(arg)) == typeid(string)); writefln("args[] = '%s'", arg); } } void test21() { string[] args; args.length = 3; args[0] = "a"; args[1] = "bc"; args[2] = "d"; foo21(args); } /**************************************************/ void test22() { int[string] map; map["hello"] = 3; map["world"] = 4; foreach (key, value; map) { assert(typeid(typeof(key)) == typeid(string)); assert(typeid(typeof(value)) == typeid(int)); writefln("map[%s] = %s", key, value); } foreach (key, int value; map) { assert(typeid(typeof(key)) == typeid(string)); assert(typeid(typeof(value)) == typeid(int)); writefln("map[%s] = %s", key, value); } foreach (string key, value; map) { assert(typeid(typeof(key)) == typeid(string)); assert(typeid(typeof(value)) == typeid(int)); writefln("map[%s] = %s", key, value); } foreach (value; map) { assert(typeid(typeof(value)) == typeid(int)); writefln("map[] = %s", value); } } /**************************************************/ class Foo23 { int array[2]; int opApply(int delegate(ref int) dg) { int result; for (int i = 0; i < array.length; i++) { result = dg(array[i]); if (result) break; } return result; } int opApply(int delegate(ref size_t, ref int) dg) { int result; for (size_t i = 0; i < array.length; i++) { result = dg(i, array[i]); if (result) break; } return result; } } void test23() { Foo23 a = new Foo23(); int i; a.array[0] = 73; a.array[1] = 82; foreach (u; a) { assert(typeid(typeof(u)) == typeid(int)); i++; u++; //writefln("u = %d", u); assert((i == 1) ? u == 74 : u == 83); } assert(i == 2); assert(a.array[0] == 73); assert(a.array[1] == 82); foreach (j, u; a) { assert(typeid(typeof(j)) == typeid(size_t)); assert(typeid(typeof(u)) == typeid(int)); i++; u++; writefln("u = %d", u); assert((i == 3) ? u == 74 : u == 83); assert(j == i - 3); } assert(i == 4); assert(a.array[0] == 73); assert(a.array[1] == 82); } /**************************************************/ struct Collection24 { int opApply(int delegate(ref int) dg){ return 0; } } bool foo24() { Collection24 a,b; foreach(int x; a){ foreach(int y; b){ return false; } } return true; } void test24() { assert(foo24() == true); } /**************************************************/ void test25() { alias void function(string[string]) FN; FN fn = function (string[string] aarray) { foreach (string s; aarray) { writeln(s); assert(s == "b"); } }; string[string] aarray; aarray["a"] = "b"; fn(aarray); } /**************************************************/ struct Foo26 { uint array[2]; int forward(int delegate(ref uint) dg) { int result; for (int i = 0; i < array.length; i++) { result = dg(array[i]); if (result) break; } return result; } int forward(int delegate(ref uint) dg, int x) { return 1; } int reverse(int delegate(ref uint) dg, int x) { return 1; } int reverse(int delegate(ref uint) dg) { int result; foreach_reverse (v; array) { auto u = v; result = dg(u); if (result) break; } return result; } } void test26() { Foo26 a; int i; a.array[0] = 73; a.array[1] = 82; foreach (u; &a.forward) { writeln(u); i++; u++; } assert(i == 2); assert(a.array[0] == 73); assert(a.array[1] == 82); foreach (uint u; &a.reverse) { writeln(u); } } /**************************************************/ struct S27 { int[] a; bool empty() { return a.length == 0; } void popFront() { a = a[1 .. $]; } int front() { return a[0]; } void popBack() { a = a[0 .. $ - 1]; } ref int back() { return a[$ - 1]; } } void test27() { S27 s; s.a = [5,6,7]; string r; foreach (e; s) { printf("%d\n", e); r ~= cast(char)(e + '0'); } assert(r == "567"); r = null; foreach_reverse (ref e; s) { e++; printf("%d\n", e); r ~= cast(char)(e + '0'); } assert(r == "876"); r = null; foreach (e; s) { printf("%d\n", e); r ~= cast(char)(e + '0'); } assert(r == "678"); } /**************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test7.d0000644000175000017500000003020213200164642022617 0ustar matthiasmatthias// PERMUTE_ARGS: // Test memset style array assignments. extern(C) int printf(const char*, ...); /**************************************/ char[] b1; char[] func1(int dim) { char[] a = new char[dim]; b1 = a; return a; } void test1() { printf("test1()\n"); int i; int j; char[1] a1; a1[] = 'x'; assert(a1[0] == 'x'); char[2] a2; a2[] = 'x'; for (i = 0; i < a2.length; i++) assert(a2[i] == 'x'); char[3] a3; a3[] = 'x'; for (i = 0; i < a3.length; i++) assert(a3[i] == 'x'); char[4] a4; a4[] = 'x'; for (i = 0; i < a4.length; i++) assert(a4[i] == 'x'); char[8] a8; a8[] = 'x'; for (i = 0; i < a8.length; i++) assert(a8[i] == 'x'); char[27] a27; a27[] = 'x'; for (i = 0; i < a27.length; i++) assert(a27[i] == 'x'); func1(33)[] = 'y'; for (i = 0; i < b1.length; i++) assert(b1[i] == 'y'); char[23] a23 = 'x'; i = 16; j = 18; a23[i++..++j] = 'c'; printf("i = %d, j = %d\n", i, j); assert(i == 17); assert(j == 19); assert(a23[15] == 'x'); assert(a23[16] == 'c'); assert(a23[17] == 'c'); assert(a23[18] == 'c'); assert(a23[19] == 'x'); assert(a23[20] == 'x'); } /**************************************/ short[] b2; short[] func2(int dim) { short[] a = new short[dim]; b2 = a; return a; } void test2() { printf("test2()\n"); int i; int j; short[1] a1; a1[] = 0x1234; assert(a1[0] == 0x1234); short[2] a2; a2[] = 0x1234; for (i = 0; i < a2.length; i++) assert(a2[i] == 0x1234); short[3] a3; a3[] = 0x1234; for (i = 0; i < a3.length; i++) assert(a3[i] == 0x1234); short[4] a4; a4[] = 0x1234; for (i = 0; i < a4.length; i++) assert(a4[i] == 0x1234); short[8] a8; a8[] = 0x1234; for (i = 0; i < a8.length; i++) assert(a8[i] == 0x1234); short[27] a27; a27[] = 0x1234; for (i = 0; i < a27.length; i++) assert(a27[i] == 0x1234); func2(33)[] = 0x5678; for (i = 0; i < b2.length; i++) assert(b2[i] == 0x5678); short[23] a23 = 0x1234; i = 16; j = 18; a23[i++..++j] = 0x4554; printf("i = %d, j = %d\n", i, j); assert(i == 17); assert(j == 19); assert(a23[15] == 0x1234); assert(a23[16] == 0x4554); assert(a23[17] == 0x4554); assert(a23[18] == 0x4554); assert(a23[19] == 0x1234); assert(a23[20] == 0x1234); } /**************************************/ int[] b3; int[] func3(int dim) { int[] a = new int[dim]; b3 = a; return a; } void test3() { printf("test3()\n"); int i; int j; int[1] a1; a1[] = 0x12345678; assert(a1[0] == 0x12345678); int[2] a2; a2[] = 0x12345678; for (i = 0; i < a2.length; i++) assert(a2[i] == 0x12345678); int[3] a3; a3[] = 0x12345678; for (i = 0; i < a3.length; i++) assert(a3[i] == 0x12345678); int[4] a4; a4[] = 0x12345678; for (i = 0; i < a4.length; i++) assert(a4[i] == 0x12345678); int[8] a8; a8[] = 0x12345678; for (i = 0; i < a8.length; i++) assert(a8[i] == 0x12345678); int[27] a27; a27[] = 0x12345678; for (i = 0; i < a27.length; i++) assert(a27[i] == 0x12345678); func3(33)[] = 0x56781234; for (i = 0; i < b3.length; i++) assert(b3[i] == 0x56781234); int[23] a23 = 0x12345678; i = 16; j = 18; a23[i++..++j] = 0x45546776; printf("i = %d, j = %d\n", i, j); assert(i == 17); assert(j == 19); assert(a23[15] == 0x12345678); assert(a23[16] == 0x45546776); assert(a23[17] == 0x45546776); assert(a23[18] == 0x45546776); assert(a23[19] == 0x12345678); assert(a23[20] == 0x12345678); } /**************************************/ long[] b4; long[] func4(int dim) { long[] a = new long[dim]; b4 = a; return a; } void test4() { printf("test4()\n"); int i; int j; long[1] a1; a1[] = 0x123456789ABCDEF0; assert(a1[0] == 0x123456789ABCDEF0); long[2] a2; a2[] = 0x123456789ABCDEF0; for (i = 0; i < a2.length; i++) assert(a2[i] == 0x123456789ABCDEF0); long[3] a3; a3[] = 0x123456789ABCDEF0; for (i = 0; i < a3.length; i++) assert(a3[i] == 0x123456789ABCDEF0); long[4] a4; a4[] = 0x123456789ABCDEF0; for (i = 0; i < a4.length; i++) assert(a4[i] == 0x123456789ABCDEF0); long[8] a8; a8[] = 0x123456789ABCDEF0; for (i = 0; i < a8.length; i++) assert(a8[i] == 0x123456789ABCDEF0); long[27] a27; a27[] = 0x123456789ABCDEF0; for (i = 0; i < a27.length; i++) assert(a27[i] == 0x123456789ABCDEF0); func4(33)[] = 0x5678889911223344; for (i = 0; i < b4.length; i++) assert(b4[i] == 0x5678889911223344); long[23] a23 = 0x123456789ABCDEF0; i = 16; j = 18; a23[i++..++j] = 0x567888991122334B; printf("i = %d, j = %d\n", i, j); assert(i == 17); assert(j == 19); assert(a23[15] == 0x123456789ABCDEF0); assert(a23[16] == 0x567888991122334B); assert(a23[17] == 0x567888991122334B); assert(a23[18] == 0x567888991122334B); assert(a23[19] == 0x123456789ABCDEF0); assert(a23[20] == 0x123456789ABCDEF0); } /**************************************/ real[] b5; real[] func5(int dim) { real[] a = new real[dim]; b5 = a; return a; } void test5() { printf("test5()\n"); int i; int j; real[1] a1; a1[] = 31234; assert(a1[0] == 31234); real[2] a2; a2[] = 31234; for (i = 0; i < a2.length; i++) assert(a2[i] == 31234); real[3] a3; a3[] = 31234; for (i = 0; i < a3.length; i++) assert(a3[i] == 31234); real[4] a4; a4[] = 31234; for (i = 0; i < a4.length; i++) assert(a4[i] == 31234); real[8] a8; a8[] = 31234; for (i = 0; i < a8.length; i++) assert(a8[i] == 31234); real[27] a27; a27[] = 31234; for (i = 0; i < a27.length; i++) assert(a27[i] == 31234); func5(33)[] = 35678; for (i = 0; i < b5.length; i++) assert(b5[i] == 35678); real[23] a23 = 31234; i = 16; j = 18; a23[i++..++j] = 34554e+4; printf("i = %d, j = %d\n", i, j); assert(i == 17); assert(j == 19); assert(a23[15] == 31234); assert(a23[16] == 34554e+4); assert(a23[17] == 34554e+4); assert(a23[18] == 34554e+4); assert(a23[19] == 31234); assert(a23[20] == 31234); } /**************************************/ struct ABC { int a,b,c,d; } ABC abc1 = { a:1, b:2, c:3, d:4 }; ABC abc2 = { a:7, b:6, c:8, d:9 }; ABC abc3 = { a:5, b:10, c:11, d:12 }; ABC[] b6; ABC[] func6(int dim) { ABC[] a = new ABC[dim]; b6 = a; return a; } void test6() { printf("test6()\n"); int i; int j; ABC[1] a1; a1[] = abc1; assert(a1[0] == abc1); ABC[2] a2; a2[] = abc1; for (i = 0; i < a2.length; i++) assert(a2[i] == abc1); ABC[3] a3; a3[] = abc1; for (i = 0; i < a3.length; i++) assert(a3[i] == abc1); ABC[4] a4; a4[] = abc1; for (i = 0; i < a4.length; i++) assert(a4[i] == abc1); ABC[8] a8; a8[] = abc1; for (i = 0; i < a8.length; i++) assert(a8[i] == abc1); ABC[27] a27; a27[] = abc1; for (i = 0; i < a27.length; i++) assert(a27[i] == abc1); func6(33)[] = abc2; for (i = 0; i < b6.length; i++) assert(b6[i] == abc2); ABC[23] a23 = abc1; i = 16; j = 18; a23[i++..++j] = abc3; printf("i = %d, j = %d\n", i, j); assert(i == 17); assert(j == 19); assert(a23[15] == abc1); assert(a23[16] == abc3); assert(a23[17] == abc3); assert(a23[18] == abc3); assert(a23[19] == abc1); assert(a23[20] == abc1); } /**************************************/ bool[] b7; bool[] func7(int dim) { bool[] a = new bool[dim]; b7 = a; return a; } void test7() { printf("test7()\n"); int i; int j; bool[1] a1; a1[] = 1; assert(a1[0] == 1); bool[2] a2; a2[] = 1; for (i = 0; i < a2.length; i++) assert(a2[i] == 1); bool[3] a3; a3[] = 1; for (i = 0; i < a3.length; i++) assert(a3[i] == 1); bool[4] a4; a4[] = 1; for (i = 0; i < a4.length; i++) assert(a4[i] == 1); bool[8] a8; a8[] = 1; for (i = 0; i < a8.length; i++) assert(a8[i] == 1); bool[27] a27; a27[] = 1; for (i = 0; i < a27.length; i++) assert(a27[i] == 1); func7(33)[] = 1; assert(b7.length == 33); for (i = 0; i < b7.length; i++) assert(b7[i] == 1); func7(33)[3..6] = 1; //printf("b7.ptr = %p, b7.length = %d\n", b7.ptr, b7.length); assert(b7.length == 33); for (i = 0; i < b7.length; i++) { //printf("b7[%d] = %d\n", i, b7[i]); if (i >= 3 && i < 6) assert(b7[i] == 1); else assert(b7[i] == 0); } bool[23] a23 = 1; i = 16; j = 18; a23[i++..++j] = 0; printf("i = %d, j = %d\n", i, j); assert(i == 17); assert(j == 19); assert(a23[15] == 1); assert(a23[16] == 0); assert(a23[17] == 0); assert(a23[18] == 0); assert(a23[19] == 1); assert(a23[20] == 1); } /**************************************/ bool[] slice8(bool[] b) { return b[8..16]; } void test8() { bool[16] b; bool[] b2; b[9] = true; b2 = slice8(b); assert(b2.length == 8); assert(b2[1] == true); b[9] = false; assert(b2[1] == false); } /**************************************/ bool[] slice9(bool[] b, int i, int j) { return b[i..j]; } void test9() { bool[17] b; bool[] b2; b[9] = true; b[16] = true; b2 = slice9(b,8,17); assert(b2.length == 9); assert(b2[1] == true); assert(b2[8] == true); b[9] = false; b[16] = false; assert(b2[1] == false); assert(b2[8] == false); } /**************************************/ bool* foo10(bool[] b, int i) { return &b[i]; } void test10() { bool[17] b; bool* pb; b[8] = true; b[9] = true; pb = foo10(b, 8); assert(*pb == true); b[8] = false; assert(*pb == false); } /**************************************/ bool* foo11(bool[] b, int i) { return &b[i]; } void test11() { bool[17] b; bool* pb; b[9] = true; b[10] = true; pb = foo11(b, 8); assert(pb[1] == true); b[9] = false; assert(pb[1] == false); } /**************************************/ bool* foo12(bool[] b, int i) { return &b[i]; } void test12() { bool[17] b; bool* pb; b[9] = true; b[10] = true; pb = foo12(b, 0); pb = pb + 8; assert(pb[1] == true); b[9] = false; assert(pb[1] == false); } /**************************************/ bool* foo13(bool* b, int i) { return &b[i]; } void test13() { bool[17] b; bool* pb; b[9] = true; b[10] = true; pb = foo13(b.ptr, 8); assert(pb[1] == true); b[9] = false; assert(pb[1] == false); } /**************************************/ void test14() { bool b = true; assert(b); b = !b; assert(!b); } /**************************************/ void test15() { bool b = 1; bool *pb = &b; *pb = false; assert(!b); } /**************************************/ void foo16(bool[] b1, bool[] b2) { b1[0..3] = b2[8..11]; } void test16() { static bool[16] b1 = [1,1,0,1,0,0,0,0]; static bool[16] b2 = [0,0,0,0,0,0,0,0, 0,0,1,0,1,1,1,1]; foo16(b1, b2); assert(b1[0] == false); assert(b1[1] == false); assert(b1[2] == true); assert(b1[3] == true); assert(b1[4] == false); assert(b1[5] == false); assert(b1[6] == false); assert(b1[7] == false); assert(b1[8] == false); } /**************************************/ void test17() { bool bi = true; byte by; by=bi; assert(by == 1); } /**************************************/ void test18() { bool b = 1; bool c = 1; b |= cast(bool)(3 + c); assert(b == true); } /**************************************/ void test19() { int i; for (i = 0; i < 10; i++){ version(dummy) i=22; } assert(i==10); char[][] args; foreach(char[] p; args){ version(dummy) int i; } } /**************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/argufilem.d0000644000175000017500000000101113200164642023520 0ustar matthiasmatthias// EXTRA_SOURCES: imports/argufile.d // NOTE: The bug only works when main.d and argufile.d are put in // separate files and compiled like 'dmd main.d argufile.d' // Also, I'm sure writefln is causing the crash cause when I // use printf(), it doesn't crash. // main.d ------------------------------------------------------- import argufile; int main(string[] args) { string message = arguments("bob is ", 7, " years old"); writefln(message); argufile.useargs(); // will crash here return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/funclit.d0000644000175000017500000007022113200164642023222 0ustar matthiasmatthiasimport core.vararg; extern (C) int printf(const char*, ...); /***************************************************/ // lambda syntax check auto una(alias dg)(int n) { return dg(n); } auto bin(alias dg)(int n, int m) { return dg(n, m); } void test1() { assert(una!( a => a*2 )(2) == 4); assert(una!( ( a) => a*2 )(2) == 4); assert(una!( (int a) => a*2 )(2) == 4); assert(una!( ( a){ return a*2; } )(2) == 4); assert(una!( function ( a){ return a*2; } )(2) == 4); assert(una!( function int( a){ return a*2; } )(2) == 4); assert(una!( function (int a){ return a*2; } )(2) == 4); assert(una!( function int(int a){ return a*2; } )(2) == 4); assert(una!( delegate ( a){ return a*2; } )(2) == 4); assert(una!( delegate int( a){ return a*2; } )(2) == 4); assert(una!( delegate (int a){ return a*2; } )(2) == 4); assert(una!( delegate int(int a){ return a*2; } )(2) == 4); // partial parameter specialization syntax assert(bin!( ( a, b) => a*2+b )(2,1) == 5); assert(bin!( (int a, b) => a*2+b )(2,1) == 5); assert(bin!( ( a, int b) => a*2+b )(2,1) == 5); assert(bin!( (int a, int b) => a*2+b )(2,1) == 5); assert(bin!( ( a, b){ return a*2+b; } )(2,1) == 5); assert(bin!( (int a, b){ return a*2+b; } )(2,1) == 5); assert(bin!( ( a, int b){ return a*2+b; } )(2,1) == 5); assert(bin!( (int a, int b){ return a*2+b; } )(2,1) == 5); assert(bin!( function ( a, b){ return a*2+b; } )(2,1) == 5); assert(bin!( function (int a, b){ return a*2+b; } )(2,1) == 5); assert(bin!( function ( a, int b){ return a*2+b; } )(2,1) == 5); assert(bin!( function (int a, int b){ return a*2+b; } )(2,1) == 5); assert(bin!( function int( a, b){ return a*2+b; } )(2,1) == 5); assert(bin!( function int(int a, b){ return a*2+b; } )(2,1) == 5); assert(bin!( function int( a, int b){ return a*2+b; } )(2,1) == 5); assert(bin!( function int(int a, int b){ return a*2+b; } )(2,1) == 5); assert(bin!( delegate ( a, b){ return a*2+b; } )(2,1) == 5); assert(bin!( delegate (int a, b){ return a*2+b; } )(2,1) == 5); assert(bin!( delegate ( a, int b){ return a*2+b; } )(2,1) == 5); assert(bin!( delegate (int a, int b){ return a*2+b; } )(2,1) == 5); assert(bin!( delegate int( a, b){ return a*2+b; } )(2,1) == 5); assert(bin!( delegate int(int a, b){ return a*2+b; } )(2,1) == 5); assert(bin!( delegate int( a, int b){ return a*2+b; } )(2,1) == 5); assert(bin!( delegate int(int a, int b){ return a*2+b; } )(2,1) == 5); } /***************************************************/ // on initializer void test2() { // explicit typed binding ignite parameter types inference int function(int) fn1 = a => a*2; assert(fn1(2) == 4); int function(int) fn2 = ( a){ return a*2; }; assert(fn2(2) == 4); int function(int) fn3 = function ( a){ return a*2; }; assert(fn3(2) == 4); int function(int) fn4 = function int( a){ return a*2; }; assert(fn4(2) == 4); int function(int) fn5 = function (int a){ return a*2; }; assert(fn5(2) == 4); int function(int) fn6 = function int(int a){ return a*2; }; assert(fn6(2) == 4); int delegate(int) dg1 = a => a*2; assert(dg1(2) == 4); int delegate(int) dg2 = ( a){ return a*2; }; assert(dg2(2) == 4); int delegate(int) dg3 = delegate ( a){ return a*2; }; assert(dg3(2) == 4); int delegate(int) dg4 = delegate int( a){ return a*2; }; assert(dg4(2) == 4); int delegate(int) dg5 = delegate (int a){ return a*2; }; assert(dg5(2) == 4); int delegate(int) dg6 = delegate int(int a){ return a*2; }; assert(dg6(2) == 4); // funciton/delegate mismatching always raises an error static assert(!__traits(compiles, { int function(int) xfg3 = delegate ( a){ return a*2; }; })); static assert(!__traits(compiles, { int function(int) xfg4 = delegate int( a){ return a*2; }; })); static assert(!__traits(compiles, { int function(int) xfg5 = delegate (int a){ return a*2; }; })); static assert(!__traits(compiles, { int function(int) xfg6 = delegate int(int a){ return a*2; }; })); static assert(!__traits(compiles, { int delegate(int) xdn3 = function ( a){ return a*2; }; })); static assert(!__traits(compiles, { int delegate(int) xdn4 = function int( a){ return a*2; }; })); static assert(!__traits(compiles, { int delegate(int) xdn5 = function (int a){ return a*2; }; })); static assert(!__traits(compiles, { int delegate(int) xdn6 = function int(int a){ return a*2; }; })); // auto binding requires explicit parameter types at least static assert(!__traits(compiles, { auto afn1 = a => a*2; })); static assert(!__traits(compiles, { auto afn2 = ( a){ return a*2; }; })); static assert(!__traits(compiles, { auto afn3 = function ( a){ return a*2; }; })); static assert(!__traits(compiles, { auto afn4 = function int( a){ return a*2; }; })); static assert(!__traits(compiles, { auto adg3 = delegate ( a){ return a*2; }; })); static assert(!__traits(compiles, { auto adg4 = delegate int( a){ return a*2; }; })); auto afn5 = function (int a){ return a*2; }; assert(afn5(2) == 4); auto afn6 = function int(int a){ return a*2; }; assert(afn6(2) == 4); auto adg5 = delegate (int a){ return a*2; }; assert(adg5(2) == 4); auto adg6 = delegate int(int a){ return a*2; }; assert(adg6(2) == 4); // partial specialized lambda string delegate(int, string) dg = (n, string s){ string r = ""; foreach (_; 0..n) r~=s; return r; }; assert(dg(2, "str") == "strstr"); } /***************************************************/ // on return statement void test3() { // inference matching system is same as on initializer int delegate(int) mul(int x) { return a => a * x; } assert(mul(5)(2) == 10); } /***************************************************/ // on function arguments auto foo4(int delegate(int) dg) { return dg(10); } auto foo4(int delegate(int, int) dg) { return dg(10, 20); } void nbar4fp(void function(int) fp) { } void nbar4dg(void delegate(int) dg) { } void tbar4fp(T,R)(R function(T) dg) { static assert(is(typeof(dg) == void function(int))); } void tbar4dg(T,R)(R delegate(T) dg) { static assert(is(typeof(dg) == void delegate(int))); } auto nbaz4(void function() fp) { return 1; } auto nbaz4(void delegate() dg) { return 2; } auto tbaz4(R)(R function() dg) { static assert(is(R == void)); return 1; } auto tbaz4(R)(R delegate() dg) { static assert(is(R == void)); return 2; } auto thoo4(T)(T lambda){ return lambda; } void tfun4a()(int function(int) a){} void tfun4b(T)(T function(T) a){} void tfun4c(T)(T f){} void test4() { int v; static void sfoo() {} void nfoo() {} // parameter type inference + overload resolution assert(foo4((a) => a * 2) == 20); assert(foo4((a,b) => a * 2 + b) == 40); // function/delegate inference nbar4fp((int x){ }); nbar4dg((int x){ }); tbar4fp((int x){ }); tbar4dg((int x){ }); // function/delegate inference + overload resolution assert(nbaz4({ }) == 1); assert(nbaz4({ v = 1; }) == 2); assert(nbaz4({ sfoo(); }) == 1); // Bugzilla 8836 assert(nbaz4({ nfoo(); }) == 2); assert(tbaz4({ }) == 1); assert(tbaz4({ v = 1; }) == 2); assert(tbaz4({ sfoo(); }) == 1); assert(tbaz4({ nfoo(); }) == 2); // template function deduction static assert(is(typeof(thoo4({ })) : void function())); static assert(is(typeof(thoo4({ v = 1; })) : void delegate())); tfun4a(a => a); static assert(!__traits(compiles, { tfun4b(a => a); })); static assert(!__traits(compiles, { tfun4c(a => a); })); } void fsvarg4(int function(int)[] a...){} void fcvarg4(int dummy, ...){} void tsvarg4a()(int function(int)[] a...){} void tsvarg4b(T)(T function(T)[] a...){} void tsvarg4c(T)(T [] a...){} void tcvarg4()(int dummy, ...){} void test4v() { fsvarg4(function(int a){ return a; }); // OK fsvarg4(a => a); // OK fcvarg4(0, function(int a){ return a; }); // OK static assert(!__traits(compiles, { fcvarg4(0, a => a); })); tsvarg4a(function(int a){ return a; }); // OK tsvarg4b(function(int a){ return a; }); // OK tsvarg4c(function(int a){ return a; }); // OK tsvarg4a(a => a); static assert(!__traits(compiles, { tsvarg4b(a => a); })); static assert(!__traits(compiles, { tsvarg4c(a => a); })); tcvarg4(0, function(int a){ return a; }); // OK static assert(!__traits(compiles, { tcvarg4(0, a => a); })); } /***************************************************/ // on CallExp::e1 void test5() { assert((a => a*2)(10) == 20); assert(( a, s){ return s~s; }(10, "str") == "strstr"); assert((int a, s){ return s~s; }(10, "str") == "strstr"); assert(( a, string s){ return s~s; }(10, "str") == "strstr"); assert((int a, string s){ return s~s; }(10, "str") == "strstr"); } /***************************************************/ // escape check to nested function symbols void checkNestedRef(alias dg)(bool isnested) { static if (is(typeof(dg) == delegate)) enum isNested = true; else static if ((is(typeof(dg) PF == F*, F) && is(F == function))) enum isNested = false; else static assert(0); assert(isnested == isNested); dg(); } void freeFunc(){} void test6() { static void localFunc(){} void nestedLocalFunc(){} checkNestedRef!({ })(false); checkNestedRef!({ freeFunc(); })(false); checkNestedRef!({ localFunc(); })(false); checkNestedRef!({ nestedLocalFunc(); })(true); checkNestedRef!({ void inner(){} inner(); })(false); checkNestedRef!({ auto f = &freeFunc; })(false); checkNestedRef!({ auto f = &localFunc; })(false); checkNestedRef!({ auto f = &nestedLocalFunc; })(true); checkNestedRef!({ void inner(){} auto f = &inner; })(false); } /***************************************************/ // on AssignExp::e2 void test7() { int function(int) fp; fp = a => a; fp = (int a) => a; fp = function(int a) => a; fp = function int(int a) => a; static assert(!__traits(compiles, { fp = delegate(int a) => a; })); static assert(!__traits(compiles, { fp = delegate int(int a) => a; })); int delegate(int) dg; dg = a => a; dg = (int a) => a; dg = delegate(int a) => a; dg = delegate int(int a) => a; static assert(!__traits(compiles, { dg = function(int a) => a; })); static assert(!__traits(compiles, { dg = function int(int a) => a; })); } /***************************************************/ // on StructLiteralExp::elements void test8() { struct S { int function(int) fp; } auto s1 = S(a => a); static assert(!__traits(compiles, { auto s2 = S((a, b) => a); })); } /***************************************************/ // on concat operation void test9() { int function(int)[] a2; a2 ~= x => x; } /***************************************************/ // on associative array key void test10() { int[int function()] aa; assert(!aa.remove(() => 1)); int[int function(int)] aa2; assert(!aa2.remove(x => 1)); } /***************************************************/ // on common type deduction void test11() { auto a1 = [x => x, (int x) => x * 2]; static assert(is(typeof(a1[0]) == int function(int) pure @safe nothrow @nogc)); assert(a1[0](10) == 10); assert(a1[1](10) == 20); //int n = 10; //auto a2 = [x => n, (int x) => x * 2]; //static assert(is(typeof(a2[0]) == int delegate(int) @safe nothrow)); //assert(a2[0](99) == 10); //assert(a2[1](10) == 20); int function(int) fp = true ? (x => x) : (x => x*2); assert(fp(10) == 10); int m = 10; int delegate(int) dg = true ? (x => x) : (x => m*2); assert(dg(10) == 10); } /***************************************************/ // 3235 void test3235() { // from TDPL auto f = (int i) {}; static if (is(typeof(f) _ == F*, F) && is(F == function)) {} else static assert(0); } /***************************************************/ // 6714 void foo6714x(int function (int, int) a){} void bar6714x(int delegate (int, int) a){} int bar6714y(double delegate(int, int) a){ return 1; } int bar6714y( int delegate(int, int) a){ return 2; } void test6714() { foo6714x((a, b) { return a + b; }); bar6714x((a, b) { return a + b; }); assert(bar6714y((a, b){ return 1.0; }) == 1); assert(bar6714y((a, b){ return 1.0f; }) == 1); assert(bar6714y((a, b){ return a; }) == 2); } /***************************************************/ // 7193 void test7193() { static assert(!__traits(compiles, { delete a => a; })); } /***************************************************/ // 7207 : on CastExp void test7202() { auto dg = cast(int function(int))(a => a); assert(dg(10) == 10); } /***************************************************/ // 7288 void test7288() { // 7288 -> OK auto foo() { int x; return () => { return x; }; } pragma(msg, typeof(&foo)); alias int delegate() pure nothrow @nogc @safe delegate() pure nothrow @nogc @safe delegate() pure nothrow @safe Dg; pragma(msg, Dg); static assert(is(typeof(&foo) == Dg)); // should pass } /***************************************************/ // 7499 void test7499() { int function(int)[] a1 = [ x => x ]; // 7499 int function(int)[][] a2 = [[x => x]]; // +a assert(a1[0] (10) == 10); assert(a2[0][0](10) == 10); } /***************************************************/ // 7500 void test7500() { alias immutable bool function(int[]) Foo; Foo f = a => true; } /***************************************************/ // 7525 void test7525() { { char[] delegate() a = { return null; }; int delegate() b = { return 1U; }; uint delegate() c = { return 1; }; float delegate() d = { return 1.0; }; double delegate() e = { return 1.0f; }; } { char[] delegate(int) a = (x){ return null; }; int delegate(int) b = (x){ return 1U; }; uint delegate(int) c = (x){ return 1; }; float delegate(int) d = (x){ return 1.0; }; double delegate(int) e = (x){ return 1.0f; }; } } /***************************************************/ // 7582 void test7582() { void delegate(int) foo; void delegate(int) foo2; foo = (a) { foo2 = (b) { }; }; } /***************************************************/ // 7649 void test7649() { void foo(int function(int) fp = x => 1) { assert(fp(1) == 1); } foo(); } /***************************************************/ // 7650 void test7650() { int[int function(int)] aa1 = [x=>x:1, x=>x*2:2]; foreach (k, v; aa1) { if (v == 1) assert(k(10) == 10); if (v == 2) assert(k(10) == 20); } int function(int)[int] aa2 = [1:x=>x, 2:x=>x*2]; assert(aa2[1](10) == 10); assert(aa2[2](10) == 20); int n = 10; int[int delegate(int)] aa3 = [x=>n+x:1, x=>n+x*2:2]; foreach (k, v; aa3) { if (v == 1) assert(k(10) == 20); if (v == 2) assert(k(10) == 30); } int delegate(int)[int] aa4 = [1:x=>n+x, 2:x=>n+x*2]; assert(aa4[1](10) == 20); assert(aa4[2](10) == 30); } /***************************************************/ // 7705 void test7705() { void foo1(void delegate(ref int ) dg){ int x=10; dg(x); } foo1((ref x){ pragma(msg, typeof(x)); assert(x == 10); }); static assert(!__traits(compiles, foo1((x){}) )); void foo2(void delegate(int, ...) dg){ dg(20, 3.14); } foo2((x,...){ pragma(msg, typeof(x)); assert(x == 20); }); void foo3(void delegate(int[]...) dg){ dg(1, 2, 3); } foo3((x ...){ pragma(msg, typeof(x)); assert(x == [1,2,3]); }); } /***************************************************/ // 7713 void foo7713(T)(T delegate(in Object) dlg) {} void test7713() { foo7713( (in obj) { return 15; } ); // line 6 } /***************************************************/ // 7743 auto foo7743a() { int x = 10; return () nothrow { return x; }; } auto foo7743b() { int x = 10; return () nothrow => x; } void test7743() { pragma(msg, typeof(&foo7743a)); static assert(is(typeof(&foo7743a) == int delegate() pure nothrow @nogc @safe function() pure nothrow @safe)); assert(foo7743a()() == 10); static assert(is(typeof(&foo7743b) == int delegate() pure nothrow @nogc @safe function() pure nothrow @safe)); assert(foo7743b()() == 10); } /***************************************************/ // 7761 enum dg7761 = (int a) pure => 2 * a; void test7761() { static assert(is(typeof(dg7761) == int function(int) pure @safe nothrow @nogc)); assert(dg7761(10) == 20); } /***************************************************/ // 7941 void test7941() { static assert(!__traits(compiles, { enum int c = function(){}; })); } /***************************************************/ // 8005 void test8005() { auto n = (a, int n = 2){ return n; }(1); assert(n == 2); } /***************************************************/ // test8198 void test8198() { T delegate(T) zero(T)(T delegate(T) f) { return x => x; } T delegate(T) delegate(T delegate(T)) succ(T)(T delegate(T) delegate(T delegate(T)) n) { return f => x => f(n(f)(x)); } uint delegate(uint) delegate(uint delegate(uint)) n = &zero!uint; foreach (i; 0..10) { assert(n(x => x + 1)(0) == i); n = succ(n); } } /***************************************************/ // 8226 immutable f8226 = (int x) => x * 2; void test8226() { assert(f8226(10) == 20); } /***************************************************/ // 8241 auto exec8241a(alias a = function(x) => x, T...)(T as) { return a(as); } auto exec8241b(alias a = (x) => x, T...)(T as) { return a(as); } void test8241() { exec8241a(2); exec8241b(2); } /***************************************************/ // 8242 template exec8242(alias a, T...) { auto func8242(T as) { return a(as); } } mixin exec8242!(x => x, int); mixin exec8242!((string x) => x, string); void test8242() { func8242(1); func8242(""); } /***************************************************/ // 8315 void test8315() { bool b; foo8315!(a => b)(); } void foo8315(alias pred)() if (is(typeof(pred(1)) == bool)) {} /***************************************************/ // 8397 void test8397() { void function(int) f; static assert(!is(typeof({ f = function(string x) {}; }))); } /***************************************************/ // 8496 void test8496() { alias extern (C) void function() Func; Func fp = (){}; fp = (){}; } /***************************************************/ // 8575 template tfunc8575(func...) { auto tfunc8575(U)(U u) { return func[0](u); } } auto bar8575(T)(T t) { return tfunc8575!(a => a)(t); } void foo8575a() { assert(bar8575(uint.init + 1) == +1); } void foo8575b() { assert(bar8575( int.init - 1) == -1); } void test8575() { foo8575a(); foo8575b(); } /***************************************************/ // 9153 void writeln9153(string s){} void test9153() { auto tbl1 = [ (string x) { writeln9153(x); }, (string x) { x ~= 'a'; }, ]; auto tbl2 = [ (string x) { x ~= 'a'; }, (string x) { writeln9153(x); }, ]; } /***************************************************/ // 9393 template ifThrown9393a(E) { void ifThrown9393a(T)(scope T delegate(E) errHandler) { } } void ifThrown9393b(E, T)(scope T delegate(E) errHandler) { } void foo9393(T)(void delegate(T) dg){ dg(T.init); } void foo9393()(void delegate(int) dg){ foo9393!int(dg); } void test9393() { ifThrown9393a!Exception(e => 10); ifThrown9393b!Exception(e => 10); foo9393((x){ assert(x == int.init); }); } /***************************************************/ // 9415 void test9415() { int z; typeof((int a){return z;}) dg; dg = (int a){return z;}; } /***************************************************/ // 9628 template TypeTuple9628(TL...) { alias TypeTuple9628 = TL; } void map9628(alias func)() { func(0); } void test9628() { auto items = [[10, 20], [30]]; size_t[] res; res = null; foreach (_; 0 .. 2) { foreach (sub; items) { map9628!(( i){ res ~= sub.length; }); map9628!((size_t i){ res ~= sub.length; }); } } assert(res == [2,2,1,1, 2,2,1,1]); res = null; foreach (_; TypeTuple9628!(0, 1)) { foreach (sub; items) { map9628!(( i){ res ~= sub.length; }); map9628!((size_t i){ res ~= sub.length; }); } } assert(res == [2,2,1,1, 2,2,1,1]); } /***************************************************/ // 9928 void test9928() { void* smth = (int x) { return x; }; } /***************************************************/ // 10133 ptrdiff_t countUntil10133(alias pred, R)(R haystack) { typeof(return) i; alias T = dchar; foreach (T elem; haystack) { if (pred(elem)) return i; ++i; } return -1; } bool func10133(string s)() if (countUntil10133!(x => x == 'x')(s) == 1) { return true; } bool func10133a(string s)() if (countUntil10133!(x => s == "x")(s) != -1) { return true; } bool func10133b(string s)() if (countUntil10133!(x => s == "x")(s) != -1) { return true; } void test10133() { func10133!("ax")(); func10133a!("x")(); static assert(!is(typeof(func10133a!("ax")()))); static assert(!is(typeof(func10133b!("ax")()))); func10133b!("x")(); } /***************************************************/ // 10219 void test10219() { interface I { } class C : I { } void test_dg(I delegate(C) dg) { C c = new C; void* cptr = cast(void*) c; void* iptr = cast(void*) cast(I) c; void* xptr = cast(void*) dg(c); assert(cptr != iptr); assert(cptr != xptr); // should pass assert(iptr == xptr); // should pass } C delegate(C c) dg = delegate C(C c) { return c; }; static assert(!__traits(compiles, { test_dg(dg); })); static assert(!__traits(compiles, { test_dg(delegate C(C c) { return c; }); })); static assert(!__traits(compiles, { I delegate(C) dg2 = dg; })); // creates I delegate(C) test_dg(c => c); test_dg(delegate(C c) => c); void test_fp(I function(C) fp) { C c = new C; void* cptr = cast(void*) c; void* iptr = cast(void*) cast(I) c; void* xptr = cast(void*) fp(c); assert(cptr != iptr); assert(cptr != xptr); // should pass assert(iptr == xptr); // should pass } C function(C c) fp = function C(C c) { return c; }; static assert(!__traits(compiles, { test_fp(fp); })); static assert(!__traits(compiles, { test_fp(function C(C c) { return c; }); })); static assert(!__traits(compiles, { I function(C) fp2 = fp; })); // creates I function(C) test_fp(c => c); test_fp(function(C c) => c); } /***************************************************/ // 10288 T foo10288(T)(T x) { void lambda() @trusted nothrow { x += 10; } lambda(); return x; } T bar10288(T)(T x) { () @trusted { x += 10; } (); return x; } T baz10288(T)(T arg) { static int g = 10; () @trusted { x += g; } (); return x; } void test10288() @safe pure nothrow { assert(foo10288(10) == 20); // OK assert(bar10288(10) == 20); // OK <- NG static assert(!__traits(compiles, baz10288(10))); } /***************************************************/ // 10666 struct S10666 { int val; ~this() {} } void foo10666(S10666 s1) { S10666 s2; /* Even if closureVars(s1 and s2) are accessed by directly called lambdas, * they won't escape the scope of this function. */ auto x1 = (){ return s1.val; }(); // OK auto x2 = (){ return s2.val; }(); // OK } /***************************************************/ // 11081 T ifThrown11081(E : Throwable, T)(T delegate(E) errorHandler) { return errorHandler(); } void test11081() { static if (__traits(compiles, ifThrown11081!Exception(e => 0))) { } static if (__traits(compiles, ifThrown11081!Exception(e => 0))) { } } /***************************************************/ // 11220 int parsePrimaryExp11220(int x) { parseAmbig11220!( (parsed){ x += 1; } )(); return 1; } typeof(handler(1)) parseAmbig11220(alias handler)() { return handler(parsePrimaryExp11220(1)); } /***************************************************/ // 11230 template map11230(fun...) { auto map11230(Range)(Range r) { return MapResult11230!(fun, Range)(r); } } struct MapResult11230(alias fun, R) { R _input; this(R input) { _input = input; } } class A11230 { A11230[] as; } class B11230 { A11230[] as; } class C11230 : A11230 {} C11230 visit11230(A11230 a) { a.as.map11230!(a => visit11230); return null; } C11230 visit11230(B11230 b) { b.as.map11230!(a => visit11230); return null; } C11230 visit11230() { return null; } /***************************************************/ // 10336 struct S10336 { template opDispatch(string name) { enum opDispatch = function(int x) { return x; }; } } void test10336() { S10336 s; assert(s.hello(12) == 12); } /***************************************************/ // 10928 struct D10928 { int x; ~this() @nogc {} } void f10928a(D10928 bar) { (){ bar.x++; }(); } void f10928b(D10928 bar) @nogc { (){ bar.x++; }(); } void test10928() { f10928a(D10928.init); f10928b(D10928.init); } /***************************************************/ // 11661 void test11661() { void delegate() dg = {}; // OK void function() fp = {}; // OK <- NG } /***************************************************/ // 11774 void f11774(T, R)(R delegate(T[]) dg) { T[] src; dg(src); } void test11774() { int[] delegate(int[]) dg = (int[] a) => a; f11774!int(dg); f11774!Object(a => a); f11774!int(dg); } /***************************************************/ // 12508 interface A12508(T) { T getT(); } class C12508 : A12508!double { double getT() { return 1; } } void f12508(A12508!double delegate() dg) { auto a = dg(); assert(a !is null); assert(a.getT() == 1.0); // fails! } void t12508(T)(A12508!T delegate() dg) { auto a = dg(); assert(a !is null); assert(a.getT() == 1.0); // fails! } ref alias Dg12508 = A12508!double delegate(); void t12508(T)(Dg12508 dg) {} void test12508() { f12508({ return new C12508(); }); t12508({ return new C12508(); }); static assert(!__traits(compiles, x12508({ return new C12508(); }))); } /***************************************************/ // 13879 void test13879() { bool function(int)[2] funcs1 = (int x) => true; // OK assert(funcs1[0] is funcs1[1]); funcs1[0] = x => true; // OK bool function(int)[2] funcs2 = x => true; // OK <- Error assert(funcs2[0] is funcs2[1]); } /***************************************************/ int main() { test1(); test2(); test3(); test4(); test4v(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test3235(); test6714(); test7193(); test7202(); test7288(); test7499(); test7500(); test7525(); test7582(); test7649(); test7650(); test7705(); test7713(); test7743(); test7761(); test7941(); test8005(); test8198(); test8226(); test8241(); test8242(); test8315(); test8397(); test8496(); test8575(); test9153(); test9393(); test9415(); test9628(); test9928(); test10133(); test10219(); test10288(); test10336(); test10928(); test11661(); test11774(); test12508(); test13879(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/tls_dup.d0000644000175000017500000000323113200164642023225 0ustar matthiasmatthias// NOTE: this is a dup of runnable/tls.d strictly to test the same code compiled // separately rather than together like the original is. // COMPILE_SEPARATELY // EXTRA_SOURCES: imports/tlsa.d // PERMUTE_ARGS: import core.stdc.stdio; import imports.tlsa; int x = 3; void bar() { int* px = &x; assert(x == 3); x++; printf("x = %d\n", x); px = &x; printf("px = %p\n", px); assert(*px == 4); (*px)++; assert(x == 5); } void test1() { bar(); printf("%d\n", x); printf("%d\n", foo!()()); } /************************************/ long fooa; long foob; int bara = 0x12345678; int barb = 0x9ABCDEFF; void test2() { fooa++; foob--; bara++; barb++; printf("%lld %lld %x %x\n", fooa, foob, bara, barb); assert(fooa == 1); assert(foob == -1); assert(bara == 0x12345679); assert(barb == 0x9ABCDF00); } /************************************/ int abc3(T)(T t) { static T qqq; static T rrr; static T sss = 8; static T ttt = 9; printf("qqq = %d, rrr = %d, sss = %d, ttt = %d\n", qqq, rrr, sss, ttt); assert(sss == 8); assert(ttt == 9); rrr += 7; return t + ++qqq + rrr; } void test3() { auto i = abc3(3); printf("i = x%x\n", i); assert(i == 11); i = abc3(4); printf("i = x%x\n", i); assert(i == 20); } /************************************/ void test4() { auto i = bar4(); printf("i = x%x\n", i); assert(i == 0x23); i = abc4(4); printf("i = x%x\n", i); assert(i == 0x31); } /************************************/ int main() { test1(); test2(); test3(); test4(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_eh.d0000644000175000017500000000073713200164642023001 0ustar matthiasmatthiasstruct S1 { int x; this(this) { } ~this() { } } S1 createS1() { // dmdfe creates try-finally there to call destructor for s1, // later the statement is rewrited to try-catch, because // s1 is a nrvo variable. Test goto in such case. S1 s1; s1.x = 1; if(true) goto Lexit; s1.x = 2; Lexit: return s1; } void test1() { auto s1 = createS1(); assert(s1.x == 1); } void main() { test1(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test40.d0000644000175000017500000000027513200164642022703 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test40a.d // PERMUTE_ARGS: // REQUIRED_ARGS: import std.stdio; import imports.test40a; class Foo { mixin Mix; } void main() { Bar.foobar(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/wc.d0000644000175000017500000000154013200164642022165 0ustar matthiasmatthias// PERMUTE_ARGS: // EXECUTE_ARGS: runnable/wc.d import std.file; extern(C) int printf(const char*, ...); int main (string[] args) { int w_total; int l_total; int c_total; printf (" lines words bytes file\n"); foreach (arg; args[1 .. args.length]) { string input; int w_cnt, l_cnt, c_cnt; int inword; input = cast(string)std.file.read(arg); foreach (char c; input) { if (c == '\n') ++l_cnt; if (c != ' ') { if (!inword) { inword = 1; ++w_cnt; } } else inword = 0; ++c_cnt; } printf ("%8lu%8lu%8lu %.*s\n", l_cnt, w_cnt, c_cnt, arg.length, arg.ptr); l_total += l_cnt; w_total += w_cnt; c_total += c_cnt; } if (args.length > 2) { printf ("--------------------------------------\n%8lu%8lu%8lu total", l_total, w_total, c_total); } return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testminit.d0000644000175000017500000000046413200164642023600 0ustar matthiasmatthias// EXTRA_SOURCES: imports/testminitAA.d imports/testminitBB.d // PERMUTE_ARGS: import core.stdc.stdio; import imports.testminitAA; private import imports.testminitBB; static this() { printf("hello\n"); assert(aa == 1); assert(bb == 1); } int main() { printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test9271.d0000644000175000017500000000040213200164642023052 0ustar matthiasmatthias// PERMUTE_ARGS: import algorithm = imports.test9271a; bool any(alias predicate, Range)(Range range) { return algorithm.any!(predicate)(range); } void main() { auto arr = ["foo"]; any!(e => e == "asd")(arr); // infinite recursive call -> OK } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link6574.d0000644000175000017500000000166113200164642023043 0ustar matthiasmatthias// PERMUTE_ARGS: module link6574; enum Method { A, B, } int foo(Method method = Method.A)() { static assert(foo.mangleof == "_D8link657428__T3fooVE8link65746Methodi0Z3fooFZi"); return 10 * foo!method(); } int foo(Method method : Method.A)() { static assert(foo.mangleof == "_D8link657429__T3fooHVE8link65746Methodi0Z3fooFZi"); return 2; } int foo(Method method : Method.B)() { static assert(0); return 3; } int bar(Method method = Method.B)() { static assert(bar.mangleof == "_D8link657428__T3barVE8link65746Methodi1Z3barFZi"); return 10 * bar!method(); } int bar(Method method : Method.A)() { static assert(0); return 2; } int bar(Method method : Method.B)() { static assert(bar.mangleof == "_D8link657429__T3barHVE8link65746Methodi1Z3barFZi"); return 3; } void main() { assert(foo!() == 10 * 2); assert(foo() == 10 * 2); assert(bar!() == 10 * 3); assert(bar() == 10 * 3); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/circular.d0000644000175000017500000000055013200164642023360 0ustar matthiasmatthias// REQUIRED_ARGS: -d // PERMUTE_ARGS: -dw // EXTRA_SOURCES: imports/circularA.d // This bug is typedef-specific. // Bugzilla 4543 import core.stdc.stdio; import imports.circularA; class bclass {}; alias bclass Tclass; struct bstruct {} alias bstruct Tstruct; /************************************/ int main() { printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testsignals.d0000644000175000017500000000357613200164642024127 0ustar matthiasmatthiasimport std.stdio; import std.signals; class Observer { // our slot void watch(string msg, int i) { writefln("Observed msg '%s' and value %s", msg, i); } void watch2(int i, int j) { writefln("Observed msg %s,%s", i, j); } } class Foo { int value() { return _value; } int value(int v) { if (v != _value) { _value = v; // call all the connected slots with the two parameters emit("setting new value", v); } return v; } // Mix in all the code we need to make Foo into a signal mixin Signal!(string, int); private : int _value; } void test1() { Foo a = new Foo; Observer o = new Observer; a.value = 3; // should not call o.watch() a.connect(&o.watch); // o.watch is the slot a.value = 4; // should call o.watch() a.disconnect(&o.watch); // o.watch is no longer a slot a.value = 5; // so should not call o.watch() a.connect(&o.watch); // connect again a.value = 6; // should call o.watch() delete o; // destroying o should automatically disconnect it a.value = 7; // should not call o.watch() } /******************************************/ class Input { mixin Signal!(int, int) click; mixin Signal!(char) keyDown; } void test2() { Observer o = new Observer(); Input a = new Input(); a.click.connect(&o.watch2); a.click.emit(5,6); } /******************************************/ class Args3 { int foo; } class Base3 { ~this() { writefln("Base3 dtor!"); } } class Test3 : Base3 { mixin Signal!(Args3) A; mixin Signal!(Args3) B; ~this() { writefln("Test3 dtor"); } } void test3() { auto test = new Test3; } /******************************************/ int main() { test1(); test2(); test3(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_179.d0000644000175000017500000000055713200164642024267 0ustar matthiasmatthiasalias __vector(int[4]) int4; alias __vector(long[2]) long2; void testVectorCast() { // TODO: Depending on the exact semantics of vector types, which are not // clear from the D reference manual, this test might be endian-sensitive. int4 a = [1, 0, 2, 0]; auto b = cast(long2) a; assert(b.array == [1, 2]); } void main() { testVectorCast(); }ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testscope2.d0000644000175000017500000000725313200164642023656 0ustar matthiasmatthias// REQUIRED_ARGS: -dip25 import core.stdc.stdio; /********************************************/ struct SS { ref int foo1(return ref int delegate() return p) return; ref int foo2(return ref int delegate() p); ref int foo3(inout ref int* p); ref int foo4(return inout ref int* p); } pragma(msg, "foo1 ", typeof(&SS.foo1)); pragma(msg, "foo2 ", typeof(&SS.foo2)); pragma(msg, "foo3 ", typeof(&SS.foo3)); pragma(msg, "foo4 ", typeof(&SS.foo4)); void test3() { version (all) { import std.stdio; writeln(SS.foo1.mangleof); writeln(SS.foo2.mangleof); writeln(SS.foo3.mangleof); writeln(SS.foo4.mangleof); writeln(typeof(SS.foo1).stringof); writeln(typeof(SS.foo2).stringof); writeln(typeof(SS.foo3).stringof); writeln(typeof(SS.foo4).stringof); } version (all) { // Test scope mangling assert(SS.foo1.mangleof == "_D10testscope22SS4foo1MFNcNjNkKDFNjZiZi"); assert(SS.foo2.mangleof == "_D10testscope22SS4foo2MFNcNkKDFZiZi"); assert(SS.foo3.mangleof == "_D10testscope22SS4foo3MFNcNkKNgPiZi"); assert(SS.foo4.mangleof == "_D10testscope22SS4foo4MFNcNkKNgPiZi"); // Test scope pretty-printing assert(typeof(SS.foo1).stringof == "ref int(return ref int delegate() return p)return "); assert(typeof(SS.foo2).stringof == "ref int(return ref int delegate() p)"); assert(typeof(SS.foo3).stringof == "ref int(return ref inout(int*) p)"); assert(typeof(SS.foo4).stringof == "ref int(return ref inout(int*) p)"); } } /********************************************/ ref int foo(return ref int x) { return x; } struct S { int x; ref S bar() return { return this; } } ref T foo2(T)(ref T x) { return x; } void test4() { int x; foo2(x); } /********************************************/ ref int foo(return ref int x, ref int y) { return x; } ref int bar() { int x; static int y = 7; return foo(y, x); } void test5() { int x = bar(); assert(x == 7); } /********************************************/ struct S6 { int x = 8; ref int bar() return { return x; } } void test6() { S6 s; int b = s.bar(); assert(b == 8); } /********************************************/ class C { int x; ref int foo(return ref int x) { return x; } ref int bar() return { return x; } } class D : C { override ref int foo(ref int x) { static int y; return y; } override ref int bar() { static int y; return y; } } void test7() { } /********************************************/ struct S8(T) { int x; ref int bar() // infer 'return' { return x; } } ref int test8a(return ref S8!int s) { return s.bar(); } void test8() { } /********************************************/ char[] foo9(return out char[4] buf) { return buf[0 .. 1]; } /********************************************/ struct S10 { int x; ref inout(int) foo() inout { return x; } } /********************************************/ struct RC { this(this) { } } struct S11 { @disable this(this); void remove() { _ptr[0] = _ptr[1]; } RC* _ptr; } void test11() { S11 ary; } /********************************************/ int[10] a12; int* foo12() { foreach (ref x; a12) return &x; return null; } /********************************************/ struct FullCaseEntry { dchar[3] seq; ubyte n, size;// n number in batch, size - size of batch ubyte entry_len; @property auto value() const @trusted pure nothrow @nogc return { return seq[0..entry_len]; } } /********************************************/ void main() { test3(); test4(); test5(); test6(); test7(); test8(); test11(); printf("Success\n"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test13944.d0000644000175000017500000000233413200164642023142 0ustar matthiasmatthias// PERMUTE_ARGS: module m; struct S {} enum E { a } void f() {} void main() { string ssc = S.stringof; assert(ssc == "S"c); wstring ssw = S.stringof; assert(ssw == "S"w); dstring ssd = S.stringof; assert(ssd == "S"d); string esc = E.stringof; assert(esc == "E"c); wstring esw = E.stringof; assert(esw == "E"w); dstring esd = E.stringof; assert(esd == "E"d); string msc = m.stringof; assert(msc == "module m"c); wstring msw = m.stringof; assert(msw == "module m"w); dstring msd = m.stringof; assert(msd == "module m"d); string smc = S.mangleof; assert(smc == "S1m1S"c); wstring smw = S.mangleof; assert(smw == "S1m1S"w); dstring smd = S.mangleof; assert(smd == "S1m1S"d); string fmc = f.mangleof; assert(fmc == "_D1m1fFZv"c); wstring fmw = f.mangleof; assert(fmw == "_D1m1fFZv"w); dstring fmd = f.mangleof; assert(fmd == "_D1m1fFZv"d); // The default type is still string static assert(is(typeof(S.stringof) == string)); static assert(is(typeof(E.stringof) == string)); static assert(is(typeof(m.stringof) == string)); static assert(is(typeof(S.mangleof) == string)); static assert(is(typeof(f.mangleof) == string)); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testinvariant.d0000644000175000017500000000623413200164642024454 0ustar matthiasmatthias// PERMUTE_ARGS: extern(C) int printf(const char*, ...); class Foo : Object { void test() { } invariant() { printf("in invariant %p\n", this); } } int testinvariant() { printf("hello\n"); Foo f = new Foo(); printf("f = %p\n", f); printf("f.sizeof = x%x\n", Foo.sizeof); printf("f.classinfo = %p\n", f.classinfo); printf("f.classinfo._invariant = %p\n", f.classinfo.base); f.test(); printf("world\n"); return 0; } /***************************************************/ // 6453 void test6453() { static class C { static uint called; invariant() { called += 1; } invariant() { called += 4; } invariant() { called += 16; } void publicMember() { assert(called == 21); } } static struct S { static uint called; invariant() { called += 1; } invariant() { called += 4; } invariant() { called += 16; } void publicMember() { assert(called == 21); } } auto c = new C(); C.called = 0; c.publicMember(); assert(C.called == 42); auto s = new S(); S.called = 0; s.publicMember(); assert(S.called == 42); // Defined symbols in one invariant cannot be seen from others. static struct S6453 { invariant() { struct S {} int x; static assert(!__traits(compiles, y)); static assert(!__traits(compiles, z)); } invariant() { struct S {} int y; static assert(!__traits(compiles, x)); static assert(!__traits(compiles, z)); } invariant() { struct S {} int z; static assert(!__traits(compiles, x)); static assert(!__traits(compiles, y)); } } static struct S6453a { pure invariant() {} nothrow invariant() {} @safe invariant() {} } static struct S6453b { pure shared invariant() {} nothrow shared invariant() {} @safe shared invariant() {} } static class C6453c { pure synchronized invariant() {} nothrow synchronized invariant() {} @safe synchronized invariant() {} } } /***************************************************/ // 13113 struct S13113 { static int count; invariant() // impure, throwable, system, and gc-able { ++count; // impure } this(int) pure nothrow @safe @nogc {} // post invaiant is called directly but doesn't interfere with constructor attributes ~this() pure nothrow @safe @nogc {} // pre invaiant is called directly but doesn't interfere with destructor attributes void foo() pure nothrow @safe @nogc {} // pre & post invariant calls don't interfere with method attributes } void test13113() { assert(S13113.count == 0); { auto s = S13113(1); assert(S13113.count == 1); s.foo(); assert(S13113.count == 3); } assert(S13113.count == 4); } /***************************************************/ void main() { testinvariant(); test6453(); test13113(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test45.d0000644000175000017500000000075713200164642022715 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test45a.d imports/test45b.d // PERMUTE_ARGS: import imports.test45a; import imports.test45b; alias int function() fp1; alias int function(int) fp2; void main() { auto i = foo(); assert(i == 1); i = foo(1); assert(i == 2); i = foo; assert(i == 1); fp1 fp = &foo; i = (*fp)(); assert(i == 1); fp2 fpi = &foo; i = (*fpi)(1); assert(i == 2); i = bar(1); assert(i == 3); i = bar(1, 2); assert(i == 4); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/template6.d0000644000175000017500000002521213200164642023457 0ustar matthiasmatthias// This is a copy of the engine here: // http://www.digitalmars.com/d/2.0/templates-revisited.html // which is a cut down version of the file here: // http://www.dsource.org/projects/ddl/browser/trunk/meta/regex.d // which has this copyright notice: /+ Copyright (c) 2005 Eric Anderton Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/ import std.stdio; const int testFail = -1; /** * Compile pattern[] and expand to a custom generated function * that will take a string str[] and apply the regular expression * to it, returning an array of matches. */ template regexMatch(string pattern) { string[] regexMatch(string str) { string[] results; int result = regexCompile!(pattern).fn(str); if(result != testFail && result > 0){ results ~= str[0..result]; } return results; } } /****************************** * The testXxxx() functions are custom generated by templates * to match each predicate of the regular expression. * * Params: * string str the input string to match against * * Returns: * testFail failed to have a match * n >= 0 matched n characters */ /// Always match template testEmpty() { int testEmpty(string str) { return 0; } } /// Match if testFirst(str) and testSecond(str) match template testUnion(alias testFirst,alias testSecond,string key) { int testUnion(string str) { int result = testFirst(str); if(result != testFail){ int nextResult = testSecond(str[result..$]); if(result != testFail) return result + nextResult; } return testFail; } } /// Match if first part of str[] matches text[] template testText(string text) { int testText(string str) { if (str.length && text.length <= str.length && str[0..text.length] == text ) return text.length; return testFail; } } /// Match if testPredicate(str) matches 0 or more times template testZeroOrMore(alias testPredicate,string key) { int testZeroOrMore(string str) { if(str.length == 0) return 0; int result = testPredicate(str); if(result != testFail){ int nextResult = .testZeroOrMore!(testPredicate,key)(str[result..$]); if(nextResult != testFail) return result + nextResult; return result; } return 0; } } /// Match if term1[0] <= str[0] <= term2[0] template testRange(string term1,string term2) { int testRange(string str) { if(str.length && str[0] >= term1[0] && str[0] <= term2[0]) return 1; return testFail; } } /// Match if ch[0]==str[0] template testChar(string ch) { int testChar(string str) { if(str.length && str[0] == ch[0]) return 1; return testFail; } } /// Match if str[0] is a word character template testWordChar() { int testWordChar(string str) { if(str.length && ( (str[0] >= 'a' && str[0] <= 'z') || (str[0] >= 'A' && str[0] <= 'Z') || (str[0] >= '0' && str[0] <= '9') || str[0] == '_' ) ) { return 1; } return testFail; } } /*****************************************************/ /** * Returns the front of pattern[] up until the end or a special character. */ template parseTextToken(string pattern){ static if(pattern.length > 0){ static if(isSpecial!(pattern)){ const string parseTextToken=""; } else{ const string parseTextToken = pattern[0] ~ parseTextToken!(pattern[1..$]); } } else{ const string parseTextToken=""; } } /** * Parses pattern[] up to and including terminator. * Returns: * token[] everything up to terminator. * consumed number of characters in pattern[] parsed */ template parseUntil(string pattern,char terminator,bool fuzzy=false){ static if(pattern.length > 0){ static if(pattern[0] == '\\'){ static if(pattern.length > 1){ const string nextSlice = pattern[2 .. $]; alias parseUntil!(nextSlice,terminator,fuzzy) next; const string token = pattern[0 .. 2] ~ next.token; const uint consumed = next.consumed+2; } else{ pragma(msg,"Error: expected character to follow \\"); static assert(false); } } else static if(pattern[0] == terminator){ const string token=""; const uint consumed = 1; } else{ const string nextSlice = pattern[1 .. $]; alias parseUntil!(nextSlice,terminator,fuzzy) next; const string token = pattern[0] ~ next.token; const uint consumed = next.consumed+1; } } else static if(fuzzy){ const string token = ""; const uint consumed = 0; } else{ pragma(msg,"Error: exptected " ~ terminator ~ " to terminate group expression"); static assert(false); } } /** * Parse contents of character class. * Params: * pattern[] rest of pattern to compile * Output: * fn generated function * consumed number of characters in pattern[] parsed */ template regexCompileCharClass2(string pattern){ static if(pattern.length > 0){ static if(pattern.length > 1){ static if(pattern[1] == '-'){ static if(pattern.length > 2){ alias testRange!(pattern[0..1], pattern[2..3]) termFn; const uint thisConsumed = 3; const string remaining = pattern[3 .. $]; } else{ // length is 2 pragma(msg,"Error: expected character following '-' in character class"); static assert(false); } } else{ // not '-' alias testChar!(pattern[0..1]) termFn; const uint thisConsumed = 1; const string remaining = pattern[1 .. $]; } } else{ alias testChar!(pattern[0..1]) termFn; const uint thisConsumed = 1; const string remaining = pattern[1 .. $]; } static if(remaining.length > 0){ static if(remaining[0] != ']'){ alias regexCompileCharClass2!(remaining) next; alias testOr!(termFn,next.fn,remaining) fn; const uint consumed = next.consumed + thisConsumed; } else{ alias termFn fn; const uint consumed = thisConsumed; } } else{ alias termFn fn; const uint consumed = thisConsumed; } } else{ alias testEmpty!() fn; const uint consumed = 0; } } /** * At start of character class. Compile it. * Params: * pattern[] rest of pattern to compile * Output: * fn generated function * consumed number of characters in pattern[] parsed */ template regexCompileCharClass(string pattern){ static if(pattern.length > 0){ static if(pattern[0] == ']'){ alias testEmpty!() fn; const uint consumed = 0; } else{ alias regexCompileCharClass2!(pattern) charClass; alias charClass.fn fn; const uint consumed = charClass.consumed; } } else{ pragma(msg,"Error: expected closing ']' for character class"); static assert(false); } } /** * Look for and parse '*' postfix. * Params: * test function compiling regex up to this point * token[] the part of original pattern that the '*' is a postfix of * pattern[] rest of pattern to compile * Output: * fn generated function * consumed number of characters in pattern[] parsed */ template regexCompilePredicate(alias test,string token,string pattern){ static if(pattern.length > 0){ static if(pattern[0] == '*'){ alias testZeroOrMore!(test,token) fn; const uint consumed = 1; } else{ alias test fn; const uint consumed = 0; } } else{ alias test fn; const uint consumed = 0; } } /** * Parse escape sequence. * Params: * pattern[] rest of pattern to compile * Output: * fn generated function * consumed number of characters in pattern[] parsed */ template regexCompileEscape(string pattern){ static if(pattern.length > 0){ static if(pattern[0] == 's'){ // whitespace char alias testRange!("\x00","\x20") fn; } else static if(pattern[0] == 'w'){ //word char alias testWordChar!() fn; } else{ alias testChar!(pattern[0 .. 1]) fn; } const uint consumed = 1; } else{ pragma(msg,"Error: expected char following '\\'"); static assert(false); } } /** * Parse and compile regex represented by pattern[]. * Params: * pattern[] rest of pattern to compile * Output: * fn generated function */ template regexCompile(string pattern) { static if(pattern.length > 0){ static if(pattern[0] == '['){ const string charClassToken = parseUntil!(pattern[1 .. $],']').token; alias regexCompileCharClass!(charClassToken) charClass; const string token = pattern[0 .. charClass.consumed+2]; const string next = pattern[charClass.consumed+2 .. $]; alias charClass.fn test; } else static if(pattern[0] == '\\'){ alias regexCompileEscape!(pattern[1..$]) escapeSequence; const string token = pattern[0 .. escapeSequence.consumed+1]; const string next = pattern[escapeSequence.consumed+1 .. $]; alias escapeSequence.fn test; } else{ const string token = parseTextToken!(pattern); static assert(token.length > 0); const string next = pattern[token.length .. $]; alias testText!(token) test; } alias regexCompilePredicate!(test,token,next) term; const string remaining = next[term.consumed .. next.length]; static if(remaining.length > 0){ alias testUnion!(term.fn,regexCompile!(remaining).fn,remaining) fn; } else{ alias term.fn fn; } } else{ alias testEmpty!() fn; } } /// Utility function for parsing template isSpecial(string pattern) { static if( pattern[0] == '*' || pattern[0] == '+' || pattern[0] == '?' || pattern[0] == '.' || pattern[0] == '[' || pattern[0] == '{' || pattern[0] == '(' || pattern[0] == '$' || pattern[0] == '^' || pattern[0] == '\\' ){ const bool isSpecial = true; } else{ const bool isSpecial = false; } } int main() { auto exp = ®exMatch!(r"[a-z]*\s*\w*"); string[] m = exp("hello world"); writefln("matches: %s", m); assert(m.length == 1); assert(m[0] == "hello world"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_131_2.d0000644000175000017500000000040613200164642024465 0ustar matthiasmatthias// EXTRA_SOURCES: imports/ldc_github_131_2a.d // Note: Crash was dependent on the command line source file order. import imports.ldc_github_131_2a; struct DirIterator {} auto dirEntries() { void f() {} return filter!f(DirIterator()); } void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test49.d0000644000175000017500000000021413200164642022705 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test49a.d // PERMUTE_ARGS: import imports.test49a; alias Foo!(int) foo; void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/xdtor.d0000644000175000017500000000253713200164642022723 0ustar matthiasmatthias// PERMUTE_ARGS: struct Field { ~this() @safe @nogc pure nothrow {} } struct Counter { static size_t cnt; ~this() @safe @nogc nothrow { ++cnt; } } struct Foo { ~this() @safe @nogc pure nothrow {} Field field; } class Bar { ~this() @safe @nogc pure nothrow {} Field field; } void test1() @safe @nogc pure nothrow { Foo foo; foo.__xdtor(); scope bar = new Bar(); bar.__xdtor(); } static assert(__traits(hasMember, Foo, "__xdtor")); static assert(__traits(hasMember, Bar, "__xdtor")); // struct FieldDtor { Counter counter; } struct AggrDtor { static size_t cnt; ~this() @safe @nogc nothrow { ++cnt; } } struct MixedDtor { static size_t cnt; Counter counter; ~this() @safe @nogc nothrow { ++cnt; } } struct SNoDtor {} class CNoDtor {} static assert(!__traits(hasMember, SNoDtor, "__xdtor")); static assert(!__traits(hasMember, CNoDtor, "__xdtor")); void test2() @safe @nogc nothrow { FieldDtor a; assert(Counter.cnt == 0); a.__xdtor(); assert(Counter.cnt == 1); AggrDtor b; assert(AggrDtor.cnt == 0); b.__xdtor(); assert(AggrDtor.cnt == 1); Counter.cnt = 0; MixedDtor c; assert(MixedDtor.cnt == 0); assert(Counter.cnt == 0); c.__xdtor(); assert(MixedDtor.cnt == 1); assert(Counter.cnt == 1); } void main() { test1(); test2(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_424.d0000644000175000017500000000057213200164642024255 0ustar matthiasmatthiasimport core.simd; import std.stdio; void main() { // ldc: Error: expression 'cast(immutable(__vector(ubyte[16LU])))cast(ubyte)123u' is not a constant static immutable ubyte16 vec1 = 123; writeln(vec1.array); // ldc: infinite loop static immutable ubyte16 vec2 = [123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123]; writeln(vec2.array); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/inline2.d0000644000175000017500000000033113200164642023111 0ustar matthiasmatthias// EXTRA_SOURCES: imports/inline2a.d // PERMUTE_ARGS: // REQUIRED_ARGS: -O -release -inline import imports.inline2a; class Foo { this () { Primes.lookup(2); } } int main() { Primes.lookup(2); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testrightthis.d0000644000175000017500000004660313200164642024472 0ustar matthiasmatthias// runnable/traits.d 9091,8972,8971,7027 // runnable/test4.d test6() extern(C) int printf(const char*, ...); template TypeTuple(TL...) { alias TypeTuple = TL; } /********************************************************/ mixin("struct S1 {"~aggrDecl1~"}"); mixin("class C1 {"~aggrDecl1~"}"); enum aggrDecl1 = q{ alias Type = typeof(this); int x = 2; void foo() { static assert( is(typeof(Type.x.offsetof))); static assert( is(typeof(Type.x.mangleof))); static assert( is(typeof(Type.x.sizeof ))); static assert( is(typeof(Type.x.alignof ))); static assert( is(typeof({ auto n = Type.x.offsetof; }))); static assert( is(typeof({ auto n = Type.x.mangleof; }))); static assert( is(typeof({ auto n = Type.x.sizeof; }))); static assert( is(typeof({ auto n = Type.x.alignof; }))); static assert( is(typeof(Type.x))); static assert( is(typeof({ auto n = Type.x; }))); static assert( __traits(compiles, Type.x)); static assert( __traits(compiles, { auto n = Type.x; })); static assert( is(typeof(x.offsetof))); static assert( is(typeof(x.mangleof))); static assert( is(typeof(x.sizeof ))); static assert( is(typeof(x.alignof ))); static assert( is(typeof({ auto n = x.offsetof; }))); static assert( is(typeof({ auto n = x.mangleof; }))); static assert( is(typeof({ auto n = x.sizeof; }))); static assert( is(typeof({ auto n = x.alignof; }))); static assert( is(typeof(x))); static assert( is(typeof({ auto n = x; }))); static assert( __traits(compiles, x)); static assert( __traits(compiles, { auto n = x; })); with (this) { static assert( is(typeof(x.offsetof))); static assert( is(typeof(x.mangleof))); static assert( is(typeof(x.sizeof ))); static assert( is(typeof(x.alignof ))); static assert( is(typeof({ auto n = x.offsetof; }))); static assert( is(typeof({ auto n = x.mangleof; }))); static assert( is(typeof({ auto n = x.sizeof; }))); static assert( is(typeof({ auto n = x.alignof; }))); static assert( is(typeof(x))); static assert( is(typeof({ auto n = x; }))); static assert( __traits(compiles, x)); static assert( __traits(compiles, { auto n = x; })); } } static void bar() { static assert( is(typeof(Type.x.offsetof))); static assert( is(typeof(Type.x.mangleof))); static assert( is(typeof(Type.x.sizeof ))); static assert( is(typeof(Type.x.alignof ))); static assert( is(typeof({ auto n = Type.x.offsetof; }))); static assert( is(typeof({ auto n = Type.x.mangleof; }))); static assert( is(typeof({ auto n = Type.x.sizeof; }))); static assert( is(typeof({ auto n = Type.x.alignof; }))); static assert( is(typeof(Type.x))); static assert(!is(typeof({ auto n = Type.x; }))); static assert( __traits(compiles, Type.x)); static assert(!__traits(compiles, { auto n = Type.x; })); static assert( is(typeof(x.offsetof))); static assert( is(typeof(x.mangleof))); static assert( is(typeof(x.sizeof ))); static assert( is(typeof(x.alignof ))); static assert( is(typeof({ auto n = x.offsetof; }))); static assert( is(typeof({ auto n = x.mangleof; }))); static assert( is(typeof({ auto n = x.sizeof; }))); static assert( is(typeof({ auto n = x.alignof; }))); static assert( is(typeof(x))); static assert(!is(typeof({ auto n = x; }))); static assert( __traits(compiles, x)); static assert(!__traits(compiles, { auto n = x; })); Type t; with (t) { static assert( is(typeof(x.offsetof))); static assert( is(typeof(x.mangleof))); static assert( is(typeof(x.sizeof ))); static assert( is(typeof(x.alignof ))); static assert( is(typeof({ auto n = x.offsetof; }))); static assert( is(typeof({ auto n = x.mangleof; }))); static assert( is(typeof({ auto n = x.sizeof; }))); static assert( is(typeof({ auto n = x.alignof; }))); static assert( is(typeof(x))); static assert( is(typeof({ auto n = x; }))); static assert( __traits(compiles, x)); static assert( __traits(compiles, { auto n = x; })); } } }; void test1() { foreach (Type; TypeTuple!(S1, C1)) { static assert( is(typeof(Type.x.offsetof))); static assert( is(typeof(Type.x.mangleof))); static assert( is(typeof(Type.x.sizeof ))); static assert( is(typeof(Type.x.alignof ))); static assert( is(typeof({ auto n = Type.x.offsetof; }))); static assert( is(typeof({ auto n = Type.x.mangleof; }))); static assert( is(typeof({ auto n = Type.x.sizeof; }))); static assert( is(typeof({ auto n = Type.x.alignof; }))); static assert( is(typeof(Type.x))); static assert(!is(typeof({ auto n = Type.x; }))); static assert( __traits(compiles, Type.x)); static assert(!__traits(compiles, { auto n = Type.x; })); Type t; static assert( is(typeof(t.x.offsetof))); static assert( is(typeof(t.x.mangleof))); static assert( is(typeof(t.x.sizeof ))); static assert( is(typeof(t.x.alignof ))); static assert( is(typeof({ auto n = t.x.offsetof; }))); static assert( is(typeof({ auto n = t.x.mangleof; }))); static assert( is(typeof({ auto n = t.x.sizeof; }))); static assert( is(typeof({ auto n = t.x.alignof; }))); static assert( is(typeof(t.x))); static assert( is(typeof({ auto n = t.x; }))); static assert( __traits(compiles, t.x)); static assert( __traits(compiles, { auto n = t.x; })); with (t) { static assert( is(typeof(x.offsetof))); static assert( is(typeof(x.mangleof))); static assert( is(typeof(x.sizeof ))); static assert( is(typeof(x.alignof ))); static assert( is(typeof({ auto n = x.offsetof; }))); static assert( is(typeof({ auto n = x.mangleof; }))); static assert( is(typeof({ auto n = x.sizeof; }))); static assert( is(typeof({ auto n = x.alignof; }))); static assert( is(typeof(x))); static assert( is(typeof({ auto n = x; }))); static assert( __traits(compiles, x)); static assert( __traits(compiles, { auto n = x; })); } } } /********************************************************/ void test2() { struct S { int val; int[] arr; int[int] aar; void foo() {} void boo()() {} static void test() { static assert(!__traits(compiles, S.foo())); static assert(!__traits(compiles, S.boo())); static assert(!__traits(compiles, foo())); static assert(!__traits(compiles, boo())); } } int v; int[] a; void f(int n) {} static assert( __traits(compiles, S.val)); // 'S.val' is treated just a symbol static assert(!__traits(compiles, { int n = S.val; })); static assert(!__traits(compiles, f(S.val))); static assert(!__traits(compiles, v = S.val) && !__traits(compiles, S.val = v)); static assert(!__traits(compiles, 1 + S.val) && !__traits(compiles, S.val + 1)); static assert(!__traits(compiles, 1 - S.val) && !__traits(compiles, S.val - 1)); static assert(!__traits(compiles, 1 * S.val) && !__traits(compiles, S.val * 1)); static assert(!__traits(compiles, 1 / S.val) && !__traits(compiles, S.val / 1)); static assert(!__traits(compiles, 1 % S.val) && !__traits(compiles, S.val % 1)); static assert(!__traits(compiles, 1 ~ S.arr) && !__traits(compiles, S.arr ~ 1)); static assert(!__traits(compiles, 1 & S.val) && !__traits(compiles, S.val & 1)); static assert(!__traits(compiles, 1 | S.val) && !__traits(compiles, S.val | 1)); static assert(!__traits(compiles, 1 ^ S.val) && !__traits(compiles, S.val ^ 1)); static assert(!__traits(compiles, 1 ~ S.val) && !__traits(compiles, S.val ~ 1)); static assert(!__traits(compiles, 1 ^^ S.val) && !__traits(compiles, S.val ^^ 1)); static assert(!__traits(compiles, 1 << S.val) && !__traits(compiles, S.val << 1)); static assert(!__traits(compiles, 1 >> S.val) && !__traits(compiles, S.val >> 1)); static assert(!__traits(compiles, 1 >>>S.val) && !__traits(compiles, S.val >>>1)); static assert(!__traits(compiles, 1 && S.val) && !__traits(compiles, S.val && 1)); static assert(!__traits(compiles, 1 || S.val) && !__traits(compiles, S.val || 1)); static assert(!__traits(compiles, 1 in S.aar) && !__traits(compiles, S.val || [1:1])); static assert(!__traits(compiles, 1 <= S.val) && !__traits(compiles, S.val <= 1)); static assert(!__traits(compiles, 1 == S.val) && !__traits(compiles, S.val == 1)); static assert(!__traits(compiles, 1 is S.val) && !__traits(compiles, S.val is 1)); static assert(!__traits(compiles, 1? 1:S.val) && !__traits(compiles, 1? S.val:1)); static assert(!__traits(compiles, (1, S.val)) && !__traits(compiles, (S.val, 1))); static assert(!__traits(compiles, &S.val)); static assert(!__traits(compiles, S.arr[0]) && !__traits(compiles, [1,2][S.val])); static assert(!__traits(compiles, S.val++) && !__traits(compiles, S.val--)); static assert(!__traits(compiles, ++S.val) && !__traits(compiles, --S.val)); static assert(!__traits(compiles, v += S.val) && !__traits(compiles, S.val += 1)); static assert(!__traits(compiles, v -= S.val) && !__traits(compiles, S.val -= 1)); static assert(!__traits(compiles, v *= S.val) && !__traits(compiles, S.val *= 1)); static assert(!__traits(compiles, v /= S.val) && !__traits(compiles, S.val /= 1)); static assert(!__traits(compiles, v %= S.val) && !__traits(compiles, S.val %= 1)); static assert(!__traits(compiles, v &= S.val) && !__traits(compiles, S.val &= 1)); static assert(!__traits(compiles, v |= S.val) && !__traits(compiles, S.val |= 1)); static assert(!__traits(compiles, v ^= S.val) && !__traits(compiles, S.val ^= 1)); static assert(!__traits(compiles, a ~= S.val) && !__traits(compiles, S.arr ~= 1)); static assert(!__traits(compiles, v ^^= S.val) && !__traits(compiles, S.val ^^= 1)); static assert(!__traits(compiles, v <<= S.val) && !__traits(compiles, S.val <<= 1)); static assert(!__traits(compiles, v >>= S.val) && !__traits(compiles, S.val >>= 1)); static assert(!__traits(compiles, v >>>=S.val) && !__traits(compiles, S.val >>>=1)); static assert(!__traits(compiles, { auto x = 1 + S.val; }) && !__traits(compiles, { auto x = S.val + 1; })); static assert(!__traits(compiles, { auto x = 1 - S.val; }) && !__traits(compiles, { auto x = S.val - 1; })); static assert(!__traits(compiles, { auto x = S.arr ~ 1; }) && !__traits(compiles, { auto x = 1 ~ S.arr; })); static assert(!__traits(compiles, S.foo())); static assert(!__traits(compiles, S.boo())); S.test(); alias foo = S.foo; alias boo = S.boo; static assert(!__traits(compiles, foo())); static assert(!__traits(compiles, boo())); // static assert(S.val); struct SW { int a; } class CW { int a; } static assert(!__traits(compiles, { with (SW) { int n = a; } })); static assert(!__traits(compiles, { with (CW) { int n = a; } })); } /********************************************************/ struct S3 { struct T3 { int val; void foo() {} } T3 member; alias member this; static void test() { static assert(!__traits(compiles, S3.val = 1 )); static assert(!__traits(compiles, { S3.val = 1; })); static assert(!__traits(compiles, T3.val = 1 )); static assert(!__traits(compiles, { T3.val = 1; })); static assert(!__traits(compiles, __traits(getMember, S3, "val") = 1 )); static assert(!__traits(compiles, { __traits(getMember, S3, "val") = 1; })); static assert(!__traits(compiles, __traits(getMember, T3, "val") = 1 )); static assert(!__traits(compiles, { __traits(getMember, T3, "val") = 1; })); static assert(!__traits(compiles, S3.foo() )); static assert(!__traits(compiles, { S3.foo(); })); static assert(!__traits(compiles, T3.foo() )); static assert(!__traits(compiles, { T3.foo(); })); static assert(!__traits(compiles, __traits(getMember, S3, "foo")() )); static assert(!__traits(compiles, { __traits(getMember, S3, "foo")(); })); static assert(!__traits(compiles, __traits(getMember, T3, "foo")() )); static assert(!__traits(compiles, { __traits(getMember, T3, "foo")(); })); static assert(!__traits(compiles, __traits(getOverloads, S3, "foo")[0]() )); static assert(!__traits(compiles, { __traits(getOverloads, S3, "foo")[0](); })); static assert(!__traits(compiles, __traits(getOverloads, T3, "foo")[0]() )); static assert(!__traits(compiles, { __traits(getOverloads, T3, "foo")[0](); })); } } void test3() { } /********************************************************/ void test4() { static struct R { void opIndex(int) {} void opSlice() {} void opSlice(int, int) {} int opDollar() { return 1; } alias length = opDollar; } R val; static struct S { R val; void foo() { static assert(__traits(compiles, val[1])); // TypeSArray static assert(__traits(compiles, val[])); // TypeDArray static assert(__traits(compiles, val[0..val.length])); // TypeSlice } } } /********************************************************/ template Test5(string name, bool result) { mixin(`static assert(__traits(compiles, `~name~`.add!"months"(1)) == result);`); } static struct Begin5 { void add(string s)(int n) {} } struct IntervalX5(TP) { Begin5 begin; static assert(__traits(compiles, begin.add!"months"(1)) == true); mixin Test5!("begin", true); void foo() { static assert(__traits(compiles, begin.add!"months"(1)) == true); mixin Test5!("begin", true); } static test() { static assert(__traits(compiles, begin.add!"months"(1)) == false); mixin Test5!("begin", false); } } alias IX5 = IntervalX5!int; alias beginX5 = IX5.begin; static assert(__traits(compiles, beginX5.add!"months"(1)) == false); mixin Test5!("beginG5", false); void test5() { static struct IntervalY5(TP) { Begin5 begin; static assert(__traits(compiles, begin.add!"months"(1)) == true); mixin Test5!("begin", true); void foo() { static assert(__traits(compiles, begin.add!"months"(1)) == true); mixin Test5!("begin", true); } static test() { static assert(__traits(compiles, begin.add!"months"(1)) == false); mixin Test5!("begin", false); } } alias IX = IntervalX5!int; alias beginX = IX.begin; static assert(__traits(compiles, beginX.add!"months"(1)) == false); mixin Test5!("beginX", false); alias IY = IntervalY5!int; alias beginY = IY.begin; static assert(__traits(compiles, beginY.add!"months"(1)) == false); mixin Test5!("beginY", false); } /********************************************************/ void test6() { static struct Foo { static struct Bar { static int get() { return 0; } static int val; void set() { assert(0); } int num; } static class Baz { static int get() { return 0; } static int val; void set() { assert(0); } int num; } Bar bar; Baz baz; } // allowed cases that do 'use' Foo.bar without this assert(Foo.bar.get() == 0); // Foo.bar.get() assert(Foo.baz.get() == 0); // Foo.bar.get() static assert(!__traits(compiles, Foo.bar.set())); static assert(!__traits(compiles, Foo.baz.set())); assert(Foo.bar.val == 0); // Foo.bar.val assert(Foo.baz.val == 0); // Foo.baz.val static assert(!__traits(compiles, Foo.bar.num = 1)); static assert(!__traits(compiles, Foo.baz.num = 1)); } /********************************************************/ struct Tuple7(T...) { T field; enum check1 = is(typeof(field[0] = 1)); enum check2 = is(typeof({ field[0] = 1; })); this(U, size_t n)(U[n] values) if (is(typeof({ foreach (i, _; T) field[0] = values[0]; }))) {} } void test7() { alias Tuple7!(int, int) Tup7; static assert(Tup7.check1); static assert(Tup7.check2); int[2] ints = [ 1, 2 ]; Tup7 t = ints; struct S7 { int value; enum check1 = is(typeof(value = 1)); enum check2 = is(typeof({ value = 1; })); void foo()(int v) if (is(typeof({ value = v; // valid }))) {} static void bar()(int v) if (is(typeof({ value = v; // always invalid }))) {} } static assert(S7.check1); static assert(S7.check2); S7 s; s.foo(1); static assert(!__traits(compiles, S7.bar(1))); } /********************************************************/ // 6430 auto bug6430(int a) { static struct Result2 {} return 4; } auto bug6430(int a, int b) { static struct Result2 { int z; int y() { return z; } } auto t = Result2(1); return 5; } /********************************************************/ // 9619 struct Foo9619 { int x; } void test9619() { void bar() { typeof(Foo9619.x) y; } } /********************************************************/ // 9633 class Foo9633 { void baz() {} void bar() { // CallExp::e1->op == TOKvar static assert(!compilesWithoutThis9633!baz); } void vaz()() { static class C { // CallExp::e1->op == TOKtemplate static assert(!__traits(compiles, vaz())); } } } template compilesWithoutThis9633(alias F) { enum bool compilesWithoutThis9633 = __traits(compiles, F()); } void test9633() { auto foo = new Foo9633; foo.bar(); foo.vaz(); } /********************************************************/ // 11245 struct Vec11245 { float[2] f; } class Bar11245 { void func() { pragma(msg, "===="); float[Vec11245.f.length] newVal; } } /********************************************************/ // 11614 struct Tuple11614(T...) { T field; alias field this; } struct Foo11614 { alias Tuple11614!(int) NEW_ARGS; NEW_ARGS args; void foo() { static if (NEW_ARGS.length == 1) {} else static assert(0); } } /********************************************************/ // 11993 struct S11993 { void foo()() const if (is(typeof(this) == const(S11993))) {} const void bar()() if (is(typeof(this) == const(S11993))) {} } void test11993() { S11993 s; s.foo(); s.bar(); } /********************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test9619(); test9633(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test10942.d0000644000175000017500000000060613200164642023135 0ustar matthiasmatthias// REQUIRED_ARGS: -g import std.string; string getEnum(size_t count) { string en; en ~= "enum KeyCode\n { \n"; foreach (i; 0 .. count) { en ~= format(" memb_%s = %s,\n", i+1, i+1); } en ~= "} "; return en; } // Linker warning: Warning 161: Unknown CV version, ignored // mixin(getEnum(1024)); // ICE mixin(getEnum(1087)); void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link14834.sh0000755000175000017500000000121313200164642023304 0ustar matthiasmatthias#!/usr/bin/env bash src=runnable${SEP}extra-files dir=${RESULTS_DIR}${SEP}runnable output_file=${dir}${SEP}link14834.sh.out rm -f ${output_file} if [ $OS == "win32" -o $OS == "win64" ]; then LIBEXT=.lib else LIBEXT=.a fi libname=${dir}${SEP}link14834${LIBEXT} exename=${dir}${SEP}link14834${EXE} $DMD -m${MODEL} -I${src} -lib -of${libname} ${src}${SEP}link14834a.d > ${output_file} || exit 1 $DMD -m${MODEL} -I${src} -inline -debug -of${exename} ${src}${SEP}link14834b.d ${libname} > ${output_file} || exit 1 ${dir}/link14834 || exit 1 rm ${libname} ${exename} ${dir}${SEP}link14834${OBJ} echo Success > ${output_file} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link7745.d0000644000175000017500000000046713200164642023047 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/link7745b.d // PERMUTE_ARGS: import imports.link7745b; bool forceSemantic7745() { C c; c.asdfg(); return true; } static assert(forceSemantic7745()); void f(C c) { auto x = &c.asdfg; } void main() { // extra test for bug 4820 nextis!(int)(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/constfold.d0000644000175000017500000004647413200164642023566 0ustar matthiasmatthias#! blah static assert(__LINE__ == 3); // fails as __LINE__ is 2 import std.stdio; import std.math : signbit, sqrt; /************************************/ static assert(-(1) == -1); static assert(-(6i) == -6i); static assert(-(1 + 6i) == -1 - 6i); static assert(!27 == 0); static assert(!0 == 1); static assert(!6.2 == 0); static assert(!0.0 == 1); static assert(!3.7i == 0); static assert(!0.0i == 1); static assert(!(2+3.7i) == 0); static assert(!(0+3.7i) == 0); static assert(!(2+0.0i) == 0); static assert(!(0+0.0i) == 1); static assert(-6i + 2i == -4i); static assert(6i - 1i == 5i); static assert((3.6 + 7.2i) / (1 + 0i) == 3.6 + 7.2i); static assert((3.6 + 7.2i) / (0.0 + 1i) == 7.2 - 3.6i); static assert((6 % 4) == 2); static assert((6u % 4u) == 2u); static assert((cast(byte)0x109 >> 1) == 4); static assert((cast(byte)-1 >> 1) == -1); static assert((cast(ubyte)0x109 >> 1) == 4); static assert((cast(short)0x10009 >> 1) == 4); static assert((cast(short)-1 >> 1) == -1); static assert((cast(ushort)0x10009 >> 1) == 4); static assert((cast(long)0x1_0000_0000_0009 >> 1) == 0x8000_0000_0004); static assert((cast(long)-1L >> 1) == -1); static assert((cast(ulong)0x10009 >> 1) == 0x8004); static assert((cast(byte)0x109 >>> 1) == 4); static assert((cast(byte)-1 >>> 1) == int.max); static assert((cast(ubyte)0x109 >>> 1) == 4); static assert((cast(short)0x10009 >>> 1) == 4); static assert((cast(short)-1 >>> 1) == int.max); static assert((cast(ushort)0x10009 >>> 1) == 4); static assert((cast(long)0x1_0000_0000_0009 >>> 1) == 0x8000_0000_0004); static assert((cast(long)-1L >>> 1) == long.max); static assert((cast(ulong)0x10009 >>> 1) == 0x8004); static assert((3 ^ 5) == 6); static assert((0 && 0) == 0); static assert((0 && 5) == 0); static assert((10 && 0) == 0); static assert((58 && 10000) == 1); static assert((0.0 && 0.0) == 0); static assert((0.0 && 5.1) == 0); static assert((10.0 && 0.0) == 0); static assert((58.6 && 10000.7) == 1); static assert((0 || 0) == 0); static assert((0 || 5) == 1); static assert((10 || 0) == 1); static assert((58 || 10000) == 1); static assert((0.0 || 0.0) == 0); static assert((0.0 || 5.1) == 1); static assert((10.0 || 0.0) == 1); static assert((58.6 || 10000.7) == 1); static assert((5 < 3) == 0); static assert((5 < 5) == 0); static assert((5 < 6) == 1); static assert((5 <= 3) == 0); static assert((5 <= 5) == 1); static assert((5 <= 6) == 1); static assert((5 > 3) == 1); static assert((5 > 5) == 0); static assert((5 > 6) == 0); static assert((5 >= 3) == 1); static assert((5 >= 5) == 1); static assert((5 >= 6) == 0); static assert((5 <>= 3) == 1); static assert((5 <>= 5) == 1); static assert((5 <>= 6) == 1); static assert((5 <> 3) == 1); static assert((5 <> 5) == 0); static assert((5 <> 6) == 1); static assert((5 !<>= 3) == 0); static assert((5 !<>= 5) == 0); static assert((5 !<>= 6) == 0); static assert((5 !<> 3) == 0); static assert((5 !<> 5) == 1); static assert((5 !<> 6) == 0); static assert((5 !<= 3) == 1); static assert((5 !<= 5) == 0); static assert((5 !<= 6) == 0); static assert((5 !< 3) == 1); static assert((5 !< 5) == 1); static assert((5 !< 6) == 0); static assert((5 !>= 3) == 0); static assert((5 !>= 5) == 0); static assert((5 !>= 6) == 1); static assert((5 !> 3) == 0); static assert((5 !> 5) == 1); static assert((5 !> 6) == 1); static assert((-5 < -3) == 1); static assert((-5 < -5) == 0); static assert((-5 < -6) == 0); static assert((-5 <= -3) == 1); static assert((-5 <= -5) == 1); static assert((-5 <= -6) == 0); static assert((-5 > -3) == 0); static assert((-5 > -5) == 0); static assert((-5 > -6) == 1); static assert((-5 >= -3) == 0); static assert((-5 >= -5) == 1); static assert((-5 >= -6) == 1); static assert((-5 <>= -3) == 1); static assert((-5 <>= -5) == 1); static assert((-5 <>= -6) == 1); static assert((-5 <> -3) == 1); static assert((-5 <> -5) == 0); static assert((-5 <> -6) == 1); static assert((-5 !<>= -3) == 0); static assert((-5 !<>= -5) == 0); static assert((-5 !<>= -6) == 0); static assert((-5 !<> -3) == 0); static assert((-5 !<> -5) == 1); static assert((-5 !<> -6) == 0); static assert((-5 !<= -3) == 0); static assert((-5 !<= -5) == 0); static assert((-5 !<= -6) == 1); static assert((-5 !< -3) == 0); static assert((-5 !< -5) == 1); static assert((-5 !< -6) == 1); static assert((-5 !>= -3) == 1); static assert((-5 !>= -5) == 0); static assert((-5 !>= -6) == 0); static assert((-5 !> -3) == 1); static assert((-5 !> -5) == 1); static assert((-5 !> -6) == 0); static assert((5u < 3u) == 0); static assert((5u < 5u) == 0); static assert((5u < 6u) == 1); static assert((5u <= 3u) == 0); static assert((5u <= 5u) == 1); static assert((5u <= 6u) == 1); static assert((5u > 3u) == 1); static assert((5u > 5u) == 0); static assert((5u > 6u) == 0); static assert((5u >= 3u) == 1); static assert((5u >= 5u) == 1); static assert((5u >= 6u) == 0); static assert((5u <>= 3u) == 1); static assert((5u <>= 5u) == 1); static assert((5u <>= 6u) == 1); static assert((5u <> 3u) == 1); static assert((5u <> 5u) == 0); static assert((5u <> 6u) == 1); static assert((5u !<>= 3u) == 0); static assert((5u !<>= 5u) == 0); static assert((5u !<>= 6u) == 0); static assert((5u !<> 3u) == 0); static assert((5u !<> 5u) == 1); static assert((5u !<> 6u) == 0); static assert((5u !<= 3u) == 1); static assert((5u !<= 5u) == 0); static assert((5u !<= 6u) == 0); static assert((5u !< 3u) == 1); static assert((5u !< 5u) == 1); static assert((5u !< 6u) == 0); static assert((5u !>= 3u) == 0); static assert((5u !>= 5u) == 0); static assert((5u !>= 6u) == 1); static assert((5u !> 3u) == 0); static assert((5u !> 5u) == 1); static assert((5u !> 6u) == 1); static assert((-5u < 3) == 0); static assert((-5u <= 3) == 0); static assert((-5u > 3) == 1); static assert((-5u >= 3) == 1); static assert((-5u <>= 3) == 1); static assert((-5u <> 3) == 1); static assert((-5u !<>= 3) == 0); static assert((-5u !<> 3) == 0); static assert((-5u !<= 3) == 1); static assert((-5u !< 3) == 1); static assert((-5u !>= 3) == 0); static assert((-5u !> 3) == 0); static assert((-5 < 3u) == 0); static assert((-5 <= 3u) == 0); static assert((-5 > 3u) == 1); static assert((-5 >= 3u) == 1); static assert((-5 <>= 3u) == 1); static assert((-5 <> 3u) == 1); static assert((-5 !<>= 3u) == 0); static assert((-5 !<> 3u) == 0); static assert((-5 !<= 3u) == 1); static assert((-5 !< 3u) == 1); static assert((-5 !>= 3u) == 0); static assert((-5 !> 3u) == 0); static assert((5.2 < double.nan) == 0); static assert((5.2 <= double.nan) == 0); static assert((5.2 > double.nan) == 0); static assert((5.2 >= double.nan) == 0); static assert((5.2 <>= double.nan) == 0); static assert((5.2 <> double.nan) == 0); static assert((5.2 !<>= double.nan) == 1); static assert((5.2 !<> double.nan) == 1); static assert((5.2 !<= double.nan) == 1); static assert((5.2 !< double.nan) == 1); static assert((5.2 !>= double.nan) == 1); static assert((5.2 !> double.nan) == 1); static assert((double.nan < 6.2) == 0); static assert((double.nan <= 6.2) == 0); static assert((double.nan > 6.2) == 0); static assert((double.nan >= 6.2) == 0); static assert((double.nan <>= 6.2) == 0); static assert((double.nan <> 6.2) == 0); static assert((double.nan !<>= 6.2) == 1); static assert((double.nan !<> 6.2) == 1); static assert((double.nan !<= 6.2) == 1); static assert((double.nan !< 6.2) == 1); static assert((double.nan !>= 6.2) == 1); static assert((double.nan !> 6.2) == 1); static assert((double.nan < double.nan) == 0); static assert((double.nan <= double.nan) == 0); static assert((double.nan > double.nan) == 0); static assert((double.nan >= double.nan) == 0); static assert((double.nan <>= double.nan) == 0); static assert((double.nan <> double.nan) == 0); static assert((double.nan !<>= double.nan) == 1); static assert((double.nan !<> double.nan) == 1); static assert((double.nan !<= double.nan) == 1); static assert((double.nan !< double.nan) == 1); static assert((double.nan !>= double.nan) == 1); static assert((double.nan !> double.nan) == 1); static assert((5.2 < 6.2) == 1); static assert((5.2 <= 6.2) == 1); static assert((5.2 > 6.2) == 0); static assert((5.2 >= 6.2) == 0); static assert((5.2 <>= 6.2) == 1); static assert((5.2 <> 6.2) == 1); static assert((5.2 !<>= 6.2) == 0); static assert((5.2 !<> 6.2) == 0); static assert((5.2 !<= 6.2) == 0); static assert((5.2 !< 6.2) == 0); static assert((5.2 !>= 6.2) == 1); static assert((5.2 !> 6.2) == 1); static assert((5.2 < 5.2) == 0); static assert((5.2 <= 5.2) == 1); static assert((5.2 > 5.2) == 0); static assert((5.2 >= 5.2) == 1); static assert((5.2 <>= 5.2) == 1); static assert((5.2 <> 5.2) == 0); static assert((5.2 !<>= 5.2) == 0); static assert((5.2 !<> 5.2) == 1); static assert((5.2 !<= 5.2) == 0); static assert((5.2 !< 5.2) == 1); static assert((5.2 !>= 5.2) == 0); static assert((5.2 !> 5.2) == 1); static assert((7.2 < 6.2) == 0); static assert((7.2 <= 6.2) == 0); static assert((7.2 > 6.2) == 1); static assert((7.2 >= 6.2) == 1); static assert((7.2 <>= 6.2) == 1); static assert((7.2 <> 6.2) == 1); static assert((7.2 !<>= 6.2) == 0); static assert((7.2 !<> 6.2) == 0); static assert((7.2 !<= 6.2) == 1); static assert((7.2 !< 6.2) == 1); static assert((7.2 !>= 6.2) == 0); static assert((7.2 !> 6.2) == 0); static assert((7.2i < 6.2i) == 0); static assert((7.2i == 6.2i) == 0); static assert((7.2i != 6.2i) == 1); static assert((7.2 == 6.2) == 0); static assert((7.2 != 6.2) == 1); static assert((7.2i == 7.2i) == 1); static assert((7.2i != 7.2i) == 0); static assert((7.2 == 7.2) == 1); static assert((7.2 != 7.2) == 0); static assert((7.2 == double.nan) == 0); static assert((7.2 != double.nan) == 1); static assert((double.nan == double.nan) == 0); static assert((double.nan != double.nan) == 1); static assert((double.nan == 7.2) == 0); static assert((double.nan != 7.2) == 1); static assert((5 is 5) == 1); static assert((5 is 4) == 0); static assert((5 !is 5) == 0); static assert((5 !is 4) == 1); static assert((5.1 is 5.1) == 1); static assert((5.1 is 4.1) == 0); static assert((5.1 !is 5.1) == 0); static assert((5.1 !is 4.1) == 1); static assert((5.1 is 5.1i) == 0); static assert((5.1 !is 5.1i) == 1); static assert((5 ? 2 : 3) == 2); static assert((0 ? 2 : 3) == 3); static assert((5.0 ? 2 : 3) == 2); static assert((0.0 ? 2 : 3) == 3); static assert("abc" == "abc"); //static assert("abc"w.sizeof == 6); //static assert("\U00010000bc"w.sizeof == 8); static assert([1,2,3][1] == 2); static assert([1,2,3] ~ [4] == [1,2,3,4]); static assert([1,2,3][1..3] == [2,3]); static assert(['a','b','c','d'] == "abcd"); static assert("efgh" == ['e','f','g','h']); static assert("efgi" != ['e','f','g','h']); static assert((2 ^^ 8) == 256); static assert((3 ^^ 8.0) == 6561); static assert((4.0 ^^ 8) == 65536); static assert((5.0 ^^ 8.0) == 390625); static assert((0.5 ^^ 3) == 0.125); static assert((1.5 ^^ 3.0) == 3.375); static assert((2.5 ^^ 3) == 15.625); static assert((3.5 ^^ 3.0) == 42.875); static assert(((-2) ^^ -5.0) == -0.031250); static assert(((-2.0) ^^ -6) == 0.015625); static assert(((-2.0) ^^ -7.0) == -0.0078125); static assert((144 ^^ 0.5) == 12); static assert((1089 ^^ 0.5) == 33); static assert((1764 ^^ 0.5) == 42); static assert((650.25 ^^ 0.5) == 25.5); void test1() { int x; int y; int* p; p = &x + cast(size_t)&y; p = &x + 2; p = 4 + &y; p = &x - 1; assert((&x is &x) == 1); assert((&x is &y) == 0); assert((&x !is &x) == 0); assert((&x !is &y) == 1); } /************************************/ void test2() { float f = float.infinity; int i = cast(int) f; writeln(i); writeln(cast(int)float.max); version (LDC) { // LDC_FIXME: This test fails in optimized builds due to the constant // folding done by the LLVM optimizer. It should be checked whether the // result of the cast is really specified in C, and as a consequence // in D (see [dmd-internals] float.infinity->int test case in constfold.d). // Update: The values are really implementation dependent. // Intel CPUs return the "indefinite interger value" (0x80000000). // ARM CPUs return 0x80000000 or 0x7FFFFFFF depending on the value. // PowerPC CPUs behave like ARM bit use 64bit values. // MIPS CPUs always return 0x7FFFFFFF_FFFFFFFF. } else { assert(i == cast(int)float.max); assert(i == 0x80000000); } } /************************************/ void test3() { real n = -0.0; const real m = -0.0; creal c = -0.0 + 3i; creal d = n + 3i; creal e = m + 3i; // should print "11111" writeln(signbit(n), signbit(m), signbit(c.re), signbit(d.re), signbit(e.re)); assert(signbit(n) == 1); assert(signbit(m) == 1); assert(signbit(c.re) == 1); assert(signbit(d.re) == 1); assert(signbit(e.re) == 1); } /************************************/ struct A4 { char [] a; } struct B4 { long x; } struct C4 { int a; static C4 opCall(int b) { C4 q; q.a=b; return q; } } static assert(!is(typeof( (){ A4 s; B4 q = s; }))); static assert(!is(typeof( (){ B4 x =1L; }))); static assert(is(typeof( (){ C4 g = 7; }))); static assert(is(typeof( (){ C4 g = 7; C4 h = g;}))); /************************************/ alias uint DWORD; MY_API_FUNCTION lpStartAddress; extern (Windows) alias DWORD function(void*) MY_API_FUNCTION; pragma(msg, MY_API_FUNCTION.stringof); static assert(MY_API_FUNCTION.stringof == "extern (Windows) uint function(void*)"); /************************************/ enum bug6 = cast(void*)0xFEFEFEFE; static assert(bug6 is bug6); /************************************/ struct S7{ double z; } int bug7(int x) { return x; } S7 s7; double e7 = 4; const double d7 = 4; static assert(!is(typeof(bug7(cast(long)e7)))); static assert(!is(typeof(bug7(cast(long)s7)))); version (LDC) {} else // cast in LDC undefined result w/ x > long.max static assert(!is(typeof(bug7(cast(long)3.256679e30)))); static assert(is(typeof(bug7(cast(long)d7)))); static assert(is(typeof(bug7(cast(long)3.256679e4)))); /************************************/ class C8 { int x; } alias C8.x F8; static assert(is(typeof(F8) == int)); static assert(is(typeof(C8.x) == int)); /************************************/ int foo9() { int u = cast(int)(0x1_0000_0000L); while (u) { if (u) { assert(u!=0); } assert(u!=0); } return 2; } static assert(foo9()==2); /************************************/ // Bugzilla 6077 void test6077() { static string scat(string s1, string s2) { return s1 ~ s2; } static string scatass(string s1, string s2) { s1 ~= s2; return s1; } static string[] arycats(string[] ary, string s) { return ary ~ s; } static string[] scatary(string s, string[] ary) { return s ~ ary; } static string[] arycatasss(string[] ary, string s) { ary ~= s; return ary; } static assert(scat(null, null) is null); static assert(scatass(null, null) is null); static assert(arycats(null, null) == cast(string[])[null]); static assert(scatary(null, null) == cast(string[])[null]); static assert(arycatasss(null, null) == cast(string[])[null]); } /************************************/ int test4() { int i; dchar d; d >>= 1; d >>>= 1; d <<= 1; d = d >> 1; d = d >>> 1; d = d << 1; wchar w; w >>= 1; w >>>= 1; w <<= 1; w = w >> 1; w = w >>> 1; i = w << 1; // promoted to int char c; c >>= 1; c >>>= 1; c <<= 1; c = c >> 1; c = c >>> 1; i = c << 1; // promoted to int return d + w + c + i; } static assert(test4() == 24666); /************************************/ // 8400 void test8400() { immutable a = [1,2]; int[a.length+0] b; // ok int[a.length ] c; // error } /************************************/ // 8939 void foo8939(T)(ref T) { } // same for `auto ref` void bar8939(ref const int) { } void bar8939(ref const S8939) { } static struct S8939 { int n; } const gn8939 = 1; // or `immutable` const gs8939 = S8939(3); static assert(__traits(compiles, foo8939(gn8939), bar8939(gn8939))); static assert(__traits(compiles, foo8939(gs8939), bar8939(gs8939))); void test8939() { foo8939(gn8939), bar8939(gn8939); foo8939(gs8939), bar8939(gs8939); const ln8939 = 1; const ls8939 = S8939(3); foo8939(ln8939), bar8939(ln8939); foo8939(ls8939), bar8939(ls8939); } class C8939regression { const int n1 = 0; const int n2 = 0; const int n3 = 0; const int n4 = 1; int refValue(V)(ref V var) { return 0; } void foo() { string[2] str; refValue(str[n1]); int[] da; refValue(da[n2]); int n; int* p = &n; refValue(*cast(int*)(p + n3)); refValue([1,2,n4].ptr[0]); } } /************************************/ // 9058 template TypeTuple9058(TL...) { alias TypeTuple9058 = TL; } template EnumMembers9058(T) { alias EnumMembers9058 = TypeTuple9058!(Foo9058.A, Foo9058.B); } enum Foo9058 { A, B } size_t bar9058(size_t n) { return 0; } void test9058() { Foo9058 x = [EnumMembers9058!Foo9058][bar9058($)]; } /************************************/ // 11159 void test11159() { import std.math : pow; enum ulong e_2_pow_64 = 2uL^^64, e_10_pow_19 = 10uL^^19, e_10_pow_20 = 10uL^^20; assert(e_2_pow_64 == pow(2uL, 64)); assert(e_10_pow_19 == pow(10uL, 19)); assert(e_10_pow_20 == pow(10uL, 20)); } /************************************/ // 12306 void test12306() { struct Point3D { ubyte x, y, z; } enum Point3D pt1 = {x:1, y:1, z:1}; const Point3D pt2 = {x:1, y:1, z:1}; immutable Point3D pt3 = {x:1, y:1, z:1}; int[pt1.z][pt1.y][pt1.x] a1; int[pt2.z][pt2.y][pt2.x] a2; int[pt3.z][pt3.y][pt3.x] a3; ubyte a = 1; const Point3D ptx = {x:a, y:1, z:1}; static assert(!__traits(compiles, { int[ptx.z][ptx.y][ptx.x] ax; })); } /************************************/ // 13977 void test13977() { bool cond(bool b) { return b; } int x = 0; void check(int n = 1) { x = n; } cond(true) && check(); assert(x == 1); x = 0; cond(false) && check(); assert(x == 0); x = 0; true && check(); assert(x == 1); x = 0; false && check(); assert(x == 0); x = 0; (int[]).init && check(); assert(x == 0); x = 0; Object.init && check(); assert(x == 0); (check(2), false) && check(); assert(x == 2); x = 0; } /************************************/ // 13978 void test13978() { bool cond(bool b) { return b; } int x = 0; void check(int n = 1) { x = n; } cond(true) || check(); assert(x == 0); x = 0; cond(false) || check(); assert(x == 1); x = 0; true || check(); assert(x == 0); x = 0; false || check(); assert(x == 1); x = 0; (int[]).init || check(); assert(x == 1); x = 0; Object.init || check(); assert(x == 1); x = 0; (check(2), true) || check(); assert(x == 2); x = 0; } /************************************/ // Pull Request 3697 void test3697and() { enum x = 0; auto y = x && 1 / x; } void test3697or() { enum x = 0; enum y = 1; auto z = y || 1 / x; } int main() { test1(); test2(); test3(); test3697and(); test3697or(); test6077(); test8400(); test8939(); test9058(); test11159(); test13977(); test13978(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/bug5.d0000644000175000017500000000041113200164642022412 0ustar matthiasmatthias// REQUIRED_ARGS: -w class F { } int test1() { scope F f = new F(); // comment out and warning goes away return 0; } int test2() { // no return at end of function try { return 0; } finally { } } void main() { test1(); test2(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test13613.d0000644000175000017500000000251613200164642023135 0ustar matthiasmatthias// PERMUTE_ARGS: // MT!"y" is analyzed from the pragma inside MT!"x" /* TEST_OUTPUT: --- CT x.offsetof = < CT y.offsetof = < 0 > y 0 > x --- */ mixin template MT(string id) { union { mixin("void* " ~ id ~ ";"); } // Evaluating `typeof(this).init` completes data layout. pragma(msg, "CT " ~ id ~ ".offsetof = <\n", cast(int)typeof(this).init.i.offsetof, " > " ~ id); } struct S1 { int i; mixin MT!"x"; mixin MT!"y"; } struct S2 { int i; union { void* x; } union { void* y; } } struct S3 { int i; void* x; void* y; } void main() { // S1, S2, and S3 should have exactly same data layout. static assert(S1.i.offsetof == S3.i.offsetof); static assert(S1.i.offsetof == S3.i.offsetof); static assert(S1.x.offsetof == S3.x.offsetof); static assert(S1.y.offsetof == S3.y.offsetof); static assert(S2.x.offsetof == S3.x.offsetof); static assert(S2.y.offsetof == S3.y.offsetof); static assert(S1.sizeof == S3.sizeof); static assert(S2.sizeof == S3.sizeof); S1 s = void; s.i = 1; assert(s.i == 1); s.x = null; assert(s.i == 1); s.y = null; assert(s.i == 1); char a, b; s.x = cast(void*)&a; assert(s.x is &a); assert(s.y is null); s.y = cast(void*)&b; assert(s.x is &a); assert(s.y is &b); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test11447a.d0000644000175000017500000000022513200164642023274 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/a11447.d // PERMUTE_ARGS: -allinst import imports.a11447; void main() { A a; TTT.yyy(a); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/bug9010.d0000644000175000017500000000061613200164642022646 0ustar matthiasmatthias// PERMUTE_ARGS: // POST_SCRIPT: runnable/extra-files/bug9010-postscript.sh // REQUIRED_ARGS: -cov // EXECUTE_ARGS: ${RESULTS_DIR}/runnable struct A { bool opEquals(A o) const { return false; } } extern(C) void dmd_coverDestPath(string pathname); void main(string[] args) { dmd_coverDestPath(args[1]); auto a = A(); auto b = A(); assert(a != b); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link9571.d0000644000175000017500000000016313200164642023037 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/link9571a.d import imports.link9571a; void main() { foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_426.d0000644000175000017500000000142313200164642024253 0ustar matthiasmatthiasint dtor; struct DestroyMe { ~this() { ++dtor; } int opApply(in int delegate(int item) dg) { throw new Exception("Here we go!"); } } void test1() { dtor = 0; try { foreach (item; DestroyMe()) {} } catch {} assert(dtor == 1); dtor = 0; try { auto lvalue = DestroyMe(); foreach (item; lvalue) {} } catch {} assert(dtor == 1); } /******************************************/ struct DoNotDestroyMe { ~this() { assert(0); } } DoNotDestroyMe doNotDestroyMe() { throw new Exception("Here we go!"); return DoNotDestroyMe(); } void fun(E)(lazy E exp) { try { exp(); } catch {} } void test2() { fun(doNotDestroyMe()); } void main() { test1(); test2(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testthread.d0000644000175000017500000000213713200164642023726 0ustar matthiasmatthias// PERMUTE_ARGS: import core.stdc.stdio; import core.thread; version (CRuntime_DigitalMars) { extern (C) { extern int _tlsstart; extern int _tlsend; } } int tlsx; class Foo { int x; void bar() { printf("bar()\n"); assert(tlsx == 0); tlsx = 5; Thread t = Thread.getThis(); version (CRuntime_DigitalMars) printf("thread ptr=%p, %p &tlsx = %p %p\n", t, &_tlsstart, &tlsx, &_tlsend); x = 3; printf("-bar()\n"); } } int main() { Foo f = new Foo(); Thread t = new Thread(&f.bar); t.start(); printf("t.start() done\n"); // There is no analog for these in druntime. //t.pause(); //t.resume(); Thread.yield(); t.join(); printf("Done waiting\n"); assert(f.x == 3); int i; Thread tx[5]; for (i = 0; i < tx.length; i++) tx[i] = new Thread(&f.bar); for (i = 0; i < tx.length; i++) tx[i].start(); for (i = 0; i < tx.length; i++) tx[i].join(); Thread.sleep(dur!"msecs"(1)); printf("**Success**\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test3.d0000644000175000017500000000100213200164642022607 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_SOURCES: imports/test3a.d imports/test3b.d import imports.test3a; extern(C) int printf(const char*, ...); class Foo { string bar; unittest { printf("in Foo.unittest()\n"); } } void test(int a) { } void test(uint b) { } int main(string[] args) { Foo a = new Foo; string baz = "lolo"; test(3); a.bar = "hello"; a.bar = baz ~ "betty"; printf("a.bar = '%.*s'\n", a.bar.length, a.bar.ptr); assert(a.bar == "lolobetty"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/declaration.d0000644000175000017500000002154513200164642024050 0ustar matthiasmatthias extern(C) int printf(const char*, ...); /***************************************************/ // 6475 class Foo6475(Value) { template T1(size_t n){ alias int T1; } } void test6475() { alias Foo6475!(int) C1; alias C1.T1!0 X1; static assert(is(X1 == int)); alias const(Foo6475!(int)) C2; alias C2.T1!0 X2; static assert(is(X2 == int)); } /***************************************************/ // 6905 void test6905() { auto foo1() { static int n; return n; } auto foo2() { int n; return n; } auto foo3() { return 1; } static assert(typeof(&foo1).stringof == "int delegate() nothrow @nogc @safe"); static assert(typeof(&foo2).stringof == "int delegate() pure nothrow @nogc @safe"); static assert(typeof(&foo3).stringof == "int delegate() pure nothrow @nogc @safe"); ref bar1() { static int n; return n; } static assert(!__traits(compiles, { ref bar2() { int n; return n; } })); static assert(!__traits(compiles, { ref bar3() { return 1; } })); auto ref baz1() { static int n; return n; } auto ref baz2() { int n; return n; } auto ref baz3() { return 1; } static assert(typeof(&baz1).stringof == "int delegate() nothrow @nogc ref @safe"); static assert(typeof(&baz2).stringof == "int delegate() pure nothrow @nogc @safe"); static assert(typeof(&baz3).stringof == "int delegate() pure nothrow @nogc @safe"); } /***************************************************/ // 7019 struct S7019 { int store; this(int n) { store = n << 3; } } S7019 rt_gs = 2; enum S7019 ct_gs = 2; pragma(msg, ct_gs, ", ", ct_gs.store); void test7019() { S7019 rt_ls = 3; // this compiles fine enum S7019 ct_ls = 3; pragma(msg, ct_ls, ", ", ct_ls.store); static class C { S7019 rt_fs = 4; enum S7019 ct_fs = 4; pragma(msg, ct_fs, ", ", ct_fs.store); } auto c = new C; assert(rt_gs == S7019(2) && rt_gs.store == 16); assert(rt_ls == S7019(3) && rt_ls.store == 24); assert(c.rt_fs == S7019(4) && c.rt_fs.store == 32); static assert(ct_gs == S7019(2) && ct_gs.store == 16); static assert(ct_ls == S7019(3) && ct_ls.store == 24); static assert(C.ct_fs == S7019(4) && C.ct_fs.store == 32); void foo(S7019 s = 5) // fixing bug 7152 { assert(s.store == 5 << 3); } foo(); } /***************************************************/ // 7239 struct vec7239 { float x, y, z, w; alias x r; //! for color access alias y g; //! ditto alias z b; //! ditto alias w a; //! ditto } void test7239() { vec7239 a = {x: 0, g: 0, b: 0, a: 1}; assert(a.r == 0); assert(a.g == 0); assert(a.b == 0); assert(a.a == 1); } /***************************************************/ struct S10635 { string str; this(string[] v) { str = v[0]; } this(string[string] v) { str = v.keys[0]; } } S10635 s10635a = ["getnonce"]; S10635 s10635b = ["getnonce" : "str"]; void test10635() { S10635 sa = ["getnonce"]; S10635 sb = ["getnonce" : "str"]; } /***************************************************/ // 8123 void test8123() { struct S { } struct AS { alias S Alias; } struct Wrapper { AS as; } Wrapper w; static assert(is(typeof(w.as).Alias == S)); // fail static assert(is(AS.Alias == S)); // ok static assert(is(typeof(w.as) == AS)); // ok static assert(is(typeof(w.as).Alias == AS.Alias)); // fail } /***************************************************/ // 8147 enum A8147 { a, b, c } @property ref T front8147(T)(T[] a) if (!is(T[] == void[])) { return a[0]; } template ElementType8147(R) { static if (is(typeof({ R r = void; return r.front8147; }()) T)) alias T ElementType8147; else alias void ElementType8147; } void test8147() { auto arr = [A8147.a]; alias typeof(arr) R; auto e = ElementType8147!R.init; } /***************************************************/ // 8410 void test8410() { struct Foo { int[15] x; string s; } Foo[5] a1 = Foo([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], "hello"); // OK Foo f = { s: "hello" }; // OK (not static) Foo[5] a2 = { s: "hello" }; // error } /***************************************************/ // 8942 alias const int A8942_0; static assert(is(A8942_0 == const int)); // passes void test8942() { alias const int A8942_1; static assert(is(A8942_1 == const int)); // passes static struct S { int i; } foreach (Unused; typeof(S.tupleof)) { alias const(int) A8942_2; static assert(is(A8942_2 == const int)); // also passes alias const int A8942_3; static assert(is(A8942_3 == const int)); // fails // Error: static assert (is(int == const(int))) is false } } /***************************************************/ // 10144 final class TNFA10144(char_t) { enum Act { don } const Act[] action_lookup1 = [ Act.don, ]; } alias X10144 = TNFA10144!char; class C10144 { enum Act { don } synchronized { enum x1 = [Act.don]; } override { enum x2 = [Act.don]; } abstract { enum x3 = [Act.don]; } final { enum x4 = [Act.don]; } synchronized { static s1 = [Act.don]; } override { static s2 = [Act.don]; } abstract { static s3 = [Act.don]; } final { static s4 = [Act.don]; } synchronized { __gshared gs1 = [Act.don]; } override { __gshared gs2 = [Act.don]; } abstract { __gshared gs3 = [Act.don]; } final { __gshared gs4 = [Act.don]; } } /***************************************************/ // 10142 class File10142 { enum Access : ubyte { Read = 0x01 } enum Open : ubyte { Exists = 0 } enum Share : ubyte { None = 0 } enum Cache : ubyte { None = 0x00 } struct Style { Access access; Open open; Share share; Cache cache; } enum Style ReadExisting = { Access.Read, Open.Exists }; this (const(char[]) path, Style style = ReadExisting) { assert(style.access == Access.Read); assert(style.open == Open .Exists); assert(style.share == Share .None); assert(style.cache == Cache .None); } } void test10142() { auto f = new File10142("dummy"); } /***************************************************/ // 11421 void test11421() { // AAs in array const a1 = [[1:2], [3:4]]; // ok <- error const int[int][] a2 = [[1:2], [3:4]]; // ok static assert(is(typeof(a1) == typeof(a2))); // AAs in AA auto aa = [1:["a":1.0], 2:["b":2.0]]; static assert(is(typeof(aa) == double[string][int])); assert(aa[1]["a"] == 1.0); assert(aa[2]["b"] == 2.0); } /***************************************************/ // 13776 enum a13776(T) = __traits(compiles, { T; }); enum b13776(A...) = 1; template x13776s() { struct S; alias x13776s = b13776!(a13776!S); } template y13776s() { struct S; alias x2 = b13776!(a13776!S); alias y13776s = x2; } template z13776s() { struct S; alias x1 = a13776!S; alias x2 = b13776!(x1); alias z13776s = x2; } template x13776c() { class C; alias x13776c = b13776!(a13776!C); } template y13776c() { class C; alias x2 = b13776!(a13776!C); alias y13776c = x2; } template z13776c() { class C; alias x1 = a13776!C; alias x2 = b13776!(x1); alias z13776c = x2; } void test13776() { alias xs = x13776s!(); // ok <- ng alias ys = y13776s!(); // ok <- ng alias zs = z13776s!(); // ok alias xc = x13776c!(); // ok <- ng alias yc = y13776c!(); // ok <- ng alias zc = z13776c!(); // ok } /***************************************************/ // 14090 template Packed14090(Args...) { enum x = __traits(compiles, { Args[0] v; }); // Args[0] is an opaque struct Empty, so the variable declaration fails to compile. // The error message creation calls TypeStruct('_Empty')->toChars(), and // it wrongly calls TemplateInstance('RoundRobin!()')->toAlias(). // Finally it will cause incorrect "recursive template instantiation" error. } template Map14090(A...) { alias Map14090 = A[0]; } template RoundRobin14090() { struct Empty; alias RoundRobin14090 = Map14090!(Packed14090!(Empty)); } alias roundRobin14090 = RoundRobin14090!(); /***************************************************/ // 13950 template Tuple13950(T...) { alias T Tuple13950; } void f13950(int x = 0, Tuple13950!() xs = Tuple13950!()) { assert(x == 0); assert(xs.length == 0); } void test13950() { f13950(); } /***************************************************/ int main() { test6475(); test6905(); test7019(); test7239(); test8123(); test8147(); test8410(); test8942(); test10142(); test11421(); test13950(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_989.d0000644000175000017500000000247713200164642024303 0ustar matthiasmatthiasstruct sockaddr { ushort sa_family; byte[14] sa_data; } struct sockaddr_in { ushort sin_family; ushort sin_port; uint sin_addr; ubyte[16 - ushort.sizeof - ushort.sizeof - uint.sizeof] __pad; } struct in6_addr { union { ubyte[16] s6_addr; ushort[8] s6_addr16; uint[4] s6_addr32; } } struct sockaddr_in6 { ushort sin6_family; ushort sin6_port; uint sin6_flowinfo; in6_addr sin6_addr; uint sin6_scope_id; } struct NetworkAddress { // if this union is removed, the segfault disappears. union { sockaddr addr; sockaddr_in addr_ip4; sockaddr_in6 addr_ip6; } } interface InputStream { } interface OutputStream { } // if ': InputStream, OutputStream' is removed, // the segfault moves from cast_.d line 71 to cast_.d line 59 interface Stream : InputStream, OutputStream { } interface TCPConnection : Stream { } class Libevent2TCPConnection : TCPConnection { // if m_localAddress or m_removeAddress is removed, // the segfault disappears NetworkAddress m_localAddress, m_remoteAddress; } void main() { // use auto or Libevent2TCPConnection instead of TCPConnection // and the segfault disappears. TCPConnection conn = new Libevent2TCPConnection(); Stream s = conn; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_176.d0000644000175000017500000000067113200164642024261 0ustar matthiasmatthiasalias __vector(float[4]) float4; void testSplatInit() { float4 a = 1, b = 2; assert((a + b).array == [3, 3, 3, 3]); } void testArrayInit() { float4 c = [1, 2, 3, 4]; assert(c.array == [1, 2, 3, 4]); } void testArrayPtrAssign() { float4 c = 1, d = 0; d.array[0] = 1; d.ptr[1] = 2; assert((c + d).array == [2, 3, 1, 1]); } void main() { testSplatInit(); testArrayInit(); testArrayPtrAssign(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test6423.d0000644000175000017500000000036613200164642023057 0ustar matthiasmatthias bool flag; void f() { } void main() { if (!flag) { flag = true; caller(); } return f(); } alias maintype = extern(C) int function(); void caller() { auto fp = cast(maintype)&main; assert(fp() == 0); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ctorpowtests.d0000644000175000017500000001251013200164642024333 0ustar matthiasmatthias// PERMUTE_ARGS: version (D_InlineAsm_X86) version = DMD_InlineAsm; else version (D_InlineAsm_X86_64) version = DMD_InlineAsm; else { version = LDC_InlineAsm; import ldc.llvmasm; } int magicVariable() { if (__ctfe) return 3; version (DMD_InlineAsm) asm { nop; } else version (LDC_InlineAsm) __asm("", ""); else static assert(0, "Unsupported platform"); return 2; } static assert(magicVariable()==3); void main() { assert(!__ctfe); assert(magicVariable()==2); } // bug 991 -- invalid. // bug 3500 -- is this related to 2127? // Tests for ^^ // TODO: These tests should not require import std.math. import std.math; // Test float ^^ int static assert( 27.0 ^^ 5 == 27.0 * 27.0 * 27.0 * 27.0 * 27.0); static assert( 2.0 ^^ 3 == 8.0); static assert( 2.0 ^^ 4 == 16.0); static assert( 2 ^^ 4 == 16); // Check the typing rules. static assert( is (typeof(2.0^^7) == double)); static assert( is (typeof(7^^3) == int)); static assert( is (typeof(7L^^3) == long)); static assert( is (typeof(7^^3L) == long)); enum short POW_SHORT_1 = 3; enum short POW_SHORT_3 = 7; static assert( is (typeof(POW_SHORT_1 * POW_SHORT_1) == typeof(POW_SHORT_1*POW_SHORT_1))); static assert( is (typeof(7.0^^3) == double)); static assert( is (typeof(7.0L^^3) == real)); static assert( is (typeof(7.0f^^3) == float)); static assert( is (typeof(POW_SHORT_1^^3.1) == double)); static assert( is (typeof(POW_SHORT_1^^3.1f) == float)); static assert( is (typeof(2.1f ^^ POW_SHORT_1) == float)); static assert( is (typeof(7.0f^^3.1) == double)); static assert( is (typeof(7.0^^3.1f) == double)); static assert( is (typeof(7.0f^^3.1f) == float)); static assert( is (typeof(7.0f^^3.1L) == real)); static assert( is (typeof(7.0L^^3.1f) == real)); // Check typing for special cases static assert( is (typeof(7.0f^^2) == float)); static assert( is (typeof(7.0f^^2.0) == double)); static assert( is (typeof(7.0f^^8.0) == double)); static assert( is (typeof(1^^0.5f) == float)); static assert( is (typeof(7^^0.5f) == float)); static assert( is (typeof(3L^^0.5) == double)); static assert( is (typeof(123^^17.0f) == float)); static assert(POW_SHORT_1 ^^ 2 == 9); static assert(4.0 ^^ POW_SHORT_1 == 4.0*4.0*4.0); static assert(4.0 ^^ 7.0 == 4.0*4.0*4.0*4.0*4.0*4.0*4.0); // ^^ has higher precedence than multiply static assert( 2 * 2 ^^ 3 + 1 == 17); static assert( 2 ^^ 3 * 2 + 1 == 17); // ^^ has higher precedence than negate static assert( -2 ^^ 3 * 2 - 1 == -17); // ^^ is right associative static assert( 2 ^^ 3 ^^ 2 == 2 ^^ 9); static assert( 2.0 ^^ -3 ^^ 2 == 2.0 ^^ -9); // 1 ^^ n is always 1, even if n is negative static assert( 1 ^^ -5 == 1); // -1 ^^ n gets transformed into n & 1 ? -1 : 1 // even if n is negative static assert( (-1) ^^ -5 == -1); static assert( (-1) ^^ -4 == 1); static assert( (-1) ^^ 0 == 1); // n ^^ 0 is always 1 static assert( (-5) ^^ 0 == 1); // n ^^ 1 is always n static assert( 6.0 ^^ 1 == 6.0); // n ^^ -1.0 gets transformed into 1.0 / n, even if n is negative static assert( (-4) ^^ -1.0 == 1.0 / -4); static assert( 9 ^^ -1.0 == 1.0 / 9); // Other integers raised to negative powers create an error static assert( !is(typeof(2 ^^ -5))); static assert( !is(typeof((-2) ^^ -4))); // Bug 3535 struct StructWithCtor { this(int _n) { n = _n; x = 5; } this(int _n, float _x) { n = _n; x = _x; } int n; float x; } int containsAsm() { version (DMD_InlineAsm) asm { nop; } else version (LDC_InlineAsm) __asm("", ""); else static assert(0, "Unsupported inline asm"); return 0; } enum A = StructWithCtor(1); enum B = StructWithCtor(7, 2.3); static assert(A.n == 1); static assert(A.x == 5.0); static assert(B.n == 7); static assert(B.x == 2.3); int bazra(int x) { StructWithCtor p = StructWithCtor(4); return p.n ^^ 3; } static assert(bazra(14)==64); void moreCommaTests() { auto k = (containsAsm(), containsAsm()); for (int i=0; i< k^^2; i+=StructWithCtor(1).n) {} } // Test copy constructors struct CopyTest { double x; this(double a) { x = a * 10.0;} this(this) { x+=2.0;} } struct CopyTest2 { int x; int x1; int x2; int x3; this(int a) { x = a * 2; x1 = 3;} this(this) { x1+=17;} } const CopyTest z = CopyTest(5.3); /+ // TODO: This is not yet supported. But it // generates an error message instead of wrong-code. const CopyTest w = z; static assert(z.x==55.0); +/ int copytest1() { CopyTest z = CopyTest(3.4); CopyTest w = z; assert(w.x == 36.0); CopyTest2 q = CopyTest2(7); CopyTest2 q2 = q; CopyTest2 q3 = q2; assert(q3.x1 == 37); return 123; } static assert(copytest1()==123); // This must not cause a segfault alias int FILTH; struct Filth { struct Impl { FILTH * handle = null; this(FILTH* h, uint r, string n) { handle = h; } } Impl * p; this(string name, in char[] stdioOpenmode = "rb") { } ~this() { if (!p) return; } this(this) { if (!p) return; } } struct InputByChar { private Filth _f; this(Filth f) { _f = f; } } static int nastyForCtfe=4; // Can't use a global variable static assert(!is(typeof( (){ static assert(0!=nastyForCtfe^^2); }))); int anotherPowTest() { double x = 5.0; return x^^4 > 2.0 ? 3: 2; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test435.d0000644000175000017500000000375313200164642022777 0ustar matthiasmatthiasimport core.stdc.stdio; class A { immutable size_t f; this(T)(T z) { f = z.sizeof; } } struct AS { immutable size_t f; this(T)(T z) { f = z.sizeof; } } void test0() { assert((new A(2.2)).f == double.sizeof); assert((new A('g')).f == char.sizeof); assert((AS(17)).f == int.sizeof); assert((AS(null)).f == typeof(null).sizeof); } //------------------------------------------------------------------------------ class C { const int x; const int y; this(T...)(T z) { this.tupleof = z; } } struct CS { const int x; const int y; this(T...)(T z) { this.tupleof = z; } } void test1() { auto c = new C(4, 6); assert(c.x == 4); assert(c.y == 6); auto cs = CS(7, 8); assert(cs.x == 7); assert(cs.y == 8); } //------------------------------------------------------------------------------ // bug 435. class B { int i; this(int k) { i = k; } } class D : B { this(A...)(A args) { super(args); } } void test2() { auto a = new D(4); assert(a.i == 4); } //------------------------------------------------------------------------------ // bug 4905 class C2 { string x; this(T...)(in string msg, T args) { x = msg; foreach (a; args) x ~= a; } } void test3() { auto c2 = new C2("test"); assert(c2.x == "test"); auto c3 = new C2("test", " variadic", " constructor"); assert(c3.x == "test variadic constructor"); } //------------------------------------------------------------------------------ // bug 4531 test case 2 class MyError : Exception { this(T...)(T msg) { assert(msg[0] == "Hello, " && msg[1] == 42); super("Hello, 42"); } } void test4() { auto err = new MyError("Hello, ", 42); assert(err.msg == "Hello, 42"); } void main() { test0(); test1(); test2(); test3(); test4(); printf("Success\n"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/foreach2.d0000644000175000017500000000753013200164642023252 0ustar matthiasmatthias import core.stdc.stdio; /**************************************************/ void test1() { uint[char[]] a; int i; a["hello"] = 73; a["world"] = 82; foreach (uint u; a) { i++; u++; } assert(i == 2); assert(a["hello"] == 73); assert(a["world"] == 82); } /**************************************************/ void test2() { uint[char[]] a; int i; a["hello"] = 73; a["world"] = 82; foreach (ref uint u; a) { i++; u++; } assert(i == 2); assert(a["hello"] == 74); assert(a["world"] == 83); } /**************************************************/ void test3() { uint[char[]] a; int i; a["hello"] = 73; a["world"] = 82; foreach (ref uint u; a) { i++; if (i) break; u++; } assert(i == 1); assert(a["hello"] == 73); assert(a["world"] == 82); } /**************************************************/ void test4() { uint[char[]] a; int i; a["hello"] = 73; a["world"] = 82; foreach (ref uint u; a) { i++; if (i == 1) continue; u++; } assert(i == 2); assert((a["hello"] == 73 && a["world"] == 83) || (a["hello"] == 74 && a["world"] == 82)); } /**************************************************/ void test5() { uint[char[]] a; int i; a["hello"] = 73; a["world"] = 82; Loop: while (1) { foreach (ref uint u; a) { i++; if (i) break Loop; u++; } } assert(i == 1); assert(a["hello"] == 73); assert(a["world"] == 82); } /**************************************************/ void test6() { uint[char[]] a; int i; a["hello"] = 73; a["world"] = 82; Loop: while (1) { foreach (ref uint u; a) { i++; if (i == 1) continue Loop; u++; } break; } assert(i == 3); assert(a["hello"] == 74); assert(a["world"] == 83); } /**************************************************/ void test7() { uint[char[]] a; int i; a["hello"] = 73; a["world"] = 82; foreach (ref uint u; a) { i++; if (i) goto Label; u++; } assert(0); Label: assert(i == 1); assert(a["hello"] == 73); assert(a["world"] == 82); } /**************************************************/ void test8_x(uint[char[]] a) { int i; foreach (ref uint u; a) { i++; if (i) return; u++; } } void test8() { uint[char[]] a; int i; a["hello"] = 73; a["world"] = 82; test8_x(a); assert(i == 0); assert(a["hello"] == 73); assert(a["world"] == 82); } /**************************************************/ int test9_x(uint[char[]] a) { int i; foreach (ref uint u; a) { i++; if (i) return 67; u++; } return 23; } void test9() { uint[char[]] a; int i; a["hello"] = 73; a["world"] = 82; i = test9_x(a); assert(i == 67); assert(a["hello"] == 73); assert(a["world"] == 82); } /**************************************************/ int test10_x(uint[char[]] a) { int i; foreach (ref uint u; a) { i++; if (i) return i; u++; } return 23; } void test10() { uint[char[]] a; int i; a["hello"] = 73; a["world"] = 82; i = test10_x(a); assert(i == 1); assert(a["hello"] == 73); assert(a["world"] == 82); } /**************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/b26.d0000644000175000017500000000030413200164642022142 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/b26a.d // PERMUTE_ARGS: // 382 struct List(T) { interface A {} } int main(char[][] args) { List!(char) list; return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link14074a.d0000644000175000017500000000034613200164642023255 0ustar matthiasmatthias// EXTRA_SOURCES: imports/link14074y.d import imports.link14074x; import imports.link14074y; struct Inner { } struct Test { Inner inner; } void main() { ubyte[] buffer; Test test; encodeArray(buffer, test); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_217.d0000644000175000017500000000025313200164642024251 0ustar matthiasmatthiasimport imports.ldc_github_217a; struct A { bool foo() { return true; } void bar() { B!((i) { return foo(); })(0); } } void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test7453.d0000644000175000017500000000022513200164642023055 0ustar matthiasmatthiasstruct S { int opApply(int delegate(string) dg) { return 0; } } void main() { foreach (_; S()) { return; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test29.d0000644000175000017500000000035013200164642022704 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test29a.d imports/test29b.d // PERMUTE_ARGS: import imports.test29a; import imports.test29b; extern(C) int printf(const char*, ...); void main() { printf("%d\n", qwert); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_430.d0000644000175000017500000000036513200164642024252 0ustar matthiasmatthiasimport std.conv; align(1) struct Foo { align(1): ushort b; uint c; } void main() { ubyte[6] arr = [0x01, 0x01, 0x01, 0x00, 0x00, 0x01]; Foo f = cast(Foo) arr; assert(to!string(f) == "Foo(257, 16777217)"); assert(f.sizeof == 6); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/a20.d0000644000175000017500000000044613200164642022142 0ustar matthiasmatthias// EXTRA_SOURCES: imports/a20a.d // PERMUTE_ARGS: // REQUIRED_ARGS: -cov // POST_SCRIPT: runnable/extra-files/a20-postscript.sh // EXECUTE_ARGS: ${RESULTS_DIR}/runnable import a20a; extern(C) void dmd_coverDestPath(string path); void main(string[] args) { dmd_coverDestPath(args[1]); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/interface1.d0000644000175000017500000000526713200164642023607 0ustar matthiasmatthias extern(C) int printf(const char*, ...); /*******************************************/ interface D { int foo(); } class A : D { int foo() { return 1; } } class B : A, D { override int foo() { return 2; } } class C : B, D { override int foo() { return 3; } } void test1() { C c = new C; A a = cast(A) c; int j = a.foo(); printf("%d\n", j); assert(j == 3); B b = cast(B) c; int k = b.foo(); printf("%d\n", k); assert(k == 3); D d1 = cast(D) c; int l = d1.foo(); printf("%d\n", l); assert(l == 3); D d2 = cast(D) b; int m = d2.foo(); printf("%d\n", m); assert(m == 3); } /*******************************************/ interface D2 { int foo(); } class A2 : D2 { int foo() { printf("A2\n"); return 1; } } class B2 : A2 { override int foo() { printf("B2\n"); return 2; } } class C2 : B2, D2 { override int foo() { printf("C2\n"); return 3; } } void test2() { int i; C2 c = new C2; D2 d = cast(D2)c; i = c.foo(); assert(i == 3); i = d.foo(); assert(i == 3); B2 b = new B2; if (cast(D2) b) { D2 e = cast(D2) b; i = e.foo(); assert(i == 2); } else assert(0); A2 a; if (cast(D2) a) assert(0); } /*******************************************/ interface C3 { int doLayout(); } class A3 { void print() { printf("A3::print\n"); } } class B3 : A3, C3 { int doLayout() { printf( "B3::doLayout\n" ); return 17; } } void callLayout(A3 b) { printf("b = %p\n", b); C3 cl = cast(C3)b; printf("cl = %p\n", cl); if (cl) { int i; i = cl.doLayout(); assert(i == 17); } else { printf("the 'A3' you passed did not implement 'C3'\n" ); assert(0); } } void test3() { callLayout(new B3()); } /*******************************************/ template IContainer(T) { interface IContainer { alias Container!(int) selected_type; bool isEmpty(); int enumerate(); } } template Container(T) { class Container : IContainer!(int) { bool isEmpty() { return false; } int enumerate() { return 3; } } } void Vector_test_IContainer_int() { alias IContainer!(int) icontainer_t; } void test4() { } /*******************************************/ interface Italy(T) { alias Foo5!(int) selected_type; bool isempty(); int enumerate(); } class Foo5(T) : Italy!(int) { bool isempty() { return false; } int enumerate() { return 3; } } void test5() { alias Italy!(int) Ic; Foo5!(int) f = new Foo5!(int); Ic i = cast(Ic)f; assert(i.isempty() == false); assert(i.enumerate() == 3); } /*******************************************/ int main (char[][] args) { test1(); test2(); test3(); test4(); test5(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link13400.d0000644000175000017500000000057513200164642023110 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/link13400a.d import imports.link13400a; void main() { BigInt r; // This comparison will instantiate BigInt.opEquals!().opEquals(const BigInt y) const pure again. // But here is non-speculative context, so this module compilation should generate its objcode. bool b = r == BigInt("2"); // comparison with rvalue } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_248.d0000644000175000017500000000022113200164642024250 0ustar matthiasmatthiasvoid test() { int a, b, c; int*[int] assArray = [ 1: &a, 2: &b, 3: &c ]; } void main() { test(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_513.d0000644000175000017500000000045513200164642024254 0ustar matthiasmatthiastemplate t9578(alias f) { void tf()() { f(); } } void g9578a(alias f)() { f(); } // Error -> OK void g9578b(alias ti)() { ti.tf(); } // Error -> OK void test9578() { int i = 0; int m() { return i; } g9578a!(t9578!m.tf)(); g9578b!(t9578!m)(); } void main() { test9578(); }ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test52.d0000644000175000017500000000047213200164642022705 0ustar matthiasmatthias// PERMUTE_ARGS: // 2311 extern(C) { void exit(int); int printf(const char*, ...); } struct X() { static this() { printf("this()\n"); } static ~this() { printf("~this()\n"); exit(0); } } static ~this() { printf("g: ~this()\n"); } int main() { alias X!() x; return 1; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/opover2.d0000644000175000017500000012235613200164642023161 0ustar matthiasmatthias// PERMUTE_ARGS: -inline -O -property // Test operator overloading extern (C) int printf(const(char*) fmt, ...); template Seq(T...){ alias T Seq; } bool thrown(E, T)(lazy T val) { try { val(); return false; } catch (E e) { return true; } } void stompStack() { int[256] sa = 0xdeadbeef; } /**************************************/ class A { string opUnary(string s)() { printf("A.opUnary!(%.*s)\n", s.length, s.ptr); return s; } } void test1() { auto a = new A(); +a; -a; ~a; *a; ++a; --a; auto x = a++; assert(x == a); auto y = a--; assert(y == a); } /**************************************/ class A2 { T opCast(T)() { auto s = T.stringof; printf("A.opCast!(%.*s)\n", s.length, s.ptr); return T.init; } } void test2() { auto a = new A2(); auto x = cast(int)a; assert(x == 0); auto y = cast(char)a; assert(y == char.init); } /**************************************/ struct A3 { int opBinary(string s)(int i) { printf("A.opBinary!(%.*s)\n", s.length, s.ptr); return 0; } int opBinaryRight(string s)(int i) if (s == "/" || s == "*") { printf("A.opBinaryRight!(%.*s)\n", s.length, s.ptr); return 0; } T opCast(T)() { auto s = T.stringof; printf("A.opCast!(%.*s)\n", s.length, s.ptr); return T.init; } } void test3() { A3 a; a + 3; 4 * a; 4 / a; a & 5; } /**************************************/ struct A4 { int opUnary(string s)() { printf("A.opUnary!(%.*s)\n", s.length, s.ptr); return 0; } T opCast(T)() { auto s = T.stringof; printf("A.opCast!(%.*s)\n", s.length, s.ptr); return T.init; } } void test4() { A4 a; if (a) int x = 3; if (!a) int x = 3; if (!!a) int x = 3; } /**************************************/ class A5 { override bool opEquals(Object o) { printf("A.opEquals!(%p)\n", o); return 1; } int opUnary(string s)() { printf("A.opUnary!(%.*s)\n", s.length, s.ptr); return 0; } T opCast(T)() { auto s = T.stringof; printf("A.opCast!(%.*s)\n", s.length, s.ptr); return T.init; } } class B5 : A5 { override bool opEquals(Object o) { printf("B.opEquals!(%p)\n", o); return 1; } } void test5() { A5 a = new A5(); A5 a2 = new A5(); B5 b = new B5(); A n = null; if (a == a) int x = 3; if (a == a2) int x = 3; if (a == b) int x = 3; if (a == n) int x = 3; if (n == a) int x = 3; if (n == n) int x = 3; } /**************************************/ struct S6 { const bool opEquals(ref const S6 b) { printf("S.opEquals(S %p)\n", &b); return true; } const bool opEquals(ref const T6 b) { printf("S.opEquals(T %p)\n", &b); return true; } } struct T6 { const bool opEquals(ref const T6 b) { printf("T.opEquals(T %p)\n", &b); return true; } /+ const bool opEquals(ref const S6 b) { printf("T.opEquals(S %p)\n", &b); return true; } +/ } void test6() { S6 s1; S6 s2; if (s1 == s2) int x = 3; T6 t; if (s1 == t) int x = 3; if (t == s2) int x = 3; } /**************************************/ struct S7 { const int opCmp(ref const S7 b) { printf("S.opCmp(S %p)\n", &b); return -1; } const int opCmp(ref const T7 b) { printf("S.opCmp(T %p)\n", &b); return -1; } } struct T7 { const int opCmp(ref const T7 b) { printf("T.opCmp(T %p)\n", &b); return -1; } /+ const int opCmp(ref const S7 b) { printf("T.opCmp(S %p)\n", &b); return -1; } +/ } void test7() { S7 s1; S7 s2; if (s1 < s2) int x = 3; T7 t; if (s1 < t) int x = 3; if (t < s2) int x = 3; } /**************************************/ struct A8 { int opUnary(string s)() { printf("A.opUnary!(%.*s)\n", s.length, s.ptr); return 0; } int opIndexUnary(string s, T)(T i) { printf("A.opIndexUnary!(%.*s)(%d)\n", s.length, s.ptr, i); return 0; } int opIndexUnary(string s, T)(T i, T j) { printf("A.opIndexUnary!(%.*s)(%d, %d)\n", s.length, s.ptr, i, j); return 0; } int opSliceUnary(string s)() { printf("A.opSliceUnary!(%.*s)()\n", s.length, s.ptr); return 0; } int opSliceUnary(string s, T)(T i, T j) { printf("A.opSliceUnary!(%.*s)(%d, %d)\n", s.length, s.ptr, i, j); return 0; } } void test8() { A8 a; -a; -a[3]; -a[3, 4]; -a[]; -a[5 .. 6]; --a[3]; } /**************************************/ struct A9 { int opOpAssign(string s)(int i) { printf("A.opOpAssign!(%.*s)\n", s.length, s.ptr); return 0; } int opIndexOpAssign(string s, T)(int v, T i) { printf("A.opIndexOpAssign!(%.*s)(%d, %d)\n", s.length, s.ptr, v, i); return 0; } int opIndexOpAssign(string s, T)(int v, T i, T j) { printf("A.opIndexOpAssign!(%.*s)(%d, %d, %d)\n", s.length, s.ptr, v, i, j); return 0; } int opSliceOpAssign(string s)(int v) { printf("A.opSliceOpAssign!(%.*s)(%d)\n", s.length, s.ptr, v); return 0; } int opSliceOpAssign(string s, T)(int v, T i, T j) { printf("A.opSliceOpAssign!(%.*s)(%d, %d, %d)\n", s.length, s.ptr, v, i, j); return 0; } } void test9() { A9 a; a += 8; a -= 8; a *= 8; a /= 8; a %= 8; a &= 8; a |= 8; a ^= 8; a <<= 8; a >>= 8; a >>>= 8; a ~= 8; a ^^= 8; a[3] += 8; a[3] -= 8; a[3] *= 8; a[3] /= 8; a[3] %= 8; a[3] &= 8; a[3] |= 8; a[3] ^= 8; a[3] <<= 8; a[3] >>= 8; a[3] >>>= 8; a[3] ~= 8; a[3] ^^= 8; a[3, 4] += 8; a[] += 8; a[5 .. 6] += 8; } /**************************************/ struct BigInt { int opEquals(T)(T n) const { return 1; } int opEquals(T:int)(T n) const { return 1; } int opEquals(T:const(BigInt))(T n) const { return 1; } } int decimal(BigInt b, const BigInt c) { while (b != c) { } return 1; } /**************************************/ struct Foo10 { int opUnary(string op)() { return 1; } } void test10() { Foo10 foo; foo++; } /**************************************/ struct S4913 { bool opCast(T : bool)() { return true; } } int bug4913() { if (S4913 s = S4913()) { return 83; } return 9; } static assert(bug4913() == 83); /**************************************/ // 5551 struct Foo11 { Foo11 opUnary(string op:"++")() { return this; } Foo11 opBinary(string op)(int y) { return this; } } void test11() { auto f = Foo11(); f++; } /**************************************/ // 4099 struct X4099 { int x; alias x this; typeof(this) opUnary (string operator) () { printf("operator called\n"); return this; } } void test4099() { X4099 x; X4099 r1 = ++x; //operator called X4099 r2 = x++; //BUG! (alias this used. returns int) } /**************************************/ void test12() { static int opeq; // xopEquals OK static struct S1a { const bool opEquals( const typeof(this) rhs) { ++opeq; return false; } } static struct S1b { const bool opEquals(ref const typeof(this) rhs) { ++opeq; return false; } } static struct S1c { const bool opEquals( typeof(this) rhs) { ++opeq; return false; } } // xopEquals NG static struct S2a { bool opEquals( typeof(this) rhs) { ++opeq; return false; } } foreach (S; Seq!(S1a, S1b, S1c)) { S s; opeq = 0; assert(s != s); // call opEquals directly assert(!typeid(S).equals(&s, &s)); // -> xopEquals (-> __xopEquals) -> opEquals assert(opeq == 2); } foreach (S; Seq!(S2a)) { S s; opeq = 0; assert(s != s); assert(thrown!Error(!typeid(S).equals(&s, &s))); // Error("notImplemented") thrown assert(opeq == 1); } } /**************************************/ void test13() { static int opeq; struct X { const bool opEquals(const X){ ++opeq; return false; } } struct S { X x; } S makeS(){ return S(); } S s; opeq = 0; assert(s != s); assert(makeS() != s); assert(s != makeS()); assert(makeS() != makeS()); assert(opeq == 4); // built-in opEquals == const bool opEquals(const S rhs); assert(s != s); assert(opeq == 5); // xopEquals assert(!typeid(S).equals(&s, &s)); assert(opeq == 6); } /**************************************/ void test14() { static int opeq; struct S { const bool opEquals(T)(const T rhs) { ++opeq; return false; } } S makeS(){ return S(); } S s; opeq = 0; assert(s != s); assert(makeS() != s); assert(s != makeS()); assert(makeS() != makeS()); assert(opeq == 4); // xopEquals (-> __xxopEquals) -> template opEquals assert(!typeid(S).equals(&s, &s)); assert(opeq == 5); } /**************************************/ void test15() { struct S { const bool opEquals(T)(const(T) rhs) if (!is(T == S)) { return false; } @disable const bool opEquals(T)(const(T) rhs) if (is(T == S)) { return false; } } S makeS(){ return S(); } S s; static assert(!__traits(compiles, s != s)); static assert(!__traits(compiles, makeS() != s)); static assert(!__traits(compiles, s != makeS())); static assert(!__traits(compiles, makeS() != makeS())); // xopEquals (-> __xxopEquals) -> Error thrown assert(thrown!Error(!typeid(S).equals(&s, &s))); } /**************************************/ void test16() { struct X { int n; const bool opEquals(T)(T t) { return false; } } struct S { X x; } S s1, s2; assert(s1 != s2); // field template opEquals should call } /**************************************/ void test17() { static int opeq = 0; struct S { bool opEquals(ref S rhs) { ++opeq; return false; } } S[] sa1 = new S[3]; S[] sa2 = new S[3]; assert(sa1 != sa2); // isn't used TypeInfo.equals assert(opeq == 1); const(S)[] csa = new const(S)[3]; static assert(!__traits(compiles, csa == sa1)); static assert(!__traits(compiles, sa1 == csa)); static assert(!__traits(compiles, csa == csa)); } /**************************************/ // 3789 bool test3789() { static struct Float { double x; } Float f; assert(f.x != f.x); // NaN != NaN assert(f != f); static struct Array { int[] x; } Array a1 = Array([1,2,3].dup); Array a2 = Array([1,2,3].dup); if (!__ctfe) { // Currently doesn't work this in CTFE - may or may not a bug. assert(a1.x !is a2.x); } assert(a1.x == a2.x); assert(a1 == a2); static struct AA { int[int] x; } AA aa1 = AA([1:1,2:2,3:3]); AA aa2 = AA([1:1,2:2,3:3]); if (!__ctfe) { // Currently doesn't work this in CTFE - may or may not a bug. assert(aa1.x !is aa2.x); } if (!__ctfe) { // This is definitely a bug. Should work in CTFE. assert(aa1.x == aa2.x); assert(aa1 == aa2); } if (!__ctfe) { // Currently union operation is not supported in CTFE. union U1 { double x; } static struct UnionA { int[] a; U1 u; } auto ua1 = UnionA([1,2,3]); auto ua2 = UnionA([1,2,3]); assert(ua1.u.x is ua2.u.x); assert(ua1.u.x != ua2.u.x); assert(ua1 == ua2); ua1.u.x = 1.0; ua2.u.x = 1.0; assert(ua1.u.x is ua2.u.x); assert(ua1.u.x == ua2.u.x); assert(ua1 == ua2); ua1.u.x = double.nan; assert(ua1.u.x !is ua2.u.x); assert(ua1.u.x != ua2.u.x); assert(ua1 != ua2); union U2 { int[] a; } static struct UnionB { double x; U2 u; } auto ub1 = UnionB(1.0); auto ub2 = UnionB(1.0); assert(ub1 == ub2); ub1.u.a = [1,2,3].dup; ub2.u.a = [1,2,3].dup; assert(ub1.u.a !is ub2.u.a); assert(ub1.u.a == ub2.u.a); assert(ub1 != ub2); ub2.u.a = ub1.u.a; assert(ub1.u.a is ub2.u.a); assert(ub1.u.a == ub2.u.a); assert(ub1 == ub2); } if (!__ctfe) { // This is definitely a bug. Should work in CTFE. static struct Class { Object x; } static class X { override bool opEquals(Object o){ return true; } } Class c1a = Class(new Object()); Class c2a = Class(new Object()); assert(c1a.x !is c2a.x); assert(c1a.x != c2a.x); assert(c1a != c2a); // Pass, Object.opEquals works like bitwise compare Class c1b = Class(new X()); Class c2b = Class(new X()); assert(c1b.x !is c2b.x); assert(c1b.x == c2b.x); assert(c1b == c2b); // Fails, should pass } return true; } static assert(test3789()); /**************************************/ // 10037 struct S10037 { bool opEquals(ref const S10037) { assert(0); } } struct T10037 { S10037 s; // Compiler should not generate 'opEquals' here implicitly: } struct Sub10037(TL...) { TL data; int value; alias value this; } void test10037() { S10037 s; T10037 t; static assert( __traits(hasMember, S10037, "opEquals")); static assert(!__traits(hasMember, T10037, "opEquals")); assert(thrown!Error(s == s)); assert(thrown!Error(t == t)); Sub10037!(S10037) lhs; Sub10037!(S10037) rhs; static assert(!__traits(hasMember, Sub10037!(S10037), "opEquals")); assert(lhs == rhs); // lowered to: lhs.value == rhs.value } /**************************************/ // 5810 struct Bug5810 { void opUnary(string op)() {} } struct Foo5810 { Bug5810 x; void bar() { x++; } } /**************************************/ // 6798 struct Tuple6798(T...) { T field; alias field this; bool opEquals(Tuple6798 rhs) { foreach (i, _; T) { if (this[i] != rhs[i]) return false; } return true; } } auto tuple6798(T...)(T args) { return Tuple6798!T(args); } int test6798a() { //import std.typecons; alias tuple6798 tuple; static struct S1 { auto opDollar(size_t dim)() { return 99; } auto opSlice(int dim)(int lwr, int upr) { return [dim, lwr, upr]; } auto opIndex(A...)(A indices) { return tuple(" []", indices); } auto opIndexUnary(string op, A...)(A indices) { return tuple(op~"[]", indices); } auto opIndexAssign(A...)(string s, A indices) { return tuple("[] =", s, indices); } auto opIndexOpAssign(string op, A...)(string s, A indices) { return tuple("[]"~op~"=", s, indices); } } S1 s1; assert( s1[] == tuple(" []")); assert( s1[10] == tuple(" []", 10)); assert( s1[10, 20] == tuple(" []", 10, 20)); assert( s1[10..20] == tuple(" []", [0, 10, 20])); assert(+s1[] == tuple("+[]")); assert(-s1[10] == tuple("-[]", 10)); assert(*s1[10, 20] == tuple("*[]", 10, 20)); assert(~s1[10..20] == tuple("~[]", [0, 10, 20])); assert((s1[] ="x") == tuple("[] =", "x")); assert((s1[10] ="x") == tuple("[] =", "x", 10)); assert((s1[10, 20] ="x") == tuple("[] =", "x", 10, 20)); assert((s1[10..20] ="x") == tuple("[] =", "x", [0, 10, 20])); assert((s1[] +="x") == tuple("[]+=", "x")); assert((s1[10] -="x") == tuple("[]-=", "x", 10)); assert((s1[10, 20]*="x") == tuple("[]*=", "x", 10, 20)); assert((s1[10..20]~="x") == tuple("[]~=", "x", [0, 10, 20])); assert( s1[20..30, 10] == tuple(" []", [0, 20, 30], 10)); assert( s1[10, 10..$, $-4, $..2] == tuple(" []", 10, [1,10,99], 99-4, [3,99,2])); assert(+s1[20..30, 10] == tuple("+[]", [0, 20, 30], 10)); assert(-s1[10, 10..$, $-4, $..2] == tuple("-[]", 10, [1,10,99], 99-4, [3,99,2])); assert((s1[20..30, 10] ="x") == tuple("[] =", "x", [0, 20, 30], 10)); assert((s1[10, 10..$, $-4, $..2] ="x") == tuple("[] =", "x", 10, [1,10,99], 99-4, [3,99,2])); assert((s1[20..30, 10] +="x") == tuple("[]+=", "x", [0, 20, 30], 10)); assert((s1[10, 10..$, $-4, $..2]-="x") == tuple("[]-=", "x", 10, [1,10,99], 99-4, [3,99,2])); // opIndex exist, but opSlice for multi-dimensional doesn't. static struct S2 { auto opSlice(size_t dim)() { return [dim]; } auto opSlice()(size_t lwr, size_t upr) { return [lwr, upr]; } auto opIndex(A...)(A indices){ return [[indices]]; } } S2 s2; assert(s2[] == [[]]); assert(s2[1] == [[1]]); assert(s2[1, 2] == [[1, 2]]); assert(s2[1..2] == [1, 2]); static assert(!__traits(compiles, s2[1, 2..3] )); static assert(!__traits(compiles, s2[1..2, 2..3] )); // opSlice for multi-dimensional exists, but opIndex for that doesn't. static struct S3 { auto opSlice(size_t dim)(size_t lwr, size_t upr) { return [lwr, upr]; } auto opIndex(size_t n){ return [[n]]; } auto opIndex(size_t n, size_t m){ return [[n, m]]; } } S3 s3; static assert(!__traits(compiles, s3[] )); assert(s3[1] == [[1]]); assert(s3[1, 2] == [[1, 2]]); static assert(!__traits(compiles, s3[1..2] )); static assert(!__traits(compiles, s3[1, 2..3] )); static assert(!__traits(compiles, s3[1..2, 2..3] )); return 0; } int test6798b() { static struct Typedef(T) { private T Typedef_payload = T.init; alias a = Typedef_payload; auto ref opIndex(this X, D...)(auto ref D i) { return a[i]; } auto ref opSlice(this X )() { return a[]; } auto ref opSlice(this X, B, E)(auto ref B b, auto ref E e) { assert(b == 0 && e == 3); return a[b..e]; } template opDispatch(string name) { // field or property function @property auto ref opDispatch(this X)() { return mixin("a."~name); } @property auto ref opDispatch(this X, V)(auto ref V v) { return mixin("a."~name~" = v"); } } static if (is(typeof(a) : E[], E)) { auto opDollar() const { return a.length; } } } Typedef!(int[]) dollar2; dollar2.length = 3; assert(dollar2.Typedef_payload.length == 3); assert(dollar2[0 .. $] is dollar2[0 .. 3]); return 0; } int test6798c() { alias T = Tuple6798!(int, int); auto n = T[].init; static assert(is(typeof(n[0]) == Tuple6798!(int, int))); return 0; } void test6798() { static assert(test6798a() == 0); // CTFE check test6798a(); static assert(test6798b() == 0); test6798b(); static assert(test6798c() == 0); test6798c(); } /**************************************/ // 12382 struct S12382 { size_t opDollar() { return 0; } size_t opIndex(size_t) { return 0; } } S12382 func12382() { return S12382(); } static assert(S12382.init[$] == 0); static assert(func12382()[$] == 0); enum e12382a = S12382.init[$]; enum e12382b = func12382()[$]; static v12382a = S12382.init[$]; static v12382b = func12382()[$]; void test12382() { static assert(S12382.init[$] == 0); static assert(func12382()[$] == 0); enum e12382a = S12382.init[$]; enum e12382b = func12382()[$]; static v12382a = S12382.init[$]; static v12382b = func12382()[$]; } /**************************************/ // 12904 struct S12904 { void opIndexAssign(U, A...)(U value, A args) { static assert(0); } void opSliceAssign(int n) { assert(n == 10); } size_t opDollar(size_t dim)() { return 7; } int opSlice(size_t dim)(size_t, size_t to) { assert(to == 7); return 1; } int opIndex(int i1, int i2) { assert(i1 == 1 && i2 == 1); return 10; } } void test12904() { S12904 s; s[] = s[0..$, 1]; s[] = s[0..$, 0..$]; } /**************************************/ // 7641 mixin template Proxy7641(alias a) { auto ref opBinaryRight(string op, B)(auto ref B b) { return mixin("b "~op~" a"); } } struct Typedef7641(T) { private T Typedef_payload; this(T init) { Typedef_payload = init; } mixin Proxy7641!Typedef_payload; } void test7641() { class C {} C c1 = new C(); auto a = Typedef7641!C(c1); static assert(!__traits(compiles, { C c2 = a; })); } /**************************************/ // 8434 void test8434() { static class Vector2D(T) { T x, y; this(T x, T y) { this.x = x; this.y = y; } U opCast(U)() const { assert(0); } } alias Vector2D!(short) Vector2s; alias Vector2D!(float) Vector2f; Vector2s vs1 = new Vector2s(42, 23); Vector2s vs2 = new Vector2s(42, 23); assert(vs1 != vs2); } /**************************************/ void test18() { // one dimensional indexing static struct IndexExp { int[] opIndex(int a) { return [a]; } int[] opIndexUnary(string op)(int a) { return [a]; } int[] opIndexAssign(int val, int a) { return [val, a]; } int[] opIndexOpAssign(string op)(int val, int a) { return [val, a]; } int opDollar() { return 8; } } IndexExp index; // opIndex assert(index[8] == [8]); assert(index[$] == [8]); assert(index[$-1] == [7]); assert(index[$-$/2] == [4]); // opIndexUnary assert(-index[8] == [8]); assert(-index[$] == [8]); assert(-index[$-1] == [7]); assert(-index[$-$/2] == [4]); // opIndexAssign assert((index[8] = 2) == [2, 8]); assert((index[$] = 2) == [2, 8]); assert((index[$-1] = 2) == [2, 7]); assert((index[$-$/2] = 2) == [2, 4]); // opIndexOpAssign assert((index[8] += 2) == [2, 8]); assert((index[$] += 2) == [2, 8]); assert((index[$-1] += 2) == [2, 7]); assert((index[$-$/2] += 2) == [2, 4]); // opDollar is only one-dimensional static assert(!is(typeof(index[$, $]))); static assert(!is(typeof(-index[$, $]))); static assert(!is(typeof(index[$, $] = 2))); static assert(!is(typeof(index[$, $] += 2))); // multi dimensional indexing static struct ArrayExp { int[] opIndex(int a, int b) { return [a, b]; } int[] opIndexUnary(string op)(int a, int b) { return [a, b]; } int[] opIndexAssign(int val, int a, int b) { return [val, a, b]; } int[] opIndexOpAssign(string op)(int val, int a, int b) { return [val, a, b]; } int opDollar(int dim)() { return dim; } } ArrayExp array; // opIndex assert(array[8, 8] == [8, 8]); assert(array[$, $] == [0, 1]); assert(array[$, $-1] == [0, 0]); assert(array[2, $-$/2] == [2, 1]); // opIndexUnary assert(-array[8, 8] == [8, 8]); assert(-array[$, $] == [0, 1]); assert(-array[$, $-1] == [0, 0]); assert(-array[2, $-$/2] == [2, 1]); // opIndexAssign assert((array[8, 8] = 2) == [2, 8, 8]); assert((array[$, $] = 2) == [2, 0, 1]); assert((array[$, $-1] = 2) == [2, 0, 0]); assert((array[2, $-$/2] = 2) == [2, 2, 1]); // opIndexOpAssign assert((array[8, 8] += 2) == [2, 8, 8]); assert((array[$, $] += 2) == [2, 0, 1]); assert((array[$, $-1] += 2) == [2, 0, 0]); assert((array[2, $-$/2] += 2) == [2, 2, 1]); // one dimensional slicing static struct SliceExp { int[] opSlice(int a, int b) { return [a, b]; } int[] opSliceUnary(string op)(int a, int b) { return [a, b]; } int[] opSliceAssign(int val, int a, int b) { return [val, a, b]; } int[] opSliceOpAssign(string op)(int val, int a, int b) { return [val, a, b]; } int opDollar() { return 8; } } SliceExp slice; // opSlice assert(slice[0 .. 8] == [0, 8]); assert(slice[0 .. $] == [0, 8]); assert(slice[0 .. $-1] == [0, 7]); assert(slice[$-3 .. $-1] == [5, 7]); // opSliceUnary assert(-slice[0 .. 8] == [0, 8]); assert(-slice[0 .. $] == [0, 8]); assert(-slice[0 .. $-1] == [0, 7]); assert(-slice[$-3 .. $-1] == [5, 7]); // opSliceAssign assert((slice[0 .. 8] = 2) == [2, 0, 8]); assert((slice[0 .. $] = 2) == [2, 0, 8]); assert((slice[0 .. $-1] = 2) == [2, 0, 7]); assert((slice[$-3 .. $-1] = 2) == [2, 5, 7]); // opSliceOpAssign assert((slice[0 .. 8] += 2) == [2, 0, 8]); assert((slice[0 .. $] += 2) == [2, 0, 8]); assert((slice[0 .. $-1] += 2) == [2, 0, 7]); assert((slice[$-3 .. $-1] += 2) == [2, 5, 7]); // test different kinds of opDollar auto dollar(string opDollar)() { static struct Dollar { size_t opIndex(size_t a) { return a; } mixin(opDollar); } Dollar d; return d[$]; } assert(dollar!q{@property size_t opDollar() { return 8; }}() == 8); assert(dollar!q{template opDollar(size_t dim) { enum opDollar = dim; }}() == 0); assert(dollar!q{static const size_t opDollar = 8;}() == 8); assert(dollar!q{enum opDollar = 8;}() == 8); assert(dollar!q{size_t length() { return 8; } alias length opDollar;}() == 8); } /**************************************/ void test19() { static struct Foo { int[] opSlice(int a, int b) { return [a, b]; } int opDollar(int dim)() { return dim; } } Foo foo; assert(foo[0 .. $] == [0, 0]); } /**************************************/ // 9453 struct Foo9453 { static int ctor = 0; this(string bar) { ++ctor; } void opIndex(size_t i) const {} void opSlice(size_t s, size_t e) const {} size_t opDollar(int dim)() const if (dim == 0) { return 1; } } void test9453() { assert(Foo9453.ctor == 0); Foo9453("bar")[$-1]; assert(Foo9453.ctor == 1); Foo9453("bar")[0..$]; assert(Foo9453.ctor == 2); } /**************************************/ // 9496 struct S9496 { static S9496* ptr; size_t opDollar() { assert(ptr is &this); return 10; } void opSlice(size_t , size_t) { assert(ptr is &this); } void getSlice() { assert(ptr is &this); this[1 .. opDollar()]; this[1 .. $]; } } void test9496() { S9496 s; S9496.ptr = &s; s.getSlice(); s[1 .. $]; } /**************************************/ // 9689 struct B9689(T) { T val; @disable this(this); bool opEquals(this X, B)(auto ref B b) { //pragma(msg, "+", X, ", B = ", B, ", ref = ", __traits(isRef, b)); return this.val == b.val; //pragma(msg, "-", X, ", B = ", B, ", ref = ", __traits(isRef, b)); } } struct S9689 { B9689!int num; } void test9689() { B9689!S9689 b; } /**************************************/ // 9694 struct S9694 { bool opEquals(ref S9694 rhs) { assert(0); } } struct T9694 { S9694 s; } void test9694() { T9694 t; assert(thrown!Error(typeid(T9694).equals(&t, &t))); } /**************************************/ // 10064 void test10064() { static struct S { int x = 3; @disable this(); this(int) { x = 7; } int opSlice(size_t, size_t) { return 0; } @property size_t opDollar() { assert(x == 7 || x == 3); // fails assert(x == 7); return 0; } } auto x = S(0)[0 .. $]; } /**************************************/ // 12585 void test12585() { struct Bar { int opIndex(size_t index) { return 0; } } struct Foo { Bar opIndex(size_t index) { throw new Exception("Fail"); } } Foo foo() { return Foo(); } void catchStuff(E)(lazy E expression) { try expression(); catch (Exception e) {} } catchStuff(foo()[0][0]); // OK <- NG catchStuff(foo().opIndex(0)[0]); // OK catchStuff(foo()[0].opIndex(0)); // OK Foo f; catchStuff(f[0][0]); // OK } /**************************************/ // 10394 void test10394() { alias Seq!(int, int) Pair; Pair pair; struct S1 { int opBinary(string op)(Pair) { return 1; } bool opEquals(Pair) { return true; } int opOpAssign(string op)(Pair) { return 1; } } S1 s1; assert((s1 + pair) == 1); assert((s1 == pair) == true); assert((s1 *= pair) == 1); struct S2 { int opBinaryRight(string op)(Pair lhs) { return 1; } int opCmp(Pair) { return -1; } } S2 s2; assert((pair in s2) == 1); assert(s2 < pair); } /**************************************/ // 10597 struct R10597 { void opIndex(int) {} void opSlice(int, int) {} int opDollar(); } R10597 r; struct S10597 { static assert(is(typeof(r[0]))); //ok static assert(is(typeof(r[$]))); //fails static assert(is(typeof(r[0..0]))); //ok static assert(is(typeof(r[$..$]))); //fails void foo() { static assert(is(typeof(r[0]))); //ok static assert(is(typeof(r[$]))); //ok static assert(is(typeof(r[0..0]))); //ok static assert(is(typeof(r[$..$]))); //ok } } static assert(is(typeof(r[0]))); //ok static assert(is(typeof(r[$]))); //fails static assert(is(typeof(r[0..0]))); //ok static assert(is(typeof(r[$..$]))); //fails void test10597() { static assert(is(typeof(r[0]))); //ok static assert(is(typeof(r[$]))); //ok static assert(is(typeof(r[0..0]))); //ok static assert(is(typeof(r[$..$]))); //ok } /**************************************/ // 10567 // doesn't require thunk struct S10567x1n { int value; int opCmp(ref const S10567x1n rhs) const { return 0; } } // requires thunk struct S10567y1n { int value; int opCmp(const S10567y1n rhs) const { return 0; } } struct S10567y1t { int value; int opCmp(S)(const S rhs) const { return 0; } } // doesn't support const comparison struct S10567z1n { int value; int opCmp(const S10567z1n rhs) { return 0; } } struct S10567z1t { int value; int opCmp(S)(const S rhs) { return 0; } } /+ struct S10567x2n { S10567x1n s; this(int n) { s = typeof(s)(n); } alias s this; } struct S10567y2n { S10567y1n s; this(int n) { s = typeof(s)(n); } alias s this; } struct S10567y2t { S10567y1t s; this(int n) { s = typeof(s)(n); } alias s this; } struct S10567z2n { S10567z1n s; this(int n) { s = typeof(s)(n); } alias s this; } struct S10567z2t { S10567z1t s; this(int n) { s = typeof(s)(n); } alias s this; } struct S10567d1 { int value; int opDispatch(string name, S)(const S rhs) const if (name == "opCmp") { assert(0); } } struct S10567d2 { int value; template opDispatch(string name) if (name == "opCmp") { int opDispatch(const S rhs) const { assert(0); } } } // recursive alias this + opCmp searching struct S10567r1 { static S10567r2 t; ref S10567r2 payload() { return t; } alias payload this; int opCmp(const S10567r1 s) const { return 0; } } struct S10567r2 { static S10567r1 s; ref S10567r1 payload() { return s; } alias payload this; } +/ void test10567() { foreach (S; Seq!(S10567x1n/+, S10567x2n+/)) { S sx = S(1); S sy = S(2); assert(!(sx < sy) && !(sx > sy)); assert(sx.opCmp(sy) == 0); assert(typeid(S).compare(&sx, &sy) == 0); static if (is(S == S10567x1n)) assert(cast(void*)typeid(S).xopCmp == cast(void*)&S.opCmp, S.stringof); } foreach (S; Seq!(S10567y1n, S10567y1t/+, S10567y2n, S10567y2t+/)) { S sx = S(1); S sy = S(2); assert(!(sx < sy) && !(sx > sy)); assert(sx.opCmp(sy) == 0); assert(typeid(S).compare(&sx, &sy) == 0); } foreach (S; Seq!(S10567z1n, S10567z1t/+, S10567z2n, S10567z2t+/)) { S sx = S(1); S sy = S(2); assert(!(sx < sy) && !(sx > sy)); assert(sx.opCmp(sy) == 0); try { auto x = typeid(S).compare(&sx, &sy); assert(0); } catch (Error e) { assert(e.msg[$-15 .. $] == "not implemented"); } } /+ foreach (S; Seq!(S10567d1, S10567d2)) { int[S] aa; aa[S(1)] = 10; aa[S(1)] = 1; aa[S(2)] = 20; aa[S(2)] = 2; assert(aa.length == 2); foreach (k, v; aa) assert(k.value == v); S sx = S(1); S sy = S(2); // Don't invoke opDispatch!"opCmp" assert(typeid(S).compare(&sx, &sy) != 0); } +/ } /**************************************/ // 11062 struct S11062ia { struct S1 { void opIndexAssign(int val, int key) {} } struct S2 { S1 headers; } private S2 m_obj; @property S2 get() { return m_obj; } alias get this; } struct S11062sa { struct S1 { void opSliceAssign(int val, int lwr, int upr) {} } struct S2 { S1 headers; } private S2 m_obj; @property S2 get() { return m_obj; } alias get this; } void test11062() { auto sia = S11062ia(); sia.headers[1] = 1; // bug auto ssa = S11062sa(); ssa.headers[1..2] = 1; // bug } /**************************************/ // 11311 void test11311() { static int ctor, cpctor, dtor; static struct S { this(int) { ++ctor; } this(this) { ++cpctor; } ~this() { ++dtor; } } static struct Arr { S data; ref S opIndex(int) { return data; } ref S opSlice(int, int) { return data; } } { Arr a = Arr(S(1)); assert(ctor == 1); assert(cpctor == 0); assert(dtor == 0); auto getA1() { return a; } //getA1().opIndex(1); // OK getA1()[1]; // NG assert(ctor == 1); assert(cpctor == 1); // getA() returns a copy of a assert(dtor == 1); // temporary returned by getA() should be destroyed } assert(dtor == 2); assert(ctor + cpctor == dtor); ctor = cpctor = dtor = 0; { Arr a = Arr(S(1)); assert(ctor == 1); assert(cpctor == 0); assert(dtor == 0); auto getA2() { return a; } //getA2().opSlice(1, 2); // OK getA2()[1..2]; // NG assert(ctor == 1); assert(cpctor == 1); // getA() returns a copy of a assert(dtor == 1); // temporary returned by getA() should be destroyed } assert(dtor == 2); assert(ctor + cpctor == dtor); } /**************************************/ // 12193 void test12193() { struct Foo { bool bar; alias bar this; void opOpAssign(string op)(size_t x) { bar = false; } } Foo foo; foo <<= 1; } /**************************************/ // 14057 struct W14057 { int[] subType; alias subType this; W14057 opSlice(size_t, size_t) { return this; } } void test14057() { auto w = W14057(); W14057 w2 = w[0 .. 1337]; } /**************************************/ struct Tuple20(T...) { T field; alias field this; } void test20a() { // ae1save in in AssignExp::semantic int a, b; struct A1 { void opIndexAssign(int v, Tuple20!(int, int) ) { a = v; } Tuple20!(int, int) opSlice(size_t dim)(int, int) { return typeof(return).init; } } struct A2 { A1 a1; alias a1 this; ref int opIndexAssign(int) { return b; } } stompStack(); A2 foo() { return A2(); } foo()[1..2] = 1; // ref A1 __tmp = foo().a1; __tmp.opIndexAssign(1, __tmp.opSlice!0(1, 2)); assert(a == 1); // should work assert(b == 0); } void test20b() { // ae1save in UnaExp::op_overload() int a, b; struct A1 { void opIndexUnary(string op)(Tuple20!(int, int) ) { a = 1; } Tuple20!(int, int) opSlice(size_t dim)(int, int) { return typeof(return).init; } void dummy() {} // nessary to make A1 nested struct } struct A2 { A1 a1; alias a1 this; int opIndexUnary(string op)(int) { return 0; } } stompStack(); A2 foo() { return A2(); } +foo()[1..2]; // ref A1 __tmp = foo().a1; __tmp.opIndexUnary!"+"(__tmp.opSlice!0(1, 2)); assert(a == 1); // should pass assert(b == 0); } void test20c() { // ae1save in ArrayExp::op_overload() int a, b; struct A1 { void opIndex(Tuple20!(int, int) ) { a = 1; } Tuple20!(int, int) opSlice(size_t dim)(int, int) { return typeof(return).init; } } struct A2 { A1 a1; alias a1 this; int opIndex(int) { return 0; } } stompStack(); A2 foo() { return A2(); } foo()[1..2]; // ref A1 __tmp = foo().a1; __tmp.opIndex(__tmp.opSlice!0(1, 2)); assert(a == 1); // should pass assert(b == 0); } void test20d() { // ae1save in BinAssignExp::op_overload() int a, b; struct A1 { void opIndexOpAssign(string op)(int v, Tuple20!(int, int) ) { a = v; } Tuple20!(int, int) opSlice(size_t dim)(int, int) { return typeof(return).init; } void dummy() {} // nessary to make A1 nested struct } struct A2 { A1 a1; alias a1 this; ref int opIndexOpAssign(alias op)(int) { return b; } } stompStack(); A2 foo() { return A2(); } foo()[1..2] += 1; // ref A1 __tmp = foo().a1; __tmp.opIndexOpAssign!"+"(1, __tmp.opSlice!0(1, 2)); assert(a == 1); // should pass assert(b == 0); } /**************************************/ // 14624 void test14624() { struct A1 { int x; ref int opIndex() { return x; } ref int opSlice() { assert(0); } } { A1 a = A1(1); auto x = a[]; // a.opIndex() assert(x == a.x); auto y = -a[]; // -a.opIndex() <-- not found: a.opIndexUnary!"-" assert(y == -a.x); a[] = 1; // a.opIndex() = 1; <-- not found: a.opIndexAssign(int) assert(a.x == 1); a[] += 1; // a.opIndex() += 1; <-- not found: a.opIndexOpAssign!"+"(int) assert(a.x == 2); } struct A2 { int x; ref int opIndex() { x = 10; return x; } ref int opSlice() { assert(0); } ref int opSliceUnary(alias op)() { x = 11; return x; } ref int opSliceAssign(int) { x = 12; return x; } ref int opSliceOpAssign(alias op)(int) { x = 13; return x; } } { A2 a = A2(1); auto x = a[]; // a.opIndex() assert(a.x == 10); auto y = -a[]; // a.opSliceUnary!"-"() is preferred than: -a.opIndex() assert(a.x == 11); a[] = 1; // a.opSliceAssign(1) is preferred than: a.opIndex() = 1; assert(a.x == 12); a[] += 1; // a.opSliceOpAssign!"+"(1) is preferred than: a.opIndex() += 1; assert(a.x == 13); } } /**************************************/ // 14625 void test14625() { struct R { @property bool empty() { return true; } @property int front() { return 0; } void popFront() {} } struct C1 { R opIndex() { return R(); } R opSlice() { assert(0); } } C1 c1; foreach (e; c1) {} // OK <- asserts in opSlice() foreach (e; c1[]) {} // OK, opIndex() struct C2 { R opIndex() { return R(); } } C2 c2; foreach (e; c2) {} // OK <- rejected foreach (e; c2[]) {} // OK, opIndex() } /**************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test4099(); test12(); test13(); test14(); test15(); test16(); test17(); test3789(); test10037(); test6798(); test12904(); test7641(); test8434(); test18(); test19(); test9453(); test9496(); test9689(); test9694(); test10064(); test12585(); test10394(); test10567(); test11062(); test11311(); test14057(); test20a(); test20b(); test20c(); test20d(); test14624(); test14625(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testbounds_on.d0000644000175000017500000000120413200164642024437 0ustar matthiasmatthias// REQUIRED_ARGS: -boundscheck=on // PERMUTE_ARGS: -inline -g -O import core.exception : RangeError; // Check for RangeError is thrown bool thrown(T)(lazy T cond) { import core.exception; bool f = false; try { cond(); } catch (RangeError e) { f = true; } return f; } @safe int safeIndex (int[] arr) { return arr[2]; } @trusted int trustedIndex(int[] arr) { return arr[2]; } @system int systemIndex (int[] arr) { return arr[2]; } void main() { int[3] data = [1,2,3]; int[] arr = data[0..2]; assert(arr. safeIndex().thrown); assert(arr.trustedIndex().thrown); assert(arr. systemIndex().thrown); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/foreach5.d0000644000175000017500000005357413200164642023266 0ustar matthiasmatthias extern(C) int printf(const char* fmt, ...); /***************************************/ void test1() { char[] a; int foo() { printf("foo\n"); a ~= "foo"; return 10; } foreach (i; 0 .. foo()) { printf("%d\n", i); a ~= cast(char)('0' + i); } assert(a == "foo0123456789"); foreach_reverse (i; 0 .. foo()) { printf("%d\n", i); a ~= cast(char)('0' + i); } assert(a == "foo0123456789foo9876543210"); } /***************************************/ // 2411 struct S2411 { int n; string s; } void test2411() { S2411 s; assert(s.n == 0); assert(s.s == ""); foreach (i, ref e; s.tupleof) { static if (i == 0) e = 10; static if (i == 1) e = "str"; } assert(s.n == 10); assert(s.s == "str"); } /***************************************/ // 2442 template canForeach(T, E) { enum canForeach = __traits(compiles, { foreach(a; new T) { static assert(is(typeof(a) == E)); } }); } void test2442() { struct S1 { int opApply(int delegate(ref const(int) v) dg) const { return 0; } int opApply(int delegate(ref int v) dg) { return 0; } } S1 ms1; const S1 cs1; foreach (x; ms1) { static assert(is(typeof(x) == int)); } foreach (x; cs1) { static assert(is(typeof(x) == const int)); } struct S2 { int opApply(int delegate(ref int v) dg) { return 0; } int opApply(int delegate(ref long v) dg) { return 0; } } S2 ms2; static assert(!__traits(compiles, { foreach ( x; ms2) {} })); // ambiguous static assert( __traits(compiles, { foreach (int x; ms2) {} })); struct S3 { int opApply(int delegate(ref int v) dg) const { return 0; } int opApply(int delegate(ref int v) dg) shared const { return 0; } } immutable S3 ms3; static assert(!__traits(compiles, { foreach (int x; ms3) {} })); // ambiguous // from https://github.com/D-Programming-Language/dmd/pull/120 static class C { int opApply(int delegate(ref int v) dg) { return 0; } int opApply(int delegate(ref const int v) dg) const { return 0; } int opApply(int delegate(ref immutable int v) dg) immutable { return 0; } int opApply(int delegate(ref shared int v) dg) shared { return 0; } int opApply(int delegate(ref shared const int v) dg) shared const { return 0; } } static class D { int opApply(int delegate(ref int v) dg) const { return 0; } } static class E { int opApply(int delegate(ref int v) dg) shared const { return 0; } } static assert( canForeach!( C , int )); static assert( canForeach!( const(C) , const(int) )); static assert( canForeach!( immutable(C) , immutable(int) )); static assert( canForeach!( shared(C) , shared(int) )); static assert( canForeach!(shared(const(C)), shared(const(int)))); static assert( canForeach!( D , int)); static assert( canForeach!( const(D) , int)); static assert( canForeach!( immutable(D) , int)); static assert(!canForeach!( shared(D) , int)); static assert(!canForeach!(shared(const(D)), int)); static assert(!canForeach!( E , int)); static assert(!canForeach!( const(E) , int)); static assert( canForeach!( immutable(E) , int)); static assert( canForeach!( shared(E) , int)); static assert( canForeach!(shared(const(E)), int)); } /***************************************/ // 2443 struct S2443 { int[] arr; int opApply(int delegate(size_t i, ref int v) dg) { int result = 0; foreach (i, ref x; arr) { if ((result = dg(i, x)) != 0) break; } return result; } } void test2443() { S2443 s; foreach (i, ref v; s) {} foreach (i, v; s) {} static assert(!__traits(compiles, { foreach (ref i, ref v; s) {} })); static assert(!__traits(compiles, { foreach (ref i, v; s) {} })); } /***************************************/ // 3187 class Collection { int opApply(int delegate(ref Object) a) { return 0; } } Object testForeach(Collection level1, Collection level2) { foreach (first; level1) { foreach (second; level2) return second; } return null; } void test3187() { testForeach(new Collection, new Collection); } /***************************************/ // 4090 void test4090a() { double[10] arr = 1; double tot = 0; static assert(!__traits(compiles, { foreach (immutable ref x; arr) {} })); foreach (const ref x; arr) { static assert(is(typeof(x) == const double)); tot += x; } foreach (immutable x; arr) { static assert(is(typeof(x) == immutable double)); tot += x; } assert(tot == 1*10 + 1*10); } void test4090b() { int tot = 0; static assert(!__traits(compiles, { foreach (immutable ref x; 1..11) {} })); foreach (const ref x; 1..11) { static assert(is(typeof(x) == const int)); tot += x; } foreach (immutable x; 1..11) { static assert(is(typeof(x) == immutable int)); tot += x; } assert(tot == 55 + 55); } /***************************************/ // 5605 struct MyRange { int theOnlyOne; @property bool empty() const { return true; } @property ref int front() { return theOnlyOne; } void popFront() {} } struct MyCollection { MyRange opSlice() const { return MyRange(); } } void test5605() { auto coll = MyCollection(); foreach (i; coll) { // <-- compilation error // ... } } /***************************************/ // 7004 void func7004(A...)(A args) { foreach (i, e; args){} // OK foreach (uint i, e; args){} // OK foreach (size_t i, e; args){} // NG } void test7004() { func7004(1, 3.14); } /***************************************/ // 7406 template TypeTuple7406(T...) { alias T TypeTuple7406; } template foobar7406(T) { enum foobar = 2; } void test7406() { foreach (sym; TypeTuple7406!(int, double)) // OK pragma(msg, sym.stringof); foreach (sym; TypeTuple7406!(foobar7406)) // OK pragma(msg, sym.stringof); foreach (sym; TypeTuple7406!(test7406)) // OK pragma(msg, sym.stringof); foreach (sym; TypeTuple7406!(int, foobar7406)) // Error: type int has no value pragma(msg, sym.stringof); foreach (sym; TypeTuple7406!(int, test7406)) // Error: type int has no value pragma(msg, sym.stringof); } /***************************************/ // 6659 void test6659() { static struct Iter { ~this() { ++_dtor; } bool opCmp(ref const Iter rhs) { return _pos == rhs._pos; } void opUnary(string op:"++")() { ++_pos; } size_t _pos; static size_t _dtor; } foreach (ref iter; Iter(0) .. Iter(10)) { assert(Iter._dtor == 0); } assert(Iter._dtor == 2); Iter._dtor = 0; // reset for (auto iter = Iter(0), limit = Iter(10); iter != limit; ++iter) { assert(Iter._dtor == 0); } assert(Iter._dtor == 2); } void test6659a() { auto value = 0; try { for ({scope(success) { assert(value == 1); value = 2;} } true; ) { value = 1; break; } assert(value == 2); } catch (Exception e) { assert(0); } assert(value == 2); } void test6659b() { auto value = 0; try { for ({scope(failure) value = 1;} true; ) { throw new Exception(""); } assert(0); } catch (Exception e) { assert(e); } assert(value == 1); } void test6659c() { auto value = 0; try { for ({scope(exit) value = 1;} true; ) { throw new Exception(""); } assert(0); } catch (Exception e) { assert(e); } assert(value == 1); } /***************************************/ // 10221 void test10221() { // All of these should work, but most are too slow. Just check they compile. foreach(char i; char.min..char.max+1) {} if (0) foreach(wchar i; wchar.min..wchar.max+1) {} if (0) foreach(dchar i; dchar.min..dchar.max+1) {} foreach(byte i; byte.min..byte.max+1) {} foreach(ubyte i; ubyte.min..ubyte.max+1) {} if (0) foreach(short i; short.min..short.max+1) {} if (0) foreach(ushort i; ushort.min..ushort.max+1) {} if (0) foreach(int i; int.min..int.max+1U) {} if (0) foreach(uint i; uint.min..uint.max+1L) {} if (0) foreach(long i; long.min..long.max+1UL) {} foreach_reverse(char i; char.min..char.max+1) { assert(i == typeof(i).max); break; } foreach_reverse(wchar i; wchar.min..wchar.max+1) { assert(i == typeof(i).max); break; } foreach_reverse(dchar i; dchar.min..dchar.max+1) { assert(i == typeof(i).max); break; } foreach_reverse(byte i; byte.min..byte.max+1) { assert(i == typeof(i).max); break; } foreach_reverse(ubyte i; ubyte.min..ubyte.max+1) { assert(i == typeof(i).max); break; } foreach_reverse(short i; short.min..short.max+1) { assert(i == typeof(i).max); break; } foreach_reverse(ushort i; ushort.min..ushort.max+1) { assert(i == typeof(i).max); break; } foreach_reverse(int i; int.min..int.max+1U) { assert(i == typeof(i).max); break; } foreach_reverse(uint i; uint.min..uint.max+1L) { assert(i == typeof(i).max); break; } foreach_reverse(long i; long.min..long.max+1UL) { assert(i == typeof(i).max); break; } } /***************************************/ // 7814 struct File7814 { ~this(){} } struct ByLine7814 { File7814 file; // foreach interface @property bool empty() const { return true; } @property char[] front() { return null; } void popFront(){} } void test7814() { int dummy; ByLine7814 f; foreach (l; f) { scope(failure) // 'failure' or 'success' fails, but 'exit' works dummy = -1; dummy = 0; } } /***************************************/ // 10049 struct ByLine10049 { bool empty() { return true; } string front() { return null; } void popFront() {} ~this() {} // necessary } void test10049() { ByLine10049 r; foreach (line; r) { doNext: {} } } /******************************************/ struct T11955(T...) { T field; alias field this; } alias X11955 = uint; struct S11955 { enum empty = false; T11955!(uint, uint) front; void popFront() {} } void test11955() { foreach(X11955 i, v; S11955()) {} } /******************************************/ // 6652 void test6652() { size_t sum; foreach (i; 0 .. 10) sum += i++; // 0123456789 assert(sum == 45); sum = 0; foreach (ref i; 0 .. 10) sum += i++; // 02468 assert(sum == 20); sum = 0; foreach_reverse (i; 0 .. 10) sum += i--; // 9876543210 assert(sum == 45); sum = 0; foreach_reverse (ref i; 0 .. 10) sum += i--; // 97531 assert(sum == 25); enum ary = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; sum = 0; foreach (i, v; ary) { assert(i == v); sum += i++; // 0123456789 } assert(sum == 45); sum = 0; foreach (ref i, v; ary) { assert(i == v); sum += i++; // 02468 } assert(sum == 20); sum = 0; foreach_reverse (i, v; ary) { assert(i == v); sum += i--; // 9876543210 } assert(sum == 45); sum = 0; foreach_reverse (ref i, v; ary) { assert(i == v); sum += i--; // 97531 } assert(sum == 25); static struct Iter { ~this() { ++_dtorCount; } bool opCmp(ref const Iter rhs) { return _pos == rhs._pos; } void opUnary(string op)() if(op == "++" || op == "--") { mixin(op ~ q{_pos;}); } size_t _pos; static size_t _dtorCount; } Iter._dtorCount = sum = 0; foreach (v; Iter(0) .. Iter(10)) sum += v._pos++; // 0123456789 assert(sum == 45 && Iter._dtorCount == 12); Iter._dtorCount = sum = 0; foreach (ref v; Iter(0) .. Iter(10)) sum += v._pos++; // 02468 assert(sum == 20 && Iter._dtorCount == 2); // additional dtor calls due to unnecessary postdecrements Iter._dtorCount = sum = 0; foreach_reverse (v; Iter(0) .. Iter(10)) sum += v._pos--; // 9876543210 assert(sum == 45 && Iter._dtorCount >= 12); Iter._dtorCount = sum = 0; foreach_reverse (ref v; Iter(0) .. Iter(10)) sum += v._pos--; // 97531 assert(sum == 25 && Iter._dtorCount >= 2); } /***************************************/ // 8595 struct OpApply8595 { int opApply(int delegate(ref int) dg) { assert(0); } } string test8595() { foreach (elem; OpApply8595.init) { static assert(is(typeof(return) == string)); } assert(0); } /***************************************/ // 9068 struct Foo9068 { static int[] destroyed; int x; ~this() { destroyed ~= x; } } struct SimpleCounter9068 { static int destroyedCount; enum int limit = 5; int counter; ~this() { destroyedCount++; } // Range primitives. @property bool empty() const { return counter >= limit; } @property int front() { return counter; } void popFront() { counter++; } } void test9068() { //---------------------------------------- // There was never a bug in this case (no range). int sum; loop_simple: foreach (i; [10, 20]) { sum += i; break loop_simple; } assert(sum == 10); //---------------------------------------- // There was a bug with loops over ranges. int last = -1; X: foreach (i; SimpleCounter9068()) { switch(i) { case 3: break X; default: last = i; } } assert(last == 2); assert(SimpleCounter9068.destroyedCount == 1); //---------------------------------------- // Simpler case: the compiler error had nothing to do with the switch. last = -1; loop_with_range: foreach (i; SimpleCounter9068()) { last = i; break loop_with_range; } assert(last == 0); assert(SimpleCounter9068.destroyedCount == 2); //---------------------------------------- // Test with destructors: the loop is implicitly wrapped into two // try/finally clauses. loop_with_dtors: for (auto x = Foo9068(4), y = Foo9068(5); x.x != 10; ++x.x) { if (x.x == 8) break loop_with_dtors; } assert(Foo9068.destroyed == [5, 8]); Foo9068.destroyed = null; //---------------------------------------- // Same with an unlabelled break. for (auto x = Foo9068(4), y = Foo9068(5); x.x != 10; ++x.x) { if (x.x == 7) break; } assert(Foo9068.destroyed == [5, 7]); Foo9068.destroyed = null; } /***************************************/ // 11885 struct Foo11885 { static int[] destroyed; int x; ~this() { destroyed ~= x; } } struct SimpleCounter11885 { static int destroyedCount; enum int limit = 5; int counter; ~this() { destroyedCount++; } // Range primitives. @property bool empty() const { return counter >= limit; } @property int front() { return counter; } void popFront() { counter++; } } void test11885() { //---------------------------------------- // There was never a bug in this case (no range). int sum; loop_simple: foreach (i; [10, 20]) { sum += i; continue loop_simple; } assert(sum == 30); //---------------------------------------- // There was a bug with loops over ranges. int last = -1; X: foreach (i; SimpleCounter11885()) { switch(i) { case 3: continue X; default: last = i; } } assert(last == 4); assert(SimpleCounter11885.destroyedCount == 1); //---------------------------------------- // Simpler case: the compiler error had nothing to do with the switch. last = -1; loop_with_range: foreach (i; SimpleCounter11885()) { last = i; continue loop_with_range; } assert(last == 4); assert(SimpleCounter11885.destroyedCount == 2); //---------------------------------------- // Test with destructors: the loop is implicitly wrapped into two // try/finally clauses. loop_with_dtors: for (auto x = Foo11885(4), y = Foo11885(5); x.x != 10; ++x.x) { if (x.x == 8) continue loop_with_dtors; } assert(Foo11885.destroyed == [5, 10]); Foo11885.destroyed = null; //---------------------------------------- // Same with an unlabelled continue. for (auto x = Foo11885(4), y = Foo11885(5); x.x != 10; ++x.x) { if (x.x == 7) continue; } assert(Foo11885.destroyed == [5, 10]); Foo11885.destroyed = null; } /***************************************/ // 10475 void test10475a() { struct DirIterator { int _store = 42; ~this() { assert(0); } } DirIterator dirEntries() { throw new Exception(""); } try { for (DirIterator c = dirEntries(); true; ) {} assert(0); } catch (Exception e) { assert(e.next is null); } } void test10475b() { uint g; struct S { uint flag; ~this() { g |= flag; } } S thrown() { throw new Exception(""); } g = 0x0; try { for (auto x = S(0x1), y = S(0x2), z = thrown(); true; ) {} assert(0); } catch (Exception e) { assert(e.next is null); } assert(g == 0x3); g = 0x0; try { for (auto x = S(0x1), y = thrown(), z = S(0x2); true; ) {} assert(0); } catch (Exception e) { assert(e.next is null); } assert(g == 0x1); g = 0x0; try { for (auto x = thrown(), y = S(0x1), z = S(0x2); true; ) {} assert(0); } catch (Exception e) { assert(e.next is null); } assert(g == 0x0); } /***************************************/ // 11291 void test11291() { struct Tuple(T...) { T field; alias field this; } struct zip { string[] s1, s2; bool empty() { return true; } auto front() { return Tuple!(string, string)(s1[0], s2[0]); } void popFront() {} } foreach (const a, const b; zip(["foo"], ["bar"])) { static assert(is(typeof(a) == const string)); static assert(is(typeof(b) == const string)); static assert(!__traits(compiles, a = "something")); static assert(!__traits(compiles, b = "something")); } } /***************************************/ // 12103 alias TypeTuple12103(TL...) = TL; alias Id12103(alias a) = a; void test12103() { alias fs1 = TypeTuple12103!(() => 0, () => 1); foreach (i, f; fs1) { static assert(f() == i); static assert(Id12103!f() == i); assert(f() == i); assert(Id12103!f() == i); } alias fs2 = TypeTuple12103!(x=>x+0, y=>y+1); foreach (i, f; fs2) { static assert(f(0) == i); static assert(Id12103!f(0) == i); assert(f(0) == i); assert(Id12103!f(0) == i); } } /***************************************/ // 12739 struct S12739 { nothrow: int opApply(int delegate(ref int) nothrow dg) { return 0; } } void test12739() nothrow { S12739 s; foreach (e; s) {} } /***************************************/ // 12932 void test12932() @nogc { int sum; foreach (e; [1,2,3]) { sum += e; } assert(sum == 6); } /***************************************/ // 13756 void test13756() { int[int] org = [1:2], aa; aa = org.dup; foreach (v; aa) { static assert(is(typeof(v) == int)); v = 20; } assert(aa == [1:2]); aa = org.dup; foreach (ref v; aa) { static assert(is(typeof(v) == int)); v = 20; } assert(aa == [1:20]); aa = org.dup; foreach (k, v; aa) { static assert(is(typeof(k) == int)); static assert(is(typeof(v) == int)); k = 10; v = 20; } assert(aa == [1:2]); aa = org.dup; foreach (k, ref v; aa) { static assert(is(typeof(k) == int)); static assert(is(typeof(v) == int)); k = 10; v = 20; } assert(aa == [1:20]); aa = org.dup; foreach (ref k, v; aa) // NG -> OK { static assert(is(typeof(k) == const int)); static assert(is(typeof(v) == int)); static assert(!__traits(compiles, k = 10)); v = 20; } assert(aa == [1:2]); aa = org.dup; foreach (ref k, ref v; aa) // NG -> OK { static assert(is(typeof(k) == const int)); static assert(is(typeof(v) == int)); static assert(!__traits(compiles, k = 10)); v = 20; } assert(aa == [1:20]); foreach (ref const k, v; aa) // NG -> OK, same with 'ref k' { static assert(is(typeof(k) == const int)); } } /***************************************/ int main() { test1(); test2411(); test2442(); test2443(); test3187(); test4090a(); test4090b(); test5605(); test7004(); test10221(); test7406(); test6659(); test6659a(); test6659b(); test6659c(); test7814(); test6652(); test9068(); test11885(); test10475a(); test10475b(); test11291(); test12103(); test12739(); test12932(); test13756(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test5.d0000644000175000017500000000205713200164642022624 0ustar matthiasmatthias// PERMUTE_ARGS: extern(C) int printf(const char*, ...); interface foo { extern (C) int testc(int i); extern (Windows) int testw(int i); extern (D) int testd(int i); } class bar : foo { int x = 47; extern (C) int testc(int i) { printf("foo.testc(%p)\n", this); assert(x == 47); return i + x; } extern (Windows) int testw(int i) { printf("foo.testw(%p)\n", this); assert(x == 47); return i + x; } extern (D) int testd(int i) { printf("foo.testd(%p)\n", this); assert(x == 47); return i + x; } } int def(foo f) { printf("def(%p), %p\n", f, (cast(int*)f)[0]); assert(f.testc(3) == 50); assert(f.testd(7) == 54); assert(f.testd(10) == 57); return 0; } void abc(bar b) { printf("abc(%p), %p\n", b, (cast(int*)b)[3]); def(b); } int main() { bar b = new bar(); printf("b.size = x%x\n", b.classinfo.init.length); printf("bar.size = x%x\n", bar.classinfo.init.length); assert(b.classinfo.init.length == bar.classinfo.init.length); abc(b); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/teststdio.d0000644000175000017500000000126213200164642023577 0ustar matthiasmatthias// PERMUTE_ARGS: import std.stdio; import core.stdc.stdio; void main() { auto f = std.stdio.File("runnable/extra-files/teststdio.txt", "r"); FILE* fp = f.getFP(); string buf; int i; do { buf = f.readln('\n'); foreach (c; buf) printf("%x\n", c); printf("\n"); switch (i) { case 0: assert(buf == "asdfasdf\n"); break; case 1: assert(buf == "a\n"); break; case 2: assert(buf == "sdf\n"); break; case 3: assert(buf == "asdf\n"); break; case 4: assert(buf == "\n"); break; case 5: assert(buf == "\n"); break; case 6: assert(buf == null); break; default: assert(0); } i++; } while (!feof(fp)); //fclose(fp); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_812.d0000644000175000017500000000017613200164642024256 0ustar matthiasmatthiasimport std.stdio; interface A {} class B : A { ubyte[0] test; } void main() { A a = new B(); B b = cast(B) a; }ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/property.d0000644000175000017500000000116413200164642023442 0ustar matthiasmatthias /******************************************/ struct Foo { int v; int bar(int value) { return v = value + 2; } int bar() { return 73; } } int test1() { Foo f; int i; i = (f.bar = 6); assert(i == 8); assert(f.v == 8); i = f.bar; assert(i == 73); return 0; } /******************************************/ // 6259 struct S6259 { private int m_prop; ref const(int) prop() { return m_prop; } void prop(int v) { m_prop = v; } } void test6259() { S6259 s; s.prop = 1; } /******************************************/ void main() { test1(); test6259(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test13666.sh0000755000175000017500000000077613200164642023345 0ustar matthiasmatthias#!/usr/bin/env bash src=runnable${SEP}extra-files dir=${RESULTS_DIR}${SEP}runnable output_file=${dir}/test13666.sh.out if [ $OS == "win32" -o $OS == "win64" ]; then LIBEXT=.lib else LIBEXT=.a fi libname=${dir}${SEP}lib13666${LIBEXT} $DMD -m${MODEL} -I${src} -of${libname} -lib ${src}${SEP}lib13666.d || exit 1 $DMD -m${MODEL} -I${src} -of${dir}${SEP}test13666${EXE} ${src}${SEP}test13666.d ${libname} || exit 1 rm ${dir}/{lib13666${LIBEXT},test13666${OBJ},test13666${EXE}} echo Success >${output_file} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testprofile.d0000644000175000017500000000172213200164642024116 0ustar matthiasmatthias// REQUIRED_ARGS: -profile module testprofile; // ------------------ struct FourUShort { this(ushort a, ushort b, ushort c, ushort d) { this.a = a; this.b = b; this.c = c; this.d = d; } ushort a, b, c, d; } void test1() { auto f = FourUShort(0, 1, 2, 3); assert(f.a == 0); assert(f.b == 1); assert(f.c == 2); assert(f.d == 3); } // ------------------ void foo5689(double a, double b) { assert(a == 17.0); assert(b == 12.0); } __gshared fun5689 = &foo5689; void test5689() { fun5689(17.0, 12.0); } // ------------------ class Foo10617 { void foo() nothrow pure @safe in { } out { } body { } } // ------------------ class C10953 { void func() nothrow pure @safe in {} out {} body {} } class D10953 : C10953 { override void func() // inherits attributes of Foo.func in {} out {} body {} } // ------------------ void main() { test1(); test5689(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ice10086b.d0000644000175000017500000000023213200164642023052 0ustar matthiasmatthias// EXTRA_SOURCES: imports/ice10086y.d // EXTRA_SOURCES: imports/ice10086x.d import imports.ice10086y; import imports.ice10086x; void main() { test(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test23.d0000644000175000017500000005637713200164642022722 0ustar matthiasmatthias// REQUIRED_ARGS: module test; import core.vararg; import core.stdc.stdlib; import std.stdio; import std.string; import core.stdc.stdlib; version(D_InlineAsm_X86_64) version = DMD_InlineAsm; version(D_InlineAsm_X86) version = DMD_InlineAsm; /*******************************************/ struct S { int opSliceAssign(int v, size_t i, size_t j) { assert(v == 5); assert(i == 9); assert(j == 10); return 3; } int opSliceAssign(int v) { assert(v == 6); return 11; } } void test1() { S s; assert((s[9 .. 10] = 5) == 3); assert((s[] = 6) == 11); } /*******************************************/ static int i2 = 1; void test2() { synchronized { int i2 = 2; } assert(i2 == 1); } /*******************************************/ void test3() { size_t border = 8; for(ulong i = 0; i < border; i++) { ulong test = 1; test <<= i; double r = test; ulong result = cast(ulong)r; if (result != test) { assert(0); } } } /*******************************************/ void test4() { writeln("",true); } /*******************************************/ void test5() { int[] qwert = new int[6]; int[] yuiop; yuiop = qwert[2..5] = 3; assert(yuiop.length == 3); assert(yuiop[0] == 3); assert(yuiop[1] == 3); assert(yuiop[2] == 3); } /*******************************************/ struct Foo6 { static int x; static int[] farray() { printf("farray\n"); assert(x == 0); x++; return new int[6]; } static int flwr() { printf("flwr\n"); assert(x == 1); x++; return 2; } static int fupr() { printf("fupr\n"); assert(x == 2); x++; return 1; } } void test6() { int[] yuiop; yuiop = Foo6.farray()[Foo6.flwr() .. $ - Foo6.fupr()] = 3; assert(Foo6.x == 3); assert(yuiop.length == 3); assert(yuiop[0] == 3); assert(yuiop[1] == 3); assert(yuiop[2] == 3); } /*******************************************/ void test7() { real a = 3.40483; // this is treated as 3.40483L real b; b = 3.40483; assert(a==b); assert(a==3.40483); assert(a==3.40483L); assert(a==3.40483F); } /*******************************************/ void test8() { real [5][5] m = 1; m[1][1..3] = 2; for (size_t i = 0; i < 5; i++) for (size_t j = 0; j < 5; j++) { if (i == 1 && (j >= 1 && j < 3)) assert(m[i][j] == 2); else assert(m[i][j] == 1); } } /*******************************************/ class ClassOf(Type) { Type val; template refx() { alias val refx; } } struct StructOf { int val; template refx() { alias val refx; } } void test9() { ClassOf!(int) c = new ClassOf!(int)(); StructOf s; int x = 10; c.refx!() = x; x = c.refx!(); assert(x == 10); x = 11; s.refx!() = x; x = s.refx!(); assert(x == 11); } /*******************************************/ void test10() { static if( int.mangleof.length > 1 && int.mangleof[1] == 'x' ) printf("'x' as second char\n"); } /*******************************************/ class Foo11 : Bar11 { } class Foo11T(V) { public void foo() {} } class Bar11 { public this(){ f = new Foo11T!(int); } Foo11T!(int) f; } void test11() { Foo11 fooIt = new Foo11(); if (fooIt !is null) writefln("fooIt should be valid"); fooIt.f.foo(); writefln("it worked"); } /*******************************************/ struct A12 { int a; union { int c; B12 b; } } struct B12 { int b1; int b2; } void test12() { A12 a; printf("%d\n", A12.sizeof); assert(A12.sizeof == 12); } /*******************************************/ template declare13(X) { X declare13; } typeof(declare13!(int[0]).ptr[0]) x13; typeof(declare13!(typeof(""))[0..$]) y13; void test13() { } /*******************************************/ interface Father {} class Mother { Father test() { writefln("Called Mother.test!"); return new Child(42); } } class Child : Mother, Father { int data; this(int d) { data = d; } override Child test() { writefln("Called Child.test!"); return new Child(69); } } void test14() { Child aChild = new Child(105); Mother childsMum = aChild; Child childsChild = aChild.test(); Child mumsChild = cast(Child) childsMum.test(); writefln("Success2"); } /*******************************************/ class A15 { int a = 3; class B { void bar() { assert(a == 3); } } void fork() { assert(a == 3); B b = new B(); // This is okay b.bar(); void knife() { assert(a == 3); B b = new B(); // No 'this' for nested class B b.bar(); } } } void test15() { A15 a = new A15(); a.fork(); } /*******************************************/ creal x16; void foo16() { x16 = -x16; } void bar16() { return foo16(); } void test16() { x16 = 2.0L + 0.0Li; bar16(); assert(x16 == -2.0L + 0.0Li); } /*******************************************/ void test17() { version (OSX) { } else version (DMD_InlineAsm) { const f = 1.2f; float g = void; asm{ fld f; // doesn't work with PIC fstp g; } assert(g == 1.2f); } } /*******************************************/ class Foo18 : Bar18 {} class FooT18(V){} class Bar18 : FooT18!(int) {} void test18() { } /*******************************************/ struct STRUCTA19 { union { int a; long b; } STRUCTB19 c; } struct STRUCTB19 { int a; } void test19() { } /*******************************************/ class Foo20 { void bar (void * src) { void baz (void function (void *, size_t) xyz) { size_t foo (void [] dst) { size_t len = dst.length; dst [0 .. len] = src [0 .. len]; xyz (dst.ptr, len); return len; } } } } void test20() { } /*******************************************/ class Baz21 { int opApply (int delegate(ref int) dg) { int i; return dg(i); } } class Foo21 { Baz21 baz; int foo (int delegate() dg) { foreach (b; baz) if (bar ()) if (dg ()) break; return 0; } bool bar () { return true; } } void test21() { } /*******************************************/ struct Bar22 { union { struct { union { Foo22 A; } } } } struct Foo22 { double d = 3; } void test22() { printf("Bar22.sizeof = %zd, double.sizeof = %zd\n", Bar22.sizeof, double.sizeof); assert(Bar22.sizeof == double.sizeof); Bar22 b; assert(b.A.d == 3); } /*******************************************/ struct Ag { static void func(){} static void foo() { void function() fnp; Ag a; fnp = &func; fnp = &Ag.func; with(a) fnp = &Ag.func; with(a) fnp = &func; } } class Ah { static void func(){} static void foo() { void function() fnp; Ah a; fnp = &func; fnp = &Ah.func; with(a) fnp = &Ah.func; with(a) fnp = &func; } } void test23() { } /*******************************************/ void test24() { uint[10] arr1; ulong idx = 3; uint[] arr3 = arr1[ cast(int)(idx) .. (cast(int) idx) + 3 ]; // OK uint[] arr4 = arr1[ cast(int) idx .. cast(int) idx + 3 ]; // OK uint[] arr5 = arr1[ cast(int)(idx) .. cast(int)(idx) + 3 ]; // C style cast illegal, use cast(idx)+3 uint[] arr6 = arr1[ cast(int)(idx) .. cast(int)(idx + 3) ]; // OK } /*******************************************/ void test25() { char[6] cstr = "123456"c; auto str1 = cast(wchar[3])(cstr); writefln("str1: ", (cast(char[])str1).length , " : ", (cast(char[])str1)); assert(cast(char[])str1 == "123456"c); auto str2 = cast(wchar[3])("789abc"c); writefln("str2: ", (cast(char[])str2).length , " : ", (cast(char[])str2)); assert(cast(char[])str2 == "789abc"c); auto str3 = cast(wchar[3])("defghi"); writefln("str3: ", (cast(char[])str3).length , " : ", (cast(char[])str3)); assert(cast(char[])str3 == "d\000e\000f\000"c); } /*******************************************/ void test26() { assert(foo26(5) == 25); } int foo26(int i) { if (auto j = i * i) return j; else return 10; } /*******************************************/ class A27 { int am; class B { this() { assert(am == 3); } } void fork() { B b = new B(); // This is okay void knife() { B b = new B(); // No 'this' for nested class B assert(am == 3); } } } void test27() { A27 a = new A27(); a.am = 3; a.fork(); } /*******************************************/ uint intRes() { return 4; } void test28() { auto s = std.string.format("%s", "abc123"[intRes() % $] ); writefln( "%s", s ); assert(s == "2"); static const char[] foo = "abc123"; s = std.string.format("%s", foo[intRes() % $] ); assert(s == "2"); static string bar = "abc123"; s = std.string.format("%s", bar[intRes() % $] ); assert(s == "2"); const char[] abc = "abc123"; s = std.string.format("%s", abc[intRes() % $] ); assert(s == "2"); string def = "abc123"; s = std.string.format("%s", def[intRes() % $] ); assert(s == "2"); } /*******************************************/ class UA { A29 f() { return null; } } class UB : UA { override B29 f() { return null; } } class A29 { } class B29 : A29 { } void test29() { } /*******************************************/ class Foo30 : Bar30 {} class FooT30(V) {} class Bar30 : FooT30!(int) {} void test30() { } /*******************************************/ int y31; struct X31 { static void opCall() { y31 = 3; } } void test31() { X31 x; typeof(x)(); assert(y31 == 3); } /*******************************************/ class Foo32 { static void* ps; new (size_t sz) { void* p = core.stdc.stdlib.malloc(sz); printf("new(sz = %d) = %p\n", sz, p); ps = p; return p; } delete(void* p) { printf("delete(p = %p)\n", p); assert(p == ps); if (p) core.stdc.stdlib.free(p); } } void test32() { Foo32 f = new Foo32; delete f; } /*******************************************/ class Foo33 { // this() { printf("this()\n"); } // ~this() { printf("~this()\n"); } static void* ps; static int del; new (size_t sz, int i) { void* p = core.stdc.stdlib.malloc(sz); printf("new(sz = %d) = %p\n", sz, p); ps = p; return p; } delete(void* p) { printf("delete(p = %p)\n", p); assert(p == ps); if (p) core.stdc.stdlib.free(p); del += 1; } } void foo33() { scope Foo33 f = new(3) Foo33; } void test33() { foo33(); assert(Foo33.del == 1); } /*******************************************/ struct o_O { int a; } union O_O { int a; } class O_o { int a; } struct Foo34 { int ok; o_O foo; O_O bar; O_o baz; } void test34() { int o1 = Foo34.ok.offsetof; assert(o1 == 0); int o2 = Foo34.foo.offsetof; assert(o2 == 4); int o3 = Foo34.bar.offsetof; assert(o3 == 8); int o4 = Foo34.baz.offsetof; assert((o4 % (void*).sizeof) == 0); assert(o4 > o3); } /*******************************************/ class Foo37 { float[4] array = 1.0; int count = 10; } void test37() { Foo37 f = new Foo37(); writefln("Foo.array[0] = %s", f.array[0] ); writefln("Foo.array[1] = %s", f.array[1] ); writefln("Foo.array[2] = %s", f.array[2] ); writefln("Foo.array[3] = %s", f.array[3] ); writefln("Foo.count = %s", f.count ); assert(f.array[0] == 1.0); assert(f.array[1] == 1.0); assert(f.array[2] == 1.0); assert(f.array[3] == 1.0); assert(f.count == 10); } /*******************************************/ void test38() in { static void checkParameters() { return; } checkParameters(); } body { } /*******************************************/ void delegate() foo39() { return &(new class { int a; this() { a = 3; } void dg() { writefln("delegate!"); assert(a == 3); } }).dg; } void test39() { void delegate() dg = foo39(); dg(); } /*******************************************/ void test40() { assert( typeid(int) == typeid(int) ); assert( (typeid(int) != typeid(int)) == false ); int x; bool b1 = (typeid(typeof(x)) != typeid(int)); TypeInfo t1 = typeid(typeof(x)); TypeInfo t2 = typeid(int); bool b2 = (t1 != t2); assert(b1 == b2); } /*******************************************/ int foo41(string s) { short shift = cast(short)(s.length * 3); int answer; for (size_t i = 0; i < s.length; i++){ answer = s[i] << shift; } return answer; } void test41() { if(foo41("\u0001") != 8){ assert(0); } } /*******************************************/ struct S42 { int i; static S42 foo(int x){ S42 s; s.i = x; return s; } } void test42() { S42[] s; s = s ~ S42.foo(6); s = s ~ S42.foo(1); if(s.length != 2){ assert(0); } if(s[0].i != 6){ assert(0); } if(s[1].i != 1){ assert(0); } } /*******************************************/ struct S43 { int i,j; static S43 foo(int x){ S43 s; s.i = x; return s; } } void test43() { S43[] s; s = s ~ S43.foo(6); s = s ~ S43.foo(1); if(s.length != 2){ assert(0); } if(s[0].i != 6){ assert(0); } if(s[1].i != 1){ assert(0); } } /*******************************************/ struct S44 { int i,j,k; static S44 foo(int x){ S44 s; s.i = x; return s; } } void test44() { S44[] s; s = s ~ S44.foo(6); s = s ~ S44.foo(1); if(s.length != 2){ assert(0); } if(s[0].i != 6){ assert(0); } if(s[1].i != 1){ assert(0); } } /*******************************************/ void test45() { char[] buffer = "abcdefghijklmnopqrstuvwxyz".dup; foreach(ref char c; buffer) { if('a' <= c && c <= 'z') { c -= cast(char)'a' - 'A'; // segfault here } } for(int i = 0; i < buffer.length; i++) { if('a' <= buffer[i] && buffer[i] <= 'z') { buffer[i] -= cast(char)'a' - 'A'; // segfault here } } writeln(buffer); } /*******************************************/ struct st46 { template t1() { template t2(int n2) { } } } alias st46.t1!().t2 a46; void test46() { } /*******************************************/ struct A47 { static int y; void opSliceAssign(int x) { printf("x = %d\n", x); y = x; } A47 d() { return this; } } void test47() { A47 a; a[] = 3; printf("y = %d\n", a.y); a.d()[] = 5; printf("y = %d\n", a.y); assert(a.y == 5); a.d[] = 6; printf("y = %d\n", a.y); assert(a.y == 6); } /*******************************************/ static uint[] sarray48 = void; void test48() { static uint[] array = void; assert(sarray48 == null); assert(array == null); } /*******************************************/ int x = 2, y = 1; void foo50(int z) { static int t; t++; assert(t == z); } void test50() { printf("test50()\n"); int res = 0; for(int i = 0; i < 10; i++) { res = res + x - y; foo50(res); } } /*******************************************/ void test52() { printf("test52()\n"); char[] s; s = ['a', 'b', 'c']; assert(s == "abc"); int[] x; x = [17, 18u, 29, 33]; assert(x.length == 4); assert(x[0] == 17); assert(x[1] == 18); assert(x[2] == 29); assert(x[3] == 33); assert(x == [17, 18, 29, 33]); } /*******************************************/ void test54() { printf("test54()\n"); uint[500][] data; data.length = 1; assert(data.length == 1); foreach (ref foo; data) { assert(foo.length == 500); foreach (ref u; foo) { //printf("u = %u\n", u); assert(u == 0); u = 23; } } foreach (ref foo; data) { assert(foo.length == 500); foreach (u; foo) { assert(u == 23); auto v = u; v = 23; } } } /*******************************************/ class Base56 { private string myfoo; private string mybar; // Get/set properties that will be overridden. void foo(string s) { myfoo = s; } string foo() { return myfoo; } // Get/set properties that will not be overridden. void bar(string s) { mybar = s; } string bar() { return mybar; } } class Derived56: Base56 { alias Base56.foo foo; // Bring in Base56's foo getter. override void foo(string s) { super.foo = s; } // Override foo setter. } void test56() { Derived56 d = new Derived56; with (d) { foo = "hi"; d.foo = "hi"; bar = "hi"; assert(foo == "hi"); assert(d.foo == "hi"); assert(bar == "hi"); } } /*******************************************/ bool[void[]] reg57; void addToReg57(const(void)[] a, int b, bool v) { if (!v) writefln("X"); auto key = a~(cast(void*)&b)[0..4]; reg57[cast(immutable(void)[])key] = v; writefln("OK"); } void test57() { addToReg57("test", 1024, true); } /*******************************************/ int bar58( string msg ){ return 1; } int foo58( lazy string dg ){ return bar58( dg() ); } void test58() { printf("test58()\n"); try{ } finally{ foo58(""); } } /*******************************************/ struct S59 { string toString() { return "foo"; } } void test59() { S59 s; writefln("s = %s", s); string p; p = std.string.format("s = %s", s); assert(p == "s = foo"); } /*******************************************/ void test60() { int[2][] a; a = [ [-1,2], [3,4] ]; assert(a[0][0] == -1); assert(a[0][1] == 2); assert(a[1][0] == 3); assert(a[1][1] == 4); int[][] b; b = [ [-1,2], [3,4] ]; assert(b[0][0] == -1); assert(b[0][1] == 2); assert(b[1][0] == 3); assert(b[1][1] == 4); } /*******************************************/ void test61() { int[][] f = [[1,2],[3,4]]; assert(f[0][0] == 1); assert(f[0][1] == 2); assert(f[1][0] == 3); assert(f[1][1] == 4); writeln(f); } /*******************************************/ struct List62 { void get() {} } struct Array62 { interface Model { List62 list(); } List62 list() { return model ? model.list() : List62.init; } void item() { list.get(); } private Model model; } void test62() { } /*******************************************/ void foo63(...) { } void test63() { int[] arr; arr = [1] ~ 2; // runtime crash, the length == 1 printf("%d\n", arr.length); assert (arr.length == 2); assert(arr[0] == 1); assert(arr[1] == 2); arr = 2 ~ [1]; assert(arr.length == 2); assert(arr[0] == 2); assert(arr[1] == 1); arr = [2, 3] ~ [1]; assert(arr.length == 3); assert(arr[0] == 2); assert(arr[1] == 3); assert(arr[2] == 1); foo63([1] ~ 2, 2 ~ [1], [1,2] ~ [3,4,5]); } /*******************************************/ void test64() { printf("test64()\n"); int[] x = [1,2,3,4]; int j = 4; foreach_reverse(v; x) { writeln(v); assert(j == v); j--; } assert(j == 0); j = 4; foreach_reverse(i, v; x) { writefln("[%s] = %s", i, v); assert(i + 1 == j); assert(j == v); j--; } assert(j == 0); printf("-test64()\n"); } /*******************************************/ void test65() { // Bugzilla Issue 407. int i = *cast(int*)cast(char[4])['0', '0', '0', '0']; // compiler seg-fault printf("i = %x\n", i); } /*******************************************/ void test66() { int[] ia; ia ~= 3; byte[] data = new byte[ia[0]]; byte[] data2 = new byte[ cast(int)(ia[0])]; } /*******************************************/ class C68 { static int value; } void test68() { auto v1 = test.C68.value; auto v2 = C68.classinfo; auto v3 = test.C68.classinfo; assert(v2 == v3); } /*******************************************/ void test69() { class Bug { char[12] str = ""; uint t = 1; } class NoBug { uint t = 2; char[12] str = ""; } class NoBug2 { char[12] str; uint t = 3; } auto b = new Bug; auto n = new NoBug; auto n2 = new NoBug2; writefln("bug %d", b.t); assert(b.t == 1); writefln("nobug %d", n.t); assert(n.t == 2); writefln("nobug2 %d", n2.t); assert(n2.t == 3); } /*******************************************/ void test70() { void foo(char[0] p) { } static const char[0] altsep; string s = std.string.format("test%spath", altsep); assert(s == "testpath"); foo(altsep); } /*******************************************/ class C71 { static int cnt; this() { printf("C()\n"); cnt++; } ~this() { printf("~C()\n"); cnt--; } } class D71 { static int cnt; this() { printf("D()\n"); cnt++; } ~this() { printf("~D()\n"); cnt--; } } class E71 { static int cnt; this() { printf("E()\n"); cnt++; } ~this() { printf("~E()\n"); cnt--; } } void test71() { { int i = 0; printf("start\n"); scope D71 d = new D71(); assert(D71.cnt == 1); for (scope E71 e = new E71(); i < 5; i++) { assert(D71.cnt == 1); assert(E71.cnt == 1); scope c = new C71(); assert(C71.cnt == 1); } assert(C71.cnt == 0); assert(E71.cnt == 0); assert(D71.cnt == 1); printf("finish\n"); } assert(D71.cnt == 0); } /*******************************************/ size_t getLength(int[] arr) { return arr.length; } void test13237() { int[] arr = [0]; immutable size_t len = getLength(arr); arr.length--; assert(len == 1); // ok if (len) { auto l = len; } assert(len == 1); // len cannot be changed, but produces Assertion failure with "-O -inline" } /*******************************************/ void main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); test28(); test29(); test30(); test31(); test32(); test33(); test34(); test37(); test38(); test39(); test40(); test41(); test42(); test43(); test44(); test45(); test46(); test47(); test48(); test50(); test52(); test54(); test56(); test57(); test58(); test59(); test60(); test61(); test62(); test63(); test64(); test65(); test66(); test68(); test69(); test70(); test71(); test13237(); printf("Success\n"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testmmfile.d0000644000175000017500000000421613200164642023730 0ustar matthiasmatthias// PERMUTE_ARGS: // REQUIRED_ARGS: import std.file; import std.mmfile; int main() { static string name = "test.tmp"; static string s = "abcd"; write(name, s); { scope MmFile mmf = new MmFile(name); string p; assert(mmf[0] == 'a'); p = cast(string)mmf[]; //printf("p.length = %d\n", p.length); assert(p[1] == 'b'); p = cast(string)mmf[0 .. 4]; assert(p[2] == 'c'); } { scope MmFile mmf = new MmFile(name, MmFile.Mode.read, 0, null); string p; assert(mmf[0] == 'a'); p = cast(string)mmf[]; //printf("p.length = %d\n", p.length); assert(mmf.length == 4); assert(p[1] == 'b'); p = cast(string)mmf[0 .. 4]; assert(p[2] == 'c'); } remove(name); { scope MmFile mmf = new MmFile(name, MmFile.Mode.readWriteNew, 4, null); char[] p; p = cast(char[])mmf[]; p[] = "1234"; mmf[3] = '5'; assert(mmf[2] == '3'); assert(mmf[3] == '5'); } { string p = cast(string)read(name); assert(p[] == "1235"); } { scope MmFile mmf = new MmFile(name, MmFile.Mode.readWriteNew, 4, null); char[] p; p = cast(char[])mmf[]; p[] = "5678"; mmf[3] = '5'; assert(mmf[2] == '7'); assert(mmf[3] == '5'); assert(cast(string)mmf[] == "5675"); } { string p = cast(string)read(name); assert(p[] == "5675"); } { scope MmFile mmf = new MmFile(name, MmFile.Mode.readWrite, 4, null); char[] p; p = cast(char[])mmf[]; assert(cast(char[])mmf[] == "5675"); p[] = "9102"; mmf[2] = '5'; assert(cast(string)mmf[] == "9152"); } { string p = cast(string)read(name); assert(p[] == "9152"); } remove(name); { scope MmFile mmf = new MmFile(name, MmFile.Mode.readWrite, 4, null); char[] p; p = cast(char[])mmf[]; p[] = "abcd"; mmf[2] = '5'; assert(cast(string)mmf[] == "ab5d"); } { string p = cast(string)read(name); assert(p[] == "ab5d"); } { scope MmFile mmf = new MmFile(name, MmFile.Mode.readCopyOnWrite, 4, null); char[] p; p = cast(char[])mmf[]; assert(cast(string)mmf[] == "ab5d"); p[] = "9102"; mmf[2] = '5'; assert(cast(string)mmf[] == "9152"); } { string p = cast(string)read(name); assert(p[] == "ab5d"); } remove(name); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test3574d.d0000644000175000017500000000023013200164642023215 0ustar matthiasmatthias//int g = 0; //static ~this() { assert(g == 100); } void main() //out //{ // g = 100; //} //body { //return; // expected return code == 0 } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test58.d0000644000175000017500000000016113200164642022706 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test58a.d // PERMUTE_ARGS: import imports.test58a; void main() { foo!(long)(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test35.sh0000755000175000017500000000152113200164642023074 0ustar matthiasmatthias#!/usr/bin/env bash dir=${RESULTS_DIR}/runnable dmddir=${RESULTS_DIR}${SEP}runnable output_file=${dir}/test35.sh.out rm -f ${output_file} $DMD -m${MODEL} -Irunnable -od${dmddir} -c runnable/extra-files/test35.d >> ${output_file} if [ $? -ne 0 ]; then cat ${output_file} rm -f ${output_file} exit 1 fi $DMD -m${MODEL} -od${dmddir} -c -release runnable/imports/test35a.d >> ${output_file} if [ $? -ne 0 ]; then cat ${output_file} rm -f ${output_file} exit 1 fi $DMD -m${MODEL} -of${dmddir}${SEP}test35${EXE} ${dir}/test35${OBJ} ${dir}/test35a${OBJ} >> ${output_file} if [ $? -ne 0 ]; then cat ${output_file} rm -f ${output_file} exit 1 fi ${dir}/test35 >> ${output_file} if [ $? -ne 0 ]; then cat ${output_file} rm -f ${output_file} exit 1 fi rm ${dir}/{test35${OBJ},test35a${OBJ},test35${EXE}} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testsocket.d0000644000175000017500000000111213200164642023737 0ustar matthiasmatthias// PERMUTE_ARGS: import std.stdio; import std.socket; class Connection { private { Socket sock; } void connect (string host, ushort port) { sock.connect (new InternetAddress (host, port)); } void poll () { SocketSet rset = new SocketSet (1); /** XXX: here is the bug */ rset.reset (); rset.add (sock); } this () { sock = new TcpSocket; sock.blocking = false; } } int main () { try { Connection ns; ns = new Connection (); ns.connect ("localhost", 80); ns.poll (); delete ns; } catch(SocketException e) { } return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testmod2.d0000644000175000017500000000026113200164642023314 0ustar matthiasmatthias// EXTRA_SOURCES: imports/testmod2a.d /**********************************/ // bug 1904 import imports.testmod2a; void main() { void whatever() {} foo!(whatever)(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test13.d0000644000175000017500000000026313200164642022700 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test13a.d // PERMUTE_ARGS: // REQUIRED_ARGS: -unittest module test13; import imports.test13a; alias Ordinal!(char) ord; int main() { return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link11395.d0000644000175000017500000000025713200164642023120 0ustar matthiasmatthias// EXTRA_SOURCES: imports/link11395a.d // PERMUTE_ARGS: // COMPILE_SEPARATELY module link11395; import imports.link11395a; void main() { SB s; SB[] a; a ~= s; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ufcs.d0000644000175000017500000005764413200164642022534 0ustar matthiasmatthias// EXTRA_SOURCES: imports/ufcs5a.d imports/ufcs5b.d imports/ufcs5c.d imports/ufcs5d.d imports/ufcs5e.d module ufcs; extern (C) int printf(const char*, ...); /*******************************************/ struct S {} int foo(int n) { return 1; } int foo(int n, int m) { return 2; } int goo(int[] a) { return 1; } int goo(int[] a, int m) { return 2; } int bar(S s) { return 1; } int bar(S s, int n) { return 2; } int baz(X)(X x) { return 1; } int baz(X)(X x, int n) { return 2; } int temp; ref int boo(int n) { return temp; } ref int coo(int[] a) { return temp; } ref int mar(S s) { return temp; } ref int maz(X)(X x) { return temp; } void test1() { int n; int[] a; S s; assert( foo(4) == 1); assert( baz(4) == 1); assert( 4.foo() == 1); assert( 4.baz() == 1); assert( 4.foo == 1); assert( 4.baz == 1); assert( foo(4, 2) == 2); assert( baz(4, 2) == 2); assert( 4.foo(2) == 2); assert( 4.baz(2) == 2); assert((4.foo = 2) == 2); assert((4.baz = 2) == 2); assert( goo(a) == 1); assert( baz(a) == 1); assert( a.goo() == 1); assert( a.baz() == 1); assert( a.goo == 1); assert( a.baz == 1); assert( goo(a, 2) == 2); assert( baz(a, 2) == 2); assert( a.goo(2) == 2); assert( a.baz(2) == 2); assert((a.goo = 2) == 2); assert((a.baz = 2) == 2); assert( bar(s) == 1); assert( baz(s) == 1); assert( s.bar() == 1); assert( s.baz() == 1); assert( s.bar == 1); assert( s.baz == 1); assert( bar(s, 2) == 2); assert( baz(s, 2) == 2); assert( s.bar(2) == 2); assert( s.baz(2) == 2); assert((s.bar = 2) == 2); assert((s.baz = 2) == 2); assert(( boo(4) = 2) == 2); assert(( maz(4) = 2) == 2); assert((4.boo = 2) == 2); assert((4.maz = 2) == 2); assert(( coo(a) = 2) == 2); assert(( maz(a) = 2) == 2); assert((a.coo = 2) == 2); assert((a.maz = 2) == 2); assert(( mar(s) = 2) == 2); assert(( maz(s) = 2) == 2); assert((s.mar = 2) == 2); assert((s.maz = 2) == 2); } int hoo(T)(int n) { return 1; } int hoo(T)(int n, int m) { return 2; } int koo(T)(int[] a) { return 1; } int koo(T)(int[] a, int m) { return 2; } int var(T)(S s) { return 1; } int var(T)(S s, int n) { return 2; } int vaz(T, X)(X x) { return 1; } int vaz(T, X)(X x, int n) { return 2; } //int temp; ref int voo(T)(int n) { return temp; } ref int woo(T)(int[] a) { return temp; } ref int nar(T)(S s) { return temp; } ref int naz(T, X)(X x) { return temp; } void test2() { int n; int[] a; S s; assert( hoo!int(4) == 1); assert( vaz!int(4) == 1); assert( 4.hoo!int() == 1); assert( 4.vaz!int() == 1); assert( 4.hoo!int == 1); assert( 4.vaz!int == 1); assert( hoo!int(4, 2) == 2); assert( vaz!int(4, 2) == 2); assert( 4.hoo!int(2) == 2); assert( 4.vaz!int(2) == 2); assert((4.hoo!int = 2) == 2); assert((4.vaz!int = 2) == 2); assert( koo!int(a) == 1); assert( vaz!int(a) == 1); assert( a.koo!int() == 1); assert( a.vaz!int() == 1); assert( a.koo!int == 1); assert( a.vaz!int == 1); assert( koo!int(a, 2) == 2); assert( vaz!int(a, 2) == 2); assert( a.koo!int(2) == 2); assert( a.vaz!int(2) == 2); assert((a.koo!int = 2) == 2); assert((a.vaz!int = 2) == 2); assert( var!int(s) == 1); assert( vaz!int(s) == 1); assert( s.var!int() == 1); assert( s.vaz!int() == 1); assert( s.var!int == 1); assert( s.vaz!int == 1); assert( var!int(s, 2) == 2); assert( vaz!int(s, 2) == 2); assert( s.var!int(2) == 2); assert( s.vaz!int(2) == 2); assert((s.var!int = 2) == 2); assert((s.vaz!int = 2) == 2); assert(( voo!int(4) = 2) == 2); assert(( naz!int(4) = 2) == 2); assert((4.voo!int = 2) == 2); assert((4.naz!int = 2) == 2); assert(( woo!int(a) = 2) == 2); assert(( naz!int(a) = 2) == 2); assert((a.woo!int = 2) == 2); assert((a.naz!int = 2) == 2); assert(( nar!int(s) = 2) == 2); assert(( naz!int(s) = 2) == 2); assert((s.nar!int = 2) == 2); assert((s.naz!int = 2) == 2); } /*******************************************/ auto init(T)(T val) { return 1; } auto sort(alias fun, T)(T val) { return 1; } @property auto max(alias fun, T)(T val) { return 1; } @property auto infinity(alias opt, T)(T val) { return 1; } void test3() { // See built-in 'init' property assert(1 .init == 0); assert([1] .init == null); assert([1:1].init == null); assert(1.0 .init is double.nan); assert(10i .init is idouble.nan); assert('c' .init == 0xFF); assert("s" .init == null); // x.init() has parens, so it runs UFCS call assert( 1 .init() == 1); assert([1] .init() == 1); assert([1:1].init() == 1); assert(1.0 .init() == 1); assert(10i .init() == 1); assert('c' .init() == 1); assert("s" .init() == 1); // x.init!YYY matches templatized UFCS call. assert( 1 .init!int() == 1); assert([1] .init!(int[])() == 1); assert([1:1].init!(int[int])() == 1); assert(1.0 .init!double() == 1); assert(10i .init!idouble() == 1); assert('c' .init!char() == 1); assert("s" .init!string() == 1); assert([1].sort!"a= 4 && name[0..4] == "test") { mixin("c5."~name~"();"); // call test function } } } } class B5 { int g5bm(int) { return 0; } static int g5bs(int) { return 0; } } class C5 : B5 { // normal import works. import imports.ufcs5a; void test1() { assert(100.f5a1() == 1); assert("s".f5a2() == 2); assert(1.4.f5a3() == 3); assert(100.f5a4() == 1); assert("s".f5a4() == 2); assert(100.f5a5() == 1); assert("s".f5a5() == 2); assert(1.4.f5a5() == 3); assert(100.p5a1 == 1); assert((100.p5a1 = 1) == 1); assert("s".p5a2 == 2); assert(("s".p5a2 = 1) == 2); assert(1.4.p5a3 == 3); assert((1.4.p5a3 = 1) == 3); assert(100.p5a4 == 1); assert((100.p5a4 = 1) == 1); assert("s".p5a4 == 2); assert(("s".p5a4 = 1) == 2); assert(100.p5a5 == 1); assert((100.p5a5 = 1) == 1); assert("s".p5a5 == 2); assert(("s".p5a5 = 1) == 2); assert(1.4.p5a5 == 3); assert((1.4.p5a5 = 1) == 3); } // selective imports also work as expected import imports.ufcs5d : f5d1, f5d2; import imports.ufcs5d : p5d1, p5d2; void test2() { assert(100.f5d1() == 1); assert("s".f5d2() == 2); static assert(!__traits(compiles, { 1.4.f5d3(); })); static assert(!__traits(compiles, { 100.f5d4(); })); static assert(!__traits(compiles, { "s".f5d4(); })); static assert(!__traits(compiles, { 100.f5d5(); })); static assert(!__traits(compiles, { "s".f5d5(); })); static assert(!__traits(compiles, { 1.4.f5d5(); })); assert(100.p5d1 == 1); assert((100.p5d1 = 1) == 1); assert("s".p5d2 == 2); assert(("s".p5d2 = 1) == 2); static assert(!__traits(compiles, { 1.4.p5d3; }) && !__traits(compiles, { 1.4.p5d3 = 1; })); static assert(!__traits(compiles, { 100.p5d4; }) && !__traits(compiles, { 100.p5d4 = 1; })); static assert(!__traits(compiles, { "s".p5d4; }) && !__traits(compiles, { "s".p5d4 = 1; })); static assert(!__traits(compiles, { 100.p5d5; }) && !__traits(compiles, { 100.p5d5 = 1; })); static assert(!__traits(compiles, { "s".p5d5; }) && !__traits(compiles, { "s".p5d5 = 1; })); static assert(!__traits(compiles, { 1.4.p5d5; }) && !__traits(compiles, { 1.4.p5d5 = 1; })); } // renamed imports also work as expected import imports.ufcs5e : f5y1 = f5e1, f5y2 = f5e2; import imports.ufcs5e : p5y1 = p5e1, p5y2 = p5e2; void test3() { assert(100.f5y1() == 1); assert("s".f5y2() == 2); static assert(!__traits(compiles, { 100.f5e1(); })); static assert(!__traits(compiles, { "s".f5e2(); })); static assert(!__traits(compiles, { 1.4.f5e3(); })); static assert(!__traits(compiles, { 100.f5e4(); })); static assert(!__traits(compiles, { "s".f5e4(); })); static assert(!__traits(compiles, { 100.f5e5(); })); static assert(!__traits(compiles, { "s".f5e5(); })); static assert(!__traits(compiles, { 1.4.f5e5(); })); assert(100.p5y1 == 1); assert((100.p5y1 = 1) == 1); assert("s".p5y2 == 2); assert(("s".p5y2 = 1) == 2); static assert(!__traits(compiles, { 100.p5e1; }) && !__traits(compiles, { (100.p5e1 = 1); })); static assert(!__traits(compiles, { "s".p5e2; }) && !__traits(compiles, { ("s".p5e2 = 1); })); static assert(!__traits(compiles, { 1.4.p5e3; }) && !__traits(compiles, { (1.4.p5e3 = 1); })); static assert(!__traits(compiles, { 100.p5e4; }) && !__traits(compiles, { (100.p5e4 = 1); })); static assert(!__traits(compiles, { "s".p5e4; }) && !__traits(compiles, { ("s".p5e4 = 1); })); static assert(!__traits(compiles, { 100.p5e5; }) && !__traits(compiles, { (100.p5e5 = 1); })); static assert(!__traits(compiles, { "s".p5e5; }) && !__traits(compiles, { ("s".p5e5 = 1); })); static assert(!__traits(compiles, { 1.4.p5e5; }) && !__traits(compiles, { (1.4.p5e5 = 1); })); } int g5cm(int) { return 0; } static int g5cs(int) { return 0; } void test4() { // UFCS does not see aggregate members static assert(!__traits(compiles, { 1.g5cm(); })); static assert(!__traits(compiles, { 1.g5cs(); })); // Even if it is in base class static assert(!__traits(compiles, { 1.g5bm(); })); static assert(!__traits(compiles, { 1.g5bs(); })); } } /*******************************************/ // 662 import std.stdio,std.string, std.conv; enum Etest { a,b,c,d } //typedef int testi = 10; //typedef Test Test2; int test() { return 33; } class Test { static int test(int i) { return i; } } int test(Etest test) { return cast(int)test; } //int test(testi i) //{ // return cast(int)i; //} void test682() { assert(22.to!string() == "22"); assert((new Test).test(11) == 11); assert(Test.test(11) == 11); //assert(Test2.test(11) == 11); assert(test() == 33); assert(ufcs.test() == 33); assert(Etest.d.test() == Etest.d); //testi i; //assert(i.test() == i.init); } /*******************************************/ // 3382 import std.range, std.algorithm; @property T twice(T)(T x){ return x * x; } real toreal(ireal x){ return x.im; } char toupper(char c){ return ('a'<=c && c<='z') ? cast(char)(c - 'a' + 'A') : c; } @property ref T setter(T)(ref T x, T v){ x = v; return x; } void test3382() { auto r = iota(0, 10).map!"a*3"().filter!"a%2 != 0"(); foreach (e; r) printf("e = %d\n", e); assert(10.twice == 100); assert(0.5.twice == 0.25); assert(1.4i.toreal() == 1.4); assert('c'.toupper() == 'C'); } /*******************************************/ // 6185 void test6185() { import std.algorithm; auto r1 = [1,2,3].map!"a*2"; assert(equal(r1, [2,4,6])); auto r2 = r1.map!"a+2"(); assert(equal(r2, [4,6,8])); } /*******************************************/ // 6070 enum test6070a = ["test"].foo6070(); enum test6070b = foo6070(["test"]); string foo6070(string[] s) { return ""; } /*******************************************/ // 7670 struct A7670 { double x; } @property ref double y7670(ref A7670 a) { return a.x; } void test7670() { A7670 a1; a1.y7670() = 2.0; // OK a1.y7670 = 2.0; // Error } /*******************************************/ // 7703 void f7703(T)(T a) { } void test7703() { int x; x.f7703; // accepted x.f7703(); // accepted x.f7703!int; // rejected -- "f(x) isn't a template" x.f7703!int(); // accepted } /*******************************************/ // 7773 //import std.stdio; void writeln7773(int n){} void test7773() { (int.max).writeln7773(); // OK int.max.writeln7773(); // error } /*******************************************/ // 7943 struct Foo7943 { int _member; alias _member this; } int foo7943(Foo7943 f) { return 1; } int foo7943(int i) { return 2; } void test7943() { Foo7943 f; assert(f.foo7943() == 1); } /*******************************************/ // 8180 int writeln8180(T...)(T args) { return 1; } struct Tuple8180(T...) { T field; alias field this; } void test8180() { auto t = Tuple8180!(int)(10); assert(t.writeln8180() == 1); } /*******************************************/ // 8245 string toStr8245(immutable(char)* p) { return null; } @property string asStr8245(immutable(char)* p) { return null; } void test8245() { immutable(char)* p = "foobar".ptr; p.toStr8245(); p.asStr8245; // Error: no property 'asStr' for type 'immutable(char)' } /*******************************************/ // 8252 bool f(int x) { return !x; } void test8252() { static assert(!1.f); // ok static assert( 0.f); // fail } /*******************************************/ // 8453 T[] sort8453(T)(T[] a) { return a; } void test8453() { int[int] foo; auto bar1 = foo.keys().sort8453(); // OK auto bar2 = foo.keys.sort8453(); // Error } /*******************************************/ // 8503 void α8503(int i) {} void test8503() { 0.α8503(); // Error 1.α8503(); // Error } /*******************************************/ // 9014 @property ref int foo9014(int[] a) { return a[0]; } void test9014() { int[] bar; static assert(!__traits(compiles, { bar.foo9014 = missing.foo9014; })); } /*******************************************/ // 9590 auto func9590(E)(lazy E expr) { } int f9590a() { assert(0); } void f9590b() { assert(0); } void test9590() { func9590(f9590a()); // ok, no exceptions (lazy) f9590a().func9590; // ok, no exceptions (lazy) func9590(f9590b()); // ok, no exceptions (lazy) f9590b().func9590; // L12: NG } /*******************************************/ // 9946 size_t count9946(alias x)(int[] haystack) { return 0; } void test9946() { int[] data; auto n1 = count9946!5(data); // OK auto n2 = data.count9946!5; // OK auto a1 = new int[count9946!5(data)]; // OK auto a2 = new int[data.count9946!5]; // Error } /*******************************************/ // 10618 template Temp10618(T) { size_t len = 1; } void test10618() { auto arr = new int[Temp10618!int.len]; assert(arr.length == 1); } /*******************************************/ // 10003 void foo10003(void *p) {} void test10003() { void* p; p.foo10003(); } /*******************************************/ // 10041 auto writeln10041(T...)(T args) { return typeof(args[0]).stringof; } void test10041() { auto aa = [1: 2]; assert(aa.writeln10041 == "int[int]"); assert(writeln10041(aa) == "int[int]"); } /*******************************************/ // 10047 struct Typedef10047(T) { template opDispatch(string name) { static assert(0); } } struct A10047 {} int foo10047(Typedef10047!A10047 a) { return 10; } void test10047() { Typedef10047!A10047 a; assert(a.foo10047() == 10); } /*******************************************/ // 10166 auto foo10166() { 0.bar10166!({})(0); } void bar10166(alias handler, T)(T t, int i) { t.bar10166!buzz10166(i); } void buzz10166() {} /*******************************************/ // 10526 struct S10526 { int opDispatch(string s, A...)(A args) if (s[0..3] == "foo") { return 1; } } int bar10526(X)(X) { return 2; } int baz10526(T, X)(X) { return 3; } void test10526() { S10526 s; // with parenthesis assert(s.foo10526() == 1); assert(s.bar10526() == 2); assert(s.baz10526!string() == 3); // without parenthesis assert(s.foo10526 == 1); assert(s.bar10526 == 2); assert(s.baz10526!string == 3); } /********************************************************/ // 10609 int foo10609(int x) { return x; } void test10609() { int x = 1; static assert(__traits(compiles, foo10609(x))); static assert(__traits(compiles, 1.foo10609 )); static assert(__traits(compiles, x.foo10609 )); } /*******************************************/ // 11312 struct S11312; S11312* getS11312() { return null; } int getValue(S11312*) { return 10; } void test11312() { S11312* op = getS11312(); int x = op.getValue(); assert(x == 10); } /*******************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test682(); test3382(); test6185(); test7670(); test7703(); test7773(); test7943(); test8180(); test8245(); test8252(); test8453(); test8503(); test9014(); test9590(); test9946(); test10618(); test10003(); test10041(); test10047(); test10526(); test11312(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test7595.d0000644000175000017500000000061513200164642023067 0ustar matthiasmatthias// EXTRA_SOURCES: imports/a7595.d template isSafe(alias func) { @safe void dummySafeFunc() { func(); } enum isSafe = is(typeof(dummySafeFunc())); } template areAllSafe(funcs...) { enum areAllSafe = isSafe!(funcs[0]); } @safe benchmark(fun...)(uint n) if (areAllSafe!fun) { foreach(i, unused; fun) { foreach (j; 0 .. n) fun[i](); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/interface3.d0000644000175000017500000000175413200164642023606 0ustar matthiasmatthias// PERMUTE_ARGS: extern(C) int printf(const char*, ...); interface IWriter { IWriter put (I1 x); } interface I1 { void write (IWriter writer); } interface I2 : I1 {} interface I3 : I2 {} class Newline : I3 { static int OKset; void write (IWriter writer) { printf ("OK\n"); OKset += 1; } } class Writer : IWriter { IWriter put (I1 x) { x.write (this); return this; } } class FlushWriter : Writer { override IWriter put (I1 x) { // have superclass handle the I1 super.put (x); // flush output when we see a newline if (cast(Newline) x) { } return this; } } void test (IWriter w) { //w.put (new Newline); I3 NL = new Newline; w.put (NL); } int main() { test (new FlushWriter); assert(Newline.OKset == 1); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/a21.d0000644000175000017500000000051613200164642022141 0ustar matthiasmatthias// EXTRA_SOURCES: imports/a21a.d // PERMUTE_ARGS: import std.stdio; import imports.a21a; template BadMixin() { int badFunc() { printf("badFunc\n"); return 2; } } int main() { int i; auto x = new SomeClass; i = x.goodFunc(); assert(i == 1); i = x.badFunc(); assert(i == 2); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_726.d0000644000175000017500000000246113200164642024261 0ustar matthiasmatthias void issue726_1() { struct Buggy { align(1): uint a = 0x0a0a0a0a; ulong b = 0x0b0b0b0b0b0b0b0b; } Buggy packed; ulong raw = *cast(ulong*)(cast(ubyte*)&packed + packed.b.offsetof); assert(packed.b == raw); } void issue726_2() { class Buggy { align(1): uint a = 0x0a0a0a0a; ulong b = 0x0b0b0b0b0b0b0b0b; } auto packed = new Buggy; ulong raw = *cast(ulong*)(cast(ubyte*)packed + packed.b.offsetof); assert(packed.b == raw); } void issue726_3() { class Buggy { align(1): uint a = 0x0a0a0a0a; ulong b = 0x0b0b0b0b0b0b0b0b; } class Derived : Buggy { } auto packed = new Derived; ulong raw = *cast(ulong*)(cast(ubyte*)packed + packed.b.offsetof); assert(packed.b == raw); } void issue726_4() { struct Buggy { align(1): uint a = 0x0a0a0a0a; ulong b = 0x0b0b0b0b0b0b0b0b; align(8): ulong c = 0x0c0c0c0c0c0c0c0c; } Buggy packed; ulong raw = *cast(ulong*)(cast(ubyte*)&packed + packed.b.offsetof); assert(packed.b == raw); raw = *cast(ulong*)(cast(ubyte*)&packed + packed.c.offsetof); assert(packed.c == raw); } void main() { issue726_1(); issue726_2(); issue726_3(); issue726_4(); }ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testkeyword.d0000644000175000017500000001322213200164642024140 0ustar matthiasmatthias// PERMUTE_ARGS: // EXTRA_SOURCES: imports/testkwd_file.d module testkeyword; import imports.testkwd; /****************************************/ // calee test static assert(getCalleeFile() == thatFile); static assert(getCalleeLine() == thatLine); static assert(getCalleeMod() == thatMod); static assert(getCalleeFunc() == thatFunc); static assert(getCalleeFunc2() == thatFunc2); void testCallee() { static assert(getCalleeFile() == thatFile); static assert(getCalleeLine() == thatLine); static assert(getCalleeMod() == thatMod); static assert(getCalleeFunc() == thatFunc); static assert(getCalleeFunc2() == thatFunc2); } /****************************************/ // caller test version(Windows) enum sep = "\\"; else enum sep = "/"; enum thisFile = "runnable"~sep~"testkeyword.d"; enum thisMod = "testkeyword"; static assert(getFuncArgFile() == thisFile); static assert(getFuncArgLine() == 33); static assert(getFuncArgMod() == thisMod); static assert(getFuncArgFunc() == ""); static assert(getFuncArgFunc2() == ""); static assert(getFuncTiargFile() == thisFile); static assert(getFuncTiargLine() == 39); static assert(getFuncTiargMod() == thisMod); static assert(getFuncTiargFunc() == ""); static assert(getFuncTiargFunc2() == ""); static assert(getInstTiargFile!() == thisFile); static assert(getInstTiargLine!() == 45); static assert(getInstTiargMod!() == thisMod); static assert(getInstTiargFunc!() == ""); static assert(getInstTiargFunc2!() == ""); void main(string[] args) nothrow { enum thisFunc = "testkeyword.main"; enum thisFunc2 = "void testkeyword.main(string[] args) nothrow"; static assert(getFuncArgFile() == thisFile); static assert(getFuncArgLine() == 56); static assert(getFuncArgMod() == thisMod); static assert(getFuncArgFunc() == thisFunc); static assert(getFuncArgFunc2() == thisFunc2); static assert(getFuncTiargFile() == thisFile); static assert(getFuncTiargLine() == 62); static assert(getFuncTiargMod() == thisMod); static assert(getFuncTiargFunc() == thisFunc); static assert(getFuncTiargFunc2() == thisFunc2); static assert(getInstTiargFile!() == thisFile); static assert(getInstTiargLine!() == 68); static assert(getInstTiargMod!() == thisMod); static assert(getInstTiargFunc!() == thisFunc); static assert(getInstTiargFunc2!() == thisFunc2); void nested(int x, float y) nothrow { enum thisFunc = "testkeyword.main.nested"; enum thisFunc2 = "void testkeyword.main.nested(int x, float y) nothrow"; static assert(getFuncArgFile() == thisFile); static assert(getFuncArgLine() == 79); static assert(getFuncArgMod() == thisMod); static assert(getFuncArgFunc() == thisFunc); static assert(getFuncArgFunc2() == thisFunc2); static assert(getFuncTiargFile() == thisFile); static assert(getFuncTiargLine() == 85); static assert(getFuncTiargMod() == thisMod); static assert(getFuncTiargFunc() == thisFunc); static assert(getFuncTiargFunc2() == thisFunc2); static assert(getInstTiargFile!() == thisFile); static assert(getInstTiargLine!() == 91); static assert(getInstTiargMod!() == thisMod); static assert(getInstTiargFunc!() == thisFunc); static assert(getInstTiargFunc2!() == thisFunc2); } nested(1, 1.0); auto funcLiteral = (int x, int y) { enum thisFunc = "testkeyword.main.__lambda3"; enum thisFunc2 = "testkeyword.main.__lambda3(int x, int y)"; static assert(getFuncArgFile() == thisFile); static assert(getFuncArgLine() == 104); static assert(getFuncArgMod() == thisMod); static assert(getFuncArgFunc() == thisFunc); static assert(getFuncArgFunc2() == thisFunc2); static assert(getFuncTiargFile() == thisFile); static assert(getFuncTiargLine() == 110); static assert(getFuncTiargMod() == thisMod); static assert(getFuncTiargFunc() == thisFunc); static assert(getFuncTiargFunc2() == thisFunc2); static assert(getInstTiargFile!() == thisFile); static assert(getInstTiargLine!() == 116); static assert(getInstTiargMod!() == thisMod); static assert(getInstTiargFunc!() == thisFunc); static assert(getInstTiargFunc2!() == thisFunc2); }; funcLiteral(1, 2); static struct S { void func(string cs, T1, alias T2, T...)(int x) const { enum thisFunc = `testkeyword.main.S.func!("foo", int, symbol, int[], float[]).func`; enum thisFunc2 = `void testkeyword.main.S.func!("foo", int, symbol, int[], float[]).func(int x) const`; static assert(getFuncArgFile() == thisFile); static assert(getFuncArgLine() == 131); static assert(getFuncArgMod() == thisMod); static assert(getFuncArgFunc() == thisFunc); static assert(getFuncArgFunc2() == thisFunc2); static assert(getFuncTiargFile() == thisFile); static assert(getFuncTiargLine() == 137); static assert(getFuncTiargMod() == thisMod); static assert(getFuncTiargFunc() == thisFunc); static assert(getFuncTiargFunc2() == thisFunc2); static assert(getInstTiargFile!() == thisFile); static assert(getInstTiargLine!() == 143); static assert(getInstTiargMod!() == thisMod); static assert(getInstTiargFunc!() == thisFunc); static assert(getInstTiargFunc2!() == thisFunc2); } } static int symbol; S s; s.func!("foo", int, symbol, int[], float[])(1); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test12197.d0000644000175000017500000000021613200164642023136 0ustar matthiasmatthias// import std.math; void foo(T)(T[] b) { b[] = b[] ^^ 4; } void main() { double[] a = [10]; foo(a); assert(a[0] == 10000); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/c22.d0000644000175000017500000000027413200164642022145 0ustar matthiasmatthias// EXTRA_SOURCES: imports/c22a.d imports/c22b.d // PERMUTE_ARGS: module main; import imports.c22a; import imports.c22b; int main() { afn1(); afn2(); bfn1(); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/opdisp.d0000644000175000017500000001400013200164642023045 0ustar matthiasmatthiasextern (C) int printf(const char* fmt, ...); int pass(int n){ return n; } struct X { int m; int opIndex(int m, int n) { return n; } } /**********************************************/ struct S1f { int opDispatch(string name, A...)(A args) { static if (args.length) return args[0]; else return 0; } } struct S1p { @property int opDispatch(string name, A...)(A args) { static if (args.length) return args[0]; else return 0; } } void test1() { S1f s1f; assert(s1f.func() == 0); // ok -> ok assert(s1f.func(1) == 1); // ok -> ok assert(pass(s1f.func()) == 0); // ok -> ok assert(pass(s1f.func(1)) == 1); // ok -> ok assert(X(s1f.func()).m == 0); assert(X()[0, s1f.func()] == 0); S1p s1p; assert(s1p.prop == 0); // ok -> ok assert((s1p.prop = 1) == 1); // CTng -> CTng assert(pass(s1p.prop) == 0); // ok -> ok assert(pass(s1p.prop = 2) == 2); // CTng -> CTng assert(X(s1p.prop).m == 0); assert(X()[0, s1p.prop] == 0); } /**********************************************/ struct S2f { template opDispatch(string name) { int opDispatch(A...)(A args) { static if (args.length) return args[0]; else return 0; } } } struct S2p { template opDispatch(string name) { @property int opDispatch(A...)(A args) { static if (args.length) return args[0]; else return 0; } } } void test2() { S2f s2f; assert(s2f.func() == 0); // ok -> ok assert(s2f.func(1) == 1); // ok -> ok assert(pass(s2f.func()) == 0); // ok -> ok assert(pass(s2f.func(1)) == 1); // ok -> ok assert(X(s2f.func()).m == 0); assert(X()[0, s2f.func()] == 0); S2p s2p; assert(s2p.prop == 0); // CTng -> ok assert((s2p.prop = 1) == 1); // ok -> ok assert(pass(s2p.prop) == 0); // CTng -> ok assert(pass(s2p.prop = 2) == 2); // ok -> ok assert(X(s2p.prop).m == 0); assert(X()[0, s2p.prop] == 0); } /**********************************************/ struct S3f { template opDispatch(string name) { template opDispatch(T) { int opDispatch(A...)(A args) { static if (args.length) return args[0]; else return 0; } } } } struct S3p { template opDispatch(string name) { template opDispatch(T) { @property int opDispatch(A...)(A args) { static if (args.length) return args[0]; else return 0; } } } } void test3() { S3f s3f; assert(s3f.func!int() == 0); // ok -> ok assert(s3f.func!int(1) == 1); // ok -> ok assert(pass(s3f.func!int()) == 0); // ok -> ok assert(pass(s3f.func!int(1)) == 1); // ok -> ok assert(X(s3f.func!int()).m == 0); assert(X()[0, s3f.func!int()] == 0); S3p s3p; assert(s3p.prop!int == 0); // CTng -> ok assert((s3p.prop!int = 1) == 1); // ok -> ok assert(pass(s3p.prop!int) == 0); // CTng -> ok assert(pass(s3p.prop!int = 2) == 2); // ok -> ok assert(X(s3p.prop!int).m == 0); assert(X()[0, s3p.prop!int] == 0); } /**********************************************/ struct S4f { ref int opDispatch(string name, A...)(A args) { static int n; n = args.length; return n; } } struct S4p { @property ref int opDispatch(string name, A...)(A args) { static int n; n = args.length; return n; } } void test4() { S4f s4f; assert(s4f.func == 0); // getter assert((s4f.func = 1) == 1); // setter S4p s4p; assert(s4p.prop == 0); // getter assert((s4p.prop = 1) == 1); // setter } /**********************************************/ struct S5f { template opDispatch(string name) { ref int opDispatch(A...)(A args) { static int n; n = args.length; return n; } } } struct S5p { template opDispatch(string name) { @property ref int opDispatch(A...)(A args) { static int n; n = args.length; return n; } } } void test5() { S5f s5f; assert(s5f.prop == 0); // getter ng -> ok assert((s5f.prop = 1) == 1); // setter S5p s5p; assert(s5p.prop == 0); // getter ng -> ok assert((s5p.prop = 1) == 1); // setter } /**********************************************/ struct S6f { template opDispatch(string name) { template opDispatch(T) { ref int opDispatch(A...)(A args) { static int n; n = args.length; return n; } } } } struct S6p { template opDispatch(string name) { template opDispatch(T) { @property ref int opDispatch(A...)(A args) { static int n; n = args.length; return n; } } } } void test6() { S6f s6f; assert(s6f.prop!int == 0); // getter ng -> ok assert((s6f.prop!int = 1) == 1); // setter S6p s6p; assert(s6p.prop!int == 0); // getter ng -> ok assert((s6p.prop!int = 1) == 1); // setter } /**********************************************/ // 7578 struct Foo7578 { static int[] opDispatch(string op, Args...)(Args) { return [0]; } } void test7578() { Foo7578.attrs[0] = 1; } /**********************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7578(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/traits_getUnitTests.d0000644000175000017500000000317713200164642025614 0ustar matthiasmatthias// REQUIRED_ARGS: -unittest // EXTRA_SOURCES: imports/traits_getUnitTests_import.d module traits_getUnitTests; import imports.traits_getUnitTests_import; template Tuple (T...) { alias Tuple = T; } int i; unittest { i++; } void test_getUnitTestsFromModule () { static assert(__traits(getUnitTests, mixin(__MODULE__)).length == 1); } struct SGetUnitTestsFromAggregate { unittest {} } class CGetUnitTestsFromAggregate { unittest {} } void test_getUnitTestsFromAggregate () { static assert(__traits(getUnitTests, SGetUnitTestsFromAggregate).length == 1); static assert(__traits(getUnitTests, CGetUnitTestsFromAggregate).length == 1); } void test_callUnitTestFunction () { __traits(getUnitTests, mixin(__MODULE__))[0](); assert(i == 2); // 2, because the standard unit test runner // will call the unit test function as well } struct GetUnitTestsWithUDA { @("asd") unittest {} } void test_getUnitTestsWithUDA () { alias tests = Tuple!(__traits(getUnitTests, GetUnitTestsWithUDA)); static assert(tests.length == 1); static assert(__traits(getAttributes, tests[0]).length == 1); } void test_getUnitTestsFromImport () { static assert(__traits(getUnitTests, imports.traits_getUnitTests_import).length == 1); static assert(__traits(getUnitTests, mixin("imports.traits_getUnitTests_import")).length == 1); } // 11358 debug { } enum len11358 = __traits(getUnitTests, mixin(__MODULE__)).length; void main () { test_getUnitTestsFromModule(); test_getUnitTestsFromAggregate(); test_callUnitTestFunction(); test_getUnitTestsWithUDA(); test_getUnitTestsFromImport(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test11039.d0000644000175000017500000000050713200164642023133 0ustar matthiasmatthias // COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test11039b.d import imports.test11039b; struct SomeStruct(T) { T field; T getInnerField() { return field; } } static globalField = SomeStruct!string("Hello!"); void main() { globalField.getInnerField(); anotherGlobalField.getInnerField(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test8.d0000644000175000017500000003330113200164642022623 0ustar matthiasmatthias module testxxx8; import core.vararg; extern(C) { int atoi(const char*); int printf(const char*, ...); size_t strlen(const char*); version(Windows) { int _snprintf(char*, size_t, const char*, ...); alias _snprintf snprintf; } else int snprintf(char*, size_t, const char*, ...); } /***********************************/ struct Foo1 { static int x = 3; int y = 4; } void test1() { Foo1 f; assert(Foo1.x == 3); assert(f.x == 3); assert(f.y == 4); } /***********************************/ class Foo2 { static int x = 5; int y = 6; } void test2() { Foo2 f = new Foo2(); assert(Foo2.x == 5); assert(f.x == 5); assert(f.y == 6); } /***********************************/ struct Foo3 { static int bar() { return 3; } int y = 4; } void test3() { Foo3 f; assert(Foo3.bar() == 3); assert(f.bar() == 3); } /***********************************/ class Foo4 { static int bar() { return 3; } int y = 4; } void test4() { Foo4 f = new Foo4(); assert(Foo4.bar() == 3); assert(f.bar() == 3); } /***********************************/ struct Foo5 { int bar() { return y + 3; } int y = 4; } void test5() { Foo5 f; assert(f.bar() == 7); } /***********************************/ class Foo6 { int bar() { return y + 3; } final int abc() { return y + 8; } int y = 4; } class FooX6 : Foo6 { override int bar() { return y + 5; } } void test6() { Foo6 f = new FooX6(); assert(f.bar() == 9); assert(f.abc() == 12); } /***********************************/ void bar7(char[3] cad) { assert(cad.length == 3); printf("cad[0] = %d\n", cad[0]); assert(cad[0] == 0xFF); assert(cad[1] == 1); assert(cad[2] == 0xFF); } void test7() { char[3] foo; foo[1] = 1; bar7(foo); } /***********************************/ class gap8 { this(char[3] cad) { assert(cad[0] == 0xFF); assert(cad[1] == 1); assert(cad[2] == 0xFF); } } void test8() { char[3] foo; gap8 g; foo[1] = 1; g = new gap8(foo); } /***********************************/ void test9() { ireal imag = 2.5i; //printf ("test of imag*imag = %Lf\n",imag*imag); real f = imag * imag; assert(f == -6.25); } /***********************************/ void test10() { creal z = 1 + 2.5i; real e = z.im; printf ("e = %Lf\n", e); assert(e == 2.5); } /***********************************/ class Foo11 { public: int a = 47; protected: int b; private: int c; int bar() { return a + b + c; } } class Bar11 : Foo11 { int abc() { return a + b; } } void test11() { Foo11 f = new Foo11(); int i = f.a; assert(i == 47); } /***********************************/ class A12 { protected void foo() { } } class B12: A12 { override void foo() { super.foo(); } } void test12() { } /***********************************/ alias void *HWND; const HWND hWnd = cast(HWND)(null); void test13() { } /***********************************/ string bar14() { return "f"; } char foo14() { return bar14()[0]; } void test14() { char f = foo14(); assert(f == 'f'); } /***********************************/ void test15() { char[30] a; char[30] b; assert(a !is b); } /***********************************/ void test16() { static int function() fp = &func16; int i = fp(); assert(i == 648); } int func16() { return 648; } /***********************************/ string returnSameString(string inputstr) { return inputstr; } string passString() { return returnSameString("First string" ~ "Concatenated with second"); } string butThisWorks() { string s = "Third string"; s = s ~ "Concatenated with fourth"; return returnSameString(s); } void test17() { string s; s = passString(); printf("passString() = %.*s\n", s.length, s.ptr); assert(s == "First stringConcatenated with second"); s = butThisWorks(); printf("butThisWorks() = %.*s\n", s.length, s.ptr); assert(s == "Third stringConcatenated with fourth"); } /***********************************/ void test18() { string[] str; str.length = 2; version (none) { str[1] = "cba"; str[0] = "zyx"; } else { str[1] = (cast(string)"cba").idup; str[0] = (cast(string)"zyx").idup; } // This sorts the strs str.sort; // This will crash the compiler str[0] = str[0].dup.sort.idup; // This will give sintax error //str[0].sort(); printf("%.*s", str[0].length, str[0].ptr); printf("%.*s", str[1].length, str[1].ptr); printf("\n"); string s = str[0] ~ str[1]; assert(s == "abczyx"); } /***********************************/ void test19() { string array = "foobar"; array = array.idup; array = array.dup.sort.idup; assert(array == "abfoor"); } /***********************************/ class A20 { private: static int a; public: int foo(B20 j) { return j.b; } } class B20 { private: static int b; public: int bar(A20 j) { return j.a; } } void test20() { } /***********************************/ alias int* IP; void test21() { int i = 5; IP ip = cast(IP) &i; assert(*ip == 5); } /***********************************/ struct RECT { int left = 1; int top = 2; int right = 3; int bottom = 4; } struct Rect { RECT theRect; } void Test(Rect pos) { //printf("left = %d\n", pos.theRect.left); assert(pos.theRect.left == 1); assert(pos.theRect.top == 2); assert(pos.theRect.right == 3); assert(pos.theRect.bottom == 4); } class Window { Rect position; void createWindow() { Test(position); } } void test22() { Window w = new Window(); w.createWindow(); } /***********************************/ struct Size { int width; int height; } Size computeSize() { Size foo; foo.width = 12; foo.height = 34; printf("Inside: %d,%d\n",foo.width,foo.height); return foo; } void test24() { Size bar; bar = computeSize(); printf("Outside: %d,%d\n",bar.width,bar.height); assert(bar.width == 12); assert(bar.height == 34); } /***********************************/ void test25() { int i = 5; while (i) { break; } } /***********************************/ int test26() in { } out (result) { } body { int i = 5; while (i) { break; } return i; } /***********************************/ class A27 { int a; this() { a = 1; } } class B27 : A27 { } class C27 : B27 { this() { super(); } this(int i) { } } void test27() { A27 a = new A27(); assert(a.a == 1); B27 b = new B27(); assert(b.a == 1); C27 c = new C27(); assert(c.a == 1); C27 c2 = new C27(2); assert(c2.a == 1); } /***********************************/ const char[1] sep = '/'; string testx28(string s, string t) { return cast(string)(s ~ sep ~ t); } void test28() { string r; r = testx28("ab", "cd"); assert(r == "ab/cd"); } /***********************************/ void test29() { } /***********************************/ bool func30(int x, int y) { bool b; b|=(x==y); return b; } void test30() { bool b; b = func30(1,1); assert(b == true); b = func30(1,2); assert(b == false); } /***********************************/ int a31; void test31() { testxxx8.a31 = 3; assert(a31 == 3); } /***********************************/ void test32() { string[] foo; int i; foo = new string[45]; for (i = 0; i < 45; i++) foo[i] = "hello"; for (i = 0; i < 45; i++) assert(foo[i] == "hello"); } /***********************************/ void test33() { string[] foo; int i = 45; foo = new string[i]; for (i = 0; i < 45; i++) foo[i] = "hello"; for (i = 0; i < 45; i++) assert(foo[i] == "hello"); } /***********************************/ void test34() { int[3][4] a; int[5][6] b = 16; int i, j; for (i = 0; i < 4; i++) for (j = 0; j < 3; j++) assert(a[i][j] == 0); for (i = 0; i < 6; i++) for (j = 0; j < 5; j++) assert(b[i][j] == 16); } /***********************************/ void test35() { ifloat b = cast(ifloat)1i; assert(b == 1.0i); ifloat c = 2fi; assert(c == 2.0i); c = 0fi; assert(c == 0i); } /***********************************/ string itoa(int i) { char[32] buffer; snprintf(buffer.ptr, 32, "%d", i); return buffer[0 .. strlen(buffer.ptr)].idup; } string testa36(int i, int j, string a, string b, string c) { string s = "string 0;" ~ itoa(i) ~ "string 1;" ~ itoa(j) ~ "string 2;" ~ itoa(i) ~ "string 3;"; // string s = a ~ b ~ c; return s; } void test36() { string s = testa36(26, 47, "a", "b", "c"); printf("s = '%.*s'\n", s.length, s.ptr); assert(s == "string 0;26string 1;47string 2;26string 3;"); } /***********************************/ void test37() { string[ulong] x; ulong v1 = 297321415603; ulong v2 = 331681153971; x[v1] = "aa"; printf( "%llx %llx\n", v1, v2 ); assert(!(v2 in x)); } /***********************************/ void test38() { int n = atoi("1"); static char flags[8192 + 1]; long i, k; int count = 0; try { while (n--) { count = 0; for (i = 2; i <= 8192; i++) flags[cast(size_t)i] = 1; for (i = 2; i <= 8192; i++) { if (flags[cast(size_t)i]) { for (k = i+i; k <= 8192; k += i) flags[cast(size_t)k] = 0; count++; } } } printf("Count: %d\n", count); assert(count == 1028); } catch { printf("Exception: %d\n", k); assert(0); } } /***********************************/ interface I39 { } class C39 : I39 { int x = 432; } void test39() { C39 c = new C39; printf("%p %d\n", c, c.x); assert(c.x == 432); printf("%p\n", cast(I39) c); c = cast(C39) cast(I39) c; printf("%p\n", c); assert(c !is null); } /***********************************/ void test40() { Object x; x = null; x = 0 ? x : null; x = 0 ? null : x; } /***********************************/ int foo42(const(char) *x, ...) { va_list ap; va_start!(typeof(x))(ap, x); printf("&x = %p, ap = %p\n", &x, ap); int i; i = va_arg!(typeof(i))(ap); printf("i = %d\n", i); long l; l = va_arg!(typeof(l))(ap); printf("l = %lld\n", l); uint k; k = va_arg!(typeof(k))(ap); printf("k = %u\n", k); va_end(ap); return cast(int)(i + l + k); } void test42() { int j; j = foo42("hello", 3, 23L, 4); printf("j = %d\n", j); assert(j == 30); } /***********************************/ void test43() { creal C,Cj; real y1,x1; C = x1 + y1*1i + Cj; C = 1i*y1 + x1 + Cj; C = Cj + 1i*y1 + x1; C = y1*1i + Cj + x1; C = 1i*y1 + Cj; C = Cj + 1i*y1; } /***********************************/ int x44; class A44 { this() { printf("A44 ctor\n"); x44 += 1; } ~this() { printf("A44 dtor\n"); x44 += 0x100; } } class B44 : A44 { } void foo44() { scope B44 b = new B44; } void test44() { printf("foo44...\n"); foo44(); printf("...foo44\n"); assert(x44 == 0x101); } /***********************************/ /* import std.stdarg; import std.utf; int unFormat( bool delegate( out dchar ) getc, bool delegate( dchar ) ungetc, TypeInfo[] arguments, void* argptr ) { size_t arg = 0; dchar[] fmt; if( arguments[arg] is typeid( string ) ) fmt = toUTF32( va_arg!(string)( argptr ) ); else if( arguments[arg] is typeid( wchar[] ) ) fmt = toUTF32( va_arg!(wchar[])( argptr ) ); else if( arguments[arg] is typeid( dchar[] ) ) fmt = va_arg!(dchar[])( argptr ); else return 0; } */ void test45() { } /***********************************/ int sreadf( ... ) { va_arg!(string)( _argptr ); return 0; } void test46() { printf( "hello world\n" ); } /***********************************/ void test48() { try{ }finally{ debug(p48) { } } } /***********************************/ void test49() { int k = 1; if(k == 0) debug{printf("test");} } /***********************************/ void test50() { int x; if (x) version (none) foo; } /***********************************/ /+ void foo51(creal a) { writeln(a); assert(a == -8i); } void test51() { cdouble a = (2-2i)*(2-2i); // This fails writeln(a); assert(a == -8i); // This works writeln((2-2i)*(2-2i)); // This fails foo51((2-2i)*(2-2i)); } +/ void foo51(creal a) { assert(a == -8i); } void test51() { assert((2-2i)*(2-2i) == -8i); cdouble a = (2-2i)*(2-2i); assert(a == -8i); foo51((2-2i)*(2-2i)); } /***********************************/ // Bug 391 void test52() { char[] a; a = "\u3026\u2021\u3061\n".dup; assert(a =="\u3026\u2021\u3061\n"); assert(a.sort == "\n\u2021\u3026\u3061"); assert(a.reverse =="\u3061\u3026\u2021\n"); } /***********************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test24(); test25(); test26(); test27(); test28(); test29(); test30(); test31(); test32(); test33(); test34(); test35(); test36(); test37(); test38(); test39(); test40(); test42(); test43(); test44(); test45(); test46(); test48(); test49(); test50(); test51(); test52(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/interpret2.d0000644000175000017500000000461313200164642023656 0ustar matthiasmatthias //import std.stdio; extern(C) int printf(const char*, ...); template Tuple(A...) { alias A Tuple; } template eval(A...) { const typeof(A[0]) eval = A[0]; } /************************************************/ int foo1() { int x; foreach (i; 0 .. 10) x += i; return x; } int bar1() { int x; foreach_reverse (i; 0 .. 10) { x <<= 1; x += i; } return x; } void test1() { const y = foo1(); //writeln(y); assert(y == 45); auto y1 = foo1(); //writeln(y1); assert(y1 == 45); const z = bar1(); //writeln(z); assert(z == 8194); auto z1 = bar1(); //writeln(z1); assert(z1 == 8194); } /***** Bug 2850 *********************************/ /* These tests are not passing, and shouldn't pass. A non-first field in a union being initialized cannot be converted to an expression, at least not until there are improvements to StructLiterals. */ version (none) { struct Bug2850 { union { int c; double d; } int b; int a; } static assert(is(typeof( () { enum Bug2850 w = {b:47, 714, d:4}; return w; } ))); static assert(is(typeof( () { enum Bug2850 w = {b:47, d:4}; return w; } ))); // union not initialized static assert(!is(typeof( () { enum Bug2850 w = {b:47, 4}; return w; } ))); // initializers for two fields in same union static assert(!is(typeof( () { enum Bug2850 w = {b:47, 4, c:5, 9}; return w; } ))); enum Bug2850 test2850 = {b:47, 714, d:23.1e-17}; struct Horrid2850 { union { int a; int b; struct { int c; int d; } } int f; double q; } enum Horrid2850 horrid2850 = {c:5,6}; Horrid2850 m2850 = {47, f:6}; Horrid2850 z2850 = {q:5, c:4, d:5}; static assert(!is(typeof( () { enum Horrid2850 w = {c:47, d:5, a:7}; return w; } ))); void test2() { assert(test2850.a == 714); assert(test2850.b == 47); assert(test2850.d == 23.1e-17); assert(test2850.c != 0); } } /***** Bug 3779 *********************************/ static const bug3779 = ["123"][0][$-1]; /***** Bug 1880 *********************************/ enum Property1880 {First=1,Second=2} struct CompileTimeCheck1880(Property1880 Prop) { alias Prop prop; } Property1880 junkprop1880; static assert(!is(CompileTimeCheck1880!(junkprop1880))); int main() { test1(); // test2(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testaa2.d0000644000175000017500000001507113200164642023123 0ustar matthiasmatthias// PERMUTE_ARGS: extern(C) int printf(const char*, ...); /************************************************/ int a[string]; size_t foo(immutable char [3] s) { printf("foo()\n"); int b[string]; string[] key; int[] value; printf("foo() 2\n"); key = a.keys; printf("foo() 3\n"); value = a.values; printf("foo() 4\n"); return a.length + b.length; } void foo2() { int c[string]; string[] key; int[] value; int i; assert(c.length == 0); key = c.keys; assert(key.length == 0); value = c.values; assert(value.length == 0); c["foo"] = 3; assert(c["foo"] == 3); assert(c.length == 1); key = c.keys; assert(key.length == 1); value = c.values; assert(value.length == 1); assert(value[0] == 3); c["bar"] = 4; assert(c["bar"] == 4); assert(c.length == 2); key = c.keys; assert(key.length == 2); value = c.values; assert(value.length == 2); for (i = 0; i < key.length; i++) { printf("c[\"%.*s\"] = %d\n", key[i].length, key[i].ptr, value[i]); } assert("foo" in c); c.remove("foo"); assert(!("foo" in c)); assert(c.length == 1); assert("bar" in c); c.remove("bar"); assert(!("bar" in c)); assert(c.length == 0); } void testaa() { size_t i = foo("abc"); printf("i = %d\n", i); assert(i == 0); foo2(); } /************************************************/ void test1899() { int[3][string] AA; int[3] x = [5,4,3]; AA["abc"] = x; assert(AA["abc"] == x); AA["def"] = [1,2,3]; assert(AA["def"]==[1,2,3]); } /************************************************/ void foo4523() { int[string] aa = ["test":0, "test2":1]; bool found = aa.remove("test"); assert(found); bool notfound = aa.remove("nothing"); assert(!notfound); } void test4523() { foo4523(); static assert({ foo4523(); return true; }()); } /************************************************/ // 3825 import std.math; // necessary for ^^= void test3825() { // Check for RangeError is thrown bool thrown(T)(lazy T cond) { import core.exception; bool f = false; try { cond(); } catch (RangeError e) { f = true; } return f; } int[int] aax; int[][int] aay; aax = null, aay = null; assert(thrown(aax[0])); assert(thrown(aax[0] = aax[0])); // rhs throws assert(thrown(aax[0] += aax[0])); // rhs throws assert(thrown(aax[0] ^^= aax[0])); // rhs throws assert(thrown(aay[0] ~= aay[0])); // rhs throws aax = null; aax[0] = 1; assert(aax[0] == 1); // setting aax[0] is OK aax = null; aax[0] += 1; assert(aax[0] == +1); // setting aax[0] to 0 and modify it is OK aax = null; aax[0] ^^= 1; assert(aax[0] == 0); // setting aax[0] to 0 and modify it is OK aay = null; aay[0] ~= []; assert(aay[0] == []); // setting aay[0] to 0 and modify it is OK aax = null; ++aax[0]; assert(aax[0] == +1); // setting aax[0] to 0 and modify it is OK aax = null; --aax[0]; assert(aax[0] == -1); // setting aax[0] to 0 and modify it is OK aax = [0:0], aay = [0:null]; assert(thrown(aax[aax[1]] = 1)); // accessing aax[1] in key part throws assert(thrown(aax[aax[1]] += 1)); // accessing aax[1] in key part throws assert(thrown(aax[aax[1]] ^^= 1)); // accessing aax[1] in key part throws assert(thrown(aay[aax[1]] ~= [])); // accessing aax[1] in key part throws //assert(thrown(aax[( aax[1], 0)] = 0)); /* accessing aax[1] in key part, why doesn't throw? * Because, in aax[(aax[1], 0)], aax[1] is in lhs of comma expression, and is treated * it has no side effect. Then optimizer eliminate it completely, and * whole expression succeed to run in runtime. */ int n = 0; assert(thrown(aax[(n=aax[1], 0)] = 0)); // accessing aax[1] in key part, throws OK // This works as expected. int[int][int] aaa; aaa[0][0] = 0; assert(aaa[0][0] == 0); // setting aaa[0][0] is OK // real test cases void bug3825() { string[] words = ["how", "are", "you", "are"]; int[string] aa1; foreach (w; words) aa1[w] = ((w in aa1) ? (aa1[w] + 1) : 2); //writeln(aa1); // Prints: [how:1,you:1,are:2] int[string] aa2; foreach (w; words) if (w in aa2) aa2[w]++; else aa2[w] = 2; //writeln(aa2); // Prints: [how:2,you:2,are:3] assert(aa1 == aa2); assert(aa1 == ["how":2, "you":2, "are":3]); assert(aa2 == ["how":2, "you":2, "are":3]); } void bug5021() { int func() { throw new Exception("It's an exception."); } int[string] arr; try { arr["hello"] = func(); } catch(Exception e) { } assert(arr.length == 0); } void bug7914() { size_t[ubyte] aa; aa[0] = aa.length; assert(aa[0] == 0); } void bug8070() { Object[string] arr; class A { this() { // at this point: assert("x" !in arr); } } arr["x"] = new A(); } bug3825(); bug5021(); bug7914(); bug8070(); } void test3825x() { return; // depends on AA implementation static int ctor, cpctor, dtor; static struct S { this(int) { ++ctor; } this(this) { ++cpctor; } ~this() { ++dtor; } } int[S] aa; { auto value = S(1); assert(ctor==1 && cpctor==0 && dtor==0); ref getRef(ref S s = value) { return s; } auto getVal() { return value; } aa[value] = 10; assert(ctor==1 && cpctor==1 && dtor==0); aa[getRef()] += 1; assert(ctor==1 && cpctor==1 && dtor==0); aa[getVal()] += 1; assert(ctor==1 && cpctor==2 && dtor==1); } assert(ctor==1 && cpctor==2 && dtor==2); assert(ctor + cpctor - aa.length == dtor); } /************************************************/ // 10106 struct GcPolicy10106 {} struct Uint24Array10106(SP = GcPolicy10106) { this(this) {} } struct InversionList10106(SP = GcPolicy10106) { Uint24Array10106!SP data; } alias InversionList10106!GcPolicy10106 CodepointSet10106; struct PropertyTable10106 { CodepointSet10106[string] table; } /************************************************/ int main() { testaa(); test1899(); test4523(); test3825(); test3825x(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/eh.d0000644000175000017500000002736013200164642022160 0ustar matthiasmatthias// PERMUTE_ARGS: -O -fPIC extern(C) int printf(const char*, ...); /****************************************************/ class Abc : Exception { this() { super(""); } int i; } int y; alias int boo; void foo(int x) { y = cast(boo)1; L6: try { printf("try 1\n"); y += 4; if (y == 5) goto L6; y += 3; } finally { y += 5; printf("finally 1\n"); } try { printf("try 2\n"); y = 1; if (y == 4) goto L6; y++; } catch (Abc c) { printf("catch 2\n"); y = 2 + c.i; } y++; printf("done\n"); } /****************************************************/ class IntException : Exception { this(int i) { m_i = i; super(""); } int getValue() { return m_i; } int m_i; } void test2() { int cIterations = 10; int i; long total_x = 0; long total_nox = 0; for(int WARMUPS = 2; WARMUPS-- > 0; ) { for(total_x = 0, i = 0; i < cIterations; ++i) { total_nox += fn2_nox(); } printf("foo\n"); for(total_nox = 0, i = 0; i < cIterations; ++i) { printf("i = %d\n", i); try { int z = 1; throw new IntException(z); } catch(IntException x) { printf("catch, i = %d\n", i); total_x += x.getValue(); } } } printf("iterations %d totals: %ld, %ld\n", cIterations, total_x, total_nox); } int fn2_nox() { return 47; } /****************************************************/ void test3() { static int x; try { } finally { printf("a\n"); assert(x == 0); x++; } printf("--\n"); assert(x == 1); try { printf("tb\n"); assert(x == 1); } finally { printf("b\n"); assert(x == 1); x++; } assert(x == 2); } /****************************************************/ class Tester { this(void delegate() dg_) { dg = dg_; } void delegate() dg; void stuff() { dg(); } } void test4() { printf("Starting test\n"); int a = 0; int b = 0; int c = 0; int d = 0; try { a++; throw new Exception("test1"); a++; } catch(Exception e) { auto es = e.toString(); printf("%.*s\n", es.length, es.ptr); b++; } finally { c++; } printf("initial test.\n"); assert(a == 1); assert(b == 1); assert(c == 1); printf("pass\n"); Tester t = new Tester( delegate void() { try { a++; throw new Exception("test2"); a++; } catch(Exception e) { b++; throw e; b++; } }); try { c++; t.stuff(); c++; } catch(Exception e) { d++; string es = e.toString; printf("%.*s\n", es.length, es.ptr); } assert(a == 2); assert(b == 2); assert(c == 2); assert(d == 1); int q0 = 0; int q1 = 0; int q2 = 0; int q3 = 0; Tester t2 = new Tester( delegate void() { try { q0++; throw new Exception("test3"); q0++; } catch(Exception e) { printf("Never called.\n"); q1++; throw e; q1++; } }); try { q2++; t2.stuff(); q2++; } catch(Exception e) { q3++; string es = e.toString; printf("%.*s\n", es.length, es.ptr); } assert(q0 == 1); assert(q1 == 1); assert(q2 == 1); assert(q3 == 1); printf("Passed!\n"); } /****************************************************/ void test5() { char[] result; int i = 3; while(i--) { try { printf("i: %d\n", i); result ~= 't'; if (i == 1) continue; } finally { printf("finally\n"); result ~= cast(char)('a' + i); } } printf("--- %.*s", result.length, result.ptr); if (result != "tctbta") assert(0); } /****************************************************/ void test6() { char[] result; while (true) { try { printf("one\n"); result ~= 'a'; break; } finally { printf("two\n"); result ~= 'b'; } } printf("three\n"); result ~= 'c'; if (result != "abc") assert(0); } /****************************************************/ string a7; void doScan(int i) { a7 ~= "a"; try { try { a7 ~= "b"; return; } finally { a7 ~= "c"; } } finally { a7 ~= "d"; } } void test7() { doScan(0); assert(a7 == "abcd"); } /**************************************************** * Exception chaining tests. See also test4.d ****************************************************/ int result1513; void bug1513a() { throw new Exception("d"); } void bug1513b() { try { try { bug1513a(); } finally { result1513 |=4; throw new Exception("f"); } } catch(Exception e) { assert(e.msg == "d"); assert(e.next.msg == "f"); assert(!e.next.next); } } void bug1513c() { try { try { throw new Exception("a"); } finally { result1513 |= 1; throw new Exception("b"); } } finally { bug1513b(); result1513 |= 2; throw new Exception("c"); } } void bug1513() { result1513 = 0; try { bug1513c(); } catch(Exception e) { assert(result1513 == 7); assert(e.msg == "a"); assert(e.next.msg == "b"); assert(e.next.next.msg == "c"); } } void collideone() { try { throw new Exception("x"); } finally { throw new Exception("y"); } } void doublecollide() { try { try { try { throw new Exception("p"); } finally { throw new Exception("q"); } } finally { collideone(); } } catch(Exception e) { assert(e.msg == "p"); assert(e.next.msg == "q"); assert(e.next.next.msg == "x"); assert(e.next.next.next.msg == "y"); assert(!e.next.next.next.next); } } void collidetwo() { try { try { throw new Exception("p2"); } finally { throw new Exception("q2"); } } finally { collideone(); } } void collideMixed() { int works = 6; try { try { try { throw new Exception("e"); } finally { throw new Error("t"); } } catch(Exception f) { // Doesn't catch, because Error is chained to it. works += 2; } } catch(Error z) { works += 4; assert(z.msg=="t"); // Error comes first assert(z.next is null); assert(z.bypassedException.msg == "e"); } assert(works == 10); } class AnotherException : Exception { this(string s) { super(s); } } void multicollide() { try { try { try { try { throw new Exception("m2"); } finally { throw new AnotherException("n2"); } } catch(AnotherException s) { // Not caught -- we needed to catch the root cause "m2", not // just the collateral "n2" (which would leave m2 uncaught). assert(0); } } finally { collidetwo(); } } catch(Exception f) { assert(f.msg == "m2"); assert(f.next.msg == "n2"); Throwable e = f.next.next; assert(e.msg == "p2"); assert(e.next.msg == "q2"); assert(e.next.next.msg == "x"); assert(e.next.next.next.msg == "y"); assert(!e.next.next.next.next); } } /****************************************************/ void use9568(char [] x, char [] y) {} int bug9568() { try return 7; finally use9568(null,null); } void test9568() { assert( bug9568() == 7 ); } /****************************************************/ version (DigitalMars) { void test8a() { int a; goto L2; // L2 is not addressable. try { a += 2; } catch (Exception) { a += 3; L2: ; a += 100; } assert(a == 100); } void test8b() { int a; goto L2; // L2 is not addressable. try { } catch (Exception) { a += 3; L2: ; a += 100; } assert(a == 100); } void test8c() { int a; goto L2; // L2 is not addressable. try static assert(true); catch (Exception) { a += 3; L2: ; a += 100; } assert(a == 100); } void test8() { test8a(); test8b(); test8c(); } } /****************************************************/ uint foo9(uint i) { try { ++i; return 3; } catch (Exception e) { debug printf("Exception happened\n"); } return 4; } void test9() { assert(foo9(7) == 3); } /****************************************************/ // 10964 void test10964() { static struct S { this(this) { throw new Exception("BOOM!"); } } S ss; S[1] sa; int result; result = 0; try { ss = ss; } catch (Exception e) result = 1; catch (Error e) result = 2; catch (Throwable e) result = 3; assert(result == 1); try { sa = ss; } catch (Exception e) result = 1; catch (Error e) result = 2; catch (Throwable e) result = 3; assert(result == 1); try { sa = sa; } catch (Exception e) result = 1; catch (Error e) result = 2; catch (Throwable e) result = 3; assert(result == 1); } /****************************************************/ alias Action = void delegate(); class A10 { invariant() { } public Action foo(Action a) { synchronized { B10 elements = new B10; Action[] actions = [a]; elements.bar(actions); if (actions.length > 1) elements.bar(actions); return actions[0]; } return null; } } class B10 { public bool bar(ref Action[]) { return false; } } class D10 { void baz() { } } void test12989() { auto a = new A10; auto d = new D10; assert(a.foo(&d.baz) == &d.baz); } /****************************************************/ int main() { printf("start\n"); foo(3); test2(); test3(); test4(); test5(); test6(); test7(); bug1513(); doublecollide(); collideMixed(); multicollide(); test9568(); version(DigitalMars) test8(); test9(); test10964(); test12989(); printf("finish\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/cabi1.d0000644000175000017500000000726413200164642022544 0ustar matthiasmatthias // EXTRA_CPP_SOURCES: cabi2.cpp import core.stdc.stdio; import core.stdc.config; struct Foo1 { char c; } struct Foo2 { short s; } struct Foo3 { char c; short s; } struct Foo4 { int i; } struct Foo5 { int i, j; } struct Foo6 { int i, j, k; } struct S7 { float a, b; } extern (C) Foo1 ctest1(); extern (C) Foo2 ctest2(); extern (C) Foo3 ctest3(); extern (C) Foo4 ctest4(); extern (C) Foo5 ctest5(); extern (C) Foo6 ctest6(); extern (C) S7 ctest10(); void test1() { Foo1 f1 = ctest1(); assert(f1.c == 3); Foo2 f2 = ctest2(); assert(f2.s == 0x1234); Foo3 f3 = ctest3(); assert(f3.s == 0x5678); Foo4 f4 = ctest4(); assert(f4.i == 0x12345678); version (Win64) { } else { Foo5 f5 = ctest5(); assert(f5.i == 0x12345678); assert(f5.j == 0x21436587); } version (X86) { Foo6 f6 = ctest6(); assert(f6.i == 0x12345678); assert(f6.j == 0x21463587); assert(f6.k == 0x24163857); } version (Win64) { } else { S7 s7 = ctest10(); assert(s7.a == 2.5); assert(s7.b == 1.5); } } /*******************************************/ extern (C) { char ctest7(char); ubyte ctest8(ubyte); byte ctest9(byte); } void test2() { assert(ctest7('a') == 'b'); assert(ctest8(7) == 8); assert(ctest9(3) == 4); } /******************************************/ extern (C) { void ctestrir(int x1, int x2, int x3, int x4, int x5, int x6, c_long_double a, int b, c_long_double c); } void test3() { ctestrir(1,2,3,4,5,6, c_long_double(100.0), 67, c_long_double(200.0)); } /******************************************/ extern (C) void dtestrir(int x1, int x2, int x3, int x4, int x5, int x6, c_long_double a, int b, c_long_double c) { assert(a == 300.0); assert(b == 68); assert(c == 401.0); } extern (C) void test4(); /******************************************/ struct S11 { ubyte a, b, c; } extern (C) S11 ctest11(ubyte x, S11, ubyte y); void test11() { version (X86) { S11 t; assert(S11.sizeof == 3); t.a = 2; t.b = 3; t.c = 4; auto s = ctest11(1, t, 5); assert(s.a == 2); assert(s.b == 3); assert(s.c == 4); } } /******************************************/ struct S12 { char a,d; char b,e; ubyte c; } extern (C) S12 ctest12(ubyte x, S12, ubyte y); void test12() { version (X86) { S12 t; printf("D sz = %d\n", cast(int)S12.sizeof); // assert(S12.sizeof == 5); t.a = 2; t.b = 3; t.c = 4; auto s = ctest12(1, t, 5); assert(s.a == 2); assert(s.b == 3); assert(s.c == 4); } } /******************************************/ struct S13 { ushort a, b, c; } extern (C) S13 ctest13(ubyte x, S13, ubyte y); void test13() { version (X86) { S13 t; assert(S13.sizeof == 6); t.a = 2; t.b = 3; t.c = 4; auto s = ctest13(1, t, 5); assert(s.a == 2); assert(s.b == 3); assert(s.c == 4); } } /******************************************/ struct S14 { char a,d,e,f; char b,g; ubyte c; } extern (C) S14 ctest14(ubyte x, S14, ubyte y); void test14() { version (X86) { S14 t; assert(S14.sizeof == 7); t.a = 2; t.b = 3; t.c = 4; auto s = ctest14(1, t, 5); assert(s.a == 2); assert(s.b == 3); assert(s.c == 4); } } /******************************************/ struct S15 { char a,d,e,f; char b,g,h,i; ubyte c; } extern (C) S15 ctest15(ubyte x, S15, ubyte y); void test15() { version (X86) { S15 t; assert(S15.sizeof == 9); t.a = 2; t.b = 3; t.c = 4; auto s = ctest15(1, t, 5); assert(s.a == 2); assert(s.b == 3); assert(s.c == 4); } } /******************************************/ int main() { test1(); test2(); test3(); version (Win64) { } else { test4(); } test11(); test12(); test13(); test14(); test15(); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/cov2.d0000644000175000017500000000205013200164642022422 0ustar matthiasmatthias// PERMUTE_ARGS: // POST_SCRIPT: runnable/extra-files/cov2-postscript.sh // REQUIRED_ARGS: -cov // EXECUTE_ARGS: ${RESULTS_DIR}/runnable extern(C) void dmd_coverDestPath(string pathname); /***************************************************/ void test1() { int counter = 20; do { --counter; } while(counter > 0); } /***************************************************/ struct S2 { this(this) { int x = 1; } ~this() { int x = 1; } ref S2 opAssign(S2) { return this; } bool opEquals(ref const S2) const { return true; } } struct T2 { S2 s; this(this) { int x = 1; } ~this() { int x = 1; } } void test2() { T2 ta; T2 tb = ta; tb = ta; typeid(T2).equals(&ta, &tb); } /***************************************************/ void test3() { long total = 0; for (size_t i = 0; i < 10_000_000; i++) total += i; } /***************************************************/ int main(string[] args) { dmd_coverDestPath(args[1]); test1(); test2(); test3(); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/bitops.d0000644000175000017500000000615313200164642023061 0ustar matthiasmatthias// PERMUTE_ARGS: import core.stdc.stdio; import core.bitop; /*****************************************************/ void test1() { size_t array[2]; uint x; version (D_LP64) size_t bitToUse = 67; else size_t bitToUse = 35; array[0] = 2; array[1] = 0x100; printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); x = btc(array.ptr, bitToUse); printf("btc(array, %d) = %d\n", bitToUse, x); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); assert(x == 0); assert(array[0] == 0x2 && array[1] == 0x108); x = btc(array.ptr, bitToUse); printf("btc(array, %d) = %d\n", bitToUse, x); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); assert(x != 0); assert(array[0] == 2 && array[1] == 0x100); x = bts(array.ptr, bitToUse); printf("bts(array, %d) = %d\n", bitToUse, x); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); assert(x == 0); assert(array[0] == 2 && array[1] == 0x108); x = btr(array.ptr, bitToUse); printf("btr(array, %d) = %d\n", bitToUse, x); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); assert(x != 0); assert(array[0] == 2 && array[1] == 0x100); x = bt(array.ptr, 1); printf("bt(array, 1) = %d\n", x); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); assert(x != 0); assert(array[0] == 2 && array[1] == 0x100); } /*****************************************************/ void test2() { uint v; int x; v = 0x21; x = bsf(v); printf("bsf(x%x) = %d\n", v, x); assert(x == 0); x = bsr(v); printf("bsr(x%x) = %d\n", v, x); assert(x == 5); } /*****************************************************/ void test3() { uint v; int b; b = inp(b); b = inpw(b); b = inpl(b); b = outp(v, cast(ubyte)b); b = outpw(v, cast(ushort)b); b = outpl(v, b); } /*****************************************************/ void test4() { uint i = 0x12_34_56_78; i = bswap(i); assert(i == 0x78_56_34_12); } /*****************************************************/ void test5() { size_t array[2]; array[0] = 2; array[1] = 0x100; printf("btc(array, 35) = %d\n", btc(array.ptr, 35)); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); printf("btc(array, 35) = %d\n", btc(array.ptr, 35)); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); printf("bts(array, 35) = %d\n", bts(array.ptr, 35)); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); printf("btr(array, 35) = %d\n", btr(array.ptr, 35)); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); printf("bt(array, 1) = %d\n", bt(array.ptr, 1)); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); } /*****************************************************/ class Node { uint leaf = 0; int m() { return leaf ? 0 : bsf(leaf); } } void test6() { Node n = new Node(); } /*****************************************************/ int main() { test1(); test2(); //test3(); test4(); test5(); test6(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test7618.d0000644000175000017500000000032413200164642023060 0ustar matthiasmatthiasinterface ITest { int foo(); final void bar(int k)() { assert(foo() == k); } } class Test : ITest { override int foo() { return 12; } } void main() { auto test = new Test; test.bar!12(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test10.d0000644000175000017500000000033213200164642022672 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test10a.d import imports.test10a; extern(C) int printf(const char*, ...); int main() { imports.test10a.init(); printf("it is %d\n", it[0]); assert(it[0] == 32); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test20.d0000644000175000017500000004624613200164642022711 0ustar matthiasmatthiasimport core.vararg; extern(C) int printf(const char*, ...); /*****************************************/ class A1 { union { struct { int x; public int y; } protected int z; } } class A2 { struct { int x; public int y; } } class A3 { union { int x; public int y; } } void test1() { A1 a1 = new A1(); A2 a2 = new A2(); A3 a3 = new A3(); a1.x = 1; a1.y = 2; a1.z = 3; assert(a1.x == 3); assert(a1.y == 2); a2.x = 1; a2.y = 2; assert(a2.x == 1); a3.x = 1; a3.y = 2; assert(a3.x == 2); } /*****************************************/ struct A4 { union { struct { int x = 13; } int y; } } void test4() { printf("A4.sizeof = %d\n", A4.sizeof); assert(A4.sizeof == 1 * int.sizeof); A4 q; assert(q.y == 13); } /*****************************************/ class A5 { union { struct { int x; } public int y; } } void test5() { A5 a = new A5; a.x = 3; a.y = 4; assert(a.x == 4); } /*****************************************/ int i6 = 5; float m6 = 5.0; void test6() { void f() { void i6(float j) { m6 = j; } void g() { i6 = 1; } g(); } f(); printf( "%d %f\n", i6, m6); assert(i6 == 5); assert(m6 == 1); } /*****************************************/ const int a1 = 50; const int a2 = 50; const int a3 = a1 * a2; const int b1 = a1 - 1; const int b2 = a2 - 1; const int c1 = 50*50; const int c2 = (a1-1)*(a2-1); const int c3 = b1*b2; int[4*c1] array1; // illegal! int[4*c2] array2; // illegal! int[4*c3] array3; // illegal! int[a3] array4; // valid! no error! void test7() { assert(a1 == 50); assert(a2 == 50); assert(a3 == 2500); assert(b1 == 49); assert(b2 == 49); assert(c1 == 2500); assert(c2 == 2401); assert(c3 == 2401); assert(array1.length == 10000); assert(array2.length == 9604); assert(array3.length == 9604); } /*****************************************/ struct Foo8 { static Foo8 bar() { Foo8 res; return res; } } void test8() { Foo8[8] x; x[] = Foo8.bar; } /*****************************************/ void test9() { try { } catch (Exception e) { debug printf("Exception happened\n"); } } /*****************************************/ struct Foo10 { const bool opEquals(const ref Foo10 x) { return this.normalize is x.normalize; } const Foo10 normalize() { Foo10 res; return res; } } void test10() { } /*****************************************/ scope class T11 { this(){} ~this(){} } void test11() { scope T11 t=new T11(); int i=1; switch(i) { case 1: break; default: break; } } /*****************************************/ void test12() { char[] s; char[] t; if (true) s = null; s = (true) ? null : t; t = (true) ? s : null; } /*****************************************/ class Foo13 { int init (int x) { return 1; } static int init (long y) { return 2; } } void test13() { Foo13 f = new Foo13(); int i; i = f.init(1); assert(i == 1); i = f.init(1L); assert(i == 2); } /*****************************************/ void write14(bool[] c) { printf("[%2d]: ", c.length); foreach (bool x; c) printf("%d,", x); printf("\n"); } void test14() { static bool[] a = [ 1, 1, 0, 1, 0 ]; static bool[] b = [ 1, 0, 0, 1 ]; bool[] c = a ~ b; static bool[] r1 = [1,1,0,1,0,1,0,0,1]; static bool[] r2 = [1,1,0,1,0,1,0,0,1,1,1,0,1,0]; static bool[] r3 = [1,1,0,1,0,1,0,0,1,1,1,0,1,0,0]; static bool[] r4 = [1,1,0,1,0,1,0,0,1,1,1,0,1,0,0,1]; write14(c); assert(c == r1); c ~= a; write14(c); assert(c == r2); c ~= 0; write14(c); assert(c == r3); c ~= 1; write14(c); assert(c == r4); } /*****************************************/ void test15() { bool[] b; bool[] c; b.length = 10; c = b[0..4]; c[] = true; assert(b[0] == true); assert(b[1] == true); assert(b[2] == true); assert(b[3] == true); assert(b[4] == false); assert(b[5] == false); assert(b[6] == false); assert(b[7] == false); assert(b[8] == false); assert(b[9] == false); } /*****************************************/ int y16; class C16 { new(size_t size, byte blah){ void* v = (new byte[C16.classinfo.init.length]).ptr; y16 = 1; assert(blah == 3); return v; } int x; this() { x = 4; } } void test16() { C16 c = new(3) C16; assert(y16 == 1); assert(c.x == 4); } /*****************************************/ ubyte* ptr17; void test17() { ubyte[16] foo; printf("foo = %p\n", foo.ptr); ptr17 = foo.ptr; abc17(foo); } void abc17(ref ubyte[16] bar) { printf("bar = %p\n", bar.ptr); assert(bar.ptr == ptr17); } /*****************************************/ struct Iterator18(T) { T* m_ptr; const bool opEquals(const ref Iterator18 iter) { return (m_ptr == iter.m_ptr); } const int opCmp(const ref Iterator18 iter) { return cast(int)(m_ptr - iter.m_ptr); } } void test18() { Iterator18!(int) iter; } /*****************************************/ struct S29(T) { const bool opEquals(const ref S29!(T) len2) { return 0; } const int opCmp(const ref S29!(T) len2) { return 0; } } void test19() { TypeInfo info = typeid(S29!(int)); } /*****************************************/ class Mapped : Buffer { this() { } ~this() { } } class Buffer { private uint limit; private uint capacity; private uint position; invariant() { assert (position <= limit); assert (limit <= capacity); } } void test20() { Buffer b = new Buffer(); delete b; } /*****************************************/ class T21 { char[1] p1; char[1] p2; public: char[] P() {return p1~p2;} } void test21() { T21 t = new T21; t.p1[0] = 'a'; t.p2[0] = 'b'; assert(t.P() == "ab"); } /*****************************************/ void test22() { struct foo1 { int a; int b; int c; } class foo2 { foo1[] x; foo1 fooret(foo1 foo2) { x.length = 9; return x[0] = foo2; // Here // x[0] = foo2; --- This version does not // return x[0]; --- cause the error. } } } /*****************************************/ void test23() { float f; double d; real r; if (f > ifloat.max) goto Loverflow; if (d > ifloat.max) goto Loverflow; if (r > ifloat.max) goto Loverflow; if (ifloat.max < f) goto Loverflow; if (ifloat.max < d) goto Loverflow; if (ifloat.max < r) goto Loverflow; return; Loverflow: return; } /*****************************************/ interface I24 { } void test24() { } /*****************************************/ interface D25{} interface C25:D25{} interface B25:C25{} interface A25:B25{} void test25() { } class A26:B26{} interface B26:C26{} interface C26:D26{} interface D26{} void test26() { } interface A27:B27{} interface B27:C27{} interface C27:D27{} interface D27{} void test27() { } /*****************************************/ void test28() { const double d = -1.0; int i = cast(int)d; printf("i = %d\n", i); assert(-1 == i); } /*****************************************/ static int[1][5] array = [[1],[2],[3],[4],[5] ]; void Lookup( int which ) { switch( which ) { case 0 : return cast(void)array[which]; default: assert(0); } } void test29() { } /*****************************************/ void test30() { double d = 1; cdouble cd = 1+0i; assert(cd == 1.0 + 0i); } /*****************************************/ void foo31(...) { byte b = va_arg!byte(_argptr); assert(b == 8); } void test31() { byte x = 9; foo31(--x); --x; foo31(++x); } /*****************************************/ template Foo33(T, int L) { T[L] arr; class Bar { int before = 6; T[L] arr; int after = 7; } } void test33() { alias Foo33!(int, 100) foo; foreach (int x; foo.arr) assert(x == int.init); foo.Bar bar = new foo.Bar(); foreach (int x; bar.arr) { //printf("%d\n", x); assert(x == int.init); } } /*****************************************/ void test34() { bool[1] a; bool[1] b; bool[] concat() { return a~b; } a[]=0; b[]=1; bool[] arr=concat(); assert(arr.length==2); assert(arr[0]==0); assert(arr[1]==1); } /*****************************************/ void dummy35(...) {} void test35() { byte x = 9; dummy35(x); int y = --x; assert (y == 8); assert (x == 8); } /*****************************************/ void test36() { int[] a; a.length = 2; a[0]=1; a[1]=2; int[] b; b.length = 1; b[0]=3; a~=b; assert(a.length==3); assert(a[0]==1); assert(a[1]==2); assert(a[2]==3); assert(b.length==1); assert(b[0]==3); } /*****************************************/ struct Range{ int width(){ return 1; } } class Container { Range opIndex(int i){ return data[i]; } Range[2] data; } void test37() { Container ranges=new Container; // fails with -inline // assert(ranges[0].width() == 1); } /*****************************************/ void test38() { uint mask = (uint.max >> 1); assert(mask == (uint.max >> 1)); } /*****************************************/ void test39() { char[] a; char[] r; a = "abcd".dup; r = a.reverse; assert(r=="dcba"); assert(r.ptr==a.ptr); a = "-\U000000A1\U00000901\U0000FFEE\U00010000\U000FFFFD_".dup; r = a.reverse; assert(r == "_\U000FFFFD\U00010000\U0000FFEE\U00000901\U000000A1-"); assert(a.ptr==r.ptr); } /*****************************************/ void test40() { wchar[] a; wchar[] r; a = "abcd"w.dup; a = a.dup; r = a.reverse; assert(r=="dcba"); assert(r.ptr==a.ptr); a = "-\U000000A1\U00000901\U0000FFEE\U00010000\U000FFFFD_"w.dup; a = a.dup; r = a.reverse; assert(r == "_\U000FFFFD\U00010000\U0000FFEE\U00000901\U000000A1-"); assert(a.ptr==r.ptr); } /*****************************************/ void test41() { assert(new void[40] == new void[40]); } /*****************************************/ void test42() { static ubyte[] master = [ 0xE3u, 0x83u, 0xAFu, 0xE3u, 0x83u, 0xADu, 0xE3u, 0x82u, 0xB9u, 0xEFu, 0xBDu, 0x97u ]; string string1 = "ワロスw"; string string2 = r"ワロスw"; string string3 = `ワロスw`; string string4 = x"E3 83 AF E3 83 AD E3 82 B9 EF BD 97"; assert(string1.length==master.length); for(int i=0; i= i; j -= i) { // interesting results follow from this: printf("%d ", i); // it prints a _lot_ of ones arr[j] = arr[j - i]; } } void test61() { real[] array; array.length = 2; // whatever, as long as it's more than 1 foreach (ref real i; array) i = 1; // just something foo61(array); } /*****************************************/ void bug7493() { string str = "abcde"; const(void) [][1] arr = [str]; assert(arr[0].length == str.length); const(void) [][1] arr2; arr2 = [str]; assert(arr[0].length == str.length); } /*****************************************/ int main() { test1(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); test28(); test29(); test30(); test31(); test33(); test34(); test35(); test36(); test37(); test38(); test39(); test40(); test41(); test42(); test43(); test44(); test45(); test46(); test47(); test48(); test49(); test50(); test51(); test52(); test53(); test54(); test55(); test56(); test57(); test58(); test59(); test60(); test61(); bug7493(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test30.d0000644000175000017500000000020313200164642022671 0ustar matthiasmatthias// 444 int main() { int nothing( int delegate(ref int) dg ) {return 0;} foreach(int x; ¬hing) return 7; return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/gdb10311.d0000644000175000017500000000031413200164642022674 0ustar matthiasmatthias/* REQUIRED_ARGS: -g PERMUTE_ARGS: GDB_SCRIPT: --- b 19 r echo RESULT= p x --- GDB_MATCH: RESULT=.*33 */ void call(void delegate() dg) { dg(); } void main() { int x=32; call({++x;}); // BP } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test2.sh0000755000175000017500000000132413200164642023007 0ustar matthiasmatthias#!/usr/bin/env bash dir=${RESULTS_DIR}/runnable dmddir=${RESULTS_DIR}${SEP}runnable output_file=${dir}/test2.sh.out rm -f ${output_file} a[0]='' a[1]='-debug' a[2]='-debug=1' a[3]='-debug=2 -debug=bar' for x in "${a[@]}"; do echo "executing with args: $x" >> ${output_file} $DMD -m${MODEL} $x -unittest -od${dmddir} -of${dmddir}${SEP}test2${EXE} runnable/extra-files/test2.d >> ${output_file} if [ $? -ne 0 ]; then cat ${output_file} rm -f ${output_file} exit 1 fi ${dir}/test2 >> ${output_file} if [ $? -ne 0 ]; then cat ${output_file} rm -f ${output_file} exit 1 fi rm ${dir}/{test2${OBJ},test2${EXE}} echo >> ${output_file} done ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test10567.sh0000755000175000017500000000071513200164642023333 0ustar matthiasmatthias#!/usr/bin/env bash src=runnable${SEP}extra-files dir=${RESULTS_DIR}${SEP}runnable output_file=${dir}/test10567.sh.out $DMD -m${MODEL} -I${src} -of${dir}${SEP}test10567a${OBJ} -c ${src}${SEP}test10567a.d || exit 1 $DMD -m${MODEL} -I${src} -of${dir}${SEP}test10567${EXE} ${src}${SEP}test10567.d ${dir}${SEP}test10567a${OBJ} || exit 1 ${RESULTS_DIR}/runnable/test10567${EXE} || exit 1 rm ${dir}/{test10567a${OBJ},test10567${EXE}} echo Success >${output_file} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/helloUTF16BE.d0000644000175000017500000000016213200164642023613 0ustar matthiasmatthiasextern(C) int printf(const char *, ...); int main(char[][] args) { printf("hello world\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ice10857.d0000644000175000017500000000012513200164642022717 0ustar matthiasmatthias// EXTRA_SOURCES: imports/ice10857a.d imports/ice10857b.d import imports.ice10857a; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test13117b.d0000644000175000017500000000043513200164642023274 0ustar matthiasmatthias// REQUIRED_ARGS: -inline // PERMUTE_ARGS: -O -release -g import std.file, std.stdio; int main() { auto size = thisExePath.getSize(); writeln(size); version (D_LP64) enum limit = 2023652; else enum limit = 1763328; return size > limit * 11 / 10; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/implicit.d0000644000175000017500000002732113200164642023373 0ustar matthiasmatthias import std.stdio; /***********************************/ template cat1(T) { T cat1(T i) { return i + 1; } } void test1() { auto a = cat1(1); assert(a == 2); } /***********************************/ template cat2(T) { T cat2(T* p) { return *p + 1; } } void test2() { int i = 1; auto a = cat2(&i); assert(a == 2); assert(typeid(typeof(a)) == typeid(int)); } /***********************************/ struct S3 { } template cat3(T) { T cat3(T* p, S3 s) { return *p + 1; } } void test3() { S3 s; int i = 1; auto a = cat3(&i, s); assert(a == 2); assert(typeid(typeof(a)) == typeid(int)); } /***********************************/ template cat4(T, int N) { T cat4(T[N] p, T[N] q) { return p[0] + N; } } void test4() { int[3] i; i[0] = 7; i[1] = 8; i[2] = 9; auto a = cat4(i, i); assert(a == 10); assert(typeid(typeof(a)) == typeid(int)); } /***********************************/ template cat5(T, U=T*, int V=7) { T cat5(T x) { U u = &x; return x + 3 + *u + V; } } void test5() { int x = 2; auto a = cat5(x); assert(a == 14); assert(typeid(typeof(a)) == typeid(int)); auto b = cat5!(int,int*,8)(x); assert(b == 15); assert(typeid(typeof(b)) == typeid(int)); } /***********************************/ int* pureMaker() pure { return [1,2,3,4].ptr + 1; } void testDIP29_1() { int* p; static assert(!__traits(compiles, { immutable x = p + 3; })); immutable x = pureMaker() + 1; immutable y = pureMaker() - 1; immutable z = 1 + pureMaker(); } /***********************************/ int** pureMaker2() pure { int*[] da = [[11,12,13].ptr, [21,22,23].ptr, [31,32,33].ptr, [41,42,43].ptr]; return da.ptr + 1; } void testDIP29_2() { immutable x2 = pureMaker2() + 1; immutable y2 = pureMaker2() - 1; immutable z2 = 1 + pureMaker2(); } /***********************************/ int[] pureMaker3a() pure { return new int[4]; } int* pureMaker3b() pure { return new int[4].ptr; } int[4] pureMaker3c() pure { int[4] buf; return buf; } void testDIP29_3() { immutable x1 = pureMaker3a()[]; immutable x2 = pureMaker3a()[0..2]; immutable y2 = pureMaker3b()[0..2]; // Conversion from *rvalue* of mutable static array to immutable slice immutable z1 = pureMaker3c()[]; immutable z2 = pureMaker3c()[0..2]; // Issue 12467 - conversion from lvalue of mutable static array to immutable slice char[3] arr = "foo"; static assert(!__traits(compiles, { string str = arr[]; })); } /***********************************/ import core.vararg; int* maker() pure { return null; } int* maker1(int *) pure { return null; } int* function(int *) pure makerfp1; int* maker2(int *, ...) pure { return null; } int* maker3(int) pure { return null; } int* maker4(ref int) pure { return null; } int* maker5(ref immutable int) pure { return null; } void testDIP29_4() { { immutable x = maker1(maker()); } { immutable x = maker1(null); } static assert(__traits(compiles, { immutable x = (*makerfp1)(maker()); })); { shared x = maker1(null); } { immutable x = maker2(null, 3); } { immutable int g; immutable x = maker2(null, 3, &g); } static assert(!__traits(compiles, { int g; immutable x = maker2(null, 3, &g); })); { immutable x = maker3(1); } static assert(!__traits(compiles, { int g; immutable x = maker4(g); })); { immutable int g; immutable x = maker5(g); } } /***********************************/ // 14155 immutable int g14155; static this() { g14155 = 1; } int* make14155m ( int* p) pure { return null; } const(int*) make14155c ( const(int*) p) pure { return &g14155; } immutable(int*) make14155i ( immutable(int*) p) pure { return &g14155; } shared(int*) make14155sm( shared(int*) p) pure { return null; } shared(const int*) make14155sc(shared(const int*) p) pure { return &g14155; } void test14155_for_testDIP29_4() { static assert( __traits(compiles, { int* p = make14155m (null); })); // m <- m (normal) static assert( __traits(compiles, { const(int*) p = make14155m (null); })); // c <- m (normal) static assert( __traits(compiles, { shared(int*) p = make14155m (null); })); // sm <- m (unique) static assert( __traits(compiles, { shared(const int*) p = make14155m (null); })); // sc <- m (unique) static assert( __traits(compiles, { immutable(int*) p = make14155m (null); })); // i <- m (unique) static assert(!__traits(compiles, { int* p = make14155c (null); })); // m <- c (NG) static assert( __traits(compiles, { const(int*) p = make14155c (null); })); // c <- c (normal) static assert(!__traits(compiles, { shared(int*) p = make14155c (null); })); // sm <- c (NG) static assert( __traits(compiles, { shared(const int*) p = make14155c (null); })); // sc <- c (unique or immutable global) static assert( __traits(compiles, { immutable(int*) p = make14155c (null); })); // i <- c (unique or immutable global) static assert(!__traits(compiles, { int* p = make14155i (null); })); // m <- i (NG) static assert( __traits(compiles, { const(int*) p = make14155i (null); })); // c <- i (normal) static assert(!__traits(compiles, { shared(int*) p = make14155i (null); })); // sm <- i (NG) static assert( __traits(compiles, { shared(const int*) p = make14155i (null); })); // sc <- i (normal) static assert( __traits(compiles, { immutable(int*) p = make14155i (null); })); // i <- i (normal) static assert( __traits(compiles, { int* p = make14155sm(null); })); // m <- sm (unique) static assert( __traits(compiles, { const(int*) p = make14155sm(null); })); // c <- sm (unique) static assert( __traits(compiles, { shared(int*) p = make14155sm(null); })); // sm <- sm (normal) static assert( __traits(compiles, { shared(const int*) p = make14155sm(null); })); // sc <- sm (normal) static assert( __traits(compiles, { immutable(int*) p = make14155sm(null); })); // i <- sm (unique) static assert(!__traits(compiles, { int* p = make14155sc(null); })); // m <- sc (NG) static assert( __traits(compiles, { const(int*) p = make14155sc(null); })); // c <- sc (unique or immutable global) static assert(!__traits(compiles, { shared(int*) p = make14155sc(null); })); // sm <- sc (NG) static assert( __traits(compiles, { shared(const int*) p = make14155sc(null); })); // sc <- sc (normal) static assert( __traits(compiles, { immutable(int*) p = make14155sc(null); })); // i <- sc int x; int* nestf() pure { return &x; } static assert(!__traits(compiles, { immutable(int*) ip = nestf(); })); } /***********************************/ // 14141 struct S14141 { Object obj; const(Object) getObj() const pure { return obj; } } void test14141() { const S14141 s; static assert(is(typeof(s.getObj()) == const Object)); // ok static assert(!__traits(compiles, { Object o = s.getObj(); })); // ok <- fails } /***********************************/ int[] test6(int[] a) pure @safe nothrow { return a.dup; } /***********************************/ int*[] pureFoo() pure { return null; } void testDIP29_5() pure { { char[] s; immutable x = s.dup; } { immutable x = (cast(int*[])null).dup; } { immutable x = pureFoo(); } { immutable x = pureFoo().dup; } } /***********************************/ void testDIP29_6() { /******* structs ************/ static assert(__traits(compiles, { static struct S { int *p; } immutable s = new S; // since p is null })); static assert(!__traits(compiles, { __gshared int x; static struct S { int *p = &x; } immutable s = new S; // x is mutable })); static assert(!__traits(compiles, { int y; struct S { int x; void bar() { y = 3; } } immutable s = new S; // nested struct })); static assert(!__traits(compiles, { static struct S { int x; this(int); } immutable s = new S(1); })); static assert(__traits(compiles, { static struct S { int x; this(int) pure; } immutable s = new S(1); })); static assert(__traits(compiles, { static struct S { int* p = void; this(int) pure; } immutable s = new S(1); })); static assert(!__traits(compiles, { static struct S { int* p = void; this(int*) pure; } int x; immutable s = new S(&x); })); static assert(__traits(compiles, { static struct S { int* p = void; this(immutable(int)*) pure; } immutable int x; immutable s = new S(&x); })); static assert(__traits(compiles, { static struct S { int* p = void; this(int*) pure; } immutable s = new S(null); })); /******* classes ************/ static assert(__traits(compiles, { static class S { int *p; } immutable s = new S; // since p is null })); static assert(!__traits(compiles, { __gshared int x; static class S { int *p = &x; } immutable s = new S; // x is mutable })); static assert(!__traits(compiles, { int y; class S { int x; void bar() { y = 3; } } immutable s = new S; // nested class })); static assert(!__traits(compiles, { static class S { int x; this(int); } immutable s = new S(1); })); static assert(__traits(compiles, { static class S { int x; this(int) pure; } immutable s = new S(1); })); static assert(__traits(compiles, { static class S { int* p = void; this(int) pure; } immutable s = new S(1); })); static assert(!__traits(compiles, { static class S { int* p = void; this(int*) pure; } int x; immutable s = new S(&x); })); static assert(__traits(compiles, { static class S { int* p = void; this(immutable(int)*) pure; } immutable int x; immutable s = new S(&x); })); static assert(__traits(compiles, { static class S { int* p = void; this(int*) pure; } immutable s = new S(null); })); } // 14155 void test14155_for_testDIP29_6() { static class CI { int* p; this(int) immutable pure { p = &g14155; } } static assert(!__traits(compiles, { CI c = new immutable CI(1); })); static assert( __traits(compiles, { const CI c = new immutable CI(1); })); static assert( __traits(compiles, { immutable CI c = new immutable CI(1); })); static assert(!__traits(compiles, { shared CI c = new immutable CI(1); })); static assert(!__traits(compiles, { CI c = new const CI(1); })); static assert( __traits(compiles, { const CI c = new const CI(1); })); static assert( __traits(compiles, { immutable CI c = new const CI(1); })); static assert(!__traits(compiles, { shared CI c = new const CI(1); })); } /***********************************/ // 13640 struct S13640 { static struct R { int* p; this(inout ref int* p) inout pure { this.p = p; } } int* p; void foo() inout pure { // Implicit conversion from inout(R) to R should be disallowed. static assert(!__traits(compiles, { R r = inout(R)(p); })); } } /***********************************/ void main() { test1(); test2(); test3(); test4(); test5(); testDIP29_1(); testDIP29_2(); testDIP29_3(); testDIP29_4(); testDIP29_5(); testDIP29_6(); writefln("Success"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link14198a.sh0000755000175000017500000000152213200164642023453 0ustar matthiasmatthias#!/usr/bin/env bash src=runnable${SEP}extra-files dir=${RESULTS_DIR}${SEP}runnable output_file=${dir}/link14198a.sh.out if [ $OS == "win32" -o $OS == "win64" ]; then LIBEXT=.lib else LIBEXT=.a fi libname=${dir}${SEP}lib14198a${LIBEXT} # build library $DMD -m${MODEL} -I${src} -of${libname} -lib ${src}${SEP}std14198${SEP}array.d ${src}${SEP}std14198${SEP}conv.d ${src}${SEP}std14198${SEP}format.d ${src}${SEP}std14198${SEP}uni.d || exit 1 # Do not link failure with library file, regardless the semantic order. $DMD -m${MODEL} -I${src} -of${dir}${SEP}test14198a${EXE} ${src}${SEP}test14198.d ${libname} || exit 1 $DMD -m${MODEL} -I${src} -of${dir}${SEP}test14198a${EXE} -version=bug14198 ${src}${SEP}test14198.d ${libname} || exit 1 rm ${libname} rm ${dir}/{test14198a${OBJ},test14198a${EXE}} echo Success > ${output_file} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/functype.d0000644000175000017500000002536013200164642023417 0ustar matthiasmatthiasextern(C) int printf(const char*, ...); /***************************************************/ void testfp() { static int func1(int n = 1) { return n; } static int func2(int n ) { return n; } static assert(typeof(func1).stringof == "int(int n = 1)"); static assert(typeof(func2).stringof == "int(int n)"); static assert( is(typeof(func1()))); // OK static assert(!is(typeof(func2()))); // NG alias typeof(func1) Func1; alias typeof(func2) Func2; static assert(is(Func1 == Func2)); static assert(Func1.stringof == "int(int n = 1)"); static assert(Func2.stringof == "int(int n)"); auto fp1 = &func1; auto fp2 = &func2; static assert(typeof(fp1).stringof == "int function(int n = 1)"); static assert(typeof(fp2).stringof == "int function(int n)"); static assert( is(typeof(fp1()))); // OK static assert(!is(typeof(fp2()))); // NG alias typeof(fp1) Fp1; alias typeof(fp2) Fp2; static assert(is(Fp1 == Fp2)); static assert(Fp1.stringof == "int function(int n = 1)"); static assert(Fp2.stringof == "int function(int n)"); typeof(fp1) fp3 = fp1; typeof(fp2) fp4 = fp2; static assert(is(typeof(fp3) == typeof(fp4))); static assert(typeof(fp3).stringof == "int function(int n = 1)"); static assert(typeof(fp4).stringof == "int function(int n)"); static assert( is(typeof(fp3()))); // OK static assert(!is(typeof(fp4()))); // NG alias typeof(fp3) Fp3; alias typeof(fp4) Fp4; static assert(is(Fp3 == Fp4)); static assert(Fp3.stringof == "int function(int n = 1)"); static assert(Fp4.stringof == "int function(int n)"); auto fplit1 = function(int n = 1) { return n; }; auto fplit2 = function(int n ) { return n; }; static assert( is(typeof(fplit1()))); // OK static assert(!is(typeof(fplit2()))); // NG } void testdg() { int nest1(int n = 1) { return n; } int nest2(int n ) { return n; } static assert(typeof(nest1).stringof == "int(int n = 1)"); static assert(typeof(nest2).stringof == "int(int n)"); static assert( is(typeof(nest1()))); // OK static assert(!is(typeof(nest2()))); // NG alias typeof(nest1) Nest1; alias typeof(nest2) Nest2; static assert(is(Nest1 == Nest2)); static assert(Nest1.stringof == "int(int n = 1)"); static assert(Nest2.stringof == "int(int n)"); auto dg1 = &nest1; auto dg2 = &nest2; static assert(typeof(dg1).stringof == "int delegate(int n = 1)"); static assert(typeof(dg2).stringof == "int delegate(int n)"); static assert( is(typeof(dg1()))); // OK static assert(!is(typeof(dg2()))); // NG alias typeof(dg1) Dg1; alias typeof(dg2) Dg2; static assert(is(Dg1 == Dg2)); static assert(Dg1.stringof == "int delegate(int n = 1)"); static assert(Dg2.stringof == "int delegate(int n)"); typeof(dg1) dg3 = dg1; typeof(dg2) dg4 = dg2; static assert(typeof(dg3).stringof == "int delegate(int n = 1)"); static assert(typeof(dg4).stringof == "int delegate(int n)"); static assert( is(typeof(dg3()))); // OK static assert(!is(typeof(dg4()))); // NG alias typeof(dg3) Dg3; alias typeof(dg4) Dg4; static assert(is(Dg3 == Dg4)); static assert(Dg3.stringof == "int delegate(int n = 1)"); static assert(Dg4.stringof == "int delegate(int n)"); auto dglit1 = delegate(int n = 1) { return n; }; auto dglit2 = delegate(int n ) { return n; }; static assert( is(typeof(dglit1()))); // OK static assert(!is(typeof(dglit2()))); // NG } void testda() { // Unsupported cases with current implementation. int function(int n = 1)[] fpda = [n => n + 1, n => n+2]; assert(fpda[0](1) == 2); assert(fpda[1](1) == 3); static assert(!is(typeof(fpda[0]() == 1))); // cannot call with using defArgs static assert(!is(typeof(fpda[1]() == 2))); // cannot call with using defArgs static assert(typeof(fpda).stringof == "int function(int)[]"); static assert(typeof(fpda).stringof != "int funciton(int n = 1)[]"); int delegate(int n = 1)[] dgda = [n => n + 1, n => n+2]; assert(dgda[0](1) == 2); assert(dgda[1](1) == 3); static assert(!is(typeof(dgda[0]() == 1))); // cannot call with using defArgs static assert(!is(typeof(dgda[1]() == 2))); // cannot call with using defArgs static assert(typeof(dgda).stringof == "int delegate(int)[]"); static assert(typeof(fpda).stringof != "int delegate(int n = 1)[]"); } template StringOf(T) { // template type parameter cannot have redundant informations enum StringOf = T.stringof; } void testti() { int[] test(int[] a = []) { return a; } static assert(typeof(test).stringof == "int[](int[] a = [])"); static assert(StringOf!(typeof(test)) == "int[](int[])"); float function(float x = 0F) fp = x => x; static assert(typeof(fp).stringof == "float function(float x = " ~ (0F).stringof ~ ")"); static assert(StringOf!(typeof(fp)) == "float function(float)"); double delegate(double x = 0.0) dg = x => x; static assert(typeof(dg).stringof == "double delegate(double x = " ~ (0.0).stringof ~ ")"); static assert(StringOf!(typeof(dg)) == "double delegate(double)"); template F(T) {} auto fp1 = (int a = 1) {}; auto fp2 = (int b = 2) {}; static assert(typeof(fp1).stringof != typeof(fp2).stringof); alias F1 = F!(typeof(fp1)); alias F2 = F!(typeof(fp2)); static assert(__traits(isSame, F1, F2)); static assert(F1.mangleof == F2.mangleof); } void testxx() { // The corner cases which I had introduced in forum discussion // f will inherit default args from its initializer, if it's declared with 'auto' auto f1 = (int n = 10){ return 10; }; assert(f1() == 10); // what is the actual default arg of f? int function(int n = 10) f2 = (int n = 20){ return n; }; int function(int n ) f3 = (int n = 30){ return n; }; int function(int n = 40) f4 = (int n ){ return n; }; assert(f2() == 10); static assert(!is(typeof(f3()))); assert(f4() == 40); // conditional expression and the type of its result auto f5 = true ? (int n = 10){ return n; } : (int n = 20){ return n; } ; auto f6 = true ? (int n = 10, string s = "hello"){ return n; } : (int n = 10, string s = "world"){ return n; } ; static assert(!is(typeof(f5()))); // cannot call static assert(!is(typeof(f6()))); // cannot call int function(int n = 10) f7; // default arg of the first parameter is 10 f7 = (int n = 20){ return n; }; // function literal's default arg will be ignored assert(f7() == 10); // returning function pointer/delegate type can have default args int delegate(int n = 10) foo(int x) { return n => n + x; } auto f = foo(1); assert(f() == 11); } /***************************************************/ // 3646 int bar3646(int x = 10) { printf("bar %d\n", x); return x; } int bam3646(int y) { printf("bam %d\n", y); return y; } int qux3646() { printf("quux\n"); return 20; } int qux3646(int i) { printf("quux %d\n", i); return 30; } void foo3646a(Fn)(Fn fn) { fn(); } void foo3646b(alias fn)(int res1, int res2) { assert(fn() == res1); assert(fn(42) == res2); } void test3646() { static assert(!is(typeof(foo3646(&bar3646)))); static assert(!is(typeof(foo3646(&bam3646)))); static assert(typeof(&bar3646).stringof == "int function(int x = 10)"); static assert(typeof(&bam3646).stringof == "int function(int y)"); foo3646b!bar3646(10, 42); static assert(!is(typeof(foo3646b!bam3646(0, 0)))); foo3646b!qux3646(20, 30); } /***************************************************/ // 3866 void test3866() { auto foo = (int a = 1) { return a; }; auto bar = (int a) { return a; }; assert(foo() == 1); static assert(!is(typeof(bar()))); assert(foo(2) == 2); assert(bar(3) == 3); } /***************************************************/ // 8579 void test8579() { static void func1(int i, double j = 1.0) {} static void func2(int x, double y) {} auto fn1 = &func1; auto fn2 = &func2; static assert(is(typeof(fn1) == typeof(fn2))); assert( typeid(fn1) is typeid(fn2) ); static assert(typeof(fn1).stringof == "void function(int i, double j = " ~ (1.0).stringof ~ ")"); static assert(typeof(fn2).stringof == "void function(int x, double y)"); static int func3(int x, double y) { return 0; } static int func4(int i, double j = 1.0) { return 0; } auto fn3 = &func3; auto fn4 = &func4; static assert(is(typeof(fn3) == typeof(fn4))); assert( typeid(fn3) is typeid(fn4) ); static assert(typeof(fn3).stringof == "int function(int x, double y)"); static assert(typeof(fn4).stringof == "int function(int i, double j = " ~ (1.0).stringof ~ ")"); } /***************************************************/ // 14210 string foo14210a(DT)(string name, DT dg) { return name ~ " :: " ~ typeof(dg).stringof; } string foo14210b(DT)(string name, DT dg) { return name ~ " :: " ~ typeof(dg).stringof; } void test14210() { assert(foo14210a("1", (int a) => a+0) == "1 :: int function(int) pure nothrow @nogc @safe"); assert(foo14210a("2", (int a=40) => a+2) == "2 :: int function(int) pure nothrow @nogc @safe"); assert(foo14210b("2", (int a=40) => a+2) == "2 :: int function(int) pure nothrow @nogc @safe"); assert(foo14210b("1", (int a) => a+0) == "1 :: int function(int) pure nothrow @nogc @safe"); } /***************************************************/ // 10734 // There's no platform independent export symbol, so // test just only in Win32. version(Win32) { extern(Windows) { // use a symbol from kernel32.lib, not user32.lib. The latter might not // be passed automatically on the command line export void* GetModuleHandleA(const(char)*moduleName); alias void* function(const(char)*moduleName) PROC; } void test10734() { PROC lpfnProc = &GetModuleHandleA; } } void test14656() { void unaryFun()(auto int a) pure nothrow @safe @nogc {} alias Identity(F) = F; unaryFun!()(41); static void fun(int n) pure nothrow @safe @nogc {} alias F = typeof(fun); assert(Identity!F.stringof == "pure nothrow @nogc @safe void(int)"); } void test14656_ref() { void unaryFun()(auto ref int a) pure nothrow @safe @nogc {} alias Identity(F) = F; unaryFun!()(41); static void fun(int n) pure nothrow @safe @nogc {} alias F = typeof(fun); assert(Identity!F.stringof == "pure nothrow @nogc @safe void(int)"); } /***************************************************/ int main() { testfp(); testdg(); testda(); testti(); testxx(); test3646(); test3866(); test8579(); test14210(); test14656(); test14656_ref(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testpic.d0000644000175000017500000000070013200164642023224 0ustar matthiasmatthias// PERMUTE_ARGS: -fPIC -O extern (C) int printf(const char*, ...); /***************************************************/ align(16) struct S41 { int[4] a; } shared int x41; shared S41 s41; void test11310() { printf("&x = %p\n", &x41); printf("&s = %p\n", &s41); assert((cast(int)&s41 & 0xF) == 0); } /***************************************************/ int main() { test11310(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/tls.d0000644000175000017500000000274713200164642022370 0ustar matthiasmatthias// EXTRA_SOURCES: imports/tlsa.d import core.stdc.stdio; import imports.tlsa; int x = 3; void bar() { int* px = &x; assert(x == 3); x++; printf("x = %d\n", x); px = &x; printf("px = %p\n", px); assert(*px == 4); (*px)++; assert(x == 5); } void test1() { bar(); printf("%d\n", x); printf("%d\n", foo!()()); } /************************************/ long fooa; long foob; int bara = 0x12345678; int barb = 0x9ABCDEFF; void test2() { fooa++; foob--; bara++; barb++; printf("%lld %lld %x %x\n", fooa, foob, bara, barb); assert(fooa == 1); assert(foob == -1); assert(bara == 0x12345679); assert(barb == 0x9ABCDF00); } /************************************/ int abc3(T)(T t) { static T qqq; static T rrr; static T sss = 8; static T ttt = 9; printf("qqq = %d, rrr = %d, sss = %d, ttt = %d\n", qqq, rrr, sss, ttt); assert(sss == 8); assert(ttt == 9); rrr += 7; return t + ++qqq + rrr; } void test3() { auto i = abc3(3); printf("i = x%x\n", i); assert(i == 11); i = abc3(4); printf("i = x%x\n", i); assert(i == 20); } /************************************/ void test4() { auto i = bar4(); printf("i = x%x\n", i); assert(i == 0x23); i = abc4(4); printf("i = x%x\n", i); assert(i == 0x31); } /************************************/ int main() { test1(); test2(); test3(); test4(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test41.d0000644000175000017500000000052213200164642022677 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test41a.d // PERMUTE_ARGS: -inline -g -O import imports.test41a; import core.exception; int main() { try { foo(); return 1; } catch (AssertError e) { } try { func!(void)(); return 1; } catch (AssertError e) { } return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/interpret.d0000644000175000017500000015063313200164642023600 0ustar matthiasmatthias import std.stdio; template Tuple(A...) { alias A Tuple; } template eval(A...) { const typeof(A[0]) eval = A[0]; } /************************************************/ int Foo1(int i) { if (i == 0) return 1; else return i * Foo1(i - 1); } void test1() { static int f = Foo1(5); printf("%d %d\n", f, 5*4*3*2); assert(f == 120); } /************************************************/ int find2(string s, char c) { if (s.length == 0) return -1; else if (c == s[0]) return 0; else return 1 + find2(s[1..$], c); } void test2() { static int f = find2("hello", 'l'); printf("%d\n", f); assert(f == 2); } /************************************************/ int bar3(int i) { int j; while (i) { j += i; i--; } return j; } void test3() { static b = bar3(7); printf("b = %d, %d\n", b, bar3(7)); assert(b == 28); } /************************************************/ int bar4(int i) { for (int j = 0; j < 10; j++) i += j; return i; } void test4() { static b = bar4(7); printf("b = %d, %d\n", b, bar4(7)); assert(b == 52); } /************************************************/ int bar5(int i) { int j; do { i += j; j++; } while (j < 10); return i; } void test5() { static b = bar5(7); printf("b = %d, %d\n", b, bar5(7)); assert(b == 52); } /************************************************/ int bar6(int i) { int j; do { i += j; j++; if (j == 4) break; } while (j < 10); return i; } void test6() { static b = bar6(7); printf("b = %d, %d\n", b, bar6(7)); assert(b == 13); } /************************************************/ int bar7(int i) { int j; do { i += j; j++; if (j == 4) return 80; } while (j < 10); return i; } void test7() { static b = bar7(7); printf("b = %d, %d\n", b, bar7(7)); assert(b == 80); } /************************************************/ int bar8(int i) { int j; do { j++; if (j == 4) continue; i += j; } while (j < 10); return i; } void test8() { static b = bar8(7); printf("b = %d, %d\n", b, bar8(7)); assert(b == 58); } /************************************************/ int bar9(int i) { int j; while (j < 10) { j++; if (j == 4) continue; i += j; } return i; } void test9() { static b = bar9(7); printf("b = %d, %d\n", b, bar9(7)); assert(b == 58); } /************************************************/ int bar10(int i) { int j; while (j < 10) { j++; if (j == 4) break; i += j; } return i; } void test10() { static b = bar10(7); printf("b = %d, %d\n", b, bar10(7)); assert(b == 13); } /************************************************/ int bar11(int i) { int j; while (j < 10) { j++; if (j == 4) return i << 3; i += j; } return i; } void test11() { static b = bar11(7); printf("b = %d, %d\n", b, bar11(7)); assert(b == 104); } /************************************************/ int bar12(int i) { for (int j; j < 10; j++) { if (j == 4) return i << 3; i += j; } return i; } void test12() { static b = bar12(7); printf("b = %d, %d\n", b, bar12(7)); assert(b == 104); } /************************************************/ int bar13(int i) { for (int j; j < 10; j++) { if (j == 4) break; i += j; } return i; } void test13() { static b = bar13(7); printf("b = %d, %d\n", b, bar13(7)); assert(b == 13); } /************************************************/ int bar14(int i) { for (int j; j < 10; j++) { if (j == 4) continue; i += j; } return i; } void test14() { static b = bar14(7); printf("b = %d, %d\n", b, bar14(7)); assert(b == 48); } /************************************************/ int bar15(int i) { foreach (k, v; "hello") { i <<= 1; if (k == 4) continue; i += v; } return i; } void test15() { static b = bar15(7); printf("b = %d, %d\n", b, bar15(7)); assert(b == 3344); } /************************************************/ int bar16(int i) { foreach_reverse (k, v; "hello") { i <<= 1; if (k == 4) continue; i += v; } return i; } void test16() { static b = bar16(7); printf("b = %d, %d\n", b, bar16(7)); assert(b == 1826); } /************************************************/ int bar17(int i) { foreach (k, v; "hello") { i <<= 1; if (k == 2) break; i += v; } return i; } void test17() { static b = bar17(7); printf("b = %d, %d\n", b, bar17(7)); assert(b == 674); } /************************************************/ int bar18(int i) { foreach_reverse (k, v; "hello") { i <<= 1; if (k == 2) break; i += v; } return i; } void test18() { static b = bar18(7); printf("b = %d, %d\n", b, bar18(7)); assert(b == 716); } /************************************************/ int bar19(int i) { assert(i > 0); foreach_reverse (k, v; "hello") { i <<= 1; if (k == 2) return 8; i += v; } return i; } void test19() { static b = bar19(7); printf("b = %d, %d\n", b, bar19(7)); assert(b == 8); } /************************************************/ int bar20(int i) { assert(i > 0); foreach (k, v; "hello") { i <<= 1; if (k == 2) return 8; i += v; } return i; } void test20() { static b = bar20(7); printf("b = %d, %d\n", b, bar20(7)); assert(b == 8); } /************************************************/ int bar21(int i) { assert(i > 0); foreach (v; Tuple!(57, 23, 8)) { i <<= 1; i += v; } return i; } void test21() { static b = bar21(7); printf("b = %d, %d\n", b, bar21(7)); assert(b == 338); } /************************************************/ int bar22(int i) { assert(i > 0); foreach_reverse (v; Tuple!(57, 23, 8)) { i <<= 1; i += v; } return i; } void test22() { static b = bar22(7); printf("b = %d, %d\n", b, bar22(7)); assert(b == 191); } /************************************************/ int bar23(int i) { assert(i > 0); foreach_reverse (v; Tuple!(57, 23, 8)) { i <<= 1; if (v == 23) return i + 1; i += v; } return i; } void test23() { static b = bar23(7); printf("b = %d, %d\n", b, bar23(7)); assert(b == 45); } /************************************************/ int bar24(int i) { assert(i > 0); foreach (v; Tuple!(57, 23, 8)) { i <<= 1; if (v == 23) return i + 1; i += v; } return i; } void test24() { static b = bar24(7); printf("b = %d, %d\n", b, bar24(7)); assert(b == 143); } /************************************************/ int bar25(int i) { assert(i > 0); foreach_reverse (v; Tuple!(57, 23, 8)) { i <<= 1; if (v == 23) break; i += v; } return i; } void test25() { static b = bar25(7); printf("b = %d, %d\n", b, bar25(7)); assert(b == 44); } /************************************************/ int bar26(int i) { assert(i > 0); foreach (v; Tuple!(57, 23, 8)) { i <<= 1; if (v == 23) break; i += v; } return i; } void test26() { static b = bar26(7); printf("b = %d, %d\n", b, bar26(7)); assert(b == 142); } /************************************************/ int bar27(int i) { foreach_reverse (v; Tuple!(57, 23, 8)) { i <<= 1; if (v == 23) continue; i += v; } return i; } void test27() { static b = bar27(7); printf("b = %d, %d\n", b, bar27(7)); assert(b == 145); } /************************************************/ int bar28(int i) { foreach (v; Tuple!(57, 23, 8)) { i <<= 1; if (v == 23) continue; i += v; } return i; } void test28() { static b = bar28(7); printf("b = %d, %d\n", b, bar28(7)); assert(b == 292); } /************************************************/ int bar29(int i) { switch (i) { case 1: i = 4; break; case 7: i = 3; break; default: assert(0); } return i; } void test29() { static b = bar29(7); printf("b = %d, %d\n", b, bar29(7)); assert(b == 3); } /************************************************/ int bar30(int i) { switch (i) { case 1: i = 4; break; case 8: i = 2; break; default: i = 3; break; } return i; } void test30() { static b = bar30(7); printf("b = %d, %d\n", b, bar30(7)); assert(b == 3); } /************************************************/ int bar31(string s) { int i; switch (s) { case "hello": i = 4; break; case "betty": i = 2; break; default: i = 3; break; } return i; } void test31() { static b = bar31("betty"); printf("b = %d, %d\n", b, bar31("betty")); assert(b == 2); } /************************************************/ int bar32(int i) { switch (i) { case 7: i = 4; goto case; case 5: i = 2; break; default: i = 3; break; } return i; } void test32() { static b = bar32(7); printf("b = %d, %d\n", b, bar32(7)); assert(b == 2); } /************************************************/ int bar33(int i) { switch (i) { case 5: i = 2; break; case 7: i = 4; goto case 5; default: i = 3; break; } return i; } void test33() { static b = bar33(7); printf("b = %d, %d\n", b, bar33(7)); assert(b == 2); } /************************************************/ int bar34(int i) { switch (i) { default: i = 3; break; case 5: i = 2; break; case 7: i = 4; goto default; } return i; } void test34() { static b = bar34(7); printf("b = %d, %d\n", b, bar34(7)); assert(b == 3); } /************************************************/ int bar35(int i) { L1: switch (i) { default: i = 3; break; case 5: i = 2; break; case 3: return 8; case 7: i = 4; goto default; } goto L1; } void test35() { static b = bar35(7); printf("b = %d, %d\n", b, bar35(7)); assert(b == 8); } /************************************************/ int square36(int x) { return x * x; } const int foo36 = square36(5); void test36() { assert(foo36 == 25); } /************************************************/ string someCompileTimeFunction() { return "writefln(\"Wowza!\");"; } void test37() { mixin(someCompileTimeFunction()); } /************************************************/ string NReps(string x, int n) { string ret = ""; for (int i = 0; i < n; i++) { ret ~= x; } return ret; } void test38() { static x = NReps("3", 6); assert(x == "333333"); } /************************************************/ bool func39() { return true; } static if (func39()) { pragma(msg, "true"); } else { pragma(msg, "false"); } void test39() { } /************************************************/ string UpToSpace(string x) { int i = 0; while (i < x.length && x[i] != ' ') { i++; } return x[0..i]; } void test40() { const y = UpToSpace("first space was after first"); writeln(y); assert(y == "first"); } /************************************************/ int bar41(ref int j) { return 5; } int foo41(int i) { int x; x = 3; bar41(x); return i + x; } void test41() { const y = foo41(3); writeln(y); assert(y == 6); } /************************************************/ int bar42(ref int j) { return 5; } int foo42(int i) { int x; x = 3; bar42(x); return i + x; } void test42() { const y = foo42(3); writeln(y); assert(y == 6); } /************************************************/ int bar(string a) { int v; for (int i = 0; i < a.length; i++) { if (a[i] != ' ') { v += a.length; } } return v; } void test43() { const int foo = bar("a b c d"); writeln(foo); assert(foo == 28); } /************************************************/ string foo44() { return ("bar"); } void test44() { const string bar = foo44(); assert(bar == "bar"); } /************************************************/ int square45(int n) { return (n * n); } void test45() { int bar = eval!(square45(5)); assert(bar == 25); } /************************************************/ const int foo46[5] = [0,1,2,3,4]; void test46() { writeln(eval!(foo46[3])); } /************************************************/ string foo47() { string s; s = s ~ 't'; return s ~ "foo"; } void test47() { static const x = foo47(); pragma(msg, x); assert(x == "tfoo"); } /************************************************/ string foo48() { string s; s = s ~ 't'; s = s.idup; return s ~ "foo"; } void test48() { static const x = foo48(); pragma(msg, x); assert(x == "tfoo"); } /************************************************/ dstring testd49(dstring input) { if (input[3..5] != "rt") { return input[1..3]; } return "my"; } void test49() { static x = testd49("hello"); writeln(x); assert(x == "el"); } /************************************************/ string makePostfix50(int x) { string first; first = "bad"; if (x) { first = "ok"; makePostfix50(0); } return first; } void test50() { static const char [] q2 = makePostfix50(1); static assert(q2 == "ok", q2); } /************************************************/ int exprLength(string s) { int numParens=0; for (int i = 0; i < s.length; ++i) { if (s[i] == '(') { numParens++; } if (s[i] == ')') { numParens--; } if (numParens == 0) { return i; } } assert(0); } string makePostfix51(string operations) { if (operations.length < 2) return "x"; int x = exprLength(operations); string first="bad"; if (x > 0) { first = "ok"; string ignore = makePostfix51(operations[1..x]); } return first; } void test51() { string q = makePostfix51("(a+b)*c"); assert(q == "ok"); static const string q2 = makePostfix51("(a+b)*c"); static assert(q2 == "ok"); static assert(makePostfix51("(a+b)*c") == "ok"); } /************************************************/ int foo52(ref int x) { x = 7; return 3; } int bar52(int y) { y = 4; foo52(y); return y; } void test52() { printf("%d\n", bar52(2)); static assert(bar52(2) == 7); } /************************************************/ void bar53(out int x) { x = 2; } int foo53() { int y; bar53(y); return y; } void test53() { const int z = foo53(); assert(z == 2); } /************************************************/ void test54() { static assert(equals54("alphabet", "alphabet")); } bool equals54(string a, string b) { return (a == b); } /************************************************/ const string foo55[2] = ["a", "b"]; string retsth55(int i) { return foo55[i]; } void test55() { writeln(eval!(foo55[0])); writeln(eval!(retsth55(0))); } /************************************************/ string retsth56(int i) { static const string foo[2] = ["a", "b"]; return foo[i]; } void test56() { writeln(eval!(retsth56(0))); } /************************************************/ int g57() { pragma(msg, "g"); return 2; } const int a57 = g57(); void test57() { assert(a57 == 2); } /************************************************/ int[] Fun58(int x) { int[] result; result ~= x + 1; return result; } void test58() { static b = Fun58(1) ~ Fun58(2); assert(b.length == 2); assert(b[0] == 2); assert(b[1] == 3); writeln(b); } /************************************************/ int Index59() { int[] data = [1]; return data[0]; } void test59() { static assert(Index59() == 1); } /************************************************/ string[int] foo60() { return [3:"hello", 4:"betty"]; } void test60() { static assert(foo60()[3] == "hello"); static assert(foo60()[4] == "betty"); } /************************************************/ string[int] foo61() { return [3:"hello", 4:"betty", 3:"world"]; } void test61() { static assert(foo61()[3] == "world"); static assert(foo61()[4] == "betty"); } /************************************************/ string foo62(int k) { string[int] aa; aa = [3:"hello", 4:"betty"]; return aa[k]; } void test62() { static assert(foo62(3) == "hello"); static assert(foo62(4) == "betty"); } /************************************************/ void test63() { static auto x = foo63(); } int foo63() { pragma(msg, "Crash!"); return 2; } /************************************************/ dstring testd64(dstring input) { debug int x = 10; return "my"; } void test64() { static x = testd64("hello"); } /************************************************/ struct S65 { int i; int j = 3; } int foo(S65 s1, S65 s2) { return s1 == s2; } void test65() { static assert(foo(S65(1, 5), S65(1, 5)) == 1); static assert(foo(S65(1, 5), S65(1, 4)) == 0); } /************************************************/ struct S66 { int i; int j = 3; } int foo66(S66 s1) { return s1.j; } void test66() { static assert(foo66(S66(1, 5)) == 5); } /************************************************/ struct S67 { int i; int j = 3; } int foo67(S67 s1) { s1.j = 3; int i = (s1.j += 2); assert(i == 5); return s1.j + 4; } void test67() { static assert(foo67(S67(1, 5)) == 9); } /************************************************/ int foo68(int[] a) { a[1] = 3; int x = (a[0] += 7); assert(x == 8); return a[0] + a[1]; } void test68() { static assert(foo68( [1,5] ) == 11); } /************************************************/ int foo69(char[] a) { a[1] = 'c'; char x = (a[0] += 7); assert(x == 'h'); assert(x == a[0]); return a[0] + a[1] - 'a'; } void test69() { static assert(foo69(['a', 'b']) == 'j'); } /************************************************/ int foo70(int[string] a) { a["world"] = 5; auto x = (a["hello"] += 7); assert(x == 10); assert(x == a["hello"]); return a["hello"] + a["betty"] + a["world"]; } void test70() { static assert(foo70(["hello":3, "betty":4]) == 19); } /************************************************/ size_t foo71(int[string] a) { return a.length; } void test71() { static assert(foo71(["hello":3, "betty":4]) == 2); } /************************************************/ string[] foo72(int[string] a) { return a.keys; } void test72() { static assert(foo72(["hello":3, "betty":4]) == ["hello", "betty"]); } /************************************************/ int[] foo73(int[string] a) { return a.values; } void test73() { static assert(foo73(["hello":3, "betty":4]) == [3, 4]); } /************************************************/ bool b74() { string a = "abc"; return (a[$-1] == 'c'); } const c74 = b74(); void test74() { assert(c74 == true); } /************************************************/ struct FormatSpec { uint leading; bool skip; uint width; char modifier; char format; uint formatStart; uint formatLength; uint length; } FormatSpec GetFormat(string s) { FormatSpec result; return result; } FormatSpec GetFormat2(string s) { FormatSpec result = FormatSpec(); result.length = 0; assert(result.length < s.length); while (result.length < s.length) { ++result.length; } return result; } void test75() { static FormatSpec spec = GetFormat("asd"); assert(spec.leading == 0); assert(spec.modifier == char.init); static FormatSpec spec2 = GetFormat2("asd"); assert(spec2.length == 3); } /************************************************/ int f76() { int[3] a = void; a[0] = 1; assert(a[0] == 1); return 1; } const i76 = f76(); void test76() { } /************************************************/ struct V77 { int a; int b; } V77 f77() { int q = 0; int unused; int unused2; return V77(q, 0); } void test77() { const w = f77(); const v = f77().b; } /************************************************/ struct Bar78 { int x; } int foo78() { Bar78 b = Bar78.init; Bar78 c; b.x = 1; b = bar(b); return b.x; } Bar78 bar(Bar78 b) { return b; } void test78() { static x = foo78(); } /************************************************/ struct Bar79 { int y,x; } int foo79() { Bar79 b = Bar79.init; b.x = 100; for (size_t i = 0; i < b.x; i++) { } b.x++; b.x = b.x + 1; return b.x; } void test79() { static x = foo79(); printf("x = %d\n", x); assert(x == 102); } /************************************************/ void test80() { } /************************************************/ string foo81() { return ""; } string rod81(string[] a) { return a[0]; } void test81() { static x = rod81([foo81(), ""]); assert(x == ""); } /************************************************/ struct S82 { string name; } const S82 item82 = {"item"}; string mixItemList82() { return item82.name; } const string s82 = mixItemList82(); void test82() { assert(s82 == "item"); } /************************************************/ struct S83 { string name; } const S83[] items83 = [ {"item"}, ]; string mixItemList83() { string s; foreach (item; items83) s ~= item.name; return s; } const string s83 = mixItemList83(); void test83() { writeln(s83); assert(s83 == "item"); } /************************************************/ struct S84 { int a; } int func84() { S84 [] s = [S84(7)]; return s[0].a; // Error: cannot evaluate func() at compile time } void test84() { const int x = func84(); assert(x == 7); } /************************************************/ struct S85 { int a; } size_t func85() { S85 [] s; s ~= S85(7); return s.length; } void test85() { const size_t x = func85(); assert(x == 1); } /************************************************/ struct Bar86 { int x; char[] s; } char[] foo86() { Bar86 bar; return bar.s; } void test86() { static x = foo86(); assert(x == null); } /************************************************/ struct Bar87 { int x; } int foo87() { Bar87 bar; bar.x += 1; bar.x++; return bar.x; } void test87() { static x = foo87(); assert(x == 2); } /************************************************/ int foo88() { char[] s; int i; if (s) { i |= 1; } if (s == null) { i |= 2; } if (s is null) { i |= 4; } if (s == "") { i |= 8; } if (s.length) { i |= 16; } if (s == ['c'][0..0]) { i |= 32; } if (null == s) { i |= 64; } if (null is s) { i |= 128; } if ("" == s) { i |= 256; } if (['c'][0..0] == s) { i |= 512; } return i; } void test88() { static x = foo88(); printf("x = %x\n", x); assert(x == (2|4|8|32|64|128|256|512)); } /************************************************/ template Tuple89(T...) { alias T val; } alias Tuple89!(int) Tup89; string gen89() { foreach (i, type; Tup89.val) { assert(i == 0); assert(is(type == int)); } return null; } void test89() { static const string text = gen89(); assert(text is null); } /************************************************/ string bar90(string z) { return z; } string foo90(string a, string b) { string f = a.length == 1 ? a: foo90("B", "C"); string g = b.length == 1 ? b: bar90(foo90("YYY", "A")); return f; } void test90() { static const string xxx = foo90("A", "xxx"); printf("%.*s\n", xxx.length, xxx.ptr); assert(xxx == "A"); } /************************************************/ struct PR91 { } int foo91() { PR91 pr; pr = PR91(); return 0; } void test91() { static const i = foo91(); } /************************************************/ char find92(immutable(char)[7] buf) { return buf[3]; } void test92() { static const pos = find92("abcdefg"); assert(pos == 'd'); } /************************************************/ static string hello93() { string result = ""; int i = 0; for (;;) { result ~= `abc`; i += 1; if (i == 3) break; } return result; } void test93() { static string s = hello93(); assert(s == "abcabcabc"); } /************************************************/ int foo94 (string[] list, string s) { if (list.length == 0) return 1; else { return 2 + foo94(list[1..$], list[0]); } } void test94() { printf("test94\n"); static const int x = foo94(["a", "b"], ""); assert(x == 5); } /************************************************/ char[] func95(immutable char[] s) { char[] u = "".dup; u ~= s; u = u ~ s; return u; } void test95() { mixin(func95(";")); } /************************************************/ char[] func96(string s) { char[] u = "".dup; u ~= s; u = u ~ s; return u; } void test96() { mixin(func96(";")); } /************************************************/ string foo97() { string a; a ~= "abc"; // ok string[] b; b ~= "abc"; // ok string[][] c; c ~= ["abc", "def"]; string[][] d = []; d ~= ["abc", "def"]; // ok return "abc"; } void test97() { static const xx97 = foo97(); } /************************************************/ immutable(int)[] foo98(immutable(int)[][] ss) { immutable(int)[] r; r ~= ss[0]; // problem here return r; } void test98() { const r = foo98([[1], [2]]); } /************************************************/ struct Number { public int value; static Number opCall(int value) { Number n = void; n.value = value; return n; } } class Crash { Number number = Number(0); } void test99() { } /************************************************/ int[] map100 = ([4:true, 5:true]).keys; bool[] foo100 = ([4:true, 5:true]).values; void test100() { } /************************************************/ int foo101() { immutable bool [int] map = [4:true, 5:true]; foreach (x; map.keys) {} return 3; } static int x101 = foo101(); void test101() { } /************************************************/ int foo102() { foreach (i; 0 .. 1) return 1; return 0; } static assert(foo102() == 1); int bar102() { foreach_reverse (i; 0 .. 1) return 1; return 0; } static assert(bar102() == 1); void test102() { } /************************************************/ int foo103() { foreach (c; '0' .. '9') { } foreach_reverse (c; '9' .. '0') { } return 0; } enum x103 = foo103(); void test103() { } /************************************************/ struct S { int x; char y; } // Functions which should fail CTFE int badfoo() { S[2] c; int w = 4; c[w].x = 6; // array bounds error return 7; } int badglobal = 1; int badfoo3() { S[2] c; c[badglobal].x = 6; // global index error return 7; } int badfoo4() { static S[2] c; c[0].x = 6; // Cannot access static return 7; } /+ // This doesn't compile at runtime int badfoo5() { S[] c = void; c[0].x = 6; // c is uninitialized, and not a static array. return 1; } +/ int badfoo6() { S[] b = [S(7), S(15), S(56), S(12)]; b[-2..4] = S(17); // exceeding (negative) array bounds return 1; } int badfoo7() { S[] b = [S(7), S(15), S(56), S(12), S(67)]; S[] c = [S(17), S(4)]; b[1..4] = c[]; // slice mismatch in dynamic array return 1; } int badfoo8() { S[] b; b[1..3] = [S(17), S(4)]; // slice assign to uninitialized dynamic array return 1; } template Compileable(int z) { bool OK = true;} static assert(!is(typeof(Compileable!(badfoo()).OK))); static assert(!is(typeof(Compileable!( (){ S[] c; return c[7].x; // uninitialized error }()).OK ))); static assert( is(typeof(Compileable!(0).OK))); static assert(!is(typeof(Compileable!(badfoo3()).OK))); static assert(!is(typeof(Compileable!(badfoo4()).OK))); //static assert(!is(typeof(Compileable!(badfoo5()).OK))); static assert(!is(typeof(Compileable!(badfoo6()).OK))); static assert(!is(typeof(Compileable!(badfoo7()).OK))); static assert(!is(typeof(Compileable!(badfoo8()).OK))); // Functions which should pass CTFE int goodfoo1() { int[8] w; // use static array in CTFE w[] = 7; // full slice assign w[$ - 1] = 538; // use of $ in index assignment assert(w[6] == 7); return w[7]; } static assert(goodfoo1() == 538); int goodfoo2() { S[4] w = S(101); // Block-initialize array of structs w[$ - 2].x = 917; // use $ in index member assignment w[$ - 2].y = 58; // this must not clobber the prev assignment return w[2].x; // check we got the correct one } static assert(goodfoo2() == 917); static assert(is(typeof(Compileable!( (){ S[4] w = void; // uninitialized array of structs w[$ - 2].x = 217; // initialize one member return w[2].x; }()).OK ))); int goodfoo4() { S[4] b = [S(7), S(15), S(56), S(12)]; // assign from array literal assert(b[3] == S(12)); return b[2].x - 55; } static assert(goodfoo4()==1); int goodfoo5() { S[4] b = [S(7), S(15), S(56), S(12)]; b[0..2] = [S(2), S(6)]; // slice assignment from array literal assert(b[3] == S(12)); assert(b[1] == S(6)); return b[0].x; } static assert(goodfoo5() == 2); static assert(goodfoo5() == 2); // check for memory corruption int goodfoo6() { S[6] b = void; b[2..5] = [S(2), S(6), S(17)]; // slice assign to uninitialized var assert(b[4] == S(17)); return b[3].x; } static assert(goodfoo6() == 6); int goodfoo7() { S[8] b = void; b[2..5] = S(217); // slice assign to uninitialized var assert(b[4] == S(217)); return b[3].x; } static assert(goodfoo7() == 217); int goodfoo8() { S[] b = [S(7), S(15), S(56), S(12), S(67)]; b[2..4] = S(17); // dynamic array block slice assign assert(b[3] == S(17)); assert(b[4] == S(67)); return b[0].x; } static assert(goodfoo8() == 7); // --------- CTFE MEMBER FUNCTION TESTS -------- struct Q { int x; char y; int opAddAssign(int w) { x += w; return x + w; } Q opSubAssign(int w) { x -= w; version(D_Version2) { mixin("return this;"); } else { mixin("return *this;"); } } int boo() { return 4; } int coo() { return x; } int foo() { return coo(); } int doo(int a) { Q z = Q(a, 'x'); z.x += 5; return z.coo() + 3 * x; } void goo(int z) { x = z; } int hoo(int y, int z) { return y + z; } void joo(int z) { x += z; } } int memtest1() { Q b = Q(15, 'a'); return b.hoo(3, 16); // simple const function } static assert(memtest1() == 19); int memtest2() { Q b = Q(15, 'x'); b.x -= 10; return b.coo(); } static assert(memtest2() == 5); int memtest3() { Q b = Q(15, 'x'); b.x -= 10; return b.foo(); } static assert(memtest3() == 5); int memtest4() { Q b = Q(12, 'x'); return b.doo(514); } static assert(memtest4() == 519 + 3 * 12); int memtest5() { Q b = Q(132, 'x'); b.goo(4178); // Call modifying member return b.x; } static assert(memtest5() == 4178); int memtest6() { Q q = Q(1); q += 3; // operator overloading return q.x; } static assert(memtest6() == 4); static assert(!is(typeof(Compileable!(Q += 2).OK))); // Mustn't cause segfault int memtest7() { Q q = Q(57); q -= 35; return q.x; } static assert(memtest7() == 57 - 35); int memtest8() { Q[3] w; w[2].x = 17; w[2].joo(6); // Modify member of array w[1].x += 18; return w[2].coo(); } static assert(memtest8() == 6 + 17); // --------- CTFE REF PASSING TESTS -------- // Bugzilla 1950 - CTFE doesn't work correctly for structs passed by ref struct S1950 { int x; } int foo1950() { S1950 s = S1950(5); // explicitly initialized bar1950(s); return s.x; } void bar1950(ref S1950 w) { w.x = 10; } static assert(foo1950() == 10); // OK <- Fails, x is 0 int foo1950b() { S1950 s; // uninitialized bar1950(s); return s.x; } static assert(foo1950b() == 10); // OK <- Fails, x is 0 // More extreme case, related to 1950 void bar1950c(ref int w) { w = 87; } int foo1950c() { int[5] x; x[] = 56; bar1950c(x[1]); // Non-trivial ref parameters return x[1]; } static assert(foo1950c() == 87); void bar1950d(ref int[] w) { w[1..$] = 87; w[0] += 15; } int foo1950d() { int[] x = [1, 2, 3, 4, 5]; x[1..$] = 56; bar1950d(x); // Non-trivial ref parameters assert(x[0] == 16); return x[1]; } static assert(foo1950d() == 87); // Nested functions int nested(int x) { int y = 3; int inner(int w) { int z = 2; ++z; y += w; return x + 3; } int z = inner(14); assert(y == 17); inner(8); assert(y == 17 + 8); return z + y; } static assert(nested(7) == 17 + 8 + 10); static assert(nested(7) == 17 + 8 + 10); // Recursive nested functions int nested2(int x) { int y = 3; int inner(int w) { int z = 2; ++z; ++y; if (w <= 1) return x + 3; else return inner(w - 1); } int z = inner(14); assert(y == 17); inner(8); assert(y == 17 + 8); return z + y; } static assert(nested2(7) == 17 + 8 + 10); // 1605 D1 & D2. break in switch with goto breaks in ctfe int bug1605() { int i = 0; while (true) { goto LABEL; LABEL: if (i != 0) return i; i = 27; } assert(i == 27); return 88; // unreachable } static assert(bug1605() == 27); // 2564. D2 only. CTFE: the index in a tuple foreach is uninitialized (bogus error) // NOTE: Beware of optimizer bug 3264. int bug2564() { version(D_Version2) { mixin("enum int Q = 0;"); }else {mixin("int Q = 0;"); } string [2] s = ["a", "b"]; assert(s[Q].dup == "a"); return 0; } static int bug2564b = bug2564(); // 1461 D1 + D2. Local variable as template alias parameter breaks CTFE void bug1461() { int x; static assert(Gen1461!(x).generate() == null); } template Gen1461(alias A) { string generate() { return null; } } /************************************************/ string foo104(string[] a...) { string result = ""; foreach (s; a) result ~= s; return result; } mixin (foo104("int ", "x;")); /************************************************/ struct SwineFlu { int a; int b; } struct Infection { SwineFlu y; } struct IveGotSwineFlu { Infection x; int z; int oink() { return x.y.a + 10; } } int quarantine() { IveGotSwineFlu d; return d.oink(); } struct Mexico { Infection x; int z = 2; int oink() { return z + x.y.b; } } int mediafrenzy() { Mexico m; return m.oink; } static assert(quarantine() == 10); static assert(mediafrenzy() == 2); /************************************************/ int ctfeArrayTest(int z) { int[] a = new int[z]; a[$ - 3] = 6; assert(a.length == z); return a[$ - 3]; } static assert(ctfeArrayTest(15) == 6); /************************************************/ char bugzilla1298() { char [4] q = "abcd".dup; char [4] r = ['a', 'b', 'c', 'd']; assert(q == r); q[0..2] = "xy"; q[2] += 3; return q[2]; } static assert(bugzilla1298() == 'f'); int bugzilla1790(Types...)() { foreach (T; Types) { ; } return 0; } const int bugs1790 = bugzilla1790!("")(); char ctfeStrTest1() { char [8] s = void; s[2..4] = 'x'; assert(s.length == 8); return s[3]; } static assert(ctfeStrTest1() == 'x'); //--------- DELEGATE TESTS ------ // Function + delegate literals inside CTFE int delegtest1() { assert(function int(int a){ return 7 + a; }(16) == 23); return delegate int(int a){ return 7 + a; }(6); } int delegtest2() { int innerfunc1() { return delegate int(int a){ return 7 + a; }(6); } int delegate() f = &innerfunc1; return 3 * f(); } int delegtest3() { int function() f = &delegtest1; return 3 * f(); } struct DelegStruct { int a; int bar(int x) { return a + x; } } int delegtest4() { DelegStruct s; s.a = 5; auto f = &s.bar; return f(3); } alias int delegate(int) DelegType; // Test arrays of delegates int delegtest5() { DelegStruct s; s.a = 5; DelegType[4] w; w[] = &s.bar; return w[2](3); } // Test arrays of structs of delegates struct FoolishStruct { DelegType z; } int delegtest6() { DelegStruct s; s.a = 5; FoolishStruct k[3]; DelegType u = &s.bar; k[1].z = u; return k[1].z(3); } static assert(delegtest1() == 13); static assert(delegtest2() == 39); static assert(delegtest3() == 39); static assert(delegtest4() == 8); static assert(delegtest5() == 8); static assert(delegtest6() == 8); // Function + delegate literals, module scope static assert(function int(int a){ return 17 + a; }(16) == 33); static assert( (int a){ return 7 + a; }(16) == 23); // --- Test lazy --- int lazyTest1(lazy int y) { return y + 1; } int lazyTest2(int x) { return lazyTest1(x); } static assert(lazyTest1(7) == 8); static assert(lazyTest2(17) == 18); /************************************************/ version(D_Version2) { // Bug 4020 and 4027 are D2 only struct PostblitCrash { int x; mixin("this(this) { ++x; }"); } int bug4020() { PostblitCrash f; f.x = 3; f = f; f = f; return f.x; } static assert(bug4020() == 5); string delegate() bug4027(string s) { return { return s; }; } // If it compiles, it must not generate wrong code on D2. static if (is(typeof((){ static const s = bug4027("aaa")(); }()))) { static assert(bug4027("aaa")() == "aaa"); static assert(bug4027("bbb")() == "bbb"); } } // --- void bug4004a(ref int a) { assert(a == 7); a += 3; } void bug4004b(ref int b) { b = 7; bug4004a(b); } int bug4004c() { int offset = 5; bug4004b(offset); return offset; } static assert(bug4004c() == 10); // --- int bug4019() { int[int] aa; aa[1] = 2; aa[4] = 6; return aa[1] + aa[4]; } static assert(bug4019() == 8); // --- string delegate() bug4029a() { return { return "abc"[]; }; } string bug4029() { return bug4029a()(); } static assert(bug4029() == "abc"); /************************************************/ int bug4078() { int[] arr = new int[1]; return arr[0]; } static assert(bug4078() == 0); int bug4052() { int[] arr = new int[1]; int s; foreach (x; arr) s += x; foreach (x; arr) s += x * x; return 4052; } static assert(bug4052() == 4052); int bug4252() { char [] s = "abc".dup; s[15] = 'd'; // Array bounds error return 3; } static assert(!is(typeof(Compileable!(bug4252())))); size_t setlen1() { int[] w = new int[4]; w[] = 7; w.length = 6; return 21 + w.length; } static assert(setlen1() == 27); size_t setlen2() { int[] w; w.length = 15; assert(w[3] == 0); w[2] = 8; w[14] = 7; w.length = 12; // check shrinking assert(w[2] == 8); return 2 + w.length; } static assert(setlen2() == 14); /************************************************/ int bug4257(ref int x) { return 3; } int bug4257c(int x) { return 3; } struct Struct4257 { int foo() { return 2; } } void bug4257b() { int y; static assert(!is(typeof(Compileable!(bug4257(y))))); static assert(!is(typeof(Compileable!(bug4257c(y))))); Struct4257 s; static assert(!is(typeof(Compileable!(s.foo())))); } /************************************************/ // 5117 static int dummy5117 = test5117(); int test5117() { S5117 s; s.change(); assert(s.value == 1); // (7) succeeds R5117 r; r.s.change(); assert(r.s.value == 1); // (11) fails, value == 0 return 0; } struct S5117 { int value; void change() { value = 1; } } struct R5117 { S5117 s; } /************************************************/ enum dummy5117b = test5117b(); int test5117b() { S5117b s; getRef5117b(s).change(); assert(s.value == 1); // fails, value == 0 return 0; } ref S5117b getRef5117b(ref S5117b s) { return s; } struct S5117b { int value; void change() { value = 1; } } /************************************************/ // 6439 struct A6439 { this(uint a, uint b) { begin = a; end = b; } union { struct { uint begin, end; } uint[2] arr; } } void test6439() { enum y = A6439(10, 20); A6439 y2 = A6439(10, 20); assert(y2.begin == y.begin && y2.end == y.end); //passes assert(y.arr != [0,0]); assert(y.arr == [10,20]); assert(y.arr == y2.arr); } /************************************************/ // from tests/fail_compilation/fail147 static assert(!is(typeof(Compileable!( (int i){ int x = void; ++x; // used before initialization return i + x; }(3) )))); // 6504 regression void test6504() { for (int i = 0; i < 3; ++i) { char[] x2 = "xxx" ~ ['c']; assert(x2[1] == 'x'); x2[1] = 'q'; } } // 8818 regression void test8818() { static bool test() { string op1 = "aa"; string op2 = "b"; assert("b" >= "aa"); assert(op2 >= op1); return true; } static assert(test()); assert(test()); } /************************************************/ struct Test104Node { int val; Test104Node* next; } Test104Node* CreateList(int[] arr) { if (!arr.length) return null; Test104Node* ret = new Test104Node; ret.val = arr[0]; ret.next = CreateList(arr[1..$]); return ret; } const(Test104Node)* root = CreateList([1, 2, 3, 4, 5]); void test104() { assert(root.val == 1); assert(root.next.val == 2); assert(root.next.next.val == 3); assert(root.next.next.next.val == 4); assert(root.next.next.next.next.val == 5); } /************************************************/ interface ITest105a { string test105a() const; } class Test105a : ITest105a { char a; int b; char c = 'C'; int d = 42; string test105a() const { return "test105a"; } } interface ITest105b { string test105b() const; } class Test105b : Test105a, ITest105b { char e; int f; this(char _e, int _f, char _a, int _b) pure { e = _e; f = _f; a = _a; b = _b; } string test105b() const { return "test105b"; } } const Test105b t105b = new Test105b('E', 88, 'A', 99); const Test105a t105a = new Test105b('E', 88, 'A', 99); const ITest105b t105ib = new Test105b('E', 88, 'A', 99); const ITest105a t105ia = new Test105b('E', 88, 'A', 99); __gshared Test105b t105gs = new Test105b('E', 88, 'A', 99); shared Test105b t105bs = new shared(Test105b)('E', 88, 'A', 99); immutable Test105b t105bi = new immutable(Test105b)('E', 88, 'A', 99); void test105() { assert(t105b.a == 'A'); assert(t105b.b == 99); assert(t105b.c == 'C'); assert(t105b.d == 42); assert(t105b.e == 'E'); assert(t105b.f == 88); assert(t105b.test105a() == "test105a"); assert(t105b.test105b() == "test105b"); assert(t105a.a == 'A'); assert(t105a.b == 99); assert(t105a.c == 'C'); assert(t105a.d == 42); assert(t105a.test105a() == "test105a"); assert(t105ia.test105a() == "test105a"); assert(t105ib.test105b() == "test105b"); assert(t105a.classinfo is Test105b.classinfo); //t105b.d = -1; //assert(t105b.d == -1); //assert(t105a.d == 42); assert(t105gs.a == 'A'); assert(t105gs.b == 99); assert(t105gs.c == 'C'); assert(t105gs.d == 42); assert(t105gs.e == 'E'); assert(t105gs.f == 88); assert(t105gs.test105a() == "test105a"); assert(t105gs.test105b() == "test105b"); assert(t105bs.a == 'A'); assert(t105bs.b == 99); assert(t105bs.c == 'C'); assert(t105bs.d == 42); assert(t105bs.e == 'E'); assert(t105bs.f == 88); assert(t105bi.a == 'A'); assert(t105bi.b == 99); assert(t105bi.c == 'C'); assert(t105bi.d == 42); assert(t105bi.e == 'E'); assert(t105bi.f == 88); assert(t105bi.test105a() == "test105a"); assert(t105bi.test105b() == "test105b"); } int bug9938() { assert(t105ia.test105a() == "test105a"); return 1; } static assert(t105ia.test105a() == "test105a"); static assert(bug9938()); /************************************************/ struct Test106 { Test106* f; Test106* s; } Test106* ctfe106() { auto s = new Test106; auto s2 = new Test106; s.f = s2; s.s = s2; assert(s.f is s.s); return s; } const(Test106)* t106 = ctfe106(); void test106() { assert(t106.f is t106.s); } /************************************************/ class Test107 { Test107 a; Test107 b; this() { } this(int) { a = new Test107(); b = a; assert(a is b); } } const Test107 t107 = new Test107(1); void test107() { assert(t107.a is t107.b); } /************************************************/ /* interface Getter { int getNum() const; } class Test108 : Getter { int f; this(int v) inout { f = v; } int getNum() const { return f; } } enum const(Test108) t108 = new Test108(38); void test108() { const Test108 obj = t108; assert(obj.classinfo is Test108.classinfo); assert(obj.f == 38); const Getter iobj = t108; assert(iobj.getNum() == 38); assert((cast(Object)iobj).classinfo is Test108.classinfo); assert(t108 is t108); } */ /***** Bug 5678 *********************************/ /* struct Bug5678 { this(int) {} } enum const(Bug5678)* b5678 = new const(Bug5678)(0); void test5678() { assert(b5678 is b5678); }*/ /************************************************/ class Test109C { this(){ this.c = this; } Test109C c; } const t109c = new Test109C(); struct Test109S { this(int){ this.s = &this; } Test109S* s; } const t109s = new Test109S(0); pragma(msg, t109s); // Make sure there is no infinite recursion. void test109() { assert(t109c.c is t109c); assert(t109s.s is t109s); } /************************************************/ struct Test110f { int f1; Test110s f2; } struct Test110s { this(int, int, int){} } auto test110 = [Test110f(1, Test110s(1, 2, 3))]; /************************************************/ // 9023 bool test9023() { string[][string] aas; assert(aas.length == 0); aas["a"] ~= "anything"; assert(aas.length == 1); assert(aas["a"] == ["anything"]); aas["a"] ~= "more"; assert(aas.length == 1); assert(aas["a"] == ["anything", "more"]); int[int] aan; assert(aan.length == 0); auto x = aan[0]++; assert(x == 0); assert(aan.length == 1); assert(aan[0] == 1); return true; } static assert(test9023()); /************************************************/ interface IBug9954 { string foo() const; } class Bug9954 : IBug9954 { string foo() const { return "hello"; } } IBug9954 makeIBug9954() { return new Bug9954; } const IBug9954 b9954 = makeIBug9954(); void test9954() { assert(b9954.foo() == "hello"); } /************************************************/ // 10483 struct Bug10483 { int val[3][4]; } struct Outer10483 { Bug10483 p = Bug10483(67); } int k10483a = Outer10483.init.p.val[2][2]; // ICE(expression.c) void test10483() { int k10483b = Outer10483.init.p.val[2][2]; // Segfault (backend/type.c) } /************************************************/ struct S10669 { uint x; } static const S10669 iid0_10669 = S10669(0); class C10669 { static const S10669 iid1_10669 = S10669(1); }; const S10669 IID0_10669 = iid0_10669; const S10669 IID1_10669 = C10669.iid1_10669; /************************************************/ TypeInfo getTi() { return typeid(int); } auto t112 = getTi(); void test112() { assert(t112.toString() == "int"); } /************************************************/ // 10687 enum Foo10687 : uint { A, B, C, D, E } immutable uint[5][] m10687 = [[0, 1, 2, 3, 4]]; void test10687() { static immutable uint[5] a1 = [0, 1, 2, 3, 4]; auto a2 = cast(immutable(Foo10687[5]))a1; static a3 = cast(immutable(Foo10687[5]))a1; auto foos1 = cast(immutable(Foo10687[5][]))m10687; static foos2 = cast(immutable(Foo10687[5][]))m10687; } /************************************************/ void test113() { import core.math; static void compare(real a, real b) { writefln("compare(%30.30f, %30.30f);", a, b); assert(fabs(a - b) < 128 * real.epsilon); } static if (__traits(compiles, (){ enum real ctval1 = yl2x(3.14, 1); })) { enum real ctval1 = yl2x(3.14, 1); enum real ctval2 = yl2x(2e1500L, 3); enum real ctval3 = yl2x(1, 5); real rtval1 = yl2x(3.14, 1); real rtval2 = yl2x(2e1500L, 3); real rtval3 = yl2x(1, 5); compare(ctval1, rtval1); compare(ctval2, rtval2); compare(ctval3, rtval3); } static if (__traits(compiles, (){ enum real ctval4 = yl2xp1(3.14, 1); })) { enum real ctval4 = yl2xp1(3.14, 1); enum real ctval5 = yl2xp1(2e1500L, 3); enum real ctval6 = yl2xp1(1, 5); real rtval4 = yl2xp1(3.14, 1); real rtval5 = yl2xp1(2e1500L, 3); real rtval6 = yl2xp1(1, 5); compare(ctval4, rtval4); compare(ctval5, rtval5); compare(ctval6, rtval6); } } /************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); test28(); test29(); test30(); test31(); test32(); test33(); test34(); test35(); test36(); test37(); test38(); test39(); test40(); test41(); test42(); test43(); test44(); test45(); test46(); test47(); test48(); test49(); test50(); test51(); test52(); test53(); test54(); test55(); test56(); test57(); test58(); test59(); test60(); test61(); test62(); test63(); test64(); test65(); test66(); test67(); test68(); test69(); test70(); test71(); test72(); test73(); test74(); test75(); test76(); test77(); test78(); test79(); test80(); test81(); test82(); test83(); test84(); test85(); test86(); test87(); test88(); test89(); test90(); test91(); test92(); test93(); test94(); test95(); test96(); test97(); test98(); test99(); test100(); test101(); test102(); test103(); test104(); test105(); test106(); test107(); //test108(); test109(); test112(); test113(); test6439(); test6504(); test8818(); test9023(); test9954(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test15.d0000644000175000017500000005041013200164642022701 0ustar matthiasmatthias// REQUIRED_ARGS: import std.array; import core.stdc.math : cos, fabs, sin, sqrt; import core.vararg; import std.math: rndtol, rint; import std.string; import std.stdio : File; extern (C) { int printf(const char*, ...); } struct A { int x; } struct B { int x = 22; } void test5() { A* a = new A; assert(a.x == 0); B* b = new B; assert(b.x == 22); } /************************************/ void test6() { assert('\x12'.sizeof == 1); assert('\u1234'.sizeof == 2); assert('\U00105678'.sizeof == 4); assert('\x12' == 0x12); assert('\u1234' == 0x1234); assert('\U00105678' == 0x105678); assert("abc\\def" == r"abc\def"); } /************************************/ void test7() { string s = `hello"there'you`; printf("s = '%.*s'\n", s.length, s.ptr); assert(s == "hello\"there'you"); ubyte[] b = cast(ubyte[])x"8B 7D f4 0d"; for (int i = 0; i < b.length; i++) printf("b[%d] = x%02x\n", i, b[i]); assert(b.length == 4); assert(b[0] == 0x8B); assert(b[1] == 0x7D); assert(b[2] == 0xF4); assert(b[3] == 0x0D); } /************************************/ void foo8(out bool b) { b = true; } void test8() { bool b; bool *pb = &b; assert(b == false); *pb = true; assert(b == true); *pb = false; assert(b == false); foo8(b); assert(b == true); } /************************************/ struct Pair { int a; int b; Pair abs () { return this; } Pair opDiv(Pair other) { Pair result; result.a = a + other.a; result.b = b + other.b; return result; } } void test9() { Pair t; t.a = 5; t.b = 23; t = t.abs () / t; printf("a = %d, b = %d\n", t.a, t.b); assert(t.a == 10); assert(t.b == 46); } /************************************/ void test10() { int b = 0b_1_1__1_0_0_0_1_0_1_0_1_0_; printf("b = %d\n", b); assert(b == 3626); b = 1_2_3_4_; printf("b = %d\n", b); assert(b == 1234); b = 0x_1_2_3_4_; printf("b = %d\n", b); assert(b == 4660); b = 0_; printf("b = %d\n", b); assert(b == 0); double d = 0_._2_3_4_; printf("d = %g\n", d); assert(d == 0.234); d = 0_._2_3_4_e+3_5_; printf("d = %g\n", d); assert(d == 0.234e+35); d = 0_._2_3_4_e3_5_; printf("d = %g\n", d); assert(d == 0.234e+35); } /************************************/ class CA14 { } class CB14 : CA14 { } class A14 { int show( CA14 a ) { printf("A14::show( CA14 )\n"); return 1; } int boat( CA14 a ) { printf("A14::boat( CA14 )\n"); return 1; } } class B14 : A14 { int show( CA14 a, CB14 b ) { printf("B14::show(CA14, CB14)\n"); return 2; } int boat( CA14 a, CB14 b ) { printf("B14::boat(CA14, CB14)\n"); return 2; } } class C14 : B14 { override int show( CA14 a ) { printf("C::show( CA14 )\n"); return 3; } alias B14.show show; alias B14.boat boat; override int boat( CA14 a ) { printf("C::boat( CA14 )\n"); return 3; } } class D14 : C14 { } void test14() { D14 b = new D14(); int i; i = b.show( new CA14(), new CB14() ); assert(i == 2); i = b.show( new CA14() ); assert(i == 3); i = b.boat( new CA14(), new CB14() ); assert(i == 2); i = b.boat( new CA14() ); assert(i == 3); } /************************************/ class A15 { void foo() { List1.rehash; List2.rehash; } private: int delegate(in int arg1) List1[char[]]; int List2[char []]; } void test15() { } /************************************/ void test16() { char[] a=new char[0]; uint c = 200000; while (c--) a ~= 'x'; //printf("a = '%.*s'\n", a.length, a.ptr); } /************************************/ class A17 { } class B17 : A17 { } void foo17(const(A17)[] a) { } void test17() { B17[] b; foo17(b); } /************************************/ void test18() { uint a; real b=4; a=cast(uint)b; } /************************************/ abstract class Foo19 { int bar() { return 1; } } void test19() { Foo19 f; } /************************************/ int foo20(string s,char d) { return 1; } int foo20(string s,double d) { return 2; } int foo20(string s,cdouble d) { return 3; } void test20() { int i; double x; i = foo20("test=",x); assert(i == 2); } /************************************/ void test21() { int[string] esdom; auto f = File("runnable/extra-files/test15.txt", "r"); foreach(it; f.byLine()) esdom[it.idup] = 0; esdom.rehash; } /************************************/ int foo22(char* p) { return 1; } int foo22(char[] s) { return 2; } void test22() { int i; i = foo22(cast(char*)"abc"); assert(i == 1); i = foo22(cast(char[])"abc"); assert(i == 2); } /************************************/ void test23() { uint v; int b; long l; real e; e = cos(e); e = fabs(e); e = rint(e); l = rndtol(e); e = sin(e); e = sqrt(e); } /************************************/ abstract class dtortest24 { this() {} ~this() {} } void test24() { } /************************************/ abstract class bar25 { this() {} void foo() {} } class subbar25 : bar25 { this() {} } void test25() { new subbar25(); } /************************************/ void test26() { string[] instructions = std.array.split("a;b;c", ";"); foreach(ref string instr; instructions) { std.string.strip(instr); } foreach(string instr; instructions) { printf("%.*s\n", instr.length, instr.ptr); } } /************************************/ void foo27(ClassInfo ci) { } class A27 { } class B27 : A27 { static this() { foo27(B27.classinfo); foo27(A27.classinfo); } } void test27() { } /************************************/ void foo28(ClassInfo ci) { printf("%.*s\n", ci.name.length, ci.name.ptr); static int i; switch (i++) { case 0: case 2: assert(ci.name == "test15.A28"); break; case 1: assert(ci.name == "test15.B28"); break; default: assert(0); } } class A28 { static this() { foo28(A28.classinfo ); } } class B28 : A28 { static this() { foo28(B28.classinfo ); (new B28()).bodge_it(); } void bodge_it() { foo28(A28.classinfo ); } } void test28() { A28 a,b; a = new A28(); b = new B28(); } /************************************/ void test29() { static void delegate() dg; dg = null; } /************************************/ string foo30(int i) { return i ? "three" : "two"; } string bar30(int i) { return i ? "one" : "five"; } void test30() { string s; s = foo30(0); assert(s == "two"); s = foo30(1); assert(s == "three"); s = bar30(0); assert(s == "five"); s = bar30(1); assert(s == "one"); } /************************************/ // http://www.digitalmars.com/d/archives/18204.html // DMD0.050 also failed with alias. alias int recls_bool_t; class Entry31 { recls_bool_t IsReadOnly() { return cast(recls_bool_t)0; } } void test31() { Entry31 entry = new Entry31(); if (entry.IsReadOnly) { } } /************************************/ class A32 { alias int delegate() mfunc; this( mfunc initv ) { } } class foo32 { static void getMemberBar() { //foo32 f = new foo32(); new A32( &(f.bar) ); new A32( &((new foo32()).bar) ); } int bar() { return 0; } } void test32() { foo32.getMemberBar(); } /************************************/ void[] foo33(int[] b) { return b; } void test33() { int[6] c; void[] v; v = foo33(c); assert(v.length == 6 * int.sizeof); } /************************************/ void test34() { version (D_Bits) { bool[8] a8; assert(a8.sizeof == 4); bool[16] a16; assert(a16.sizeof == 4); bool[32] a32; assert(a32.sizeof == 4); bool[256] a256; assert(a256.sizeof == 32); } } /************************************/ void test35() { typeof(1 + 2) i; assert(i.sizeof == int.sizeof); assert(typeof('c').sizeof == char.sizeof); assert(typeof(1).sizeof == int.sizeof); assert(typeof(1.0F).sizeof == float.sizeof); assert(typeof(1.0).sizeof == double.sizeof); assert(typeof(1.0L).sizeof == real.sizeof); //assert(((typeof(1.0L))i).sizeof == real.sizeof); assert((cast(typeof(1.0L))i).sizeof == real.sizeof); } /************************************/ void test36x() { version (Win32) { // stdin.getch(); } } void test36() { } /************************************/ struct T37 { char x; T37 create() { T37 t; t.x = 3; return t; } bool test1() { return create() == this; } bool test2() { return this == create(); } } void test37() { T37 t; assert(!t.test1()); t.x = 3; assert(t.test1()); t.x = 0; assert(!t.test2()); t.x = 3; assert(t.test2()); } /************************************/ void test38() { uint f(uint n) { return n % 10; } printf("%u\n", uint.max); printf("%u\n", f(uint.max)); assert(f(uint.max) == 5); } /************************************/ void test39() { short s=HIWORD (0x0FFFDDDD); short t=LOWORD (0xFFFFCCCC); short v=HIWORD_(0x0FFFEEEE); short x=HIWORD_(0xFFFFAAAA); printf("%x %x %x %x\n",s,t,v,x); assert(s == 0xFFF); assert(t == 0xFFFFCCCC); assert(v == 0xFFF); assert(x == 0xFFFFFFFF); } short HIWORD(uint i) { return cast(short)(( i >> 16) & 0xFFFF); } short LOWORD(uint i) { return cast(short)i; } extern (C) short HIWORD_(uint i) { return cast(short)(( i >> 16) & 0xFFFF); } /************************************/ class caller40 { caller40 opCall (out int i) { i = 10; return this; } } void test40() { caller40 c = new caller40; int x,y; c(x)(y); assert(x == 10); assert(y == 10); } /************************************/ class Foo41 { void print() {printf("Foo41\n");} } class Bar41 : Foo41 { void test() { void printFoo41() { super.print(); // DMD crashes here } printFoo41(); } } void test41() { Bar41 b = new Bar41(); b.test(); } /************************************/ interface Interface { void foo42(); } void bar42(Interface i) { i.foo42(); } class Abstract : Interface { abstract void foo42(); } class Concrete : Abstract { override void foo42() { printf("Concrete.foo42(this = %p)\n", this); } } class Sub : Concrete { } void test42() { Sub s = new Sub(); s.foo42(); bar42(s); } /************************************/ class A43 { int foo() { return 6; } } int bar43(A43 a) { return a.foo; } void test43() { A43 a = new A43(); assert(bar43(a) == 6); } /************************************/ class C44 { const char[][] arrArr=["foo"]; } void test44() { C44 c= new C44(); printf("%.*s\n", c.arrArr[0].length, c.arrArr[0].ptr); assert(c.arrArr[0] == "foo"); } /************************************/ void test45() { void* p; void[] data; data = p[0 .. 5]; } /************************************/ union A46 { char c; struct { short s; } struct { long l; } int a; struct { float f; } } void test46() { A46 a; printf("%d\n", cast(byte*)&a.c - cast(byte*)&a); printf("%d\n", cast(byte*)&a.s - cast(byte*)&a); printf("%d\n", cast(byte*)&a.l - cast(byte*)&a); printf("%d\n", cast(byte*)&a.a - cast(byte*)&a); printf("%d\n", cast(byte*)&a.f - cast(byte*)&a); assert(cast(byte*)&a.c == cast(byte*)&a); assert(cast(byte*)&a.s == cast(byte*)&a); assert(cast(byte*)&a.l == cast(byte*)&a); assert(cast(byte*)&a.a == cast(byte*)&a); assert(cast(byte*)&a.f == cast(byte*)&a); } /************************************/ class Bug47 { void foo() { } static void foo(int i) { } static void bar() { foo(1); } } void test47() { } /************************************/ int[2] x48 = 3; float y48 = 0.0f; void test48() { printf("%d, %d\n", x48[0], x48[1]); assert(x48[0] == 3 && x48[1] == 3); y48 = -100; printf("%d, %d\n", x48[0], x48[1]); assert(x48[0] == 3 && x48[1] == 3); } /************************************/ struct Baz49 { int x,y,z,t; } void foo49(out Baz49 x, out int y) { } void test49() { int y = 3; Baz49 b; assert(b.x == 0); assert(b.y == 0); assert(b.z == 0); assert(b.t == 0); b.x = 1; b.y = 6; b.z = 10; b.t = 11; foo49(b, y); assert(b.x == 0); assert(b.y == 0); assert(b.z == 0); assert(b.t == 0); assert(y == 0); } /************************************/ void foo50(int[] f, ...) { foreach(int i, TypeInfo ti; _arguments) { } } void bar50(out int[] f, ...) { foreach(int i, TypeInfo ti; _arguments) { } } void test50() { int[] a; foo50(a, 1, 2, 3); bar50(a, 1, 2, 3); } /************************************/ deprecated int tri(int x) { return x*(x+1)/2; } deprecated int pent(int x) { return x*x + tri(x) - x; } deprecated class Qwert { int yuiop; this(int y) { yuiop = y; } int twiceYuiop() { return 2 * yuiop; } invariant() { assert (yuiop < 100); } } void test51() { } /************************************/ void foo52(double d) {} deprecated void foo52(int i) {} deprecated void bar52(int i) {} void bar52(double d) {} void test52() { // foo52(1); foo52(1.0); bar52(1.0); } /************************************/ class X53 { void foo(double d) {} deprecated void foo(int i) {} deprecated void bar(int i) {} void bar(double d) {} } void test53() { X53 x = new X53(); //x.foo(1); //x.bar(1); x.foo(1.0); x.bar(1.0); } /************************************/ interface B54 : A54 { A54 getParent(); } interface A54 { void parse(char[] systemId); } void test54() { } /************************************/ class Writer { int put (bool x){ return 1; } int put (int x){ return 2; } } class MyWriter : Writer { alias Writer.put put; override int put (bool x){ return 3; } } void test55() { MyWriter m = new MyWriter(); assert(m.put(false) == 3); assert(m.put(1) == 2); } /************************************/ class Foo56 { alias int baseType; } void test56() { Foo56 f = new Foo56; f.baseType s = 10; } /************************************/ void det(float mat[][]) { float newmat[][]; size_t i = newmat[0 .. (mat.length - 1)].length; } void test57() { } /************************************/ int foo58 (int a, int t) { return 2; } class A58 { int foo58 ( ) { return 3; } alias .foo58 foo58; } void test58() { int y, x; with ( new A58 ) { y = foo58(0,1); x = foo58(); } assert(y == 2); assert(x == 3); } /************************************/ void test59() { struct data { int b1=-1; int b2=2; } data d; assert(d.b1 == -1); assert(d.b2 == 2); } /************************************/ class Foo60 { int x; static: this() { x = 3; } ~this() { } } void test60() { Foo60 f = new Foo60(); assert(f.x == 3); } /************************************/ class StdString { alias std.string.format toString; } void test61() { int i = 123; StdString g = new StdString(); string s = g.toString("%s", i); printf("%.*s\n", s.length, s.ptr); assert(s == "123"); } /************************************/ void test62() { char[4] a; assert(a[0] == 0xFF); assert(a[1] == 0xFF); assert(a[2] == 0xFF); assert(a[3] == 0xFF); } /************************************/ void test63() { bool b; real r; int i; i=cast(double) b ? 1 : 4; r=cast(real) b ? 1.0 : 2.0; } /************************************/ struct MyStruct64 { int test(short s){printf("dynamic short\n"); return 1; } int test(int i){printf("dynamic int\n"); return 2; } static int staticTest(short s){printf("static short\n"); return 3; } static int staticTest(int i){printf("static int\n"); return 4; } } void test64() { MyStruct64 S; int j; short s = 1; int i = 1; j = S.test(s); assert(j == 1); j = S.test(i); assert(j == 2); j = S.staticTest(s); assert(j == 3); j = S.staticTest(i); assert(j == 4); } /************************************/ void test65() { int[8] qwert; int[] yuiop = qwert[2..5] = 4; assert(yuiop.length == 3); assert(yuiop[0] == 4); assert(yuiop[1] == 4); assert(yuiop[2] == 4); yuiop[1] = 2; assert(qwert[0] == 0); assert(qwert[1] == 0); assert(qwert[2] == 4); assert(qwert[3] == 2); assert(qwert[4] == 4); assert(qwert[5] == 0); assert(qwert[6] == 0); assert(qwert[7] == 0); } /************************************/ void foo66(ref bool b) { b = true; } void test66() { bool[3] a; foo66(a[0]); assert(a[0] == true); assert(a[1] == false); assert(a[2] == false); } /************************************/ class FuBar { void foo () { printf ("should never get here\n"); assert(0); } const(void)[] get () { return "weqweqweqweqwee"; } void test (void* dst) { uint count = 7; while (count) { // get as much as there is available in the buffer uint available = 10; // cap bytes read if (available > count) available = count; // copy them over dst[0..available] = get ()[0..available]; // bump counters dst += available; if ((count -= available) > 0) foo (); } } } void test67() { FuBar b = new FuBar(); char[10] dst; b.test(&dst[0]); } /************************************/ struct Foo68 { int a,b,c,d; } void bar68(out Foo68 f) { f.a = 28; } void test68() { Foo68 f; bar68(f); assert(f.a == 28); } /************************************/ class ConduitStyle { // static ConduitStyle Read; // static ConduitStyle ReadWrite; static ConduitStyle Read, ReadWrite; } void test69() { } /************************************/ void test70() { printf("-5/3 prints: %d\n", -5/3); printf("-5/2 prints: %d\n", -5/2); printf("-7/3 prints: %d\n", -7/3); printf("-7/4 prints: %d\n", -7/4); printf("-7/7 prints: %d\n", -7/7); printf("-8/7 prints: %d\n", -8/7); printf("-12/6 prints: %d\n", -12/6); printf("12/6 prints: %d\n", 12/6); printf("-9/7 prints: %d\n", -9/7); printf("-11/8 prints: %d\n", -11/8); printf("-7/9 prints: %d\n", -7/9); assert(-5/3 == -1); assert(-5/2 == -2); assert(-7/3 == -2); assert(-7/4 == -1); assert(-7/7 == -1); assert(-8/7 == -1); assert(-12/6 == -2); assert(12/6 == 2); assert(-9/7 == -1); assert(-11/8 == -1); assert(-7/9 == 0); } /************************************/ void insertText(string str) { assert(str == "a "); } char getCharAt() { return 'a'; } void test71() { insertText(getCharAt() ~ " "); } /************************************/ public class Foo72 { public this() { } } void test72() { Foo72[] foos; foos = new Foo72() ~ foos[]; assert(foos.length == 1); } /************************************/ int main() { test5(); test6(); test7(); test8(); test9(); test10(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); test28(); test29(); test30(); test31(); test32(); test33(); test34(); test35(); test36(); test37(); test38(); test39(); test40(); test41(); test42(); test43(); test44(); test45(); test46(); test47(); test48(); test49(); test50(); test51(); test52(); test53(); test54(); test55(); test56(); test57(); test58(); test59(); test60(); test61(); test62(); test63(); test64(); test65(); test66(); test67(); test68(); test69(); test70(); test71(); test72(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test8544.d0000644000175000017500000000063713200164642023066 0ustar matthiasmatthias// EXECUTE_ARGS: foo bar doo // PERMUTE_ARGS: import std.stdio; import std.conv; import core.runtime; void main(string[] args) { string[] dArgs = Runtime.args; CArgs cArgs = Runtime.cArgs; assert(dArgs.length && cArgs.argc); // ensure we've passed some args assert(dArgs.length == cArgs.argc); assert(dArgs[1] == to!string(cArgs.argv[1])); assert(args[1] == to!string(cArgs.argv[1])); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link14074b.d0000644000175000017500000000010613200164642023250 0ustar matthiasmatthiasimport imports.link14074z; void main() { replaceAllWith!()(1); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_extern_weak.d0000644000175000017500000000077213200164642024720 0ustar matthiasmatthiasextern __gshared pragma(LDC_extern_weak) int nonExistent; bool doesNonExistentExist() { return &nonExistent !is null; } void main() { // Make sure that the frontend does not statically fold the address check // to 'true' for weak symbols. assert(!doesNonExistentExist()); } // OS X note: ld complains extern_weak symbols are undefined unless ld options // -undefined dynamic_lookup or -U __D15ldc_extern_weak11nonExistenti are // provided. extern_weak not really needed on OS X though. ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/uda.d0000644000175000017500000002704113200164642022331 0ustar matthiasmatthias import core.stdc.stdio; template Tuple(T...) { alias T Tuple; } enum EEE = 7; @("hello") struct SSS { } @(3) { @(4)@(EEE)@(SSS) int foo; } pragma(msg, __traits(getAttributes, foo)); alias Tuple!(__traits(getAttributes, foo)) TP; pragma(msg, TP); pragma(msg, TP[2]); TP[3] a; pragma(msg, typeof(a)); alias Tuple!(__traits(getAttributes, typeof(a))) TT; pragma(msg, TT); @('c') string s; pragma(msg, __traits(getAttributes, s)); /************************************************/ enum FFF; @(FFF) int x1; pragma(msg, __traits(getAttributes, x1)); void test1() { alias Tuple!(__traits(getAttributes, x1)) tp; assert(tp.length == 1); if (!is(FFF == tp[0])) assert(0); } /************************************************/ void test2() { int x; alias Tuple!(__traits(getAttributes, x)) tp; assert(tp.length == 0); } /************************************************/ void test3() { alias Tuple!(__traits(getAttributes, foo)) tp; assert(tp.length == 4); assert(tp[0] == 3); assert(tp[1] == 4); assert(tp[2] == 7); } /************************************************/ @(1) void foo4(); @(2) void foo4(int x); void test4() { int i = 1; foreach (o; __traits(getOverloads, uda, "foo4")) { alias Tuple!(__traits(getAttributes, o)) attrs; pragma(msg, attrs.stringof); assert(attrs[0] == i); ++i; } } /************************************************/ pragma(msg, __traits(getAttributes, aa)); alias Tuple!(__traits(getAttributes, aa)) Taa; @(10) int aa; pragma(msg, __traits(getAttributes, bb)); alias Tuple!(__traits(getAttributes, bb)) Tbb; @(20) int bb; alias Tuple!(__traits(getAttributes, bb)) Tbbc; @(30) int cc; pragma(msg, __traits(getAttributes, cc)); alias Tuple!(__traits(getAttributes, cc)) Tcc; void test5() { assert(Taa[0] == 10); assert(Tbb[0] == 20); assert(Tbbc[0] == 20); assert(Tcc[0] == 30); } /************************************************/ enum Test6; @Test6 int x6; pragma(msg, __traits(getAttributes, x6)); void test6() { alias Tuple!(__traits(getAttributes, x6)) tp; assert(tp.length == 1); if (!is(Test6 == tp[0])) assert(0); } /************************************************/ struct Test7 { int a; string b; } @Test7(3, "foo") int x7; pragma(msg, __traits(getAttributes, x7)); void test7() { alias Tuple!(__traits(getAttributes, x7)) tp; assert(tp.length == 1); if (!is(Test7 == typeof(tp[0]))) assert(0); assert(tp[0] == Test7(3, "foo")); } /************************************************/ struct Test8 (string foo) {} @Test8!"foo" int x8; pragma(msg, __traits(getAttributes, x8)); void test8() { alias Tuple!(__traits(getAttributes, x8)) tp; assert(tp.length == 1); if (!is(Test8!("foo") == tp[0])) assert(0); } /************************************************/ struct Test9 (string foo) {} @Test9!("foo") int x9; pragma(msg, __traits(getAttributes, x9)); void test9() { alias Tuple!(__traits(getAttributes, x9)) tp; assert(tp.length == 1); if (!is(Test9!("foo") == tp[0])) assert(0); } /************************************************/ struct Test10 (string foo) { int a; } @Test10!"foo"(3) int x10; pragma(msg, __traits(getAttributes, x10)); void test10() { alias Tuple!(__traits(getAttributes, x10)) tp; assert(tp.length == 1); if (!is(Test10!("foo") == typeof(tp[0]))) assert(0); assert(tp[0] == Test10!("foo")(3)); } /************************************************/ struct Test11 (string foo) { int a; } @Test11!("foo")(3) int x11; pragma(msg, __traits(getAttributes, x11)); void test11() { alias Tuple!(__traits(getAttributes, x11)) tp; assert(tp.length == 1); if (!is(Test11!("foo") == typeof(tp[0]))) assert(0); assert(tp[0] == Test11!("foo")(3)); } /************************************************/ void test12() { @(1) static struct S1 { } S1 s1; static @(2) struct S2 { } S2 s2; @(1) @(2) struct S3 { } @(1) static @(2) struct S { } alias Tuple!(__traits(getAttributes, S)) tps; assert(tps.length == 2); assert(tps[0] == 1); assert(tps[1] == 2); @(3) int x; alias Tuple!(__traits(getAttributes, x)) tpx; assert(tpx.length == 1); assert(tpx[0] == 3); x = x + 1; @(4) int bar() { return x; } alias Tuple!(__traits(getAttributes, bar)) tpb; assert(tpb.length == 1); assert(tpb[0] == 4); bar(); } /************************************************/ // 9178 void test9178() { static class Foo { @(1) int a; } Foo foo = new Foo; static assert(__traits(getAttributes, foo.tupleof[0])[0] == 1); } /************************************************/ // 9652 struct Bug9652 { pragma(msg, __traits(getAttributes, enum_field)); alias Tuple!(__traits(getAttributes, enum_field)) Tenum_field; private @(10) enum enum_field = 42; static assert(Tenum_field[0] == 10); static assert(__traits(getAttributes, enum_field)[0] == 10); static assert(__traits(getProtection, enum_field) == "private"); static assert(__traits(isSame, __traits(parent, enum_field), Bug9652)); static assert(__traits(isSame, enum_field, enum_field)); pragma(msg, __traits(getAttributes, anon_enum_member)); alias Tuple!(__traits(getAttributes, anon_enum_member)) Tanon_enum_member; private @(20) enum {anon_enum_member} static assert(Tanon_enum_member[0] == 20); static assert(__traits(getAttributes, anon_enum_member)[0] == 20); static assert(__traits(getProtection, anon_enum_member) == "private"); static assert(__traits(isSame, __traits(parent, anon_enum_member), Bug9652)); static assert(__traits(isSame, anon_enum_member, anon_enum_member)); pragma(msg, __traits(getAttributes, Foo.enum_member)); alias Tuple!(__traits(getAttributes, Foo.enum_member)) Tfoo_enum_member; private @(30) enum Foo {enum_member} static assert(Tfoo_enum_member.length == 0); //Foo has attributes, not Foo.enum_member static assert(__traits(getAttributes, Foo.enum_member).length == 0); static assert(__traits(getProtection, Foo.enum_member) == "public"); static assert(__traits(isSame, __traits(parent, Foo.enum_member), Foo)); static assert(__traits(isSame, Foo.enum_member, Foo.enum_member)); pragma(msg, __traits(getAttributes, anon_enum_member_2)); alias Tuple!(__traits(getAttributes, anon_enum_member_2)) Tanon_enum_member_2; private @(40) enum {long anon_enum_member_2 = 2L} static assert(Tanon_enum_member_2[0] == 40); static assert(__traits(getAttributes, anon_enum_member_2)[0] == 40); static assert(__traits(getProtection, anon_enum_member_2) == "private"); static assert(__traits(isSame, __traits(parent, anon_enum_member_2), Bug9652)); static assert(__traits(isSame, anon_enum_member_2, anon_enum_member_2)); template Bug(alias X, bool is_exp) { static assert(is_exp == !__traits(compiles, __traits(parent, X))); static assert(is_exp == !__traits(compiles, __traits(getAttributes, X))); static assert(is_exp == !__traits(compiles, __traits(getProtection, X))); enum Bug = 0; } enum en = 0; enum dummy1 = Bug!(5, true); enum dummy2 = Bug!(en, false); } /************************************************/ // 9741 import imports.a9741; struct A9741 {} alias X9741 = ShowAttributes!(B9741); @A9741 struct B9741 {} /************************************************/ // 12160 auto before12160(alias Hook)(string) { return 0; } template checkUDAs12160(alias Func) { enum x = __traits(getAttributes, Func).length; } void test12160() { int foo() { return 42; } // OK <- NG @before12160!foo("name1") void bar(int name1, double name2) {} alias X = checkUDAs12160!(bar); } /************************************************/ // 10208 @( 10) enum int x10208_01 = 100; @( 20) int x10208_02; @( 30) const int x10208_03; @( 40) immutable int x10208_04; @( 50) int x10208_05 = 500; @( 60) const int x10208_06 = 600; @( 70) immutable int x10208_07 = 700; @( 80) __gshared enum int x10208_08 = 800; @( 90) __gshared int x10208_09; @(100) __gshared const int x10208_10; @(110) __gshared immutable int x10208_11; @(120) __gshared int x10208_12 = 1200; @(130) __gshared const int x10208_13 = 1300; @(140) __gshared immutable int x10208_14 = 1400; static assert(__traits(getAttributes, x10208_01)[0] == 10); // OK static assert(__traits(getAttributes, x10208_02)[0] == 20); // OK static assert(__traits(getAttributes, x10208_03)[0] == 30); // OK static assert(__traits(getAttributes, x10208_04)[0] == 40); // OK static assert(__traits(getAttributes, x10208_05)[0] == 50); // OK static assert(__traits(getAttributes, x10208_06)[0] == 60); // Error -> OK static assert(__traits(getAttributes, x10208_07)[0] == 70); // Error -> OK static assert(__traits(getAttributes, x10208_08)[0] == 80); // OK static assert(__traits(getAttributes, x10208_09)[0] == 90); // OK static assert(__traits(getAttributes, x10208_10)[0] == 100); // OK static assert(__traits(getAttributes, x10208_11)[0] == 110); // OK static assert(__traits(getAttributes, x10208_12)[0] == 120); // OK static assert(__traits(getAttributes, x10208_13)[0] == 130); // Error -> OK static assert(__traits(getAttributes, x10208_14)[0] == 140); // Error -> OK /************************************************/ // 11677, 11678 bool test_uda(alias func)() @safe { alias Tuple!(__traits(getAttributes, func)) udas; static assert([udas] == [10, 20]); func(); // @safe attribute check return true; } @(10) @(20) @safe void func11677a() {} // OK @safe @(10) @(20) void func11677b() {} // OK <- NG @(10) @safe @(20) void func11677c() {} // OK <- NG static assert(test_uda!func11677a()); static assert(test_uda!func11677b()); static assert(test_uda!func11677c()); void func11678a() @safe @(10) @(20) {} // OK <- NG void func11678b() @(10) @safe @(20) {} // OK <- NG void func11678c() @(10) @(20) @safe {} // OK <- NG static assert(test_uda!func11678a()); static assert(test_uda!func11678b()); static assert(test_uda!func11678c()); /************************************************/ // 11678 class C11678 { this() @(10) @(20) {} ~this() @(10) @(20) {} } //static this() @(10) @(20) {} static ~this() @(10) @(20) {} //shared static this() @(10) @(20) {} shared static ~this() @(10) @(20) {} /************************************************/ // 11679 void test11679() { @(10) @(20) auto var = 1; static assert([__traits(getAttributes, var)] == [10, 20]); } /************************************************/ // 11680 @(10) gvar11680 = 1; // OK <- NG @(10) gfun11680() {} // OK <- NG void test11680() { @(10) lvar11680 = 1; // OK <- NG @(10) lfun11680() {} // OK <- NG } /************************************************/ // 11844 auto make_encode11844(T, string name)() { return mixin("function(T self) { return self.encodeField!\""~ name ~ "\"();}"); } class FileData11844 { ulong _member; @make_encode11844!(FileData11844, "member")() ulong member() const { return _member; } ubyte[] encodeField(string key)() { return [1,2,3]; } } static assert(__traits(getAttributes, FileData11844.member)[0](new FileData11844()) == [1,2,3]); /************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test9178(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/gdb14225.d0000644000175000017500000000031313200164642022703 0ustar matthiasmatthias/* REQUIRED_ARGS: -g PERMUTE_ARGS: GDB_SCRIPT: --- b 17 r echo RESULT= p lok --- GDB_MATCH: RESULT=.*Something */ void main() { string lok = "Something"; auto chars = "Anything".dup; // BP } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/helloUTF16.d0000644000175000017500000000016213200164642023404 0ustar matthiasmatthiasextern(C) int printf(const char *, ...); int main(char[][] args) { printf("hello world\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test17.d0000644000175000017500000000112413200164642022701 0ustar matthiasmatthias import core.stdc.stdio: fflush, stdout; extern(C) int printf(const char*, ...); void ulog(string s) { printf("%.*s\n",s.length, s.ptr); fflush(stdout); } int open() { char *s; char abs[2000]; char qu[100]; int a; ulog("reaches this only 9 times of 10!\n"); return 0; } int yhenda() { char MEM[2200]; int a; ulog("point(2.1) \n"); open(); ulog("point(2.2) \n"); return 0; } int main() { printf("Content-type: text/html\n\n"); fflush(stdout); ulog("point(1.1)\n"); yhenda(); ulog("point(1.2)\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testabi.d0000644000175000017500000006351413200164642023220 0ustar matthiasmatthias// PERMUTE_ARGS: -release -gc version(Windows) {} else version(X86_64) { /* uncomment to enable tests! */ //version = Run_X86_64_Tests; } extern (C) int printf(const char*, ...); template tuple(A...) { alias A tuple; } alias byte B; alias short S; alias int I; alias long L; alias float F; alias double D; alias real R; // Single Type struct b { B a; } struct bb { B a,b; } struct bbb { B a,b,c; } struct bbbb { B a,b,c,d; } struct bbbbb { B a,b,c,d, e; } struct b6 { B a,b,c,d, e,f; } struct b7 { B a,b,c,d, e,f,g; } struct b8 { B a,b,c,d, e,f,g,h; } struct b9 { B a,b,c,d, e,f,g,h, i; } struct b10 { B a,b,c,d, e,f,g,h, i,j; } struct b11 { B a,b,c,d, e,f,g,h, i,j,k; } struct b12 { B a,b,c,d, e,f,g,h, i,j,k,l; } struct b13 { B a,b,c,d, e,f,g,h, i,j,k,l, m; } struct b14 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n; } struct b15 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n,o; } struct b16 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p; } struct b17 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p, q; } struct b18 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p, q,r; } struct b19 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p, q,r,s; } struct b20 { B a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p, q,r,s,t;} struct s { S a; } struct ss { S a,b; } struct sss { S a,b,c; } struct ssss { S a,b,c,d; } struct sssss { S a,b,c,d, e; } struct s6 { S a,b,c,d, e,f; } struct s7 { S a,b,c,d, e,f,g; } struct s8 { S a,b,c,d, e,f,g,h; } struct s9 { S a,b,c,d, e,f,g,h, i; } struct s10 { S a,b,c,d, e,f,g,h, i,j;} struct i { I a; } struct l { L a; } struct ii { I a,b; } struct ll { L a,b; } struct iii { I a,b,c; } struct lll { L a,b,c; } struct iiii { I a,b,c,d; } struct llll { L a,b,c,d; } struct iiiii { I a,b,c,d,e; } struct lllll { L a,b,c,d,e; } struct f { F a; } struct d { D a; } struct ff { F a,b; } struct dd { D a,b; } struct fff { F a,b,c; } struct ddd { D a,b,c; } struct ffff { F a,b,c,d; } struct dddd { D a,b,c,d; } struct fffff { F a,b,c,d,e; } struct ddddd { D a,b,c,d,e; } // Mixed Size struct js { I a; S b; } struct iss { I a; S b,c; } struct si { S a; I b; } struct ssi { S a,b; I c; } struct sis { S a; I b; S c; } struct ls { L a; S b; } struct lss { L a; S b,c; } struct sl { S a; L b; } struct ssl { S a,b; L c; } struct sls { S a; L b; S c; } struct li { L a; I b; } struct lii { L a; I b,c; } struct il { I a; L b; } struct iil { I a,b; L c; } struct ili { I a; L b; I c; } struct df { D a; F b; } struct dff { D a; F b,c; } struct fd { F a; D b; } struct ffd { F a,b; D c; } struct fdf { F a; D b; F c; } // Mixed Types struct fi { F a; I b; } struct fii { F a; I b,c; } struct jf { I a; F b; } struct iif { I a,b; F c; } struct ifi { I a; F b; I c; } struct ffi { F a,b; I c; } struct ffii { F a,b; I c,d; } struct iff { I a; F b,c; } struct iiff { I a,b; F c,d; } struct ifif { I a; F b; I c; F d;} struct di { D a; I b; } struct dii { D a; I b,c; } struct id { I a; D b; } struct iid { I a,b; D c; } struct idi { I a; D b; I c; } // Real ( long double ) struct r { R a; } struct rr { R a,b; } struct rb { R a; B b; } struct rf { R a; F b; } struct fr { F a; R b; } // Int Registers only alias tuple!( b,bb,bbb,bbbb,bbbbb, b6, b7, b8, b9, b10, b11,b12,b13,b14,b15, b16,b17,b18,b19,b20, s,ss,sss,ssss,sssss, s6, s7, s8, s9, s10, i,ii,iii,iiii,iiiii, l,ll,lll,llll,lllll, // js,iss,si,ssi, sis, ls,lss,sl,ssl, sls, li,lii,il,iil, ili, fi,fii,jf,iif, ifi, ffi,ffii,iff,iiff,ifif, // INT_END // SSE registers only f,ff,fff,ffff,fffff, d,dd,ddd,dddd,ddddd, // df,dff,fd,ffd, fdf, // SSE_END // Int and SSE di, dii,id, iid, idi, // MIX_END // --- ) ALL_T; enum INT_END = 65; enum SSE_END = 80; enum MIX_END = ALL_T.length; // x87 alias tuple!( r,rr,rb,rf,fr, // --- ) R_T; //"r","rr","rb","rf","fr", string[] ALL_S=[ "b","bb","bbb","bbbb","bbbbb", "b6", "b7", "b8", "b9", "b10", "b11","b12","b13","b14","b15", "b16","b17","b18","b19","b20", "s","ss","sss","ssss","sssss", "s6","s7","s8","s9" , "s10", "i","ii","iii","iiii","iiiii", "l","ll","lll","llll","lllll", // --- "js","iss","si","ssi", "sis", "ls","lss","sl","ssl", "sls", "li","lii","il","iil", "ili", "fi","fii","jf","iif", "ifi", "ffi","ffii","iff","iiff","ifif", // --- "f","ff","fff","ffff","fffff", "d","dd","ddd","dddd","ddddd", "df","dff","fd","ffd", "dfd", // --- "di","dii","id","iid","idi", ]; /* *********************************************************************** All ************************************************************************/ // test1 Struct passing and return int[MIX_END] results_1; T test1_out(T)( ) { T t; foreach( i, ref e; t.tupleof ) e = i+1; return t; } T test1_inout(T)( T t) { foreach( i, ref e; t.tupleof ) e += 10; return t; } void test1_call_out(T)( int n ) { T t1; foreach( i, ref e; t1.tupleof ) e = i+1; T t2 = test1_out!(T)(); if( t1 == t2 ) results_1[n] |= 1; } void test1_call_inout(T)( int n ) { T t1; foreach( i, ref e; t1.tupleof ) e = i+1; T t2 = test1_inout!(T)( t1 ); foreach( i, ref e; t1.tupleof ) e += 10; if( t1 == t2 ) results_1[n] |= 2; } void D_test1( ) { // Run Tests foreach( n, T; ALL_T ) { test1_call_out!(T)(n); test1_call_inout!(T)(n); } bool pass = true; foreach( i, r; results_1 ) { if( ~r & 1 ) { pass = false; printf( "Test1 out %s \tFail\n", ALL_S[i].ptr ); } if( ~r & 2 ) { pass = false; printf( "Test1 inout %s \tFail\n", ALL_S[i].ptr ); } } assert( pass ); results_1[0..5] = 0; foreach( n, T; R_T ) { test1_call_out!(T)(n); test1_call_inout!(T)(n); } } /************************************************************************/ // based on runnable/test23.d : test44() // Return Struct into an Array struct S1 { int i,j; static S1 foo(int x) { S1 s; s.i = x; return s; } } struct S2 { int i,j,k; static S2 foo(int x) { S2 s; s.i = x; return s; } } struct S3 { float i,j; static S3 foo(int x) { S3 s; s.i = x; return s; } } struct S4 { float i,j,k; static S4 foo(int x) { S4 s; s.i = x; return s; } } struct S5 { float i,j; int k; static S5 foo(float x) { S5 s; s.i = x; return s; } } void D_test2() { S1[] s1; S2[] s2; S3[] s3; S4[] s4; S5[] s5; s1 = s1 ~ S1.foo(6); s1 = s1 ~ S1.foo(1); s2 = s2 ~ S2.foo(6); s2 = s2 ~ S2.foo(1); s3 = s3 ~ S3.foo(6); s3 = s3 ~ S3.foo(1); s4 = s4 ~ S4.foo(6); s4 = s4 ~ S4.foo(1); s5 = s5 ~ S5.foo(6); s5 = s5 ~ S5.foo(1); assert( s1.length == 2 ); assert( s1[0].i == 6 ); assert( s1[1].i == 1 ); assert( s2.length == 2 ); assert( s2[0].i == 6 ); assert( s2[1].i == 1 ); /+ // These Fail on Mainline DMD64 ( Should pass! ) assert( s3.length == 2 ); assert( s3[0].i == 6 ); assert( s3[1].i == 1 ); assert( s4.length == 2 ); assert( s4[0].i == 6 ); assert( s4[1].i == 1 ); +/ assert( s5.length == 2 ); assert( s5[0].i == 6 ); assert( s5[1].i == 1 ); } /* *********************************************************************** X86_64 ************************************************************************/ version(Run_X86_64_Tests) { struct TEST { immutable int num; immutable string desc; bool[MIX_END] result; } /** * 0 = Should Fail * 1 = Should Pass */ immutable int[MIX_END] expected = [ 1,1,1,1,1, // b 1,1,1,1,1, // b6 1,1,1,1,1, // b11 1,0,0,0,0, // b16 1,1,1,1,1, // s 1,1,1,0,0, // s6 1,1,1,1,0, // i 1,1,0,0,0, // l 1,1,1,1,1, // si mix 1,1,1,1,0, // sl 1,1,1,1,0, // il 1,1,1,1,1, // int and float 1,1,1,1,1, // int and float // SSE regs only 1,1,1,1,0, // f 1,1,0,0,0, // d 1,1,1,1,0, // float and double // SSE + INT regs 1,1,1,1,0, // int and double ]; /** * Describes value expected in registers * * null means do not test * ( because value is passed on the stack ). */ immutable long[][] RegValue = [ /* 0 b */ [ 0x0000000000000001, ], /* 1 bb */ [ 0x0000000000000201, ], /* 2 bbb */ [ 0x0000000000030201, ], /* 3 bbbb */ [ 0x0000000004030201, ], /* 4 bbbbb */ [ 0x0000000504030201, ], /* 5 b6 */ [ 0x0000060504030201, ], /* 6 b7 */ [ 0x0007060504030201, ], /* 7 b8 */ [ 0x0807060504030201, ], /* 8 b9 */ [ 0x0807060504030201, 0x0000000000000009 ], /* 9 b10 */ [ 0x0807060504030201, 0x0000000000000a09 ], /* 10 b11 */ [ 0x0807060504030201, 0x00000000000b0a09 ], /* 11 b12 */ [ 0x0807060504030201, 0x000000000c0b0a09 ], /* 12 b13 */ [ 0x0807060504030201, 0x0000000d0c0b0a09 ], /* 13 b14 */ [ 0x0807060504030201, 0x00000e0d0c0b0a09 ], /* 14 b15 */ [ 0x0807060504030201, 0x000f0e0d0c0b0a09 ], /* 15 b16 */ [ 0x0807060504030201, 0x100f0e0d0c0b0a09 ], /* 16 b17 */ null, /* 17 b18 */ null, /* 18 b19 */ null, /* 19 b20 */ null, /* 20 s */ [ 0x0000000000000001, ], /* 21 ss */ [ 0x0000000000020001, ], /* 22 sss */ [ 0x0000000300020001, ], /* 23 ssss */ [ 0x0004000300020001, ], /* 24 sssss */ [ 0x0004000300020001, 0x0000000000000005 ], /* 25 s6 */ [ 0x0004000300020001, 0x0000000000060005 ], /* 26 s7 */ [ 0x0004000300020001, 0x0000000700060005 ], /* 27 s8 */ [ 0x0004000300020001, 0x0008000700060005 ], /* 28 s9 */ null, /* 29 s10 */ null, /* 30 i */ [ 0x0000000000000001, ], /* 31 ii */ [ 0x0000000200000001, ], /* 32 iii */ [ 0x0000000200000001, 0x0000000000000003 ], /* 33 iiii */ [ 0x0000000200000001, 0x0000000400000003 ], /* 34 iiiii */ null, /* 35 l */ [ 0x0000000000000001, ], /* 36 ll */ [ 0x0000000000000001, 0x0000000000000002 ], /* 37 lll */ null, /* 38 llll */ null, /* 39 lllll */ null, /* 40 js */ [ 0x0000000200000001, ], /* 41 iss */ [ 0x0003000200000001, ], /* 42 si */ [ 0x0000000200000001, ], /* 43 ssi */ [ 0x0000000300020001, ], /* 44 sis */ [ 0x0000000200000001, 0x0000000000000003 ], /* 45 ls */ [ 0x0000000000000001, 0x0000000000000002 ], /* 46 lss */ [ 0x0000000000000001, 0x0000000000030002 ], /* 47 sl */ [ 0x0000000000000001, 0x0000000000000002 ], /* 48 ssl */ [ 0x0000000000020001, 0x0000000000000003 ], /* 49 sls */ null, /* 50 li */ [ 0x0000000000000001, 0x0000000000000002 ], /* 51 lii */ [ 0x0000000000000001, 0x0000000300000002 ], /* 52 il */ [ 0x0000000000000001, 0x0000000000000002 ], /* 53 iil */ [ 0x0000000200000001, 0x0000000000000003 ], /* 54 ili */ null, /* 55 fi */ [ 0x000000023f800000, ], /* 56 fii */ [ 0x000000023f800000, 0x0000000000000003 ], /* 57 jf */ [ 0x4000000000000001, ], /* 58 iif */ [ 0x0000000200000001, 0x0000000040400000 ], /* 59 ifi */ [ 0x4000000000000001, 0x0000000000000003 ], /* 60 ffi */ [ 0x0000000000000003, 0x400000003f800000 ], /* 61 ffii */ [ 0x0000000400000003, 0x400000003f800000 ], /* 62 iff */ [ 0x4000000000000001, 0x0000000040400000 ], /* 63 iiff */ [ 0x0000000200000001, 0x4080000040400000 ], /* 64 ifif */ [ 0x4000000000000001, 0x4080000000000003 ], /* 65 f */ [ 0x000000003f800000, ], /* 66 ff */ [ 0x400000003f800000, ], /* 67 fff */ [ 0x400000003f800000, 0x0000000040400000 ], /* 68 ffff */ [ 0x400000003f800000, 0x4080000040400000 ], /* 69 fffff */ null, /* 70 d */ [ 0x3ff0000000000000, ], /* 71 dd */ [ 0x3ff0000000000000, 0x4000000000000000 ], /* 72 ddd */ null, /* 73 dddd */ null, /* 74 ddddd */ null, /* 75 df */ [ 0x3ff0000000000000, 0x0000000040000000 ], /* 76 dff */ [ 0x3ff0000000000000, 0x4040000040000000 ], /* 77 fd */ [ 0x000000003f800000, 0x4000000000000000 ], /* 78 ffd */ [ 0x400000003f800000, 0x4008000000000000 ], /* 79 fdf */ null, /* 80 di */ [ 0x3ff0000000000000, 0x0000000000000002 ], /* 81 dii */ [ 0x3ff0000000000000, 0x0000000300000002 ], /* 82 id */ [ 0x4000000000000000, 0x0000000000000001 ], /* 83 iid */ [ 0x4008000000000000, 0x0000000200000001 ], /* 84 idi */ null, ]; /* Have to do it this way for OSX: Issue 7354 */ __gshared long[2] dump; /** * Generate Register capture */ string gen_reg_capture( int n, string registers )( ) { if( RegValue[n] == null ) return "return;"; string[] REG = mixin(registers); // ["RDI","RSI"]; // Which type of compare static if(n < INT_END) enum MODE = 1; // Int else static if(n < SSE_END) enum MODE = 2; // Float else enum MODE = 3; // Mix /* Begin */ string code = "asm {\n"; final switch( MODE ) { case 1: code ~= "mov [dump], "~REG[0]~";\n"; REG = REG[1..$]; break; case 2: case 3: code ~= "movq [dump], XMM0;\n"; } if( RegValue[n].length == 2 ) final switch( MODE ) { case 1: case 3: code ~= "mov [dump+8], "~REG[0]~";\n"; break; case 2: code ~= "movq [dump+8], XMM1;\n"; } else { code ~= "xor R8, R8;\n"; code ~= "mov [dump+8], R8;\n"; } return code ~ "}\n"; } /** * Check the results */ bool check( TEST data ) { bool pass = true; foreach( i, e; expected ) { if( data.result[i] != (e & 1) ) { printf( "Test%d %s \tFail\n", data.num, ALL_S[i].ptr); pass = false; } } return pass; } /************************************************************************/ // test1 Return Struct in Registers // ( if RDI == 12 we have no hidden pointer ) TEST data1 = { 1, "RDI hidden pointer" }; T test1_asm( T, int n )( int i ) { asm { cmp EDI, 12; je L1; leave; ret; } L1: data1.result[n] = true; } void test1() { printf("\nRunning iasm Test 1 ( %s )\n", data1.desc.ptr); foreach( int n, T; ALL_T ) test1_asm!(T,n)(12); check( data1 ); } /************************************************************************/ // test2 Pass Struct in Registers // ( if RDI == 0 we have no stack pointer ) TEST data2 = { 2, "RDI struct pointer" }; T test2_asm( T, int n )( T t ) { asm { mov [dump], RDI; mov [dump+8], RSP; cmp EDI, 0; // TODO test RDI is a ptr to stack ? ? je L1; leave; ret; } L1: data2.result[n] = true; } T test2f_asm( T, int n )( T t, int x ) { asm { cmp EDI, 12; je L1; leave; ret; } L1: data2.result[n] = true; } void test2() { printf("\nRunning iasm Test 2 ( %s )\n", data2.desc.ptr); // Integer foreach( int n, T; ALL_T ) { T t = { 0 }; test2_asm!(T,n)( t ); } // float alternative test foreach( int n, T; ALL_T[INT_END..SSE_END] ) { enum n2 = n + INT_END; data2.result[n2] = false; test2f_asm!(T,n2)( T.init, 12 ); } check( data2 ); } /************************************************************************/ // test3 TEST data3 = { 3, "Check Return Register value" }; void test3_run( T, int n )( ) { test3_ret!T(); mixin( gen_reg_capture!(n,`["RAX","RDX"]`)() ); //dbg!(T,n)( ); enum len = RegValue[n].length; if( dump[0..len] == RegValue[n] ) data3.result[n] = true; } T test3_ret( T )( ) { T t; foreach( i, ref e; t.tupleof ) e = i+1; return t; } void test3() { printf("\nRunning iasm Test 3 ( %s )\n", data3.desc.ptr); foreach( int n, T; ALL_T ) test3_run!(T,n)( ); check( data3 ); } /************************************************************************/ // test4 TEST data4 = { 4, "Check Input Register value" }; void test4_run( T, int n )( T t ) { mixin( gen_reg_capture!(n,`["RDI","RSI"]`)() ); //dbg!(T,n)( ); enum len = RegValue[n].length; if( dump[0..len] == RegValue[n] ) data4.result[n] = true; } void dbg( T, int n )( ) { import std.stdio; writefln( "D %s\t[ %16x, %16x ]", T.stringof, dump[0], dump[1], ); writef( "C %s\t[ %16x", T.stringof, RegValue[n][0] ); if( RegValue[n].length == 2 ) writef( ", %16x", RegValue[n][1] ); writefln( " ]" ); } void test4() { printf("\nRunning iasm Test 4 ( %s )\n", data4.desc.ptr); foreach( int n, T; ALL_T ) { T t; foreach( i, ref e; t.tupleof ) e = i+1; test4_run!(T,n)( t ); } check( data4 ); } } // end version(Run_X86_64_Tests) /************************************************************************/ void main() { D_test1(); D_test2(); version(Run_X86_64_Tests) { test1(); test2(); test3(); test4(); } } /+ /** * C code to generate the table RegValue */ string c_generate_returns() { string value = " 1, 2, 3, 4, 5, 6, 7, 8, 9,10," "11,12,13,14,15,16,17,18,19,20,"; string code = "#include \"cgen.h\"\n"; // Generate return functions foreach( int n, T; ALL_T ) { auto Ts = T.stringof; auto len = T.tupleof.length; code ~= "struct "~Ts~" func_ret_"~Ts~"(void) { \n"; code ~= "struct "~Ts~" x = { "; code ~= value[0..len*3] ~ " };\n"; code ~= "return x;\n}\n"; } return code; } string c_generate_pass() { string value = " 1, 2, 3, 4, 5, 6, 7, 8, 9,10," "11,12,13,14,15,16,17,18,19,20,"; string code; // Generate return functions foreach( int n, T; ALL_T ) { auto Ts = T.stringof; auto len = T.tupleof.length; code ~= "void func_pass_"~Ts~"( struct "~Ts~" x ) {\n"; //////////////// // Which type of compare static if(n < INT_END) enum MODE = 1; // Int else static if(n < SSE_END) enum MODE = 2; // Float else enum MODE = 3; // Mix auto nn = n.stringof; /* Begin */ code ~= "asm(\n"; final switch( MODE ) { case 1: code ~= `"movq %rdi, reg\n" "movq %rsi, reg+8\n"`; break; case 2: code ~= `"movq %xmm0, reg\n" "movq %xmm1, reg+8\n"`; break; case 3: code ~= `"movq %xmm0, reg\n" "movq %rdi, reg+8\n"`; } code ~= "\n);\n"; code ~= "}\n"; //////////////// code ~= "void func_call_"~Ts~"( void ) {\n"; code ~= "struct "~Ts~" x = { "; code ~= value[0..len*3] ~ " };\n"; code ~= "func_pass_"~Ts~"( x );\n}\n"; } return code; } string c_generate_main() { string code = "void main() {\n"; foreach( int n, T; ALL_T ) { // Which type of compare static if(n < INT_END) enum MODE = 1; // Int else static if(n < SSE_END) enum MODE = 2; // Float else enum MODE = 3; // Mix auto nn = n.stringof; auto Ts = T.stringof; /* Begin */ code ~= `printf("/* %3d `~Ts~`\t*/ ", `~nn~`);`"\n"; if( !(expected[n] & 1) ) { code ~= `printf("null,\n");`"\n"; continue; } code ~= "asm(\n"; code ~= `"call func_ret_`~Ts~`\n"`"\n"; final switch( MODE ) { case 1: code ~= `"movq %rax, reg\n" "movq %rdx, reg+8\n"`; break; case 2: code ~= `"movq %xmm0, reg\n" "movq %xmm1, reg+8\n"`; break; case 3: code ~= `"movq %xmm0, reg\n" "movq %rax, reg+8\n"`; } code ~= "\n);\n"; code ~= `printf("[ 0x%016lx", reg.r1 );`"\n"; if( T.sizeof > 8 || MODE == 3 ) code ~= `printf(", 0x%016lx ],\n", reg.r2 );`"\n"; else code ~= `printf(", %015c ],\n", ' ' );`"\n"; } foreach( int n, T; ALL_T ) { // Which type of compare static if(n < INT_END) enum MODE = 1; // Int else static if(n < SSE_END) enum MODE = 2; // Float else enum MODE = 3; // Mix auto nn = n.stringof; auto Ts = T.stringof; /* Begin */ code ~= `printf("/* %3d `~Ts~`\t*/ ", `~nn~`);`"\n"; if( !(expected[n] & 1) ) { code ~= `printf("null,\n");`"\n"; continue; } code ~= "func_call_"~Ts~"();\n"; code ~= `printf("[ 0x%016lx", reg.r1 );`"\n"; if( T.sizeof > 8 || MODE == 3 ) code ~= `printf(", 0x%016lx ],\n", reg.r2 );`"\n"; else code ~= `printf(", %015c ],\n", ' ' );`"\n"; } return code ~ "}"; } pragma(msg, c_generate_returns() ); pragma(msg, c_generate_pass() ); pragma(msg, c_generate_main() ); // +/ /+ /** * Generate Functions that pass/return each Struct type * * ( Easier to look at objdump this way ) */ string d_generate_functions( ) { string code = "extern(C) {"; // pass foreach( s; ALL_T ) { string ss = s.stringof; code ~= "void func_in_"~ss~"( "~ss~" t ) { t.a = 12; }\n"; } // return foreach( s; ALL_T[0..10] ) { string ss = s.stringof; code ~= ` auto func_out_`~ss~`() { `~ss~` t; foreach( i, ref e; t.tupleof ) e = i+1; return t; }`; } // pass & return foreach( s; ALL_T[0..10] ) { string ss = s.stringof; code ~= ` auto func_inout_`~ss~`( `~ss~` t ) { foreach( i, ref e; t.tupleof ) e += 10; return t; }`; } return code ~ "\n} // extern(C)\n"; } //pragma( msg, d_generate_functions() ); mixin( d_generate_functions() ); // +/ ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/0000755000175000017500000000000013200164642023104 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test49a.d0000644000175000017500000000042113200164642024543 0ustar matthiasmatthiasmodule imports.test49a; import std.stdio; int x; template Foo(T) { static this() { printf("static this()\n"); assert(x == 0); x++; } static ~this() { printf("static ~this()\n"); assert(x == 1); x--; } } void baz() { alias Foo!(int) bar; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test11931d.d0000644000175000017500000000071113200164642024772 0ustar matthiasmatthiasmodule imports.test11931d; import std.array; import std.algorithm; struct ConnectionPoint { void disconnect() { if(_f) { _f(); _f = null; } } private void delegate() _f; } struct Signal(T, A...) { ConnectionPoint add(D f) { auto rf = { _arr = _arr.filter!(a => a != f).array; }; return ConnectionPoint(); } private: alias D = T delegate(A); D _arr[]; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test10441c.d0000644000175000017500000000004513200164642024764 0ustar matthiasmatthias auto boo(T)(T t) { return 1; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/b15030.d0000644000175000017500000000062113200164642024062 0ustar matthiasmatthiasmodule b; import imports.std15030algo; unittest { auto dg = // __lambda1 (int[] delegate(int[]) self) => // __lambda2 (int[] arr) => arr ? self([arr.filter!( // __lambda2.__lambda2 a => a ).front]) : null; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link13394a.d0000644000175000017500000000032613200164642024754 0ustar matthiasmatthiasmodule imports.link13394a; class A { this() { } } class Btpl(T) : T { this()() { } invariant() {} } alias B = Btpl!A; struct Stpl() { void func()() {} invariant() {} } alias S = Stpl!(); ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link2500a.d0000644000175000017500000000013613200164642024656 0ustar matthiasmatthiasmodule imports.link2500a; import link2500; import imports.link2500b; class B { S!A t; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test11745b.d0000644000175000017500000000014013200164642024767 0ustar matthiasmatthiasmodule imports.test11745b; unittest { } private unittest { } private: unittest { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test7494a.d0000644000175000017500000000024713200164642024724 0ustar matthiasmatthiasmodule imports.test7494a; template map(alias fun) { auto map(R)(R range) { return [4,5,6]; } } auto writeln(A...)(A args) { return [7,8,9]; } auto foo() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a12874.d0000644000175000017500000000023713200164642024101 0ustar matthiasmatthiasmodule imports.a12874; template foo(alias x) { void check(int[] arr) { auto n = arr[0]; } void foo() { check([]); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test10736b.d0000644000175000017500000000035313200164642024774 0ustar matthiasmatthiasmodule imports.test10736b; version(A) import std.range; else import imports.test10736c; void main() { int[] arr = [0, 1, 2, 3]; auto x = chunks(arr, 4); // error import core.stdc.stdio; printf("success\n"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test45b.d0000644000175000017500000000025413200164642024544 0ustar matthiasmatthiasmodule imports.test45b; import std.stdio; int foo(int i) { printf("foo(int)\n"); return 2; } int bar(T)(T t, int i) { printf("bar(t,i)\n"); return 4; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link11069y.d0000644000175000017500000000030213200164642024773 0ustar matthiasmatthiasimport std.traits; void readWriteVariable(T)(ref T data) { foreach (it; __traits(allMembers, T)) { enum vValid = mixin(`is(FunctionTypeOf!(T.` ~ it ~ `) == function)`); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link9571a.d0000644000175000017500000000021613200164642024674 0ustar matthiasmatthiasstruct MapResult(alias fun) { void bar() { fun(0); } } auto foo() { alias MapResult!(function(int c) => 0) M; M m; m.bar(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a19a.d0000644000175000017500000000025013200164642024001 0ustar matthiasmatthiasmodule imports.a19a; struct Dummy { } struct TemplatedStruct(Param) { static real fgh = 0; } void foo() { alias TemplatedStruct!(Dummy) X; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test46c.d0000644000175000017500000000007513200164642024547 0ustar matthiasmatthiasmodule imports.test46c; class C(T) { void foo() { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link11395a.d0000644000175000017500000000024113200164642024747 0ustar matthiasmatthiasmodule imports.link11395a; struct SA { bool flag; int[] nums; bool opEquals(bool b) { return flag == b; } } struct SB { int num; SA sa; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/tlsa.d0000644000175000017500000000105313200164642024213 0ustar matthiasmatthiasmodule imports.tlsa; import core.stdc.stdio; int foo()() { static int z = 7; return ++z; } /*************************************/ int abc4(T)(T t) { static T qqq; // TLS comdef static T rrr; // comdef static T sss = 8; // TLS comdat static T ttt = 9; // comdat printf("qqq = %d, rrr = %d, sss = %d, ttt = %d\n", qqq, rrr, sss, ttt); qqq += 2; rrr += 3; sss += 4; ttt += 5; return t + qqq + rrr + sss + ttt; } int bar4() { return abc4(4); } /*************************************/ ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link7745b.d0000644000175000017500000000014713200164642024701 0ustar matthiasmatthiasstruct C { auto asdfg() {} } // extreme test of bug 4820 void nextis(W)(void delegate() dg = {}) {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a12010.d0000644000175000017500000000012313200164642024051 0ustar matthiasmatthiasimport imports.std12010container : Array, BinaryHeap; BinaryHeap!(Array!int) test; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a12037.d0000644000175000017500000000401613200164642024067 0ustar matthiasmatthiasmodule imports.aXXXXX; auto min(A, B)(A a, B b) { return a < b ? a : b; } alias TypeTuple(T...) = T; private template CustomFloatParams(uint bits) { static if (bits == 8) alias CustomFloatParams!( 4, 3) CustomFloatParams; static if (bits == 16) alias CustomFloatParams!(10, 5) CustomFloatParams; static if (bits == 32) alias CustomFloatParams!(23, 8) CustomFloatParams; static if (bits == 64) alias CustomFloatParams!(52, 11) CustomFloatParams; static if (bits == 80) alias CustomFloatParams!(64, 15) CustomFloatParams; } private template CustomFloatParams(uint precision, uint exponentWidth) { alias TypeTuple!( precision, exponentWidth, ) CustomFloatParams; } struct CustomFloat(uint precision, uint exponentWidth) if ((1 + precision + exponentWidth) % 8 == 0 && precision + exponentWidth > 0) { private: union ToBinary(F) if (is(typeof(CustomFloatParams!(F.sizeof*8))) || is(F == real)) { F set; // If on Linux or Mac, where 80-bit reals are padded, ignore the // padding. CustomFloat!(CustomFloatParams!(min(F.sizeof*8, 80))) get; // Convert F to the correct binary type. static typeof(get) opCall(F value) { ToBinary r; r.set = value; return r.get; } alias get this; } public: @property bool sign() { return 1; } @property void sign(bool) {} this(F)(F input) if (__traits(compiles, cast(real)input)) { this = input; } void opAssign(F)(F input) if (__traits(compiles, cast(real)input)) { static if (is(F == float) || is(F == double) || is(F == real)) auto value = ToBinary!(F)(input); else auto value = ToBinary!(real)(input); sign = value.sign; } @property F get(F)() if (is(F == float) || is(F == double) || is(F == real)) { ToBinary!F result; return F.init; } T opCast(T)() if (__traits(compiles, get!T)) { return get!T; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test38a.d0000644000175000017500000000007613200164642024547 0ustar matthiasmatthiasmodule imports.test38a; int bar(int i) { return i * i; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link10920a.d0000644000175000017500000000060713200164642024746 0ustar matthiasmatthiasmodule imports.link10920a; struct FormatSpec(C) { void func() {} } struct BitArray { auto toString() { // An auto function may runs semantic3 to calculate return type, // even if it's non-root symbol. // But inside the function body, all instantiations should be treated // as speculative. FormatSpec!char fs; fs.func(); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/std11863conv.d0000644000175000017500000000473513200164642025345 0ustar matthiasmatthiasmodule imports.std11863conv; import imports.std11863format; template to(T) { T to(A...)(A args) { return toImpl!T(args); } } T toImpl(T, S)(S value) { static if (is(S == int) && is(T == string)) { // other integral-to-string conversions with default radix return toImpl!(T, S)(value, 10); } else static assert(0); } @trusted pure T toImpl(T, S)(S value, uint radix/*, LetterCase letterCase = LetterCase.upper*/) { static assert(is(S == int) && is(T == string)); alias EEType = char/*Unqual!(typeof(T.init[0]))*/; T toStringRadixConvert(size_t bufLen, uint radix = 0, bool neg = false)(uint runtimeRadix = 0) { static if (neg) ulong div = void, mValue = cast(uint)(-value); else uint/*Unsigned!(Unqual!S)*/ div = void, mValue = cast(uint)(value); size_t index = bufLen; EEType[bufLen] buffer = void; char baseChar = /*letterCase == LetterCase.lower ? 'a' : */'A'; char mod = void; do { static if (radix == 0) { div = cast(S)(mValue / runtimeRadix ); mod = cast(ubyte)(mValue % runtimeRadix); mod += mod < 10 ? '0' : baseChar - 10; } else static if (radix > 10) { div = cast(S)(mValue / radix ); mod = cast(ubyte)(mValue % radix); mod += mod < 10 ? '0' : baseChar - 10; } else { div = cast(S)(mValue / radix); mod = mValue % radix + '0'; } buffer[--index] = cast(char)mod; mValue = div; } while (mValue); static if (neg) { buffer[--index] = '-'; } return cast(T)buffer[index .. $].dup; } //enforce(radix >= 2 && radix <= 36, new ConvException("Radix error")); switch(radix) { case 10: if (value < 0) return toStringRadixConvert!(S.sizeof * 3 + 1, 10, true)(); else return toStringRadixConvert!(S.sizeof * 3, 10)(); //case 16: // return toStringRadixConvert!(S.sizeof * 2, 16)(); //case 2: // return toStringRadixConvert!(S.sizeof * 8, 2)(); //case 8: // return toStringRadixConvert!(S.sizeof * 3, 8)(); default: assert(0);//return toStringRadixConvert!(S.sizeof * 6)(radix); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/bug10425.d0000644000175000017500000000044713200164642024427 0ustar matthiasmatthiasmodule imports.bug10425; struct A() { int opCmp(const ref A p) const { return 0; } string toString() { return ""; } } struct B() { void foo() { auto a = new A!(); } } struct C { alias A!() a_t; this(B!() b) { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/extern1a.d0000644000175000017500000000003613200164642024777 0ustar matthiasmatthiasextern (C) { int x = 3; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/testmod1b.d0000644000175000017500000000011513200164642025150 0ustar matthiasmatthiasmodule imports.testmod1b; import testmod1; void bar3() { Foo!(int) w; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/template_ovs2.d0000644000175000017500000000267313200164642026045 0ustar matthiasmatthiasmodule imports.template_ovs2; /***************************************************/ // 1900 - template overload set auto foo1900a(T)(T arg) if (is(T : const(char)[])) { return 2; } auto foo1900b(int num) { return 1; } auto bar1900a(T)(T arg) if (is(T : const(char)[])) { return 2; } auto bar1900b(T)(T arg) if (is(T : double)) { return 1; } auto baz1900(T)(T arg) if (is(T : Object)) { return 3; } auto baz1900(T)(T arg) if (is(T : const(char)[])) { return 4; } auto bad1900(string op)() if (op == "++") { return 2; } mixin template Mix1900_B() { auto mixfooa(T)(T) { return 2; } auto mixfoob() { return 1; } mixin Mix1900_SubB; } mixin template Mix1900_SubB() { auto mixsubfooa(T)(T) { return 2; } auto mixsubfoob() { return 1; } } auto merge1900(T)(string) { return 2; } /***************************************************/ // 1900 class BClass1900 {} template Traits1900(T : BClass1900) { enum name = "BClass"; } string func1900(BClass1900 b) { return "BClass"; } void Value1900a() {} template Value1900a(T) if (is(T == string)) { enum Value1900a = 2; } template Value1900b(T) if (is(T == string)) { enum Value1900b = 2; } void Value1900b() {} /***************************************************/ // 8352 void remove8352a(in char[] name) {} Range remove8352b(alias pred, Range)(Range range) { return range; } /***************************************************/ // 10658 template Val10658(long n) { enum Val10658 = 2; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link8023b.d0000644000175000017500000000005313200164642024663 0ustar matthiasmatthiasmodule imports.link8023b; import link8023; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a20a.d0000644000175000017500000000001413200164642023767 0ustar matthiasmatthiasimport a20; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test46a.d0000644000175000017500000000030313200164642024537 0ustar matthiasmatthiasmodule imports.test46a; private import imports.test46c; interface I { void anything(); } class A : I { private C!(char) c; this() { c = new C!(char) (); } void anything() {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link14074y.d0000644000175000017500000000077713200164642025012 0ustar matthiasmatthiasmodule imports.link14074y; void encode(R, E)(R sink, E value) { encodeInt(sink); encodeArray(sink, value); static assert(false); } void encodeInt(R)(R sink) { encodeLongType(sink); } void encodeLongType(R)(R sink) { import imports.link14074x; put(sink); } void encodeArray(R, A)(R sink, A) { encodeArrayHead(sink, __traits(compiles, { encode(cast(ubyte[])null, A.tupleof[0].init); })); } void encodeArrayHead(R)(R sink, ulong arrayLength) { encodeLongType(sink); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test40a.d0000644000175000017500000000112513200164642024534 0ustar matthiasmatthiasmodule imports.test40a; import std.stdio; template Mix() { static void foobar() { auto context = new Context; auto ts = context.toString; printf("context: %.*s %p\n", ts.length, ts.ptr, context); context.func!(typeof(this))(); printf("returning from opCall\n"); } } class Bar { mixin Mix; } void someFunc(string z) { printf("str length: %d\n", z.length); printf("str: '%.*s'\n", z.length, z.ptr); } class Context { void func(T)() { printf("\n"); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link2644a.d0000644000175000017500000000023313200164642024665 0ustar matthiasmatthiasmodule imports.link2644a; import imports.link2644c; import imports.link2644b; version(X) struct X { alias C!(bool) CA; } else alias C!(bool) CA; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ice4481a.d0000644000175000017500000000020113200164642024464 0ustar matthiasmatthiasmodule imports.ice4481a; template reduce(alias pred) { auto reduce(R)(R range) { return pred(range[0]); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/testkwd_file.d0000644000175000017500000000367213200164642025745 0ustar matthiasmatthiasmodule imports.testkwd; /****************************************/ version(Windows) enum sep = "\\"; else enum sep = "/"; enum thatFile = "runnable"~sep~"imports"~sep~"testkwd_file.d"; enum thatMod = "imports.testkwd"; //enum thatLine; enum thatFunc = "imports.testkwd.getCalleeFunc"; enum thatFunc2 = `string imports.testkwd.getCalleeFunc2(int x = 1, string s = "hello")`; string getCalleeFile() { return __FILE__; } ulong getCalleeLine() { return __LINE__; } enum thatLine = 14; string getCalleeMod() { return __MODULE__; } string getCalleeFunc() { return __FUNCTION__; } string getCalleeFunc2(int x = 1, string s = "hello") { return __PRETTY_FUNCTION__; } /****************************************/ string getFuncArgFile (string name = __FILE__ ) { return name; } ulong getFuncArgLine (ulong lnum = __LINE__ ) { return lnum; } string getFuncArgMod (string name = __MODULE__ ) { return name; } string getFuncArgFunc (string name = __FUNCTION__ ) { return name; } string getFuncArgFunc2(string name = __PRETTY_FUNCTION__) { return name; } string getFuncTiargFile (string name = __FILE__ )() { return name; } ulong getFuncTiargLine (ulong lnum = __LINE__ )() { return lnum; } string getFuncTiargMod (string name = __MODULE__ )() { return name; } string getFuncTiargFunc (string name = __FUNCTION__ )() { return name; } string getFuncTiargFunc2(string name = __PRETTY_FUNCTION__)() { return name; } template getInstTiargFile (string name = __FILE__ ) { enum getInstTiargFile = name; } template getInstTiargLine (ulong lnum = __LINE__ ) { enum getInstTiargLine = lnum; } template getInstTiargMod (string name = __MODULE__ ) { enum getInstTiargMod = name; } template getInstTiargFunc (string name = __FUNCTION__ ) { enum getInstTiargFunc = name; } template getInstTiargFunc2(string name = __PRETTY_FUNCTION__) { enum getInstTiargFunc2 = name; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a15030.d0000644000175000017500000000005013200164642024055 0ustar matthiasmatthiasmodule a; import imports.std15030algo; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/linktypeinfo_file.d0000644000175000017500000000113713200164642026765 0ustar matthiasmatthiasmodule imports.linktypeinfo_file; auto filter(alias pred, R)(R r) { return FilterResult!(pred, R)(r); } struct FilterResult(alias pred, R) { R r; bool empty() { return r.empty; } auto front() { return r.front; } void popFront() { while (!r.empty && pred(r.front)) r.popFront(); } } struct DirIterator { int[] r; @property bool empty() { return r.length == 0; } @property auto front() { return r[0]; } void popFront() { r = r[1..$]; } } auto dirEntries(string path) { bool f(int de) { return 1; } return filter!f(DirIterator()); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test29a.d0000644000175000017500000000015113200164642024541 0ustar matthiasmatthiasmodule imports.test29a; private import imports.test29b; deprecated alias imports.test29b.qwert qwert; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ovs1528b.d0000644000175000017500000000044713200164642024547 0ustar matthiasmatthiasmodule imports.ovs1528b; auto func1528(string) { return 3; } auto func1528(T)(T[]) { return 4; } auto bunc1528(T)(T[]) { return 4; } auto bunc1528(string) { return 3; } auto vunc1528(T)(T[]) { return 2; } auto wunc1528(int) { return 1; } auto opUnary1528(string op : "-")(int) { return 2; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/inc11239.d0000644000175000017500000000012413200164642024417 0ustar matthiasmatthias// REQUIRED_ARGS: int foo(T)(T x) { return 3; } debug { int x = foo(2); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link14074x.d0000644000175000017500000000005713200164642025000 0ustar matthiasmatthiasmodule imports.link14074x; void put(R)(R) { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ovs1528a.d0000644000175000017500000000047313200164642024545 0ustar matthiasmatthiasmodule imports.ovs1528a; auto func1528() { return 1; } auto func1528(T)(T) if (is(T : real)) { return 2; } auto bunc1528(T)(T) if (is(T : real)) { return 2; } auto bunc1528() { return 1; } auto vunc1528(int) { return 1; } auto wunc1528(T)(T[]) { return 2; } auto opUnary1528(string op : "+")(int) { return 1; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test29b.d0000644000175000017500000000005713200164642024547 0ustar matthiasmatthiasmodule imports.test29b; const int qwert = 42; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/b26a.d0000644000175000017500000000010113200164642023773 0ustar matthiasmatthiasmodule imports.b26a; import b26; void foo(List!(char) list) {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link14074z.d0000644000175000017500000000151113200164642024776 0ustar matthiasmatthiasimport imports.link14074z; void replaceAllWith(RE)(RE re) if (is(RE == S!()) || true) { auto m = RegexMatch!()(re); } struct RegexMatch() { this(RE)(RE prog) { enum x = is(RE == S!()); } } struct S() // StaticRegex { alias Matcher = BTM!(); alias M = Matcher!(); } struct Input() { struct L { auto loopBack() { return Input(); } } auto loopBack() { return L(); } } template BTM() // BacktrackingMatcher { struct BTM(Stream = Input!()) { Stream s; dchar front; this(Stream stream) { } auto bwdMatcher(ref BTM matcher) { alias BMTempl = .BTM!(); alias BM = BMTempl!(typeof(s.loopBack())); auto m = BM(s.loopBack()); } } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/b11447.d0000644000175000017500000000022513200164642024072 0ustar matthiasmatthiasclass A {} void map(alias dg)(int b) { } auto aaa(A a) { int bs; static A ggg; bs.map!( b => (a is ggg ? "a" : "b") ); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/m1a.d0000644000175000017500000000016113200164642023725 0ustar matthiasmatthiasmodule imports.m1a; import m1; A aFunc( aliasM1 f ) { return f(); // line 7 } //A aFunc( A function() f ); ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ice10857b.d0000644000175000017500000000050013200164642024553 0ustar matthiasmatthiasmodule imports.ice10857b; import imports.ice10857a; import imports.ice10857b; void foo(int outer) { int[] infos = [1]; auto f1 = filter!(s => outer)(infos); // NG: error is triggered here f1.popFront(); auto f2 = filter!((int s)=>outer)(infos); // OK f2.popFront(); } void main() { foo(123); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/bug846.d0000644000175000017500000000135513200164642024274 0ustar matthiasmatthiasmodule imports.bug846; template ElemTypeOf( T ) { alias typeof(T.init[0]) ElemTypeOf; } template removeIf_( Elem, Pred ) { size_t fn( Elem[] buf, Pred pred ) { void exch( size_t p1, size_t p2 ) { Elem t = buf[p1]; buf[p1] = buf[p2]; buf[p2] = t; } size_t cnt = 0; for( size_t pos = 0, len = buf.length; pos < len; ++pos ) { if( pred( buf[pos] ) ) ++cnt; else exch( pos, pos - cnt ); } return buf.length - cnt; } } template removeIf( Buf, Pred ) { size_t removeIf( Buf buf, Pred pred ) { return removeIf_!(ElemTypeOf!(Buf), Pred).fn( buf, pred ); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ldc_github_131_1a.d0000644000175000017500000000070213200164642026321 0ustar matthiasmatthiasmodule imports.ldc_github_131_1a; struct FilterResult(alias pred, Range) { Range _input; this(Range r) { auto a = pred(); } } struct RefCounted(T) { T payload; ~this() {} } struct DirIteratorImpl {} struct DirIterator { RefCounted!(DirIteratorImpl) impl; @property int front(){ return 0; } } auto dirEntries() { static bool f() { return false; } return FilterResult!(f, DirIterator)(DirIterator()); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/std11863bitmanip.d0000644000175000017500000000032713200164642026174 0ustar matthiasmatthiasmodule imports.std11863bitmanip; import imports.std11863format : FormatSpec; struct BitArray { void toString(scope void delegate(const(char)[]) sink, FormatSpec!char fmt) const { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/std11069container.d0000644000175000017500000000045213200164642026350 0ustar matthiasmatthiasmodule imports.std11069container; import imports.std11069range, imports.std11069typecons; struct BinaryHeap(Store) if (isInputRange!Store) //if (isRandomAccessRange!Store) { // The payload includes the support store and the effective length private RefCounted!(Tuple!(Store)) _payload; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ldc_github_131_2a.d0000644000175000017500000000027413200164642026326 0ustar matthiasmatthiasmodule imports.ldc_github_131_2a; auto filter(alias pred, Range)(Range rs) { return FilterResult!(pred, Range)(rs); } struct FilterResult(alias pred, Range) { this(Range r) {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ice10086y.d0000644000175000017500000000025613200164642024604 0ustar matthiasmatthiasmodule imports.ice10086y; auto bind(alias f, bindValues...)() { auto bind(Types...)(Types values) { return f(bindValues, values); } return bind(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a11447.d0000644000175000017500000000021013200164642024063 0ustar matthiasmatthiasstruct A { } void map(alias dg)(A r) { } struct TTT { static auto yyy(A a) { map!(b => 0)(a); } } void bar() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test35a.d0000644000175000017500000000116013200164642024537 0ustar matthiasmatthiasmodule imports.test35a; template ElemTypeOf( T ) { alias typeof(T.init[0]) ElemTypeOf; } template removeIf_( Elem, Pred ) { size_t fn( Elem[] buf, Pred pred ) { void exch( size_t p1, size_t p2 ) { Elem t = buf[p1]; buf[p1] = buf[p2]; buf[p2] = t; } size_t cnt = 0; for( size_t pos = 0, len = buf.length; pos < len; ++pos ) { if( pred( buf[pos] ) ) ++cnt; else exch( pos, pos - cnt ); } return buf.length - cnt; } } template removeIf( Buf, Pred ) { size_t removeIf( Buf buf, Pred pred ) { return removeIf_!(ElemTypeOf!(Buf), Pred).fn( buf, pred ); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test11039b.d0000644000175000017500000000016013200164642024765 0ustar matthiasmatthias module imports.test11039b; import test11039; static anotherGlobalField = SomeStruct!string("Hello Again!"); ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a18a.d0000644000175000017500000000046513200164642024010 0ustar matthiasmatthiasmodule imports.a18a; interface IEnumerator { } class Enumerator(T) : IEnumerator { this() { } } interface IContainer(T) { alias Container!(int) selected_type; IEnumerator enumerate(); } class Container(T) : IContainer!(int) { IEnumerator enumerate() { return new Enumerator!(int)(); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ldc_github_217a.d0000644000175000017500000000014313200164642026105 0ustar matthiasmatthiasmodule imports.ldc_github_217a; struct B(alias pred) { this(int r) { pred(0); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link2500b.d0000644000175000017500000000007513200164642024661 0ustar matthiasmatthiasmodule imports.link2500b; struct S(T) { void foo() {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/mangle10077.d0000644000175000017500000000027113200164642025113 0ustar matthiasmatthiasmodule imports.mangle10077; //UTF-8 chars __gshared pragma(mangle, "test_ÑльфийÑкие_пиÑьмена_9") ubyte test10077i_v; void setTest10077i() { test10077i_v = 42; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test11931a.d0000644000175000017500000000027613200164642024775 0ustar matthiasmatthiasmodule imports.test11931a; import std.stdio; import imports.test11931d; import imports.test11931b; final class Engine { package: mixin GUIManager; public: Signal!void onLeftUp; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test11931b.d0000644000175000017500000000040113200164642024764 0ustar matthiasmatthiasmodule imports.test11931b; import imports.test11931c; import imports.test11931d; class GUIElement { public: Signal!void onSubmit; } mixin template GUIManager() { public: void foo() { onLeftUp.add(&guiUp); } void guiUp() {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test14901b.d0000644000175000017500000000022713200164642024772 0ustar matthiasmatthiasmodule imports.test14901b; import imports.test14901a; alias bar = make!"bar"; struct User(int id) { int foo() { return bar; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/template13478a.d0000644000175000017500000000047513200164642025642 0ustar matthiasmatthiasmodule imports.template13478a; bool foo(T)() { // Make sure this is not inlined so template13478.o actually // needs to reference it. version (LDC) { pragma(LDC_never_inline); import ldc.llvmasm; __asm("", ""); } else { asm { nop; } } return false; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test24a.d0000644000175000017500000000006313200164642024536 0ustar matthiasmatthiasmodule imports.test24a; public import std.string; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ufcs5e.d0000644000175000017500000000107713200164642024450 0ustar matthiasmatthiasmodule imports.ufcs5e; auto f5e1(int) { return 1; } auto f5e2(string) { return 2; } auto f5e3(double) { return 3; } alias f5e4 = f5e1, f5e4 = f5e2; alias f5e5 = f5e3, f5e5 = f5e4; @property p5e1(int) { return 1; } @property p5e1(int, int) { return 1; } @property p5e2(string) { return 2; } @property p5e2(string, int) { return 2; } @property p5e3(double) { return 3; } @property p5e3(double, int) { return 3; } alias p5e4 = p5e1, p5e4 = p5e2; alias p5e4 = p5e1, p5e4 = p5e2; alias p5e5 = p5e3, p5e5 = p5e4; alias p5e5 = p5e3, p5e5 = p5e4; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/std15021conv.d0000644000175000017500000000031513200164642025321 0ustar matthiasmatthiasmodule imports.std15021conv; T to(T, A...)(A args) { return toImpl!T(args); } T toImpl(T, S)(S value) { import imports.std15021format; enforceValidFormatSpec!(S, char)('c'); return ""; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test14901c.d0000644000175000017500000000016213200164642024771 0ustar matthiasmatthiasmodule imports.test14901c; import imports.test14901b; shared static this() {} void caller1() { User!1 u; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test3b.d0000644000175000017500000000007713200164642024461 0ustar matthiasmatthiasmodule imports.test3b; import imports.test3a; class Bfoo { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/std15017variant.d0000644000175000017500000000112313200164642026023 0ustar matthiasmatthiasmodule imports.std15017; struct VariantN(size_t maxDataSize) { VariantN opAssign() { return this; } bool opEquals(T)(T) { return true; } bool opEquals(T)(ref const T) const { return true; } size_t toHash() const nothrow @trusted { return 0; } ~this() {} } alias Variant1 = VariantN!(1); alias Variant2 = VariantN!(2); alias Variant3 = VariantN!(3); alias Variant4 = VariantN!(4); alias Variant5 = VariantN!(5); alias Variant6 = VariantN!(6); alias Variant7 = VariantN!(7); alias Variant8 = VariantN!(8); alias Variant9 = VariantN!(9); alias Variant10 = VariantN!(10); ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test57a.d0000644000175000017500000000023013200164642024540 0ustar matthiasmatthiasmodule imports.test57a; import imports.test57b; // works - even fixes the error from below! // C!(int) x; // doesn't work void foo() { C!(int) x; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/depsprot_private.d0000644000175000017500000000001713200164642026641 0ustar matthiasmatthiasvoid priv() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ice10086x.d0000644000175000017500000000056713200164642024610 0ustar matthiasmatthiasmodule imports.ice10086x; import imports.ice10086y; struct S1 { int a1 = 123; } @safe auto f1(S1 r) { return r; } @safe auto f2a()(S1 r) { return bind!(f1, r); } @safe auto f2b(S1 r) { return bind!(f1, r); } void test() { S1 s1; auto za = bind!(f2a, s1)(); assert(za.a1 == 123); auto zb = bind!(f2b, s1)(); assert(zb.a1 == 123); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/c22a.d0000644000175000017500000000006513200164642024001 0ustar matthiasmatthiasmodule imports.c22a; void afn1() {} void afn2() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ufcs5b.d0000644000175000017500000000134013200164642024436 0ustar matthiasmatthiasmodule imports.ufcs5b; auto f5b1(int) { return 1; } auto f5b2(string) { return 2; } auto f5b3(double) { return 3; } alias f5b4 = f5b1, f5b4 = f5b2; alias f5b5 = f5b3, f5b5 = f5b4; @property p5b1(int) { return 1; } @property p5b1(int, int) { return 1; } @property p5b2(string) { return 2; } @property p5b2(string, int) { return 2; } @property p5b3(double) { return 3; } @property p5b3(double, int) { return 3; } alias p5b4 = p5b1, p5b4 = p5b2; alias p5b4 = p5b1, p5b4 = p5b2; alias p5b5 = p5b3, p5b5 = p5b4; alias p5b5 = p5b3, p5b5 = p5b4; /***************************************/ auto f5ov(int) { return 1; } @property p5ov(int) { return 1; } @property p5ov(int, int) { return 1; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test45a.d0000644000175000017500000000023413200164642024541 0ustar matthiasmatthiasmodule imports.test45a; import std.stdio; int foo() { printf("foo()\n"); return 1; } int bar(T)(T t) { printf("bar(t)\n"); return 3; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/template_ovs3.d0000644000175000017500000000156013200164642026040 0ustar matthiasmatthiasmodule imports.template_ovs3; /***************************************************/ // 1900 - template overload set import imports.template_ovs1; import imports.template_ovs2; struct S1900 { alias .foo1900a foo1900a; alias .foo1900b foo1900b; alias .bar1900a bar1900a; alias .bar1900b bar1900b; alias .baz1900 baz1900; alias .bad1900 bad1900; // This is a kind of Issue 1528, cannot make overload contains both templates and functions //void funcF() {} //void funcT(T)(T) {} //alias funcF funca; // make overload with alias declaration //alias funcT funca; //alias funcT funcb; // make overload with alias declaration //alias funcF funcb; mixin Mix1900_A a; mixin Mix1900_B b; } /***************************************************/ // 1900 struct Traits1900(T) if (!is(T == class)) { enum name = "any"; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test10736c.d0000644000175000017500000000065613200164642025003 0ustar matthiasmatthiasmodule imports.test10736c; struct Chunks(Source) { this(Source source, size_t chunkSize) { _source = source; _chunkSize = chunkSize; } typeof(this) opSlice(size_t, size_t) { return chunks(_source, _chunkSize); } private: Source _source; size_t _chunkSize; } Chunks!Source chunks(Source)(Source source, size_t chunkSize) { return typeof(return)(source, chunkSize); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link11069x.d0000644000175000017500000000014213200164642024774 0ustar matthiasmatthiasimport imports.link11069z; import std.algorithm; void bar() { Vector2[] tc; sort(tc); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/testmod1a.d0000644000175000017500000000011413200164642025146 0ustar matthiasmatthiasmodule imports.testmod1a; import testmod1; void bar2() { Foo!(int) w; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test39a.d0000644000175000017500000000033513200164642024546 0ustar matthiasmatthiasmodule imports.test39a; extern (C) int printf (const char*, ...); class Test (T) { final void show (in T[] msg) { printf ("%.*s\n", msg.length, msg.ptr); } } Test!(char) Global; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test9271a.d0000644000175000017500000000013113200164642024707 0ustar matthiasmatthiasmodule imports.test9271a; bool any(alias pred, Range)(Range range) { return true; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a9741.d0000644000175000017500000000020713200164642024015 0ustar matthiasmatthiasmodule imports.a9741b; template ShowAttributes(alias X) { pragma(msg, X.stringof); pragma(msg, __traits(getAttributes, X)); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ice4481b.d0000644000175000017500000000042413200164642024474 0ustar matthiasmatthiasmodule imports.ice4481b; import imports.ice4481a; class Font { public: int charHeight(dchar c) { return c == 's'; } int textHeight(in string text) { auto maxHeight = (dchar ch) { return charHeight(ch); }; return reduce!(maxHeight)(text); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/m8668b.d0000644000175000017500000000010713200164642024201 0ustar matthiasmatthiasmodule imports.m8668b; void split8668(T)(T k) if(is(T : int)) { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test10736a.d0000644000175000017500000000013713200164642024773 0ustar matthiasmatthiasmodule imports.test10736a; version(A) import std.range; else import imports.test10736c; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/std15030algo.d0000644000175000017500000000115313200164642025277 0ustar matthiasmatthiasmodule imports.std15030algo; template filter(alias pred) { auto filter(R)(R r) { return FilterResult!(pred, R)(r); } } private struct FilterResult(alias pred, R) { R _input; this(R r) { _input = r; while (_input.length != 0 && !pred(_input[0])) { _input = _input[1..$]; } } @property bool empty() { return _input.length == 0; } @property auto ref front() { return _input[0]; } void popFront() { do { _input = _input[1..$]; } while (_input.length != 0 && !pred(_input[0])); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/c22b.d0000644000175000017500000000011213200164642023773 0ustar matthiasmatthiasmodule imports.c22b; public import imports.c22a : afn1; void bfn1() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test41a.d0000644000175000017500000000020013200164642024526 0ustar matthiasmatthiasmodule imports.test41a; void foo() { assert(false, "GO"); } public void func(T)() { assert(false, "Blah"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/c11447.d0000644000175000017500000000226313200164642024077 0ustar matthiasmatthiastemplate map(fun...) { auto map(Range)(Range r) { return MapResult!(fun, Range)(r); } } private struct MapResult(alias fun, R) { R _input; this(R input) { _input = input; } @property bool empty() { return _input.length == 0; } @property auto ref front() { return fun(_input[0]); } void popFront() { _input = _input[1..$]; } } class A {} struct TemplateInstancier { auto instanciateFromResolvedArgs(A a) { auto bs = [B(a)]; static A gladeulfeurah; gladeulfeurah = a; auto r = bs.map!( b => b.apply!( function string() { assert(0); }, delegate string(i) { assert(a is gladeulfeurah, "tagazok"); return ""; } ) ); foreach (e; r) {} } } enum Tag { Undefined, A, } struct B { A a; Tag tag; this(A a) { tag = Tag.A; this.a = a; } } auto apply(alias undefinedHandler, alias handler)(B b) { final switch(b.tag) with(Tag) { case Undefined : return undefinedHandler(); case A : return handler(b.a); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link2644b.d0000644000175000017500000000023313200164642024666 0ustar matthiasmatthiasmodule imports.link2644b; import imports.link2644c; import imports.link2644a; version(X) struct X { alias C!(bool) CB; } else alias C!(bool) CB; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/depsprot_public.d0000644000175000017500000000001613200164642026444 0ustar matthiasmatthiasvoid pub() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test21a.d0000644000175000017500000000027113200164642024534 0ustar matthiasmatthiasmodule imports.test21a; struct TC(T) { void method() { void inline_function() { } } } template TB(T) { alias TC!(T) tc_instance; } struct TA(T) { mixin TB!(T); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a9546.d0000644000175000017500000000031213200164642024015 0ustar matthiasmatthiasmodule imports.a9546; struct S { private int privA; protected int protA; package int packA; private void privF() {} protected void protF() {} package void packF() {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test32a.d0000644000175000017500000000012413200164642024533 0ustar matthiasmatthiasmodule imports.test32a; struct S{ int i; } int f(){ return S.sizeof; // OK } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/std11069array.d0000644000175000017500000000037613200164642025511 0ustar matthiasmatthiasmodule imports.std11069array; @property bool empty(T)(in T[] a) @safe pure nothrow { return !a.length; } void popFront(T)(ref T[] a) @safe pure nothrow { a = a[1 .. $]; } @property ref T front(T)(T[] a) @safe pure nothrow { return a[0]; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ufcs5a.d0000644000175000017500000000107713200164642024444 0ustar matthiasmatthiasmodule imports.ufcs5a; auto f5a1(int) { return 1; } auto f5a2(string) { return 2; } auto f5a3(double) { return 3; } alias f5a4 = f5a1, f5a4 = f5a2; alias f5a5 = f5a3, f5a5 = f5a4; @property p5a1(int) { return 1; } @property p5a1(int, int) { return 1; } @property p5a2(string) { return 2; } @property p5a2(string, int) { return 2; } @property p5a3(double) { return 3; } @property p5a3(double, int) { return 3; } alias p5a4 = p5a1, p5a4 = p5a2; alias p5a4 = p5a1, p5a4 = p5a2; alias p5a5 = p5a3, p5a5 = p5a4; alias p5a5 = p5a3, p5a5 = p5a4; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link13400a.d0000644000175000017500000000070113200164642024735 0ustar matthiasmatthiasmodule imports.link13400a; struct BigInt { this(string s) {} // This template opEquals is determined to 'identity opEquals' by // hasIdentityOpEquals() in clone.c with the speculative instantiation // with dummy rvalue argument. // Then BigInt.opEquals!().opEquals(const BigInt y) const pure is stored // in template instance cache. bool opEquals()(auto ref const BigInt y) const pure { return true; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/template2962a.d0000644000175000017500000000024013200164642025544 0ustar matthiasmatthiasmodule imports.template2962a; import template2962; alias bug2962comment36!() bug2962_comment36_alias; void main() { funcC!(bool)(1.0); foo!int(0); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test3a.d0000644000175000017500000000023313200164642024452 0ustar matthiasmatthiasmodule imports.test3a; import imports.test3b; extern(C) int printf(const char*, ...); class Afoo { static this() { printf("Afoo()\n"); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/testminitAA.d0000644000175000017500000000016113200164642025471 0ustar matthiasmatthiasmodule imports.testminitAA; import core.stdc.stdio; int aa; static this() { printf("AA\n"); aa = 1; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link12144a.d0000644000175000017500000000411613200164642024745 0ustar matthiasmatthiasstruct S1 { bool opEquals(T : typeof(this))(T) { return false; } } struct S2 { bool opEquals(T : typeof(this))(T) { return false; } } struct S3 { bool opEquals(T : typeof(this))(T) { return false; } } struct S4 { bool opEquals(T : typeof(this))(T) { return false; } } struct S5 { bool opEquals(T : typeof(this))(T) { return false; } } struct S6 { bool opEquals(T : typeof(this))(T) { return false; } ~this(){} } struct S7 { bool opEquals(T : typeof(this))(T) { return false; } } struct S8 { bool opEquals(T : typeof(this))(T) { return false; } } struct S9 { bool opEquals(T : typeof(this))(T) { return false; } } struct S10 { bool opEquals(T : typeof(this))(T) { return false; } } struct S11 { bool opEquals(T : typeof(this))(T) const { return false; } int opCmp(T : typeof(this))(T) const { return 0; } size_t toHash() const nothrow @safe { return 0; } } struct S12 { bool opEquals(T : typeof(this))(T) { return false; } } struct S13 { bool opEquals(T : typeof(this))(T) { return false; } } struct S14 { bool opEquals(T : typeof(this))(T) { return false; } } struct S15 { bool opEquals(T : typeof(this))(T) { return false; } } struct S16 { bool opEquals(T : typeof(this))(T) { return false; } } struct S17 { bool opEquals(T : typeof(this))(T) { return false; } } struct S18 { bool opEquals(T : typeof(this))(T) { return false; } } void fun()() { { auto a = new S1[1]; } { auto p = new S2(); } { alias P = S3*; auto p = new P; } { S4[int] aa; auto b = (aa == aa); } { S5[] a; a.length = 10; } { S6[] a; delete a; } { S7[] a = []; } { S8[] a = [S8.init]; } { S9[int] aa = [1:S9.init]; } { auto ti = typeid(S10[int]); } { auto ti = typeid(int[S11]); } { auto ti = typeid(S12[]); } { auto ti = typeid(S13*); } { auto ti = typeid(S14[3]); } { auto ti = typeid(S15 function()); } { auto ti = typeid(S16 delegate()); } { auto ti = typeid(void function(S17)); } // TypeInfo_Function doesn't have parameter types { auto ti = typeid(void delegate(S18)); } // ditto } struct B12146 { bool opCmp(ubyte val) { return false; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/inline2a.d0000644000175000017500000002271613200164642024762 0ustar matthiasmatthias/******************************************************************************* @file Primes.d Copyright (C) 2004 Kris Bell This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for damages of any kind arising from the use of this software. Permission is hereby granted to anyone to use this software for any purpose, including commercial applications, and to alter it and/or redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment within documentation of said product would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any distribution of the source. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @version Initial version, April 2004 @author Kris *******************************************************************************/ // originally: module primes; module imports.inline2a; class Primes { private static const short primes[] = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919 ]; /********************************************************************* Binary-chop search on sorted data. *********************************************************************/ private static ptrdiff_t bsearch (in short[] array, short match) { ptrdiff_t l, u, m; l = -1; u = array.length; while (l+1 != u) { m = (l + u) / 2; if (array[m] < match) l = m; else u = m; } if (u >= array.length || array[u] != match) return -u; return u; } /********************************************************************** return a prime number between 2 and 7919 (inclusive) that is equal to or larger than the given 'target' number. **********************************************************************/ static int lookup (short target) { auto index = bsearch (primes, target); if (index < 0) index = -index; if (index >= primes.length) index = primes.length - 1; return primes[index]; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test57b.d0000644000175000017500000000006413200164642024546 0ustar matthiasmatthiasmodule imports.test57b; class C(T) { struct X {} } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/testminitBB.d0000644000175000017500000000016113200164642025473 0ustar matthiasmatthiasmodule imports.testminitBB; import core.stdc.stdio; int bb; static this() { printf("BB\n"); bb = 1; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link13415a.d0000644000175000017500000000034713200164642024751 0ustar matthiasmatthiasstruct S(alias func) { void call() { func(); } } extern(C) int printf(in char*, ...); void f(int i = 77) { void g() { printf("i = %d;\n", i); assert(i == 77); } S!g().call(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test8997a.d0000644000175000017500000000007513200164642024734 0ustar matthiasmatthiasmodule imports.test8997a; class A { A[string] foobar; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link14541traits.d0000644000175000017500000000213413200164642026034 0ustar matthiasmatthiasmodule imports.link14541traits; template hasElaborateAssign(S) { static if (is(S == struct)) { extern __gshared S lvalue; enum hasElaborateAssign = is(typeof(S.init.opAssign(S.init))) || is(typeof(S.init.opAssign(lvalue))); } else { enum bool hasElaborateAssign = false; } } void swap(T)(ref T lhs, ref T rhs) @trusted pure nothrow @nogc { static if (hasElaborateAssign!T) { } else { } } template Tuple(Types...) { struct Tuple { Types field; alias field this; this(Types values) { field[] = values[]; } void opAssign(R)(auto ref R rhs) { static if (is(R : Tuple!Types) && !__traits(isRef, rhs)) { // Use swap-and-destroy to optimize rvalue assignment swap!(Tuple!Types)(this, rhs); } else { // Do not swap; opAssign should be called on the fields. field[] = rhs.field[]; } } } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/Other.d0000644000175000017500000000041713200164642024334 0ustar matthiasmatthiasmodule imports.Other; // makes no difference if removed import Same; import core.stdc.stdio; class Other : Same // segfault // class Other : Same.Same //***UGLY ALERT*** but doesn't segfault { this() { printf("other\n"); } } int main() { new Other; return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/std15021format.d0000644000175000017500000000033613200164642025647 0ustar matthiasmatthiasmodule imports.std15021format; T enforceEx(T)(T value, lazy string msg = "") { if (!value) throw new Exception(msg); return value; } void enforceValidFormatSpec(T, Char)(int spec) { enforceEx(spec == 's'); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link13043a.d0000644000175000017500000000046213200164642024744 0ustar matthiasmatthiasmodule imports.lin13043a; struct QualifiedNameTests { struct Inner { const int opCmp(ref const Inner) { return 0; } } shared(const(Inner[string])[]) data; version(bug) size_t toHash() const { return typeid(typeof(data)).getHash(cast(const void*)&data); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/std11863format.d0000644000175000017500000000037013200164642025657 0ustar matthiasmatthiasmodule imports.std11863format; import imports.std11863bitmanip; import imports.std11863conv; struct FormatSpec(Char) { string toString() { // text(width) return to!string(1); // instantiate toImpl!(string, int) } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test27a.d0000644000175000017500000000020713200164642024541 0ustar matthiasmatthiasmodule imports.test27a; import std.variant; class myClass(T) { public: void func(T v) { Variant b = Variant(v); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a7595.d0000644000175000017500000000062213200164642024023 0ustar matthiasmatthias@trusted: import test7595; struct Matrix { int[4] _data; } void inverse(const ref Matrix m) { for (size_t i = 0; i < 4; i++) assert(m._data[i] == i + 1); } void main() { Matrix m9; m9._data[0] = 1; m9._data[1] = 2; m9._data[2] = 3; m9._data[3] = 4; for (size_t i = 0; i < 4; i++) assert(m9._data[i] == i + 1); benchmark!({ inverse(m9); })(1); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test13a.d0000644000175000017500000000264213200164642024541 0ustar matthiasmatthiasmodule imports.test13a; extern(C) int printf(const char*, ...); public alias bool boolean; public alias int Order; public const Order LESS_THAN = -1; public const Order EQUALS_TO = 0; public const Order GREATER_THAN = +1; template Ordinal(T) { public T min(T left, T right) { return left < right ? left: right; } public T max(T left, T right) { return left > right ? left: right; } public T clamp(T item, T lower, T upper) in { assert(lower <= upper); } body { return max(min(item, upper), lower); } } template TPair(T, U) { public class Pair { private T _left; private U _right; public this(T left, U right) { this._left = left; this._right = right; } public T left() { return this._left; } public U right() { return this._right; } override public boolean opEquals(Object obj) { Pair other = cast(Pair) obj; if (other !is null) { return (left() == other.left()) && (right() == other.right()); } else { return false; } } } } unittest { alias TPair!(char, char) charPair; charPair.Pair pairA = new charPair.Pair('a', 'b'); charPair.Pair pairB = new charPair.Pair('a', 'b'); assert(pairA == pairB); printf("Pair tests passed!\r\n"); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/testmod2a.d0000644000175000017500000000024213200164642025151 0ustar matthiasmatthiasmodule imports.testmod2a; /**********************************/ // bug 1904 // testmod.d private void bar(alias a)() {} void foo(alias a)() { .bar!(a)(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/template13478b.d0000644000175000017500000000034313200164642025635 0ustar matthiasmatthiasimport imports.template13478b; import imports.template13478a; // Note that foo is only used in the template constraint here. T barImpl(T)(T t) if (is(typeof({ foo!T(); }))) { return t; } int bar(int a) { return barImpl(a); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ufcs5c.d0000644000175000017500000000135113200164642024441 0ustar matthiasmatthiasmodule imports.ufcs5c; auto f5c1(int) { return 1; } auto f5c2(string) { return 2; } auto f5c3(double) { return 3; } alias f5c4 = f5c1, f5c4 = f5c2; alias f5c5 = f5c3, f5c5 = f5c4; @property p5c1(int) { return 1; } @property p5c1(int, int) { return 1; } @property p5c2(string) { return 2; } @property p5c2(string, int) { return 2; } @property p5c3(double) { return 3; } @property p5c3(double, int) { return 3; } alias p5c4 = p5c1, p5c4 = p5c2; alias p5c4 = p5c1, p5c4 = p5c2; alias p5c5 = p5c3, p5c5 = p5c4; alias p5c5 = p5c3, p5c5 = p5c4; /***************************************/ auto f5ov(string) { return 2; } @property p5ov(string) { return 2; } @property p5ov(string, int) { return 2; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/traits_getUnitTests_import.d0000644000175000017500000000011013200164642030663 0ustar matthiasmatthiasmodule imports.traits_getUnitTests_import; unittest { assert(1); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test14901a.d0000644000175000017500000000052513200164642024772 0ustar matthiasmatthiasmodule imports.test14901a; //extern(C) int printf(const char*, ...); extern extern(C) __gshared static int initCount; int make(string s)() { __gshared static int value; struct WithCtor { shared static this() { //printf("%s\n", s.ptr); initCount++; } } return value; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/circularA.d0000644000175000017500000000046413200164642025162 0ustar matthiasmatthiasmodule imports.circularA; import circular; class A { struct { Tclass a; Tstruct b; } union { Tclass c; Tstruct d; } } struct B { struct { Tclass a; Tstruct b; } union { Tclass c; Tstruct d; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link11127a.d0000644000175000017500000000044113200164642024742 0ustar matthiasmatthiasmodule imports.link11127a; struct Cycle(Range) { alias Range R; R _original; size_t _index; this(R input, size_t index = 0) {} } Cycle!R cycle(R)(R input) { return Cycle!R(input); } Cycle!R cycle(R)(R input, size_t index = 0) { return Cycle!R(input, index); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link14814a.d0000644000175000017500000000020013200164642024741 0ustar matthiasmatthiasmodule imports.link14814a; void fun0() { } void fun4() { void function()[TypeInfo] funs; funs[typeid(int)] = &fun0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a14267.d0000644000175000017500000000077313200164642024104 0ustar matthiasmatthiasmodule imports.a14267; struct SysTime14267 { // semantic() is called twice, and its scope is wrongly set to NULL // at the second call. this(long stdTime) {} this(this) {} ~this() {} static SysTime14267 min() { // inlining this function will call the semantic3() of SysTime14267 constructor. // but its 'scope' field is NULL so unintentionally semantic3() call fails. auto st = SysTime14267(long.min); auto st2 = st; return st2; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test48a.d0000644000175000017500000000013613200164642024545 0ustar matthiasmatthiasmodule imports.test48a; struct S { int a = 1; int b = 2; private: int c = 3; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test10573a.d0000644000175000017500000000033713200164642024774 0ustar matthiasmatthiasmodule imports.test10573a; abstract class base {} class mysql : base {} class handler { private mysql[int] mysql_servers; public void foo() { base[int] hServers = cast(base[int])mysql_servers; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test31a.d0000644000175000017500000000011413200164642024531 0ustar matthiasmatthiasmodule imports.test31a; template Baz() { private void privfunc(){ } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/argufile.d0000644000175000017500000000121513200164642025046 0ustar matthiasmatthias// argufile.d ---------------------------------------------------- public: import core.vararg; import std.stdio; import std.format; import std.utf; dstring formatstring(TypeInfo[] arguments, va_list argptr) { dstring message = null; void putc(dchar c) { message ~= c; } std.format.doFormat(&putc, arguments, argptr); return message; } string arguments(...) // turns a bunch of arguments into a formatted char[] string { return std.utf.toUTF8(formatstring(_arguments, _argptr)); } void useargs(...) { string crashage = arguments("why is 8 scared of 7? because", 7,8,9); //printf("%.*s\n", crashage); writefln(crashage); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a21a.d0000644000175000017500000000031713200164642023776 0ustar matthiasmatthiasmodule imports.a21a; import std.stdio; import a21; template GoodMixin() { int goodFunc() { printf("goodFunc\n"); return 1; } } class SomeClass { mixin GoodMixin; mixin BadMixin; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/m8668a.d0000644000175000017500000000011213200164642024174 0ustar matthiasmatthiasmodule imports.m8668a; void split8668(T)(T k) if(is(T : string)) { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test44a.d0000644000175000017500000000013013200164642024533 0ustar matthiasmatthiasmodule imports.test44a; import test44; enum DAY { SUN, MON, TUE, WED, THU, FRI, SAT } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test58a.d0000644000175000017500000000011013200164642024536 0ustar matthiasmatthiasmodule imports.test58a; void foo(T)() { long[] a; a[] = -a[]; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link11069z.d0000644000175000017500000000051113200164642024776 0ustar matthiasmatthiasstruct Matrix(T, uint _M) { int opCmp()(auto ref in Matrix b) const { return 0; } pure auto opDispatch(string s)() { enum L = s.length; Matrix!(T, L) ret; return ret; } pure Matrix normalized() { return Matrix(); } } alias Matrix!(float, 2) Vector2; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link2644c.d0000644000175000017500000000005213200164642024666 0ustar matthiasmatthiasmodule imports.link2644c; class C(T) { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/A16a.d0000644000175000017500000000024313200164642023740 0ustar matthiasmatthiasimport A16; import std.stdio; class B16 : AA16 { public this() { super(); printf("class B16\n"); } } int main() { new B16; return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/a17a.d0000644000175000017500000000011513200164642023777 0ustar matthiasmatthiasmodule imports.a17a; private import a17; class foo2x : barx { int x; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/depsprot_default.d0000644000175000017500000000001713200164642026613 0ustar matthiasmatthiasvoid pack() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ufcs5d.d0000644000175000017500000000107713200164642024447 0ustar matthiasmatthiasmodule imports.ufcs5d; auto f5d1(int) { return 1; } auto f5d2(string) { return 2; } auto f5d3(double) { return 3; } alias f5d4 = f5d1, f5d4 = f5d2; alias f5d5 = f5d3, f5d5 = f5d4; @property p5d1(int) { return 1; } @property p5d1(int, int) { return 1; } @property p5d2(string) { return 2; } @property p5d2(string, int) { return 2; } @property p5d3(double) { return 3; } @property p5d3(double, int) { return 3; } alias p5d4 = p5d1, p5d4 = p5d2; alias p5d4 = p5d1, p5d4 = p5d2; alias p5d5 = p5d3, p5d5 = p5d4; alias p5d5 = p5d3, p5d5 = p5d4; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/link14588a.d0000644000175000017500000000017713200164642024766 0ustar matthiasmatthiasmodule imports.link14588a; void func(alias a)() { } class A { int i; void all()() { func!(i)(); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test10441b.d0000644000175000017500000000011413200164642024760 0ustar matthiasmatthias public import test10441c; auto foo()() if (boo(1)) { return 1; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test24b.d0000644000175000017500000000006313200164642024537 0ustar matthiasmatthiasmodule imports.test24b; public import std.string; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/std11069range.d0000644000175000017500000000060313200164642025460 0ustar matthiasmatthiasmodule imports.std11069range; public import imports.std11069array; template isInputRange(R) { enum bool isInputRange = is(typeof( (inout int = 0) { R r = void; // can define a range object if (r.empty) {} // can test for empty r.popFront(); // can invoke popFront() auto h = r.front; // can get the front of the range })); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test46b.d0000644000175000017500000000020013200164642024534 0ustar matthiasmatthiasmodule imports.test46b; private import imports.test46c; class B { private C!(char) c; this() { c = new C!(char); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test10a.d0000644000175000017500000000010613200164642024527 0ustar matthiasmatthiasmodule imports.test10a; void init() { it[0] = 32; } int[1] it; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/template_ovs1.d0000644000175000017500000000260013200164642026032 0ustar matthiasmatthiasmodule imports.template_ovs1; /***************************************************/ // 1900 - template overload set auto foo1900a(int num) { return 1; } auto foo1900b(T)(T arg) if (is(T : const(char)[])) { return 2; } auto bar1900a(T)(T arg) if (is(T : double)) { return 1; } auto bar1900b(T)(T arg) if (is(T : const(char)[])) { return 2; } auto baz1900(T)(T arg) if (is(T : double)) { return 1; } auto baz1900(T)(T arg) if (is(T : int[int])) { return 2; } auto bad1900(string op)() if (op == "++") { return 1; } mixin template Mix1900_A() { auto mixfooa() { return 1; } auto mixfoob(T)(T) { return 2; } mixin Mix1900_SubA; } mixin template Mix1900_SubA() { auto mixsubfooa() { return 1; } auto mixsubfoob(T)(T) { return 2; } } auto merge1900(T)(int) { return 1; } /***************************************************/ // 1900 class AClass1900 {} template Traits1900(T : AClass1900) { enum name = "AClass"; } void Value1900a() {} template Value1900a(T) if (is(T == double)) { enum Value1900a = 1; } template Value1900b(T) if (is(T == double)) { enum Value1900b = 1; } void Value1900b() {} /***************************************************/ // 8352 Range remove8352a(alias pred, Range)(Range range) { return range; } void remove8352b(in char[] name) {} /***************************************************/ // 10658 template Val10658(int n) { enum Val10658 = 1; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test61a.d0000644000175000017500000000006613200164642024542 0ustar matthiasmatthiasmodule imports.test61a; int bar() { return 12; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/m8668c.d0000644000175000017500000000015513200164642024205 0ustar matthiasmatthias//drop in another one to pull split from m2 module imports.m8668c; public import imports.m8668b: split8668; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/std12010container.d0000644000175000017500000000165613200164642026342 0ustar matthiasmatthiasstruct Array(T) { private struct Payload { size_t _capacity; T[] _payload; ~this() { } this(this) { } } private alias RefCounted!(Payload) Data; private Data _data; bool opEquals(ref const Array rhs) const { return true; } } struct BinaryHeap(Store) { private static struct Data { Store _store; size_t _length; } private RefCounted!(Data) _payload; } struct RefCounted(T) { struct RefCountedStore { private struct Impl { T _payload; size_t _count; } private Impl* _store; } RefCountedStore _refCounted; this(this) { } ~this() { .destroy(_refCounted._store._payload); } void opAssign(typeof(this) rhs) { } void opAssign(T rhs) { typeid(T).destroy(&rhs); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test11931c.d0000644000175000017500000000006713200164642024775 0ustar matthiasmatthiasmodule imports.test11931c; import imports.test11931a; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/mod2.d0000644000175000017500000000017613200164642024116 0ustar matthiasmatthias// mod2.d module imports.mod2; import mod1; extern(C) int printf(const char*, ...); void greet() { printf(name().ptr); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/test14901d.d0000644000175000017500000000013113200164642024766 0ustar matthiasmatthiasmodule imports.test14901d; import imports.test14901b; void caller2() { User!2 u; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/ice10857a.d0000644000175000017500000000043613200164642024562 0ustar matthiasmatthiasmodule imports.ice10857a; template filter(alias pred) { auto filter(Range)(Range rs) { return FilterResult!(pred, Range)(rs); } } private struct FilterResult(alias pred, R) { R _input; void popFront() { assert(pred(_input[0]) == 123); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/imports/std11069typecons.d0000644000175000017500000000102513200164642026227 0ustar matthiasmatthiasmodule imports.std11069typecons; import imports.std11069array; template Tuple(Specs...) { struct Tuple { Specs expand; string toString() { expand[0].empty; expand[0].front; expand[0].popFront(); return null; } } } struct RefCounted(T) { T payload; ~this() { //.destroy(_refCounted._store._payload); //auto init = typeid(payload).init(); payload.toString(); // refer Tuple.toString symbol? } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test8997.d0000644000175000017500000000030013200164642023065 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test8997a.d module test8997; import imports.test8997a; void main() { auto a = new A(); foreach(key; a.foobar.byKey()) { } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/pi.d0000644000175000017500000000441213200164642022165 0ustar matthiasmatthias// PERMUTE_ARGS: // EXECUTE_ARGS: 1000 import core.stdc.stdio; import core.stdc.time; const int LONG_TIME=4000; byte[] p; byte[] t; int q; int main(char[][] args) { time_t startime, endtime; int i; if (args.length == 2) { sscanf(&args[1][0],"%d",&q); } else { printf("Usage: pi [precision]\n"); return 1; } if (q < 0) { printf("Precision was too low, running with precision of 0.\n"); q = 0; } if (q > LONG_TIME) { printf("Be prepared to wait a while...\n"); } // Compute one more digit than we display to compensate for rounding q++; p.length = q + 1; t.length = q + 1; /* compute pi */ time(&startime); arctan(2); arctan(3); mul4(); time(&endtime); // Return to the number of digits we want to display q--; /* print pi */ printf("pi = %d.",cast(int)(p[0])); for (i = 1; i <= q; i++) printf("%d",cast(int)(p[i])); printf("\n"); printf("%lld seconds to compute pi with a precision of %d digits.\n", cast(long)(endtime-startime),q); return 0; } void arctan(int s) { int n; t[0] = 1; div(s); /* t[] = 1/s */ add(); n = 1; do { mul(n); div(s * s); div(n += 2); if (((n-1) / 2) % 2 == 0) add(); else sub(); } while (!tiszero()); } void add() { int j; for (j = q; j >= 0; j--) { if (t[j] + p[j] > 9) { p[j] += t[j] - 10; p[j-1] += 1; } else p[j] += t[j]; } } void sub() { int j; for (j = q; j >= 0; j--) if (p[j] < t[j]) { p[j] -= t[j] - 10; p[j-1] -= 1; } else p[j] -= t[j]; } void mul(int multiplier) { int b; int i; int carry = 0, digit = 0; for (i = q; i >= 0; i--) { b = (t[i] * multiplier + carry); digit = b % 10; carry = b / 10; t[i] = cast(byte)digit; } } /* t[] /= l */ void div(int divisor) { int i, b; int quotient, remainder = 0; foreach (ref x; t) { b = (10 * remainder + x); quotient = b / divisor; remainder = b % divisor; x = cast(byte)quotient; } } void div4() { int i, c, d = 0; for (i = 0; i <= q; i++) { c = (10 * d + p[i]) / 4; d = (10 * d + p[i]) % 4; p[i] = cast(byte)c; } } void mul4() { int i, c, d; d = c = 0; for (i = q; i >= 0; i--) { d = (p[i] * 4 + c) % 10; c = (p[i] * 4 + c) / 10; p[i] = cast(byte)d; } } int tiszero() { int k; for (k = 0; k <= q; k++) if (t[k] != 0) return false; return true; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testzip.d0000644000175000017500000000512513200164642023261 0ustar matthiasmatthias// PERMUTE_ARGS: // EXECUTE_ARGS: runnable/extra-files/testzip.zip ${RESULTS_DIR}/runnable/testzip-out.zip // POST_SCRIPT: runnable/extra-files/testzip-postscript.sh import core.stdc.stdio; import std.conv; import std.stdio; import std.file; import std.datetime; import std.zip; import std.zlib; int main(string[] args) { byte[] buffer; std.zip.ZipArchive zr; string zipname; string outzipname; ubyte[] data; testzlib(); testzlib2(); if (args.length > 1) zipname = args[1]; else zipname = "test.zip"; if (args.length > 2) outzipname = args[2]; else outzipname = "foo.zip"; buffer = cast(byte[])std.file.read(zipname); zr = new std.zip.ZipArchive(cast(void[])buffer); printf("comment = '%.*s'\n", zr.comment.length, zr.comment.ptr); writeln(zr.toString()); foreach (ArchiveMember de; zr.directory) { writeln(de.toString()); auto s = DosFileTimeToSysTime(de.time).toString(); printf("date = '%.*s'\n", s.length, s.ptr); arrayPrint(de.compressedData); data = zr.expand(de); printf("data = '%.*s'\n", data.length, data.ptr); } printf("**Success**\n"); zr = new std.zip.ZipArchive(); ArchiveMember am = new ArchiveMember(); am.compressionMethod = 8; am.name = "foo.bar"; //am.extra = cast(ubyte[])"ExTrA"; am.expandedData = cast(ubyte[])"We all live in a yellow submarine, a yellow submarine"; zr.addMember(am); void[] data2 = zr.build(); std.file.write(outzipname, cast(byte[])data2); return 0; } void arrayPrint(ubyte[] array) { //printf("array %p,%d\n", (void*)array, array.length); for (int i = 0; i < array.length; i++) { printf("%02x ", array[i]); if (((i + 1) & 15) == 0) printf("\n"); } printf("\n\n"); } /******************************************/ void testzlib() { ubyte[] src = cast(ubyte[]) "the quick brown fox jumps over the lazy dog\r the quick brown fox jumps over the lazy dog\r "; ubyte[] dst; arrayPrint(src); dst = cast(ubyte[])std.zlib.compress(cast(void[])src); arrayPrint(dst); src = cast(ubyte[])std.zlib.uncompress(cast(void[])dst); arrayPrint(src); } /******************************************/ void testzlib2() { static ubyte [] buf = [1,2,3,4,5,0,7,8,9]; auto ar = new ZipArchive; auto am = new ArchiveMember; // 10 am.name = "buf"; am.expandedData = buf; am.compressionMethod = 8; am.time = SysTimeToDosFileTime(Clock.currTime()); ar.addMember (am); // 15 auto zip1 = ar.build (); ar = new ZipArchive (zip1); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/xtest46.d0000644000175000017500000043465613200164642023117 0ustar matthiasmatthiasimport std.stdio; import core.stdc.stdio; /******************************************/ struct S { int opStar() { return 7; } } void test1() { S s; printf("%d\n", *s); assert(*s == 7); } /******************************************/ void test2() { double[1][2] bar; bar[0][0] = 1.0; bar[1][0] = 2.0; foo2(bar); } void foo2(T...)(T args) { foreach (arg; args[0 .. $]) { //writeln(arg); bar2!(typeof(arg))(&arg); } } void bar2(D)(const(void)* arg) { D obj = *cast(D*) arg; } /***************************************************/ void test3() { version (unittest) { printf("unittest!\n"); } else { printf("no unittest!\n"); } version (assert) { printf("assert!\n"); } else { printf("no assert!\n"); } } /***************************************************/ void test4() { immutable int maxi = 8; int[][maxi] neighbors = [ cast(int[])[ ], [ 0 ], [ 0, 1], [ 0, 2], [1, 2], [1, 2, 3, 4], [ 2, 3, 5], [ 4, 5, 6 ] ]; int[maxi] grid; // neighbors[0].length = 0; void place(int k, uint mask) { if(k 1) { return T.length; } int foo36(T...)(T ts) if (T.length <= 1) { return T.length * 7; } void test36() { auto i = foo36!(int,int)(1, 2); assert(i == 2); i = foo36(1, 2, 3); assert(i == 3); i = foo36(1); assert(i == 7); i = foo36(); assert(i == 0); } /***************************************************/ void test6685() { struct S { int x; }; with({ return S(); }()) { x++; } } /***************************************************/ struct A37(alias T) { } void foo37(X)(X x) if (is(X Y == A37!(U), alias U)) { } void bar37() {} void test37() { A37!(bar37) a2; foo37(a2); foo37!(A37!bar37)(a2); } /***************************************************/ struct A38 { this(this) { printf("B's copy\n"); } bool empty() {return false;} void popFront() {} int front() { return 1; } // ref A38 opSlice() { return this; } } void test38() { A38 a; int i; foreach (e; a) { if (++i == 100) break; } } /***************************************************/ alias int function() Fun39; alias ref int function() Gun39; static assert(!is(Fun39 == Gun39)); void test39() { } /***************************************************/ int x40; struct Proxy { ref int at(int i)() { return x40; } } void test40() { Proxy p; auto x = p.at!(1); } /***************************************************/ template Foo41(TList...) { alias TList Foo41; } alias Foo41!(immutable(ubyte)[], ubyte[]) X41; void test41() { } /***************************************************/ bool endsWith(A1, A2)(A1 longer, A2 shorter) { static if (is(typeof(longer[0 .. 0] == shorter))) { } else { } return false; } void test42() { char[] a; byte[] b; endsWith(a, b); } /***************************************************/ void f43(S...)(S s) if (S.length > 3) { } void test43() { f43(1, 2, 3, 4); } /***************************************************/ struct S44(int x = 1){} void fun()(S44!(1) b) { } void test44() { S44!() s; fun(s); } /***************************************************/ // 2006 void test2006() { string [][] aas = []; assert(aas.length == 0); aas ~= cast (string []) []; assert(aas.length == 1); aas = aas ~ cast (string []) []; assert(aas.length == 2); } /***************************************************/ // 8442 void test8442() { enum int[] fooEnum = []; immutable fooImmutable = fooEnum; } /***************************************************/ class A45 { int x; int f() { printf("A\n"); return 1; } } class B45 : A45 { override const int f() { printf("B\n"); return 2; } } void test45() { A45 y = new B45; int i = y.f; assert(i == 2); } /***************************************************/ void text10682() { ulong x = 1; ulong y = 2 ^^ x; } /***************************************************/ struct Test46 { int foo; } void test46() { enum Test46 test = {}; enum q = test.foo; } /***************************************************/ pure int double_sqr(int x) { int y = x; void do_sqr() { y *= y; } do_sqr(); return y; } void test47() { assert(double_sqr(10) == 100); } /***************************************************/ void sort(alias less)(string[] r) { bool pred() { return less("a", "a"); } .sort!(less)(r); } void foo48() { int[string] freqs; string[] words; sort!((a, b) { return freqs[a] > freqs[b]; })(words); sort!((string a, string b) { return freqs[a] > freqs[b]; })(words); //sort!(bool (a, b) { return freqs[a] > freqs[b]; })(words); //sort!(function (a, b) { return freqs[a] > freqs[b]; })(words); //sort!(function bool(a, b) { return freqs[a] > freqs[b]; })(words); sort!(delegate bool(string a, string b) { return freqs[a] > freqs[b]; })(words); } void test48() { } /***************************************************/ // 6408 static assert(!is(typeof(string[0..1].init))); static assert(is(typeof(string[].init) == string[])); static assert(is(typeof(string[][].init) == string[][])); static assert(is(typeof(string[][][].init) == string[][][])); static assert(is(typeof(string[1].init) == string[1])); static assert(is(typeof(string[1][1].init) == string[1][1])); static assert(is(typeof(string[1][1][1].init) == string[1][1][1])); static assert(is(typeof(string[string].init) == string[string])); static assert(is(typeof(string[string][string].init) == string[string][string])); static assert(is(typeof(string[string][string][string].init) == string[string][string][string])); template TT6408(T...) { alias T TT6408; } static assert(is(typeof(TT6408!(int, int)[].init) == TT6408!(int, int))); static assert(is(typeof(TT6408!(int, int)[0..$].init) == TT6408!(int, int))); static assert(is(typeof(TT6408!(int, int)[$-1].init) == int)); /***************************************************/ // 9409 template TT9409(T...) { alias T TT9409; } template idxTypes9409(Prefix...) { TT9409!((Prefix[$-1])) idxTypes9409; } alias idxTypes9409!(int) Types9409; /***************************************************/ struct S49 { static void* p; this( string name ) { printf( "(ctor) &%.*s.x = %p\n", name.length, name.ptr, &x ); p = cast(void*)&x; } invariant() {} int x; } void test49() { auto s = new S49("s2"); printf( "&s2.x = %p\n", &s.x ); assert(cast(void*)&s.x == S49.p); } /***************************************************/ auto max50(Ts...)(Ts args) if (Ts.length >= 2 && is(typeof(Ts[0].init > Ts[1].init ? Ts[1].init : Ts[0].init))) { static if (Ts.length == 2) return args[1] > args[0] ? args[1] : args[0]; else return max50(max50(args[0], args[1]), args[2 .. $]); } void test50() { assert(max50(4, 5) == 5); assert(max50(2.2, 4.5) == 4.5); assert(max50("Little", "Big") == "Little"); assert(max50(4, 5.5) == 5.5); assert(max50(5.5, 4) == 5.5); } /***************************************************/ void test51() { static immutable int[2] array = [ 42 ]; enum e = array[1]; static immutable int[1] array2 = [ 0: 42 ]; enum e2 = array2[0]; assert(e == 0); assert(e2 == 42); } /***************************************************/ enum ubyte[4] a52 = [5,6,7,8]; void test52() { int x=3; assert(a52[x]==8); } /***************************************************/ void test53() { size_t func2(immutable(void)[] t) { return 0; } } /***************************************************/ void foo54(void delegate(void[]) dg) { } void test54() { void func(void[] t) pure { } foo54(&func); // void func2(const(void)[] t) { } // foo54(&func2); } /***************************************************/ class Foo55 { synchronized void noop1() { } void noop2() shared { } } void test55() { auto foo = new shared(Foo55); foo.noop1(); foo.noop2(); } /***************************************************/ enum float one56 = 1 * 1; template X56(float E) { int X56 = 2; } alias X56!(one56 * one56) Y56; void test56() { assert(Y56 == 2); } /***************************************************/ void test57() { alias shared(int) T; assert (is(T == shared)); } /***************************************************/ struct A58 { int a,b; } void test58() { A58[2] rg=[{1,2},{5,6}]; assert(rg[0].a == 1); assert(rg[0].b == 2); assert(rg[1].a == 5); assert(rg[1].b == 6); } /***************************************************/ class A59 { const foo(int i) { return i; } } /***************************************************/ void test60() { enum real ONE = 1.0; real x; for (x=0.0; x<10.0; x+=ONE) printf("%Lg\n", x); printf("%Lg\n", x); assert(x == 10); } /***************************************************/ pure immutable(T)[] fooPT(T)(immutable(T)[] x, immutable(T)[] y){ immutable(T)[] fooState; immutable(T)[] bar(immutable(T)[] x){ fooState = "hello "; return x ~ y; } return fooState ~ bar(x); } void test61() { writeln(fooPT("p", "c")); } /***************************************************/ void test9577() { static int function(int)[] foo = [x => x]; foo[0](0); } /***************************************************/ int[3] foo62(int[3] a) { a[1]++; return a; } void test62() { int[3] b; b[0] = 1; b[1] = 2; b[2] = 3; auto c = foo62(b); assert(b[0] == 1); assert(b[1] == 2); assert(b[2] == 3); assert(c[0] == 1); assert(c[1] == 3); assert(c[2] == 3); } /***************************************************/ void test3927() { int[] array; assert(array.length++ == 0); assert(array.length == 1); assert(array.length-- == 1); assert(array.length == 0); } /***************************************************/ void test63() { int[3] b; b[0] = 1; b[1] = 2; b[2] = 3; auto c = b; b[1]++; assert(b[0] == 1); assert(b[1] == 3); assert(b[2] == 3); assert(c[0] == 1); assert(c[1] == 2); assert(c[2] == 3); } /***************************************************/ void test64() { int[3] b; b[0] = 1; b[1] = 2; b[2] = 3; int[3] c; c = b; b[1]++; assert(b[0] == 1); assert(b[1] == 3); assert(b[2] == 3); assert(c[0] == 1); assert(c[1] == 2); assert(c[2] == 3); } /***************************************************/ int[2] foo65(int[2] a) { a[1]++; return a; } void test65() { int[2] b; b[0] = 1; b[1] = 2; int[2] c = foo65(b); assert(b[0] == 1); assert(b[1] == 2); assert(c[0] == 1); assert(c[1] == 3); } /***************************************************/ int[1] foo66(int[1] a) { a[0]++; return a; } void test66() { int[1] b; b[0] = 1; int[1] c = foo66(b); assert(b[0] == 1); assert(c[0] == 2); } /***************************************************/ int[2] foo67(out int[2] a) { a[0] = 5; a[1] = 6; return a; } void test67() { int[2] b; b[0] = 1; b[1] = 2; int[2] c = foo67(b); assert(b[0] == 5); assert(b[1] == 6); assert(c[0] == 5); assert(c[1] == 6); } /***************************************************/ void test68() { digestToString(cast(ubyte[16])x"c3fcd3d76192e4007dfb496cca67e13b"); } void digestToString(const ubyte[16] digest) { assert(digest[0] == 0xc3); assert(digest[15] == 0x3b); } /***************************************************/ void test69() { digestToString69(cast(ubyte[16])x"c3fcd3d76192e4007dfb496cca67e13b"); } void digestToString69(ref const ubyte[16] digest) { assert(digest[0] == 0xc3); assert(digest[15] == 0x3b); } /***************************************************/ void test70() { digestToString70("1234567890123456"); } void digestToString70(ref const char[16] digest) { assert(digest[0] == '1'); assert(digest[15] == '6'); } /***************************************************/ void foo71(out shared int o) {} /***************************************************/ struct foo72 { int bar() shared { return 1; } } void test72() { shared foo72 f; auto x = f.bar; } /***************************************************/ class Foo73 { static if (is(typeof(this) T : shared T)) static assert(0); static if (is(typeof(this) U == shared U)) static assert(0); static if (is(typeof(this) U == const U)) static assert(0); static if (is(typeof(this) U == immutable U)) static assert(0); static if (is(typeof(this) U == const shared U)) static assert(0); static assert(!is(int == const)); static assert(!is(int == immutable)); static assert(!is(int == shared)); static assert(is(int == int)); static assert(is(const(int) == const)); static assert(is(immutable(int) == immutable)); static assert(is(shared(int) == shared)); static assert(is(const(shared(int)) == shared)); static assert(is(const(shared(int)) == const)); static assert(!is(const(shared(int)) == immutable)); static assert(!is(const(int) == immutable)); static assert(!is(const(int) == shared)); static assert(!is(shared(int) == const)); static assert(!is(shared(int) == immutable)); static assert(!is(immutable(int) == const)); static assert(!is(immutable(int) == shared)); } template Bar(T : T) { alias T Bar; } template Barc(T : const(T)) { alias T Barc; } template Bari(T : immutable(T)) { alias T Bari; } template Bars(T : shared(T)) { alias T Bars; } template Barsc(T : shared(const(T))) { alias T Barsc; } void test73() { auto f = new Foo73; alias int T; // 5*5 == 25 combinations, plus 2 for swapping const and shared static assert(is(Bar!(T) == T)); static assert(is(Bar!(const(T)) == const(T))); static assert(is(Bar!(immutable(T)) == immutable(T))); static assert(is(Bar!(shared(T)) == shared(T))); static assert(is(Bar!(shared(const(T))) == shared(const(T)))); static assert(is(Barc!(const(T)) == T)); static assert(is(Bari!(immutable(T)) == T)); static assert(is(Bars!(shared(T)) == T)); static assert(is(Barsc!(shared(const(T))) == T)); static assert(is(Barc!(T) == T)); static assert(is(Barc!(immutable(T)) == T)); static assert(is(Barc!(const(shared(T))) == shared(T))); static assert(is(Barsc!(immutable(T)) == T)); static assert(is(Bars!(const(shared(T))) == const(T))); static assert(is(Barsc!(shared(T)) == T)); Bars!(shared(const(T))) b; pragma(msg, typeof(b)); static assert(is(Bars!(shared(const(T))) == const(T))); static assert(is(Barc!(shared(const(T))) == shared(T))); static assert(!is(Bari!(T))); static assert(!is(Bari!(const(T)))); static assert(!is(Bari!(shared(T)))); static assert(!is(Bari!(const(shared(T))))); static assert(is(Barc!(shared(T)))); static assert(!is(Bars!(T))); static assert(!is(Bars!(const(T)))); static assert(!is(Bars!(immutable(T)))); static assert(!is(Barsc!(T))); static assert(!is(Barsc!(const(T)))); } /***************************************************/ pure nothrow { alias void function(int) A74; } alias void function(int) pure nothrow B74; alias pure nothrow void function(int) C74; void test74() { A74 a = null; B74 b = null; C74 c = null; a = b; a = c; } /***************************************************/ void test9212() { int[int] aa; foreach (const key, const val; aa) {} foreach (size_t key, size_t val; aa) {} } /***************************************************/ class A75 { pure static void raise(string s) { throw new Exception(s); } } void test75() { int x = 0; try { A75.raise("a"); } catch (Exception e) { x = 1; } assert(x == 1); } /***************************************************/ void test76() { int x, y; bool which; (which ? x : y) += 5; assert(y == 5); } /***************************************************/ void test77() { auto a = ["hello", "world"]; pragma(msg, typeof(a)); auto b = a; assert(a is b); assert(a == b); b = a.dup; assert(a == b); assert(a !is b); } /***************************************************/ void test78() { auto array = [0, 2, 4, 6, 8, 10]; array = array[0 .. $ - 2]; // Right-shrink by two elements assert(array == [0, 2, 4, 6]); array = array[1 .. $]; // Left-shrink by one element assert(array == [2, 4, 6]); array = array[1 .. $ - 1]; // Shrink from both sides assert(array == [4]); } /***************************************************/ void test79() { auto a = [87, 40, 10]; a ~= 42; assert(a == [87, 40, 10, 42]); a ~= [5, 17]; assert(a == [87, 40, 10, 42, 5, 17]); } /***************************************************/ void test6317() { int b = 12345; struct nested { int a; int fun() { return b; } } static assert(!__traits(compiles, { nested x = { 3, null }; })); nested g = { 7 }; auto h = nested(7); assert(g.fun() == 12345); assert(h.fun() == 12345); } /***************************************************/ void test80() { auto array = new int[10]; array.length += 1000; assert(array.length == 1010); array.length /= 10; assert(array.length == 101); array.length -= 1; assert(array.length == 100); array.length |= 1; assert(array.length == 101); array.length ^= 3; assert(array.length == 102); array.length &= 2; assert(array.length == 2); array.length *= 2; assert(array.length == 4); array.length <<= 1; assert(array.length == 8); array.length >>= 1; assert(array.length == 4); array.length >>>= 1; assert(array.length == 2); array.length %= 2; assert(array.length == 0); int[]* foo() { static int x; x++; assert(x == 1); auto p = &array; return p; } (*foo()).length += 2; assert(array.length == 2); } /***************************************************/ void test81() { int[3] a = [1, 2, 3]; int[3] b = a; a[1] = 42; assert(b[1] == 2); // b is an independent copy of a int[3] fun(int[3] x, int[3] y) { // x and y are copies of the arguments x[0] = y[0] = 100; return x; } auto c = fun(a, b); // c has type int[3] assert(c == [100, 42, 3]); assert(b == [1, 2, 3]); // b is unaffected by fun } /***************************************************/ void test82() { auto a1 = [ "Jane":10.0, "Jack":20, "Bob":15 ]; auto a2 = a1; // a1 and a2 refer to the same data a1["Bob"] = 100; // Changing a1 assert(a2["Bob"] == 100); //is same as changing a2 a2["Sam"] = 3.5; //and vice assert(a2["Sam"] == 3.5); // versa } /***************************************************/ void test7942() { string a = "a"; wstring b = "b"; dstring c = "c"; a ~= "a"c; static assert(!is(typeof(a ~= "b"w))); static assert(!is(typeof(a ~= "c"d))); static assert(!is(typeof(b ~= "a"c))); b ~= "b"w; static assert(!is(typeof(b ~= "c"d))); static assert(!is(typeof(c ~= "a"c))); static assert(!is(typeof(c ~= "b"w))); c ~= "c"d; assert(a == "aa"); assert(b == "bb"); assert(c == "cc"); } /***************************************************/ void bump(ref int x) { ++x; } void test83() { int x = 1; bump(x); assert(x == 2); } /***************************************************/ interface Test4174 { void func(T)() {} } /***************************************************/ auto foo84 = [1, 2.4]; void test84() { pragma(msg, typeof([1, 2.4])); static assert(is(typeof([1, 2.4]) == double[])); pragma(msg, typeof(foo84)); static assert(is(typeof(foo84) == double[])); } /***************************************************/ void test85() { dstring c = "V\u00E4rld"; c = c ~ '!'; assert(c == "V\u00E4rld!"); c = '@' ~ c; assert(c == "@V\u00E4rld!"); wstring w = "V\u00E4rld"; w = w ~ '!'; assert(w == "V\u00E4rld!"); w = '@' ~ w; assert(w == "@V\u00E4rld!"); string s = "V\u00E4rld"; s = s ~ '!'; assert(s == "V\u00E4rld!"); s = '@' ~ s; assert(s == "@V\u00E4rld!"); } /***************************************************/ void test86() { int[][] a = [ [1], [2,3], [4] ]; int[][] w = [ [1, 2], [3], [4, 5], [] ]; int[][] x = [ [], [1, 2], [3], [4, 5], [] ]; } /***************************************************/ // Bugzilla 3379 T1[] find(T1, T2)(T1[] longer, T2[] shorter) if (is(typeof(longer[0 .. 1] == shorter) : bool)) { while (longer.length >= shorter.length) { if (longer[0 .. shorter.length] == shorter) break; longer = longer[1 .. $]; } return longer; } auto max(T...)(T a) if (T.length == 2 && is(typeof(a[1] > a[0] ? a[1] : a[0])) || T.length > 2 && is(typeof(max(max(a[0], a[1]), a[2 .. $])))) { static if (T.length == 2) { return a[1] > a[0] ? a[1] : a[0]; } else { return max(max(a[0], a[1]), a[2 .. $]); } } // Cases which would ICE or segfault struct Bulldog(T){ static void cat(Frog)(Frog f) if (true) { } } void mouse(){ Bulldog!(int).cat(0); } void test87() { double[] d1 = [ 6.0, 1.5, 2.4, 3 ]; double[] d2 = [ 1.5, 2.4 ]; assert(find(d1, d2) == d1[1 .. $]); assert(find(d1, d2) == d1[1 .. $]); // Check for memory corruption assert(max(4, 5) == 5); assert(max(3, 4, 5) == 5); } /***************************************************/ template test4284(alias v) { enum test4284 = v.length == 0; } static assert(test4284!(cast(string)null)); static assert(test4284!(cast(string[])null)); /***************************************************/ struct S88 { void opDispatch(string s, T)(T i) { printf("S.opDispatch('%.*s', %d)\n", s.length, s.ptr, i); } } class C88 { void opDispatch(string s)(int i) { printf("C.opDispatch('%.*s', %d)\n", s.length, s.ptr, i); } } struct D88 { template opDispatch(string s) { enum int opDispatch = 8; } } void test88() { S88 s; s.opDispatch!("hello")(7); s.foo(7); auto c = new C88(); c.foo(8); D88 d; printf("d.foo = %d\n", d.foo); assert(d.foo == 8); } /***************************************************/ void test89() { static struct X { int x; int bar() { return x; } } X s; printf("%d\n", s.sizeof); assert(s.sizeof == 4); } /***************************************************/ struct S90 { void opDispatch( string name, T... )( T values ) { assert(values[0] == 3.14); } } void test90( ) { S90 s; s.opDispatch!("foo")( 3.14 ); s.foo( 3.14 ); } /***************************************************/ struct A7439(int r, int c) { alias r R; alias c C; alias float[R * C] Data; Data _data; alias _data this; this(Data ar){ _data = ar; } pure ref float opIndex(size_t rr, size_t cc){ return _data[cc + rr * C]; } } void test7439() { A7439!(2, 2) a = A7439!(2, 2)([8, 3, 2, 9]); a[0,0] -= a[0,0] * 2.0; } /***************************************************/ void foo91(uint line = __LINE__) { printf("%d\n", line); } void test91() { foo91(); printf("%d\n", __LINE__); } /***************************************************/ bool fun13468(Object e, typeof(null) needle) { return (e == needle); } void test13468() { assert(fun13468(null, null)); } /***************************************************/ auto ref foo92(ref int x) { return x; } int bar92(ref int x) { return x; } void test92() { int x = 3; int i = bar92(foo92(x)); assert(i == 3); } /***************************************************/ struct Foo93 { public int foo() const { return 2; } } void test93() { const Foo93 bar = Foo93(); enum bla = bar.foo(); assert(bla == 2); } /***************************************************/ extern(C++) class C1687 { void func() {} } void test1687() { auto c = new C1687(); assert(c.__vptr[0] == (&c.func).funcptr); } /***************************************************/ struct Foo94 { int x, y; real z; } pure nothrow Foo94 makeFoo(const int x, const int y) { return Foo94(x, y, 3.0); } void test94() { auto f = makeFoo(1, 2); assert(f.x==1); assert(f.y==2); assert(f.z==3); } /***************************************************/ struct T95 { @disable this(this) { } } struct S95 { T95 t; } @disable void foo95() { } struct T95A { @disable this(this); } struct S95A { T95A t; } @disable void foo95A() { } void test95() { S95 s; S95 t; static assert(!__traits(compiles, t = s)); static assert(!__traits(compiles, foo95())); S95A u; S95A v; static assert(!__traits(compiles, v = u)); static assert(!__traits(compiles, foo95A())); } /***************************************************/ struct S96(alias init) { int[] content = init; } void test96() { S96!([12, 3]) s1; S96!([1, 23]) s2; writeln(s1.content); writeln(s2.content); assert(!is(typeof(s1) == typeof(s2))); } /***************************************************/ struct A97 { const bool opEquals(ref const A97) { return true; } ref A97 opUnary(string op)() if (op == "++") { return this; } } void test97() { A97 a, b; foreach (e; a .. b) { } } /***************************************************/ void test98() { auto a = new int[2]; // the name "length" should not pop up in an index expression static assert(!is(typeof(a[length - 1]))); } /***************************************************/ string s99; void bar99(string i) { } void function(string) foo99(string i) { return &bar99; } void test99() { foo99 (s99 ~= "a") (s99 ~= "b"); assert(s99 == "ab"); } /***************************************************/ // 5081 void test5081() { static pure immutable(int[]) x1() { int[] a = new int[](10); return a; } static pure immutable(int[]) x2(int len) { int[] a = new int[](len); return a; } static pure immutable(int[]) x3(immutable(int[]) org) { int[] a = new int[](org.length); return a; } immutable a1 = x1(); immutable a2 = x2(10); immutable a3 = x3([1,2]); static pure int[] y1() { return new int[](10); } immutable b1 = y1(); } /***************************************************/ void test100() { string s; /* Testing order of evaluation */ void delegate(string, string) fun(string) { s ~= "b"; return delegate void(string x, string y) { s ~= "e"; }; } fun(s ~= "a")(s ~= "c", s ~= "d"); assert(s == "abcde", s); } /***************************************************/ void test101() { int[] d1 = [ 6, 1, 2 ]; byte[] d2 = [ 6, 1, 2 ]; assert(d1 == d2); d2 ~= [ 6, 1, 2 ]; assert(d1 != d2); } /***************************************************/ void test5403() { struct S { static int front; enum back = "yes!"; bool empty; void popAny() { empty = true; } alias popAny popFront; alias popAny popBack; } S.front = 7; foreach(int i; S()) assert(i == 7); S.front = 2; foreach(i; S()) assert(i == 2); foreach_reverse(i; S()) assert(i == "yes!"); } /***************************************************/ static assert([1,2,3] == [1.0,2,3]); /***************************************************/ int transmogrify(uint) { return 1; } int transmogrify(long) { return 2; } void test103() { assert(transmogrify(42) == 1); } /***************************************************/ int foo104(int x) { int* p = &(x += 1); return *p; } int bar104(int *x) { int* p = &(*x += 1); return *p; } void test104() { auto i = foo104(1); assert(i == 2); i = bar104(&i); assert(i == 3); } /***************************************************/ ref int bump105(ref int x) { return ++x; } void test105() { int x = 1; bump105(bump105(x)); // two increments assert(x == 3); } /***************************************************/ pure int genFactorials(int n) { static pure int factorial(int n) { if (n==2) return 1; return factorial(2); } return factorial(n); } /***************************************************/ void test107() { int[6] a; writeln(a); writeln(a.init); assert(a.init == [0,0,0,0,0,0]); } /***************************************************/ class A109 {} void test109() { immutable(A109) b; A109 c; auto z = true ? b : c; //writeln(typeof(z).stringof); static assert(is(typeof(z) == const(A109))); } /***************************************************/ template Boo(T) {} struct Foo110(T, alias V = Boo!T) { pragma(msg, V.stringof); static const s = V.stringof; } alias Foo110!double B110; alias Foo110!int A110; static assert(B110.s == "Boo!double"); static assert(A110.s == "Boo!int"); /***************************************************/ int test11247() { static assert(is(byte[typeof(int.init).sizeof] == byte[4])); static assert(is(byte[typeof(return).sizeof] == byte[4])); return 0; } /***************************************************/ // 3716 void test111() { auto k1 = true ? [1,2] : []; // OK auto k2 = true ? [[1,2]] : [[]]; auto k3 = true ? [] : [[1,2]]; auto k4 = true ? [[[]]] : [[[1,2]]]; auto k5 = true ? [[[1,2]]] : [[[]]]; auto k6 = true ? [] : [[[]]]; static assert(!is(typeof(true ? [[[]]] : [[1,2]]))); // Must fail } /***************************************************/ // 658 void test658() { struct S { int i; } class C { int i; } S s; S* sp = &s; with (sp) i = 42; assert(s.i == 42); with (&s) i = 43; assert(s.i == 43); C c = new C; C* cp = &c; with (cp) i = 42; assert(c.i == 42); with (&c) i = 43; assert(c.i == 43); } /***************************************************/ void test3069() { ubyte id = 0; void[] v = [id] ~ [id]; } /***************************************************/ // 4303 template foo112() if (__traits(compiles,undefined)) { enum foo112 = false; } template foo112() if (true) { enum foo112 = true; } pragma(msg,__traits(compiles,foo112!())); static assert(__traits(compiles,foo112!())); const bool bar112 = foo112!(); /***************************************************/ struct File113 { this(int name) { } ~this() { } void opAssign(File113 rhs) { } struct ByLine { File113 file; this(int) { } } ByLine byLine() { return ByLine(1); } } auto filter113(File113.ByLine rs) { struct Filter { this(File113.ByLine r) { } } return Filter(rs); } void test113() { auto f = File113(1); auto rx = f.byLine(); auto file = filter113(rx); } /***************************************************/ template foo114(fun...) { auto foo114(int[] args) { return 1; } } pragma(msg, typeof(foo114!"a + b"([1,2,3]))); /***************************************************/ // Bugzilla 3935 struct Foo115 { void opBinary(string op)(Foo other) { pragma(msg, "op: " ~ op); assert(0); } } void test115() { Foo115 f; f = f; } /***************************************************/ // Bugzilla 2477 void foo116(T,)(T t) { T x; } void test116() { int[] data = [1,2,3,]; // OK data = [ 1,2,3, ]; // fails auto i = data[1,]; foo116!(int)(3); foo116!(int,)(3); foo116!(int,)(3,); } /***************************************************/ void test1891() { struct C { char[8] x = "helloabc"; } int main() { C* a = new C; C*[] b; b ~= new C; auto g = a ~ b; assert(g[0] && g[1] && g[0].x == g[1].x); return 0; } } /***************************************************/ // Bugzilla 4291 void test117() pure { mixin declareVariable; var = 42; mixin declareFunction; readVar(); } template declareVariable() { int var; } template declareFunction() { int readVar() { return var; } } /***************************************************/ // Bugzilla 4177 pure real log118(real x) { if (__ctfe) return 0.0; else return 1.0; } enum x118 = log118(4.0); void test118() {} /***************************************************/ void bug4465() { const a = 2 ^^ 2; int b = a; } /***************************************************/ pure void foo(int *p) { *p = 3; } pure void test120() { int i; foo(&i); assert(i == 3); } /***************************************************/ // 4866 immutable int[3] statik = [ 1, 2, 3 ]; enum immutable(int)[] dynamic = statik; static assert(is(typeof(dynamic) == immutable(int)[])); static if (! is(typeof(dynamic) == immutable(int)[])) { static assert(0); // (7) } pragma(msg, "!! ", typeof(dynamic)); /***************************************************/ // 2943 struct Foo2943 { int a; int b; alias b this; } void test122() { Foo2943 foo, foo2; foo.a = 1; foo.b = 2; foo2.a = 3; foo2.b = 4; foo2 = foo; assert(foo2.a == foo.a); } /***************************************************/ // 4641 struct S123 { int i; alias i this; } void test123() { S123[int] ss; ss[0] = S123.init; // This line causes Range Violation. } /***************************************************/ // 2451 struct Foo124 { int z = 3; void opAssign(Foo124 x) { z= 2;} } struct Bar124 { int z = 3; this(this){ z = 17; } } void test124() { Foo124[string] stuff; stuff["foo"] = Foo124.init; assert(stuff["foo"].z == 3); stuff["foo"] = Foo124.init; assert(stuff["foo"].z == 2); Bar124[string] stuff2; Bar124 q; stuff2["dog"] = q; assert(stuff2["dog"].z == 17); } /***************************************************/ void test3022() { static class Foo3022 { new(size_t) { assert(0); } } scope x = new Foo3022; } /***************************************************/ void doNothing() {} void bug5071(short d, ref short c) { assert(c==0x76); void closure() { auto c2 = c; auto d2 = d; doNothing(); } auto useless = &closure; } void test125() { short c = 0x76; bug5071(7, c); } /***************************************************/ struct Foo126 { static Foo126 opCall(in Foo126 _f) pure { return _f; } } /***************************************************/ void test796() { struct S { invariant() { throw new Exception(""); } } S* s; try { assert(s); } catch (Error) { } } /***************************************************/ void test7077() { if(0) mixin("auto x = 2;"); auto x = 1; } /***************************************************/ struct Tuple127(S...) { S expand; alias expand this; } alias Tuple127!(int, int) Foo127; void test127() { Foo127[] m_array; Foo127 f; m_array ~= f; } /***************************************************/ struct Bug4434 {} alias const Bug4434* IceConst4434; alias shared Bug4434* IceShared4434; alias shared Bug4434[] IceSharedArray4434; alias immutable Bug4434* IceImmutable4434; alias shared const Bug4434* IceSharedConst4434; alias int MyInt4434; alias const MyInt4434[3] IceConstInt4434; alias immutable string[] Bug4830; /***************************************************/ // 4254 void bub(const inout int other) {} void test128() { bub(1); } /***************************************************/ pure nothrow @safe auto bug4915a() { return 0; } pure nothrow @safe int bug4915b() { return bug4915a(); } void bug4915c() { pure nothrow @safe int d() { return 0; } int e() pure nothrow @safe { return d(); } } /***************************************************/ // 5164 static if (is(int Q == int, Z...)) { } /***************************************************/ // 5195 alias typeof(foo5195) food5195; const int * foo5195 = null; alias typeof(foo5195) good5195; static assert( is (food5195 == good5195)); /***************************************************/ version (Windows) { } else { int[0] var5332; void test5332() { auto x = var5332; } } /***************************************************/ // 5191 struct Foo129 { void add(T)(T value) nothrow { this.value += value; } this(int value) { this.value = value; } int value; } void test129() { auto foo = Foo129(5); assert(foo.value == 5); foo.add(2); writeln(foo.value); assert(foo.value == 7); foo.add(3); writeln(foo.value); assert(foo.value == 10); foo.add(3); writeln(foo.value); assert(foo.value == 13); void delegate (int) nothrow dg = &foo.add!(int); dg(7); assert(foo.value == 20); } /***************************************************/ // 6169 auto ctfefunc6169() { return ";"; } enum ctfefptr6169 = &ctfefunc6169; int ctfefunc6169a() { return 1; } template x6169(string c) { alias int x6169; } template TT6169(T...) { alias T TT6169; } @property ctfeprop6169() { return "g"; } void test6169() pure @safe { enum a = ctfefunc6169(); static b = ctfefunc6169(); x6169!(ctfefunc6169()) tt; mixin(ctfefunc6169()); static if(ctfefunc6169()) {} pragma(msg, ctfefunc6169()); enum xx { k = 0, j = ctfefunc6169a() } auto g = mixin('"' ~ ctfefunc6169() ~ '"'); //auto h = import("testx.d" ~ false ? ctfefunc() : ""); alias TT6169!(int, int)[ctfefunc6169a()..ctfefunc6169a()] i; alias TT6169!(int, int)[ctfefunc6169a()] j; int[ctfefunc6169a()+1] k; alias int[ctfefunc6169a()] l; switch(1) { //case ctfefunc6169a(): // Can't do this because of case variables case ctfefunc6169a()+1: .. case ctfefunc6169a()+2: default: break; } static assert(ctfefunc6169a()); void fun(int i : ctfefunc6169a() = ctfefunc6169a(), alias j)() if (ctfefunc6169a()) {} fun!(ctfefunc6169a(), ctfefunc6169())(); enum z = ctfefptr6169(); auto p = mixin(ctfeprop6169); } /***************************************************/ // 10506 void impureFunc10506() {} string join10506(RoR)(RoR ror) { impureFunc10506(); return ror[0] ~ ror[1]; } void test10506() pure { void foobar() {} mixin(["foo", "bar"].join10506()~";"); } /***************************************************/ const shared class C5107 { int x; } static assert(is(typeof(C5107.x) == const)); // okay static assert(is(typeof(C5107.x) == shared)); // fails! /***************************************************/ immutable struct S3598 { static void funkcja() { } } /***************************************************/ // 4211 @safe struct X130 { void func() { } } @safe class Y130 { void func() { } } @safe void test130() { X130 x; x.func(); auto y = new Y130; y.func(); } /***************************************************/ template Return(alias fun) { static if (is(typeof(fun) R == return)) alias R Return; } interface I4217 { int square(int n); real square(real n); } alias Return!( __traits(getOverloads, I4217, "square")[0] ) R4217; alias Return!( __traits(getOverloads, I4217, "square")[1] ) S4217; static assert(! is(R4217 == S4217)); /***************************************************/ // 5094 void test131() { S131 s; int[] conv = s; } struct S131 { @property int[] get() { return [1,2,3]; } alias get this; } /***************************************************/ struct S7545 { uint id; alias id this; } void test7545() { auto id = 0 ? S7545() : -1; } /***************************************************/ // 5020 void test132() { S132 s; if (!s) {} } struct S132 { bool cond; alias cond this; } /***************************************************/ // 5343 struct Tuple5343(Specs...) { Specs[0] field; } struct S5343(E) { immutable E x; } enum A5343{a,b,c} alias Tuple5343!(A5343) TA5343; alias S5343!(A5343) SA5343; /***************************************************/ // 5365 interface IFactory { void foo(); } class A133 { protected static class Factory : IFactory { void foo() { } } this() { _factory = createFactory(); } protected IFactory createFactory() { return new Factory; } private IFactory _factory; @property final IFactory factory() { return _factory; } alias factory this; } void test133() { IFactory f = new A133; f.foo(); // segfault } /***************************************************/ // 5365 class B134 { } class A134 { B134 _b; this() { _b = new B134; } B134 b() { return _b; } alias b this; } void test134() { auto a = new A134; B134 b = a; // b is null assert(a._b is b); // fails } /***************************************************/ // 5025 struct S135 { void delegate() d; } void test135() { shared S135[] s; if (0) s[0] = S135(); } /***************************************************/ // 5545 bool enforce136(bool value, lazy const(char)[] msg = null) { if(!value) { return false; } return value; } struct Perm { byte[3] perm; ubyte i; this(byte[] input) { foreach(elem; input) { enforce136(i < 3); perm[i++] = elem; std.stdio.stderr.writeln(i); // Never gets incremented. Stays at 0. } } } void test136() { byte[] stuff = [0, 1, 2]; auto perm2 = Perm(stuff); writeln(perm2.perm); // Prints [2, 0, 0] assert(perm2.perm[] == [0, 1, 2]); } /***************************************************/ // 4097 void foo4097() { } alias typeof(&foo4097) T4097; static assert(is(T4097 X : X*) && is(X == function)); static assert(!is(X)); /***************************************************/ // 5798 void assign9(ref int lhs) pure { lhs = 9; } void assign8(ref int rhs) pure { rhs = 8; } int test137(){ int a=1,b=2; assign8(b),assign9(a); assert(a == 9); assert(b == 8); // <-- fail assign9(b),assign8(a); assert(a == 8); assert(b == 9); // <-- fail return 0; } /***************************************************/ // 9366 static assert(!is(typeof((void[]).init ~ cast(void)0))); static assert(!is(typeof(cast(void)0 ~ (void[]).init))); /***************************************************/ struct Size138 { union { struct { int width; int height; } long size; } } enum Size138 foo138 = {2 ,5}; Size138 bar138 = foo138; void test138() { assert(bar138.width == 2); assert(bar138.height == 5); } /***************************************************/ void test3822() { import core.stdc.stdlib; int i = 0; void* ptr; while(i++ != 2) { auto p = alloca(2); assert(p != ptr); ptr = p; } } /***************************************************/ // 5939, 5940 template map(fun...) { auto map(double[] r) { struct Result { this(double[] input) { } } return Result(r); } } void test139() { double[] x; alias typeof(map!"a"(x)) T; T a = void; auto b = map!"a"(x); auto c = [map!"a"(x)]; T[3] d = void; } /***************************************************/ // 5966 string[] foo5966(string[] a) { a[0] = a[0][0..$]; return a; } enum var5966 = foo5966([""]); /***************************************************/ // 5975 int foo5975(wstring replace) { wstring value = ""; value ~= replace; return 1; } enum X5975 = foo5975("X"w); /***************************************************/ // 5965 template mapx(fun...) if (fun.length >= 1) { int mapx(Range)(Range r) { return 1; } } void test140() { int foo(int i) { return i; } int[] arr; auto x = mapx!( (int a){return foo(a);} )(arr); } /***************************************************/ void bug5976() { int[] barr; int * k; foreach (ref b; barr) { scope(failure) k = &b; k = &b; } } /***************************************************/ // 5771 struct S141 { this(A)(auto ref A a){} } void test141() { S141 s = S141(10); } /***************************************************/ class test5498_A {} class test5498_B : test5498_A {} class test5498_C : test5498_A {} static assert(is(typeof([test5498_B.init, test5498_C.init]) == test5498_A[])); /***************************************************/ // 3688 struct S142 { int v; this(int n) pure { v = n; } const bool opCast(T:bool)() { return true; } } void test142() { if (int a = 1) assert(a == 1); else assert(0); if (const int a = 2) assert(a == 2); else assert(0); if (immutable int a = 3) assert(a == 3); else assert(0); if (auto s = S142(10)) assert(s.v == 10); else assert(0); if (auto s = const(S142)(20)) assert(s.v == 20); else assert(0); if (auto s = immutable(S142)(30)) assert(s.v == 30); else assert(0); } /***************************************************/ // 6072 static assert({ if (int x = 5) {} return true; }()); /***************************************************/ // 5959 int n; void test143() { ref int f(){ return n; } // NG f() = 1; assert(n == 1); nothrow ref int f1(){ return n; } // OK f1() = 2; assert(n == 2); auto ref int f2(){ return n; } // OK f2() = 3; assert(n == 3); } /***************************************************/ // 6119 void startsWith(alias pred) () if (is(typeof(pred('c', 'd')) : bool)) { } void startsWith(alias pred) () if (is(typeof(pred('c', "abc")) : bool)) { } void test144() { startsWith!((a, b) { return a == b; })(); } /***************************************************/ void test145() { import core.stdc.stdio; printf("hello world 145\n"); } void test146() { test1(); static import core.stdc.stdio; core.stdc.stdio.printf("hello world 146\n"); } /***************************************************/ // 5856 struct X147 { void f() { writeln("X.f mutable"); } void f() const { writeln("X.f const"); } void g()() { writeln("X.g mutable"); } void g()() const { writeln("X.g const"); } void opOpAssign(string op)(int n) { writeln("X+= mutable"); } void opOpAssign(string op)(int n) const { writeln("X+= const"); } } void test147() { X147 xm; xm.f(); // prints "X.f mutable" xm.g(); // prints "X.g mutable" xm += 10; // should print "X+= mutable" (1) const(X147) xc; xc.f(); // prints "X.f const" xc.g(); // prints "X.g const" xc += 10; // should print "X+= const" (2) } /***************************************************/ void test3559() { static class A { int foo(int a) { return 0; } int foo(float a) { return 1; } int bar(float a) { return 1; } int bar(int a) { return 0; } } static class B : A { override int foo(float a) { return 2; } alias A.foo foo; alias A.bar bar; override int bar(float a) { return 2; } } { auto x = new A; auto f1 = cast(int delegate(int))&x.foo; auto f2 = cast(int delegate(float))&x.foo; int delegate(int) f3 = &x.foo; int delegate(float) f4 = &x.foo; assert(f1(0) == 0); assert(f2(0) == 1); assert(f3(0) == 0); assert(f4(0) == 1); } { auto x = new B; auto f1 = cast(int delegate(int))&x.foo; auto f2 = cast(int delegate(float))&x.foo; int delegate(int) f3 = &x.foo; int delegate(float) f4 = &x.foo; assert(f1(0) == 0); assert(f2(0) == 2); assert(f3(0) == 0); assert(f4(0) == 2); } { auto x = new A; auto f1 = cast(int delegate(int))&x.bar; auto f2 = cast(int delegate(float))&x.bar; int delegate(int) f3 = &x.bar; int delegate(float) f4 = &x.bar; assert(f1(0) == 0); assert(f2(0) == 1); assert(f3(0) == 0); assert(f4(0) == 1); } { auto x = new B; auto f1 = cast(int delegate(int))&x.bar; auto f2 = cast(int delegate(float))&x.bar; int delegate(int) f3 = &x.bar; int delegate(float) f4 = &x.bar; assert(f1(0) == 0); assert(f2(0) == 2); assert(f3(0) == 0); assert(f4(0) == 2); } } /***************************************************/ extern(C++) class C13182 { } void test13182() { scope C13182 c = new C13182(); } /***************************************************/ // 5897 struct A148{ int n; } struct B148{ int n, m; this(A148 a){ n = a.n, m = a.n*2; } } struct C148{ int n, m; static C148 opCall(A148 a) { C148 b; b.n = a.n, b.m = a.n*2; return b; } } void test148() { auto a = A148(10); auto b = cast(B148)a; assert(b.n == 10 && b.m == 20); auto c = cast(C148)a; assert(c.n == 10 && c.m == 20); } /***************************************************/ // 4969 class MyException : Exception { this() { super("An exception!"); } } void throwAway() { throw new MyException; } void cantthrow() nothrow { try throwAway(); catch(MyException me) assert(0); catch(Exception e) assert(0); } /***************************************************/ // 2356 void test2356() { int[3] x = [1,2,3]; printf("x[] = [%d %d %d]\n", x[0], x[1], x[2]); assert(x[0] == 1 && x[1] == 2 && x[2] == 3); struct S { static int pblit; int n; this(this) { ++pblit; printf("postblit: %d\n", n); } } S s2 = S(2); S[3] s = [S(1), s2, S(3)]; assert(s[0].n == 1 && s[1].n == 2 && s[2].n == 3); printf("s[].n = [%d %d %d]\n", s[0].n, s[1].n, s[2].n); assert(S.pblit == 1); ubyte[1024] v; v = typeof(v).init; printf("v[] = [%d %d %d, ..., %d]\n", v[0], v[1], v[2], v[$-1]); foreach (ref a; v) assert(a == 0); int n = 5; int[3] y = [n, n, n]; printf("y[] = [%d %d %d]\n", y[0], y[1], y[2]); assert(y[0] == 5 && y[1] == 5 && y[2] == 5); S[3] z = [s2, s2, s2]; assert(z[0].n == 2 && z[1].n == 2 && z[2].n == 2); printf("z[].n = [%d %d %d]\n", z[0].n, z[1].n, z[2].n); assert(S.pblit == 1 + 3); int[0] nsa0 = []; void[0] vsa0 = []; void foo(T)(T){} foo(vsa0); ref int[0] bar() { static int[1] sa; return *cast(int[0]*)&sa; } bar() = []; } /***************************************************/ // 11238 void test11238() { int[2] m; m[0] = 4,m[1] = 6; //printf("%d,%d\n", m[0], m[1]); assert(m[0] == 4 && m[1] == 6); m = [m[1], m[0]]; // swap assert(m[0] == 6 && m[1] == 4); //printf("%d,%d\n", m[0], m[1]); m = [m[1], m[0]]; // swap //printf("%d,%d\n", m[0], m[1]); assert(m[0] == 4 && m[1] == 6); } /***************************************************/ void test11805() { int i; i = 47; i = 1 && i; assert(i == 1); i = 0 || i; assert(i == 1); } /***************************************************/ class A2540 { int a; int foo() { return 0; } alias int X; } class B2540 : A2540 { int b; override super.X foo() { return 1; } alias this athis; alias this.b thisb; alias super.a supera; alias super.foo superfoo; alias this.foo thisfoo; } struct X2540 { alias this athis; } void test2540() { auto x = X2540.athis.init; static assert(is(typeof(x) == X2540)); B2540 b = new B2540(); assert(&b.a == &b.supera); assert(&b.b == &b.thisb); assert(b.thisfoo() == 1); } /***************************************************/ class B14348 { int foo() { return 0; } } class C14348 : B14348 { override int foo() { return 1; } alias superfoo = typeof(super).foo; alias thisfoo = typeof(this).foo; } B14348 test14348() { alias foo = typeof(return).foo; // currently doesn't work. assert(&B14348.foo is &C14348.superfoo); assert(&C14348.foo is &C14348.thisfoo); return null; } /***************************************************/ // 7295 struct S7295 { int member; @property ref int refCountedPayload() { return member; } alias refCountedPayload this; } void foo7295(S)(immutable S t, int qq) pure { } void foo7295(S)(S s) pure { } void bar7295() pure { S7295 b; foo7295(b); } /***************************************************/ // 5659 void test149() { import std.traits; char a; immutable(char) b; static assert(is(typeof(true ? a : b) == const(char))); static assert(is(typeof([a, b][0]) == const(char))); static assert(is(CommonType!(typeof(a), typeof(b)) == const(char))); } /***************************************************/ // 1373 void func1373a(){} static assert(typeof(func1373a).stringof == "void()"); static assert(typeof(func1373a).mangleof == "FZv"); static assert(!__traits(compiles, typeof(func1373a).alignof)); static assert(!__traits(compiles, typeof(func1373a).init)); static assert(!__traits(compiles, typeof(func1373a).offsetof)); void func1373b(int n){} static assert(typeof(func1373b).stringof == "void(int n)"); static assert(typeof(func1373b).mangleof == "FiZv"); static assert(!__traits(compiles, typeof(func1373b).alignof)); static assert(!__traits(compiles, typeof(func1373b).init)); static assert(!__traits(compiles, typeof(func1373b).offsetof)); /***************************************************/ void bar150(T)(T n) { } @safe void test150() { bar150(1); } /***************************************************/ void test5785() { static struct x { static int y; } assert(x.y !is 1); assert(x.y !in [1:0]); } /***************************************************/ void bar151(T)(T n) { } nothrow void test151() { bar151(1); } /***************************************************/ @property int coo() { return 1; } @property auto doo(int i) { return i; } @property int eoo() { return 1; } @property auto ref hoo(int i) { return i; } // 3359 int goo(int i) pure { return i; } auto ioo(int i) pure { return i; } auto ref boo(int i) pure nothrow { return i; } class A152 { auto hoo(int i) pure { return i; } const boo(int i) nothrow { return i; } auto coo(int i) const { return i; } auto doo(int i) immutable { return i; } auto eoo(int i) shared { return i; } } // 4706 struct Foo152(T) { @property auto ref front() { return T.init; } @property void front(T num) {} } void test152() { Foo152!int foo; auto a = foo.front; foo.front = 2; } /***************************************************/ // 6733 void bug6733(int a, int b) pure nothrow { } void test6733() { int z = 1; bug6733(z++, z++); assert(z==3); } /***************************************************/ // 3799 void test153() { void bar() { } static assert(!__traits(isStaticFunction, bar)); } /***************************************************/ // 3632 void test154() { float f; assert(f is float.init); double d; assert(d is double.init); real r; assert(r is real.init); assert(float.nan is float.nan); assert(double.nan is double.nan); assert(real.nan is real.nan); } /***************************************************/ void test6545() { static int[] func() { auto a = [1, 2, 3]; auto b = [2, 3, 4]; auto c = [3, 4, 5]; a[] = b[] + c[]; return a; } auto a = func(); enum b = func(); assert(a == b); } /***************************************************/ // 3147 void test155() { byte b = 1; short s; int i; long l; s = b + b; b = s % b; s = s >> b; b = 1; b = i % b; b = b >> i; } /***************************************************/ // 2486 void test2486() { void foo(ref int[] arr) {} int[] arr = [1,2,3]; foo(arr); //OK static assert(!__traits(compiles, foo(arr[1..2]))); // should be NG struct S { int[] a; auto ref opSlice(){ return a[]; } // line 4 } S s; s[]; // opSlice should return rvalue static assert(is(typeof(&S.opSlice) == int[] function() pure nothrow @nogc @safe)); static assert(!__traits(compiles, foo(s[]))); // should be NG } /***************************************************/ // 2521 immutable int val = 23; const int val2 = 23; ref immutable(int) func2521_() { return val; } ref immutable(int) func2521_2() { return *&val; } ref immutable(int) func2521_3() { return func2521_; } ref const(int) func2521_4() { return val2; } ref const(int) func2521_5() { return val; } auto ref func2521_6() { return val; } ref func2521_7() { return val; } /***************************************************/ void test5554() { class MA { } class MB : MA { } class MC : MB { } class A { abstract MA foo(); } interface I { MB foo(); } class B : A { override MC foo() { return null; } } class C : B, I { override MC foo() { return null; } } } /***************************************************/ // 5962 struct S156 { auto g()(){ return 1; } const auto g()(){ return 2; } } void test156() { auto ms = S156(); assert(ms.g() == 1); auto cs = const(S156)(); assert(cs.g() == 2); } /***************************************************/ void test10724() { const(char)* s = "abc"[0..$-1]; assert(s[2] == '\0'); } /***************************************************/ void test6708(const ref int y) { immutable int x; test6708(x); } /***************************************************/ // 4258 struct Vec4258 { Vec4258 opOpAssign(string Op)(auto ref Vec4258 other) if (Op == "+") { return this; } Vec4258 opBinary(string Op:"+")(Vec4258 other) { Vec4258 result; return result += other; } } void test4258() { Vec4258 v; v += Vec4258() + Vec4258(); // line 12 } // regression fix test struct Foo4258 { // binary ++/-- int opPostInc()() if (false) { return 0; } // binary 1st int opAdd(R)(R rhs) if (false) { return 0; } int opAdd_r(R)(R rhs) if (false) { return 0; } // compare int opCmp(R)(R rhs) if (false) { return 0; } // binary-op assign int opAddAssign(R)(R rhs) if (false) { return 0; } } struct Bar4258 { // binary commutive 1 int opAdd_r(R)(R rhs) if (false) { return 0; } // binary-op assign int opOpAssign(string op, R)(R rhs) if (false) { return 0; } } struct Baz4258 { // binary commutive 2 int opAdd(R)(R rhs) if (false) { return 0; } } static assert(!is(typeof(Foo4258.init++))); static assert(!is(typeof(Foo4258.init + 1))); static assert(!is(typeof(1 + Foo4258.init))); static assert(!is(typeof(Foo4258.init < Foo4258.init))); static assert(!is(typeof(Foo4258.init += 1))); static assert(!is(typeof(Bar4258.init + 1))); static assert(!is(typeof(Bar4258.init += 1))); static assert(!is(typeof(1 + Baz4258.init))); /***************************************************/ // 4539 void test4539() { static assert(!__traits(compiles, "hello" = "red")); void foo1(ref string s){} void foo2(ref const char[10] s){} void foo3(ref char[5] s){} void foo4(ref const char[5] s) { assert(s[0] == 'h'); assert(s[4] == 'o'); } void foo5(ref const ubyte[5] s) { assert(s[0] == 0xc3); assert(s[4] == 0x61); } static assert(!__traits(compiles, foo1("hello"))); static assert(!__traits(compiles, foo2("hello"))); static assert(!__traits(compiles, foo3("hello"))); // same as test68, 69, 70 foo4("hello"); foo5(cast(ubyte[5])x"c3fcd3d761"); //import std.conv; //static assert(!__traits(compiles, parse!int("10") == 10)); } /***************************************************/ // 1471 void test1471() { int n; string bar = "BOOM"[n..$-1]; assert(bar == "BOO"); } /***************************************************/ deprecated @disable int bug6389; static assert(!is(typeof(bug6389 = bug6389))); /***************************************************/ void test10927() { static assert( (1+2i) ^^ 3 == -11 - 2i ); auto a = (1+2i) ^^ 3; } /***************************************************/ void test4963() { struct Value { byte a; }; Value single() { return Value(); } Value[] list; auto x = single() ~ list; } /***************************************************/ pure int test4031() { static const int x = 8; return x; } /***************************************************/ // 5437 template EnumMembers5437(E) { template TypeTuple(T...){ alias T TypeTuple; } alias TypeTuple!("A", "B") EnumMembers5437; } template IntValue5437() { int IntValue5437 = 10; } void test5437() { enum Foo { A, B } alias EnumMembers5437!Foo members; // OK enum n1 = members.length; // OK enum n2 = (EnumMembers5437!Foo).length; // NG, type -> symbol enum s1 = IntValue5437!().sizeof; // OK enum s2 = (IntValue5437!()).sizeof; // NG, type -> expression } /***************************************************/ // 1962 void test1962() { class C { abstract void x(); } assert(C.classinfo.create() is null); } /***************************************************/ // 6228 void test6228() { const(int)* ptr; const(int) temp; auto x = (*ptr) ^^ temp; } /***************************************************/ int test7544() { try { throw new Exception(""); } catch (Exception e) static assert(1); return 1; } static assert(test7544()); /***************************************************/ struct S6230 { int p; int q() const pure { return p; } void r() pure { p = 231; } } class C6230 { int p; int q() const pure { return p; } void r() pure { p = 552; } } int q6230(ref const S6230 s) pure { // <-- Currently OK return s.p; } int q6230(ref const C6230 c) pure { // <-- Currently OK return c.p; } void r6230(ref S6230 s) pure { s.p = 244; } void r6230(ref C6230 c) pure { c.p = 156; } bool test6230pure() pure { auto s = S6230(4); assert(s.p == 4); assert(q6230(s) == 4); assert(s.q == 4); auto c = new C6230; c.p = 6; assert(q6230(c) == 6); assert(c.q == 6); r6230(s); assert(s.p == 244); s.r(); assert(s.p == 231); r6230(c); assert(c.p == 156); c.r(); assert(c.p == 552); return true; } void test6230() { assert(test6230pure()); } /***************************************************/ void test6264() { struct S { auto opSlice() { return this; } } int[] a; S s; static assert(!is(typeof(a[] = s[]))); int*[] b; static assert(is(typeof(b[] = [new immutable(int)]))); char[] c = new char[](5); c[] = "hello"; } /***************************************************/ // 5046 void test5046() { auto va = S5046!("", int)(); auto vb = makeS5046!("", int)(); } struct S5046(alias p, T) { T s; T fun() { return s; } // (10) } S5046!(p, T) makeS5046(alias p, T)() { return typeof(return)(); } /***************************************************/ // 6335 struct S6335 { const int value; this()(int n){ value = n; } } void test6335() { S6335 s = S6335(10); } /***************************************************/ struct S6295(int N) { int[N] x; const nothrow pure @safe f() { return x.length; } } void test6295() { auto bar(T: S6295!(N), int N)(T x) { return x.f(); } S6295!4 x; assert(bar(x) == 4); } /***************************************************/ template TT4536(T...) { alias T TT4536; } void test4536() { auto x = TT4536!(int, long, [1, 2]).init; assert(x[0] is int.init); assert(x[1] is long.init); assert(x[2] is [1, 2].init); } /***************************************************/ struct S6284 { int a; } class C6284 { int a; } pure int bug6284a() { S6284 s = {4}; auto b = s.a; // ok with (s) { b += a; // should be ok. } return b; } pure int bug6284b() { auto s = new S6284; s.a = 4; auto b = s.a; with (*s) { b += a; } return b; } pure int bug6284c() { auto s = new C6284; s.a = 4; auto b = s.a; with (s) { b += a; } return b; } void test6284() { assert(bug6284a() == 8); assert(bug6284b() == 8); assert(bug6284c() == 8); } /***************************************************/ class C6293 { C6293 token; } void f6293(in C6293[] a) pure { auto x0 = a[0].token; assert(x0 is a[0].token.token.token); assert(x0 is (&x0).token); auto p1 = &x0 + 1; assert(x0 is (p1 - 1).token); int c = 0; assert(x0 is a[c].token); } void test6293() { auto x = new C6293; x.token = x; f6293([x]); } /***************************************************/ // 3733 class C3733 { int foo() { return 1; } int foo() shared { return 2; } int bar() { return foo(); } } void test3733() { auto c = new C3733(); assert(c.bar() == 1); } /***************************************************/ // 4392 class C4392 { int foo() const { return 1; } int foo() { return 2; } int bar() const { return foo(); } } void test4392() { auto c = new C4392(); assert(c.bar() == 1); } /***************************************************/ // 6220 void test6220() { struct Foobar { real x; real y; real z;}; switch("x") { foreach(i,member; __traits(allMembers, Foobar)) { case member : break; } default : break; } } /***************************************************/ // 5799 void test5799() { int a; int *u = &(a ? a : (a ? a : a)); assert(u == &a); } /***************************************************/ // 6529 enum Foo6529 : char { A='a' } ref const(Foo6529) func6529(const(Foo6529)[] arr){ return arr[0]; } /***************************************************/ void test783() { const arr = [ 1,2,3 ]; const i = 2; auto jhk = new int[arr[i]]; // "need size of rightmost array, not type arr[i]" } /***************************************************/ template X157(alias x) { alias x X157; } template Parent(alias foo) { alias X157!(__traits(parent, foo)) Parent; } template ParameterTypeTuple(alias foo) { static if (is(typeof(foo) P == function)) alias P ParameterTypeTuple; else static assert(0, "argument has no parameters"); } template Mfp(alias foo) { auto Mfp = function(Parent!foo self, ParameterTypeTuple!foo i) { return self.foo(i); }; } class C157 { int a = 3; int foo(int i, int y) { return i + a + y; } } void test157() { auto c = new C157(); auto mfp = Mfp!(C157.foo); auto i = mfp(c, 1, 7); assert(i == 11); } /***************************************************/ // 6473 struct Eins6473 { ~this() {} } struct Zwei6473 { void build(Eins6473 devices = Eins6473()) { } } void build(Eins6473 devices = Eins6473()) {} void test6473() { void build(Eins6473 devices = Eins6473()) {} } /***************************************************/ uint rol11417(uint n)(in uint x) { return x << n | x >> 32 - n; } uint ror11417(uint n)(in uint x) { return x >> n | x << 32 - n; } void test11417() { assert(rol11417!1(0x8000_0000) == 0x1); assert(ror11417!1(0x1) == 0x8000_0000); } /***************************************************/ void test6578() { static struct Foo { this(int x) pure {} } auto f1 = new const(Foo)(1); auto f2 = new immutable(Foo)(1); auto f3 = new shared(Foo)(1); auto f4 = const(Foo)(1); auto f5 = immutable(Foo)(1); auto f6 = shared(Foo)(1); static assert(is(typeof(f1) == const(Foo)*)); static assert(is(typeof(f2) == immutable(Foo)*)); static assert(is(typeof(f3) == shared(Foo)*)); static assert(is(typeof(f4) == const(Foo))); static assert(is(typeof(f5) == immutable(Foo))); static assert(is(typeof(f6) == shared(Foo))); static struct Bar { this(int x) const pure {} } auto g1 = new const(Bar)(1); auto g2 = new immutable(Bar)(1); auto g3 = new shared(Bar)(1); auto g4 = const(Bar)(1); auto g5 = immutable(Bar)(1); auto g6 = shared(Bar)(1); static assert(is(typeof(g1) == const(Bar)*)); static assert(is(typeof(g2) == immutable(Bar)*)); static assert(is(typeof(g3) == shared(Bar)*)); static assert(is(typeof(g4) == const(Bar))); static assert(is(typeof(g5) == immutable(Bar))); static assert(is(typeof(g6) == shared(Bar))); static struct Baz { this()(int x) const pure {} } auto h1 = new const(Baz)(1); auto h2 = new immutable(Baz)(1); auto h3 = new shared(const(Baz))(1); auto h4 = const(Baz)(1); auto h5 = immutable(Baz)(1); auto h6 = shared(const(Baz))(1); static assert(is(typeof(h1) == const(Baz)*)); static assert(is(typeof(h2) == immutable(Baz)*)); static assert(is(typeof(h3) == shared(const(Baz))*)); static assert(is(typeof(h4) == const(Baz))); static assert(is(typeof(h5) == immutable(Baz))); static assert(is(typeof(h6) == shared(const(Baz)))); } /***************************************************/ // 6630 void test6630() { static class B {} static class A { this() { b = new B(); } B b; alias b this; } void fun(A a) { a = null; assert(a is null); } auto a = new A; assert(a.b !is null); fun(a); assert(a !is null); assert(a.b !is null); } /***************************************************/ int i199 = 1; void test199() { label: { int i199 = 2; } assert(i199 == 1); } /***************************************************/ // 6690 T useLazy6690(T)(lazy T val) { return val; // val is converted to delegate call, but it is typed as int delegate() - not @safe! } void test6690() @safe { useLazy6690(0); // Error: safe function 'test6690' cannot call system function 'useLazy6690' } /***************************************************/ template Hoge6691() { immutable static int[int] dict; immutable static int value; static this() { dict = [1:1, 2:2]; value = 10; } } alias Hoge6691!() H6691; /***************************************************/ void test10626() { double[2] v, x; struct Y { double u; } double z; Y y; double[2] r = v[] * x[0]; //double[2] s = v[] * z++; //double[2] t = v[] * z--; double[2] a = v[] * ++z; double[2] b = v[] * --z; double[2] c = v[] * y.u; double[2] d = v[] * (x[] = 3, x[0]); double[2] e = v[] * (v[] ~ z)[0]; } /***************************************************/ // 2953 template Tuple2953(T...) { alias T Tuple2953; } template Range2953(int b) { alias Tuple2953!(1) Range2953; } void foo2953()() { Tuple2953!(int, int) args; foreach( x ; Range2953!(args.length) ){ } } void test2953() { foo2953!()(); } /***************************************************/ // 2997 abstract class B2997 { void foo(); } interface I2997 { void bar(); } abstract class C2997 : B2997, I2997 {} //pragma(msg, __traits(allMembers, C).stringof); void test2997() { enum ObjectMembers = ["toString","toHash","opCmp","opEquals","Monitor","factory"]; static assert([__traits(allMembers, C2997)] == ["foo"] ~ ObjectMembers ~ ["bar"]); } /***************************************************/ // 6596 extern (C) int function() pfunc6596; extern (C) int cfunc6596(){ return 0; } static assert(typeof(pfunc6596).stringof == "extern (C) int function()"); static assert(typeof(cfunc6596).stringof == "extern (C) int()"); /***************************************************/ // 4423 struct S4423 { this(string phrase, int num) { this.phrase = phrase; this.num = num; } int opCmp(const ref S4423 rhs) { if (phrase < rhs.phrase) return -1; else if (phrase > rhs.phrase) return 1; if (num < rhs.num) return -1; else if (num > rhs.num) return 1; return 0; } string phrase; int num; } enum E4423 : S4423 { a = S4423("hello", 1), b = S4423("goodbye", 45), c = S4423("world", 22), }; void test4423() { E4423 e; assert(e.phrase == "hello"); e = E4423.b; assert(e.phrase == "goodbye"); } /***************************************************/ // 4647 interface Timer { final int run() { printf("Timer.run()\n"); fun(); return 1; }; int fun(); } interface Application { final int run() { printf("Application.run()\n"); fun(); return 2; }; int fun(); } class TimedApp : Timer, Application { int funCalls; override int fun() { printf("TimedApp.fun()\n"); funCalls++; return 2; } } class SubTimedApp : TimedApp { int subFunCalls; override int fun() { printf("SubTimedApp.fun()\n"); subFunCalls++; return 1; } } void test4647() { //Test access to TimedApps base interfaces auto app = new TimedApp(); assert((cast(Application)app).run() == 2); assert((cast(Timer)app).run() == 1); assert(app.Timer.run() == 1); // error, no Timer property assert(app.Application.run() == 2); // error, no Application property assert(app.run() == 1); // This would call Timer.run() if the two calls // above were commented out assert(app.funCalls == 5); assert(app.TimedApp.fun() == 2); assert(app.funCalls == 6); //Test direct access to SubTimedApp interfaces auto app2 = new SubTimedApp(); assert((cast(Application)app2).run() == 2); assert((cast(Timer)app2).run() == 1); assert(app2.Application.run() == 2); assert(app2.Timer.run() == 1); assert(app2.funCalls == 0); assert(app2.subFunCalls == 4); assert(app2.fun() == 1); assert(app2.SubTimedApp.fun() == 1); assert(app2.funCalls == 0); assert(app2.subFunCalls == 6); //Test access to SubTimedApp interfaces via TimedApp auto app3 = new SubTimedApp(); (cast(Timer)cast(TimedApp)app3).run(); app3.TimedApp.Timer.run(); assert((cast(Application)cast(TimedApp)app3).run() == 2); assert((cast(Timer)cast(TimedApp)app3).run() == 1); assert(app3.TimedApp.Application.run() == 2); assert(app3.TimedApp.Timer.run() == 1); assert(app3.funCalls == 0); assert(app3.subFunCalls == 6); } /***************************************************/ template T1064(E...) { alias E T1064; } int[] var1064 = [ T1064!(T1064!(T1064!(1, 2), T1064!(), T1064!(3)), T1064!(4, T1064!(T1064!(T1064!(T1064!(5)))), T1064!(T1064!(T1064!(T1064!())))),6) ]; void test1064() { assert(var1064 == [1,2,3,4,5,6]); } /***************************************************/ // 5696 template Seq5696(T...){ alias T Seq5696; } template Pred5696(T) { alias T Pred5696; } // TOKtemplate template Scope5696(int n){ template X(T) { alias T X; } } // TOKimport T foo5696(T)(T x) { return x; } void test5696() { foreach (pred; Seq5696!(Pred5696, Pred5696)) { static assert(is(pred!int == int)); } foreach (scop; Seq5696!(Scope5696!0, Scope5696!1)) { static assert(is(scop.X!int == int)); } alias Seq5696!(foo5696, foo5696) funcs; assert(funcs[0](0) == 0); assert(funcs[1](1) == 1); foreach (i, fn; funcs) { assert(fn(i) == i); } } /***************************************************/ // 5933 int dummyfunc5933(); alias typeof(dummyfunc5933) FuncType5933; struct S5933a { auto x() { return 0; } } static assert(is(typeof(&S5933a.init.x) == int delegate() pure nothrow @nogc @safe)); struct S5933b { auto x() { return 0; } } //static assert(is(typeof(S5933b.init.x) == FuncType5933)); struct S5933c { auto x() { return 0; } } static assert(is(typeof(&S5933c.x) == int function())); struct S5933d { auto x() { return 0; } } static assert(is(typeof(S5933d.x) == FuncType5933)); class C5933a { auto x() { return 0; } } static assert(is(typeof(&(new C5933b()).x) == int delegate() pure nothrow @nogc @safe)); class C5933b { auto x() { return 0; } } //static assert(is(typeof((new C5933b()).x) == FuncType5933)); class C5933c { auto x() { return 0; } } static assert(is(typeof(&C5933c.x) == int function())); class C5933d { auto x() { return 0; } } static assert(is(typeof(C5933d.x) == FuncType5933)); /***************************************************/ // 6084 template TypeTuple6084(T...){ alias T TypeTuple6084; } void test6084() { int foo(int x)() { return x; } foreach(i; TypeTuple6084!(0)) foo!(i); } /***************************************************/ // 6763 template TypeTuple6763(TList...) { alias TList TypeTuple6763; } alias TypeTuple6763!(int) T6763; void f6763( T6763) { } /// void c6763(const T6763) { } ///T now is (const int) void r6763(ref T6763) { } ///T now is(ref const int) void i6763(in T6763) { } ///Uncomment to get an Assertion failure in 'mtype.c' void o6763(out T6763) { } ///ditto void test6763() { int n; f6763(0); //With D2: Error: function main.f ((ref const const(int) _param_0)) is not callable using argument types (int) c6763(0); r6763(n); static assert(!__traits(compiles, r6763(0))); i6763(0); o6763(n); static assert(!__traits(compiles, o6763(0))); // 6755 static assert(typeof(f6763).stringof == "void(int _param_0)"); static assert(typeof(c6763).stringof == "void(const(int) _param_0)"); static assert(typeof(r6763).stringof == "void(ref int _param_0)"); static assert(typeof(i6763).stringof == "void(const(int) _param_0)"); static assert(typeof(o6763).stringof == "void(out int _param_0)"); } /***************************************************/ // 6695 struct X6695 { void mfunc() { static assert(is(typeof(this) == X6695)); } void cfunc() const { static assert(is(typeof(this) == const(X6695))); } void ifunc() immutable { static assert(is(typeof(this) == immutable(X6695))); } void sfunc() shared { static assert(is(typeof(this) == shared(X6695))); } void scfunc() shared const { static assert(is(typeof(this) == shared(const(X6695)))); } void wfunc() inout { static assert(is(typeof(this) == inout(X6695))); } void swfunc() shared inout { static assert(is(typeof(this) == shared(inout(X6695)))); } static assert(is(typeof(this) == X6695)); } /***************************************************/ // 6087 template True6087(T) { immutable True6087 = true; } struct Foo6087 { static assert( True6087!(typeof(this)) ); } struct Bar6087 { static assert( is(typeof(this) == Bar6087) ); } /***************************************************/ // 6848 class Foo6848 {} class Bar6848 : Foo6848 { void func() immutable { static assert(is(typeof(this) == immutable(Bar6848))); // immutable(Bar6848) auto t = this; static assert(is(typeof(t) == immutable(Bar6848))); // immutable(Bar6848) static assert(is(typeof(super) == immutable(Foo6848))); // Foo6848 instead of immutable(Foo6848) auto s = super; static assert(is(typeof(s) == immutable(Foo6848))); // Foo6848 instead of immutable(Foo6848) } } /***************************************************/ version(none) { cent issue785; ucent issue785; } static assert(is(cent) && is(ucent) || !is(cent) && !is(ucent)); static if (is(cent)) static assert(__traits(compiles, { cent x; })); else static assert(!__traits(compiles, { cent x; })); /***************************************************/ // 6847 template True6847(T) { immutable True6847 = true; } class Foo6847 {} class Bar6847 : Foo6847 { static assert( True6847!(typeof(super)) ); static assert( is(typeof(super) == Foo6847) ); } /***************************************************/ // http://d.puremagic.com/issues/show_bug.cgi?id=6488 struct TickDuration { template to(T) if (__traits(isIntegral,T)) { const T to() { return 1; } } template to(T) if (__traits(isFloating,T)) { const T to() { return 0; } } const long seconds() { return to!(long)(); } } void test6488() { TickDuration d; d.seconds(); } /***************************************************/ // 6565 void foo6565(out int[2][2] m) {} void test6565() { int[2][2] mat = [[1, 2], [3, 4]]; foo6565(mat); assert(mat == [[0, 0], [0, 0]]); } /***************************************************/ // 6836 template map6836(fun...) if (fun.length >= 1) { auto map6836(Range)(Range r) { } } void test6836() { [1].map6836!"a"(); } /***************************************************/ string func12864() { return ['a', 'b', 'c']; } void test12864(string s) { switch (s) { case func12864(): break; default: break; } } /***************************************************/ void test5448() { int[int][] aaa = [[1: 2]]; int[string][] a2 = [["cc":0], ["DD":10]]; } /***************************************************/ // 6837 struct Ref6837a(T) { T storage; alias storage this; } struct Ref6837b(T) { T storage; @property ref T get(){ return storage; } alias get this; } int front6837(int[] arr){ return arr[0]; } void popFront6837(ref int[] arr){ arr = arr[1..$]; } void test6837() { assert([1,2,3].front6837 == 1); auto r1 = Ref6837a!(int[])([1,2,3]); assert(r1.front6837() == 1); // ng assert(r1.front6837 == 1); // ok r1.popFront6837(); // ng r1.storage.popFront6837(); // ok auto r2 = Ref6837b!(int[])([1,2,3]); assert(r2.front6837() == 1); // ng assert(r2.front6837 == 1); // ok r2.popFront6837(); // ng r2.get.popFront6837(); // ng r2.get().popFront6837(); // ok } /***************************************************/ // 6927 @property int[] foo6927() { return [1, 2]; } int[] bar6927(int[] a) { return a; } void test6927() { bar6927(foo6927); // OK foo6927.bar6927(); // line 9, Error } /***************************************************/ struct Foo6813(T) { Foo6813 Bar() { return Foo6813(_indices.abc()); } T _indices; } struct SortedRange(alias pred) { SortedRange abc() { return SortedRange(); } } void test6813() { auto ind = SortedRange!({ })(); auto a = Foo6813!(typeof(ind))(); } /***************************************************/ struct Interval6753{ int a,b; } @safe struct S6753 { int[] arr; @trusted @property auto byInterval() const { return cast(const(Interval6753)[])arr; } } /***************************************************/ // 6859 class Parent6859 { public: bool isHage() const @property; public: abstract void fuga() out { assert(isHage); } body { } } class Child6859 : Parent6859 { override bool isHage() const @property { return true; } override void fuga() { //nop } } void test6859() { auto t = new Child6859; t.fuga(); printf("done.\n"); } /***************************************************/ // 6910 template Test6910(alias i, B) { void fn() { foreach(t; B.Types) { switch(i) { case 0://IndexOf!(t, B.Types): { pragma(msg, __traits(allMembers, t)); pragma(msg, __traits(hasMember, t, "m")); static assert(__traits(hasMember, t, "m")); // test break; } default: {} } } } } void test6910() { static struct Bag(S...) { alias S Types; } static struct A { int m; } int i; alias Test6910!(i, Bag!(A)).fn func; } /***************************************************/ void fun12503() { string b = "abc"; try { try { b = null; return; } catch { } } finally { assert("abc" !is b); } } void test12503() { fun12503(); } /***************************************************/ // 6902 void test6902() { static assert(is(typeof({ return int.init; // int, long, real, etc. }))); int f() pure nothrow { assert(0); } alias int T() pure nothrow; static if(is(typeof(&f) DT == delegate)) { static assert(is(DT* == T*)); // ok // Error: static assert (is(pure nothrow int() == pure nothrow int())) is false static assert(is(DT == T)); } } /***************************************************/ // 6330 struct S6330 { void opAssign(S6330 s) @disable { assert(0); // This fails. } } void test6330() { S6330 s; S6330 s2; static assert(!is(typeof({ s2 = s; }))); } /***************************************************/ struct S8269 { bool dtor = false; ~this() { dtor = true; } } void test8269() { with(S8269()) { assert(!dtor); } } /***************************************************/ // 5311 class C5311 { private static int globalData; void breaksPure() pure const { static assert(!__traits(compiles, { globalData++; })); // SHOULD BE ERROR static assert(!__traits(compiles, { C5311.globalData++; }));// SHOULD BE ERROR static assert(!__traits(compiles, { this.globalData++; })); // SHOULD BE ERROR static assert(!__traits(compiles, { int a = this.globalData; })); } } static void breaksPure5311a(C5311 x) pure { static assert(!__traits(compiles, { x.globalData++; })); // SHOULD BE ERROR static assert(!__traits(compiles, { int a = x.globalData; })); } struct S5311 { private static int globalData; void breaksPure() pure const { static assert(!__traits(compiles, { globalData++; })); // SHOULD BE ERROR static assert(!__traits(compiles, { S5311.globalData++; }));// SHOULD BE ERROR static assert(!__traits(compiles, { this.globalData++; })); // SHOULD BE ERROR static assert(!__traits(compiles, { int a = this.globalData; })); } } static void breaksPure5311b(S5311 x) pure { static assert(!__traits(compiles, { x.globalData++; })); // SHOULD BE ERROR static assert(!__traits(compiles, { int a = x.globalData; })); } /***************************************************/ // 6868 @property bool empty6868(T)(in T[] a) @safe pure nothrow { return !a.length; } void test6868() { alias int[] Range; static if (is(char[1 + Range.empty6868])) // Line 9 enum bool isInfinite = true; char[0] s; // need } /***************************************************/ // 2856 struct foo2856 { static void opIndex(int i) { printf("foo\n"); } } struct bar2856(T) { static void opIndex(int i) { printf("bar\n"); } } void test2856() { foo2856[1]; bar2856!(float)[1]; // Error (# = __LINE__) alias bar2856!(float) B; B[1]; // Okay } /***************************************************/ void test13947() { struct S {} static assert(S.sizeof == 1); S a; S b; *cast(ubyte*)&a = 1; *cast(ubyte*)&b = 2; assert(a == b); assert(a is b); assert(!(a != b)); assert(!(a !is b)); static assert(S() == S()); static assert(S() is S()); static assert(!(S() != S())); static assert(!(S() !is S())); } /***************************************************/ // 3091 void test3091(inout int = 0) { struct Foo {} auto pm = new Foo; static assert(is( typeof( pm) == Foo * )); auto pc = new const Foo; static assert(is( typeof( pc) == const(Foo) * )); auto pw = new inout Foo; static assert(is( typeof( pw) == inout(Foo) * )); auto psm = new shared Foo; static assert(is( typeof(psm) == shared(Foo) * )); auto psc = new shared const Foo; static assert(is( typeof(psc) == shared(const(Foo))* )); auto psw = new shared inout Foo; static assert(is( typeof(psw) == shared(inout(Foo))* )); auto pi = new immutable Foo; static assert(is( typeof( pi) == immutable(Foo) * )); auto m = Foo(); static assert(is( typeof( m) == Foo )); auto c = const Foo(); static assert(is( typeof( c) == const(Foo) )); auto w = inout Foo(); static assert(is( typeof( w) == inout(Foo) )); auto sm = shared Foo(); static assert(is( typeof(sm) == shared(Foo) )); auto sc = shared const Foo(); static assert(is( typeof(sc) == shared(const(Foo)) )); auto sw = shared inout Foo(); static assert(is( typeof(sw) == shared(inout(Foo)) )); auto i = immutable Foo(); static assert(is( typeof( i) == immutable(Foo) )); } /***************************************************/ // 6837 template Id6837(T) { alias T Id6837; } static assert(is(Id6837!(shared const int) == shared const int)); static assert(is(Id6837!(shared inout int) == shared inout int)); /***************************************************/ // 6056 fixup template ParameterTypeTuple6056(func) { static if (is(func Fptr : Fptr*) && is(Fptr P == function)) alias P ParameterTypeTuple6056; else static assert(0, "argument has no parameters"); } extern(C) alias void function() fpw_t; alias void function(fpw_t fp) cb_t; void bar6056(ParameterTypeTuple6056!(cb_t) args) { pragma (msg, "TFunction1: " ~ typeof(args[0]).stringof); } extern(C) void foo6056() { } void test6056() { bar6056(&foo6056); } /***************************************************/ // 6356 int f6356()(int a) { return a*a; } alias f6356!() g6356; // comment this out to eliminate the errors pure nothrow @safe int i6356() { return f6356(1); } void test6356() { assert(i6356() == 1); } /***************************************************/ // 7108 static assert(!__traits(hasMember, int, "x")); static assert( __traits(hasMember, int, "init")); /***************************************************/ // 7073 void test7073() { string f(int[] arr...) { return ""; } } /***************************************************/ // 7104 void test7104() { typeof(new class {}) c; c = new typeof(c); } /***************************************************/ // 7150 struct A7150 { static int cnt; this(T)(T thing, int i) { this(thing, i > 0); // Error: constructor call must be in a constructor ++cnt; } this(T)(T thing, bool b) { ++cnt; } } void test7150() { auto a = A7150(5, 5); // Error: template instance constructtest.A.__ctor!(int) error instantiating assert(A7150.cnt == 2); } /***************************************************/ // 7159 alias void delegate() Void7159; class HomeController7159 { Void7159 foo() { return cast(Void7159)&HomeController7159.displayDefault; } auto displayDefault() { return 1; } } /***************************************************/ // 7160 class HomeController { static if (false) { mixin(q{ int a; }); } void foo() { foreach (m; __traits(derivedMembers, HomeController)) { } } } void test7160() {} /***************************************************/ // 7168 void test7168() { static class X { void foo(){} } static class Y : X { void bar(){} } enum ObjectMembers = ["toString","toHash","opCmp","opEquals","Monitor","factory"]; static assert([__traits(allMembers, X)] == ["foo"]~ObjectMembers); // pass static assert([__traits(allMembers, Y)] == ["bar", "foo"]~ObjectMembers); // fail static assert([__traits(allMembers, Y)] != ["bar", "foo"]); // fail } /***************************************************/ // 7170 T to7170(T)(string x) { return 1; } void test7170() { // auto i = to7170!int("1"); // OK auto j = "1".to7170!int(); // NG, Internal error: e2ir.c 683 } /***************************************************/ // 7196 auto foo7196(int x){return x;} auto foo7196(double x){return x;} void test7196() { auto x = (&foo7196)(1); // ok auto y = (&foo7196)(1.0); // fail } /***************************************************/ // 7285 int[2] spam7285() { int[2] ab; if (true) return (true) ? ab : [0, 0]; // Error else return (true) ? [0, 0] : ab; // OK } void test7285() { auto sa = spam7285(); } /***************************************************/ // 14737 void test14737() { // compile-time enum string[2] a1 = ["d", "e"]; enum b1x = ["a", "b", "c"] ~ a1; // Tarray vs Tsarray enum b1y = a1 ~ ["a", "b", "c"]; // Tsarray vs Tarray static assert(is(typeof(b1x) == string[])); static assert(is(typeof(b1y) == string[])); static assert(b1x == ["a", "b", "c", "d", "e"]); static assert(b1y == ["d", "e", "a", "b", "c"]); // runtime string[2] a2 = ["d", "e"]; auto b2x = ["a", "b", "c"] ~ a2; // Tarray vs Tsarray auto b2y = a2 ~ ["a", "b", "c"]; // Tsarray vs Tarray static assert(is(typeof(b2x) == string[])); static assert(is(typeof(b2y) == string[])); assert(b2x == ["a", "b", "c", "d", "e"]); assert(b2y == ["d", "e", "a", "b", "c"]); } /***************************************************/ // 7321 void test7321() { static assert(is(typeof((){})==void function()pure nothrow @nogc @safe)); // ok static assert(is(typeof((){return;})==void function()pure nothrow @nogc @safe)); // fail } /***************************************************/ class A158 { pure void foo1() { } const void foo2() { } nothrow void foo3() { } @safe void foo4() { } } class B158 : A158 { override void foo1() { } override void foo2() const { } override void foo3() { } override void foo4() { } } /***************************************************/ // 9231 class B9231 { void foo() inout pure {} } class D9231 : B9231 { override void foo() inout {} } /***************************************************/ // 3282 class Base3282 { string f() { return "Base.f()"; } } class Derived3282 : Base3282 { override string f() { return "Derived.f()"; } /*override*/ string f() const { return "Derived.f() const"; } } void test3282() { auto x = new Base3282; assert(x.f() == "Base.f()"); auto y = new Derived3282; assert(y.f() == "Derived.f()");// calls "Derived.f() const", but it is expected that be called non-const. auto z = new const(Derived3282); assert(z.f() == "Derived.f() const"); } /***************************************************/ // 7534 class C7534 { int foo(){ return 1; } } class D7534 : C7534 { override int foo(){ return 2; } /*override*/ int foo() const { return 3; } // Error: D.foo multiple overrides of same function } void test7534() { C7534 mc = new C7534(); assert(mc.foo() == 1); D7534 md = new D7534(); assert(md.foo() == 2); mc = md; assert(mc.foo() == 2); const(D7534) cd = new const(D7534)(); assert(cd.foo() == 3); md = cast()cd; assert(md.foo() == 2); } /***************************************************/ // 7534 + return type covariance class X7534 {} class Y7534 : X7534 { int value; this(int n){ value = n; } } class V7534 { X7534 foo(){ return new X7534(); } } class W7534 : V7534 { override Y7534 foo(){ return new Y7534(1); } /*override*/ Y7534 foo() const { return new Y7534(2); } } void test7534cov() { auto mv = new V7534(); assert(typeid(mv.foo()) == typeid(X7534)); auto mw = new W7534(); assert(typeid(mw.foo()) == typeid(Y7534)); assert(mw.foo().value == 1); mv = mw; assert(typeid(mv.foo()) == typeid(Y7534)); assert((cast(Y7534)mv.foo()).value == 1); auto cw = new const(W7534)(); assert(typeid(cw.foo()) == typeid(Y7534)); assert(cw.foo().value == 2); } /***************************************************/ // 7562 static struct MyInt { private int value; mixin ProxyOf!value; } mixin template ProxyOf(alias a) { template X1(){} template X2(){} template X3(){} template X4(){} template X5(){} template X6(){} template X7(){} template X8(){} template X9(){} template X10(){} void test1(this X)(){} void test2(this Y)(){} } /***************************************************/ import core.stdc.stdlib; void test13427(void* buffer = alloca(100)) { } /***************************************************/ // 7583 template Tup7583(E...) { alias E Tup7583; } struct S7583 { Tup7583!(float, char) field; alias field this; this(int x) { } } int bug7583() { S7583[] arr; arr ~= S7583(0); return 1; } static assert (bug7583()); /***************************************************/ // 7618 void test7618(const int x = 1) { int func(ref int x) { return 1; } static assert(!__traits(compiles, func(x))); // Error: function test.foo.func (ref int _param_0) is not callable using argument types (const(int)) int delegate(ref int) dg = (ref int x) => 1; static assert(!__traits(compiles, dg(x))); // --> no error, bad! int function(ref int) fp = (ref int x) => 1; static assert(!__traits(compiles, fp(x))); // --> no error, bad! } /***************************************************/ // 7621 void test7621() { enum uint N = 4u; char[] A = "hello".dup; uint[immutable char[4u]] dict; dict[*cast(immutable char[4]*)(A[0 .. N].ptr)] = 0; // OK dict[*cast(immutable char[N]*)(A[0 .. N].ptr)] = 0; // line 6, error } /***************************************************/ // 7682 template ConstOf7682(T) { alias const(T) ConstOf7682; } bool pointsTo7682(S)(ref const S source) @trusted pure nothrow { return true; } void test7682() { shared(ConstOf7682!(int[])) x; // line A struct S3 { int[10] a; } shared(S3) sh3; shared(int[]) sh3sub = sh3.a[]; assert(pointsTo7682(sh3sub)); // line B } /***************************************************/ // 7735 void a7735(void[][] data...) { //writeln(data); assert(data.length == 1); b7735(data); } void b7735(void[][] data...) { //writeln(data); assert(data.length == 1); c7735(data); } void c7735(void[][] data...) { //writeln(data); assert(data.length == 1); } void test7735() { a7735([]); a7735([]); } /***************************************************/ struct A7823 { long a; enum A7823 b = {0}; } void test7823(A7823 a = A7823.b) { } /***************************************************/ // 7871 struct Tuple7871 { string field; alias field this; } //auto findSplitBefore(R1)(R1 haystack) auto findSplitBefore7871(string haystack) { return Tuple7871(haystack); } void test7871() { string line = ``; auto a = findSplitBefore7871(line[0 .. $])[0]; } /***************************************************/ // 7906 void test7906() { static assert(!__traits(compiles, { enum s = [string.min]; })); } /***************************************************/ // 7907 template Id7907(E) { alias E Id7907; } template Id7907(alias E) { alias E Id7907; } void test7907() { static assert(!__traits(compiles, { alias Id7907!([string.min]) X; })); } /***************************************************/ // 1175 class A1175 { class I1 { } } class B1175 : A1175 { class I2 : I1 { } I1 getI() { return new I2; } } /***************************************************/ // 7983 class A7983 { void f() { g7983(this); } unittest { } } void g7983(T)(T a) { foreach (name; __traits(allMembers, T)) { pragma(msg, name); static if (__traits(compiles, &__traits(getMember, a, name))) { } } } /***************************************************/ // 8004 void test8004() { auto n = (int n = 10){ return n; }(); assert(n == 10); } /***************************************************/ // 8064 void test8064() { uint[5] arry; ref uint acc(size_t i) { return arry[i]; } auto arryacc = &acc; arryacc(3) = 5; // same error } /***************************************************/ // 8220 void foo8220(int){} static assert(!__traits(compiles, foo8220(typeof(0)))); // fail /***************************************************/ void func8105(in ref int x) { } void test8105() { } /***************************************************/ template ParameterTypeTuple159(alias foo) { static if (is(typeof(foo) P == __parameters)) alias P ParameterTypeTuple159; else static assert(0, "argument has no parameters"); } int func159(int i, long j = 7) { return 3; } alias ParameterTypeTuple159!func159 PT; int bar159(PT) { return 4; } pragma(msg, typeof(bar159)); pragma(msg, PT[1]); PT[1] boo159(PT[1..2] a) { return a[0]; } void test159() { assert(bar159(1) == 4); assert(boo159() == 7); } /***************************************************/ // 8283 struct Foo8283 { this(long) { } } struct FooContainer { Foo8283 value; } auto get8283() { union Buf { FooContainer result; } Buf buf = {}; return buf.result; } void test8283() { auto a = get8283(); } /***************************************************/ // 8395 struct S8395 { int v; this(T : long)(T x) { v = x * 2; } } void test8395() { S8395 ms = 6; assert(ms.v == 12); const S8395 cs = 7; assert(cs.v == 14); } /***************************************************/ // 5749 void test5749() { static struct A { A foo(int x, int i) { //printf("this = %p, %d: i=%d\n", &this, x, i); assert(i == x); return this; } A bar(int x, ref int i) { //printf("this = %p, %d: i=%d\n", &this, x, i); assert(i == x); return this; } } static int inc1(ref int i) { return ++i; } static ref int inc2(ref int i) { return ++i; } int i; A a; //printf("&a = %p\n", &a); i = 0; a.foo(1, ++i).foo(2, ++i); // OK <-- 2 1 i = 0; a.bar(1, ++i).bar(2, ++i); // OK <-- 2 2 i = 0; a.foo(1, inc1(i)).foo(2, inc1(i)); // OK <-- 2 1 i = 0; a.bar(1, inc2(i)).bar(2, inc2(i)); // OK <-- 2 2 //printf("\n"); A getVal() { static A a; return a; } i = 0; getVal().foo(1, ++i).foo(2, ++i); // OK <-- 2 1 i = 0; getVal().bar(1, ++i).bar(2, ++i); // OK <-- 2 2 i = 0; getVal().foo(1, inc1(i)).foo(2, inc1(i)); // OK <-- 2 1 i = 0; getVal().bar(1, inc2(i)).bar(2, inc2(i)); // OK <-- 2 2 //printf("\n"); ref A getRef() { static A a; return a; } i = 0; getRef().foo(1, ++i).foo(2, ++i); // OK <-- 2 1 i = 0; getRef().bar(1, ++i).bar(2, ++i); // OK <-- 2 2 i = 0; getRef().foo(1, inc1(i)).foo(2, inc1(i)); // OK <-- 2 1 i = 0; getRef().bar(1, inc2(i)).bar(2, inc2(i)); // OK <-- 2 2 } /***************************************************/ // 8396 void test8396() { static int g; static extern(C) int bar(int a, int b) { //printf("a = %d, b = %d\n", a, b); assert(b - a == 1); return ++g; } static auto getFunc(int n) { assert(++g == n); return &bar; } static struct Tuple { int _a, _b; } static Tuple foo(int n) { assert(++g == n); return Tuple(1, 2); } g = 0; assert(bar(foo(1).tupleof) == 2); g = 0; assert(getFunc(1)(foo(2).tupleof) == 3); } /***************************************************/ enum E160 : ubyte { jan = 1 } struct D160 { short _year = 1; E160 _month = E160.jan; ubyte _day = 1; this(int year, int month, int day) pure { _year = cast(short)year; _month = cast(E160)month; _day = cast(ubyte)day; } } struct T160 { ubyte _hour; ubyte _minute; ubyte _second; this(int hour, int minute, int second = 0) pure { _hour = cast(ubyte)hour; _minute = cast(ubyte)minute; _second = cast(ubyte)second; } } struct DT160 { D160 _date; T160 _tod; this(int year, int month, int day, int hour = 0, int minute = 0, int second = 0) pure { _date = D160(year, month, day); _tod = T160(hour, minute, second); } } void foo160(DT160 dateTime) { printf("test7 year %d, day %d\n", dateTime._date._year, dateTime._date._day); assert(dateTime._date._year == 1999); assert(dateTime._date._day == 6); } void test160() { auto dateTime = DT160(1999, 7, 6, 12, 30, 33); printf("test5 year %d, day %d\n", dateTime._date._year, dateTime._date._day); assert(dateTime._date._year == 1999); assert(dateTime._date._day == 6); foo160(DT160(1999, 7, 6, 12, 30, 33)); } /***************************************************/ // 8437 class Cgi8437 { struct PostParserState { UploadedFile piece; } static struct UploadedFile { string contentFilename; } } /***************************************************/ // 8665 auto foo8665a(bool val) { if (val) return 42; else return 1.5; } auto foo8665b(bool val) { if (!val) return 1.5; else return 42; } void test8665() { static assert(is(typeof(foo8665a(true)) == double)); static assert(is(typeof(foo8665b(false)) == double)); assert(foo8665a(true) == 42); // assertion failure assert(foo8665b(true) == 42); // assertion failure assert(foo8665a(false) == 1.5); assert(foo8665b(false) == 1.5); static assert(foo8665a(true) == 42); static assert(foo8665b(true) == 42); static assert(foo8665a(false) == 1.5); static assert(foo8665b(false) == 1.5); } /***************************************************/ int foo8108(int, int); int foo8108(int a, int b) { return a + b; } void test8108() { foo8108(1,2); } /***************************************************/ // 8360 struct Foo8360 { int value = 0; int check = 1337; this(int value) { assert(0); this.value = value; } ~this() { assert(0); assert(check == 1337); } string str() { assert(0); return "Foo"; } } Foo8360 makeFoo8360() { assert(0); return Foo8360(2); } void test8360() { size_t length = 0; // The message part 'makeFoo().str()' should not be evaluated at all. assert(length < 5, makeFoo8360().str()); } /***************************************************/ // 8361 struct Foo8361 { string bar = "hello"; ~this() {} } void test8361() { assert(true, Foo8361().bar); } /***************************************************/ // 6141 + 8526 void test6141() { static void takeADelegate(void delegate()) {} auto items = new int[1]; items[0] = 17; foreach (ref item; items) { // both asserts fail assert(item == 17); assert(&item == items.ptr); takeADelegate({ auto x = &item; }); } foreach(ref val; [3]) { auto dg = { int j = val; }; assert(&val != null); // Assertion failure assert(val == 3); } static void f(lazy int) {} int i = 0; auto dg = { int j = i; }; foreach(ref val; [3]) { f(val); assert(&val != null); // Assertion failure assert(val == 3); } } void test8526() { static void call(void delegate() dg) { dg(); } foreach (i, j; [0]) { call({ assert(i == 0); // fails, i is corrupted }); } foreach (n; 0..1) { call({ assert(n == 0); // fails, n is corrupted }); } } /***************************************************/ template ParameterTuple(alias func) { static if(is(typeof(func) P == __parameters)) alias P ParameterTuple; else static assert(0); } int foo161(ref float y); void test161() { alias PT = ParameterTuple!foo161; auto x = __traits(identifier, PT); assert(x == "y"); } /***************************************************/ // 7175 void test7175() { struct S { ubyte[0] arr; } S s; assert(s.arr.ptr !is null); assert(cast(void*)s.arr.ptr is cast(void*)&s); } /***************************************************/ // 8819 void test8819() { void[1] sa1 = (void[1]).init; assert((cast(ubyte*)sa1.ptr)[0] == 0); void[4] sa4 = [cast(ubyte)1,cast(ubyte)2,cast(ubyte)3,cast(ubyte)4]; assert((cast(ubyte*)sa4.ptr)[0] == 1); assert((cast(ubyte*)sa4.ptr)[1] == 2); assert((cast(ubyte*)sa4.ptr)[2] == 3); assert((cast(ubyte*)sa4.ptr)[3] == 4); auto sa22 = (void[2][2]).init; static assert(sa22.sizeof == ubyte.sizeof * 2 * 2); ubyte[4]* psa22 = cast(ubyte[4]*)sa22.ptr; assert((*psa22)[0] == 0); assert((*psa22)[1] == 0); assert((*psa22)[2] == 0); assert((*psa22)[3] == 0); } /***************************************************/ // 8897 class C8897 { static mixin M8897!(int); static class causesAnError {} } template M8897 ( E ) { } /***************************************************/ // 8917 void test8917() { int[3] a; int[3] a2; int[3] b = a[] + a2[]; } /***************************************************/ // 8945 struct S8945 // or `class`, or `union` { struct S0(T) { int i; } struct S1(T) { this(int){} } } void test8945() { auto cs0a = const S8945.S0!int(); // ok auto cs0b = const S8945.S0!int(1); // ok auto cs1 = const S8945.S1!int(1); // ok auto s0a = S8945.S0!int(); // Error: struct S0 does not overload () auto s0b = S8945.S0!int(1); // Error: struct S0 does not overload () auto s1 = S8945.S1!int(1); // Error: struct S1 does not overload () } /***************************************************/ struct S162 { static int generateMethodStubs( Class )() { int text; foreach( m; __traits( allMembers, Class ) ) { static if( is( typeof( mixin( m ) ) ) && is( typeof( mixin( m ) ) == function ) ) { pragma(msg, __traits( getOverloads, Class, m )); } } return text; } enum int ttt = generateMethodStubs!( S162 )(); float height(); int get( int ); int get( long ); void clear(); void draw( int ); void draw( long ); } /***************************************************/ void test163() { static class C { int x; int y; } immutable C c = new C(); shared C c2 = new C(); shared const C c3 = new C(); class D { int x; int y; } immutable D d; assert(!__traits(compiles, d = new D())); static struct S { int x; int y; } immutable S* s = new S(); shared S* s2 = new S(); shared const S* s3 = new S(); shared S* s4; assert(__traits(compiles, s4 = new immutable(S)())); struct T { int x; int y; } immutable T* t; assert(!__traits(compiles, t = new T())); immutable int* pi = new int(); immutable void* pv = new int(); immutable int[] ai = new int[1]; immutable void[] av = new int[2]; } /***************************************************/ struct S9000 { ubyte i = ubyte.max; } enum E9000 = S9000.init; /***************************************************/ mixin template DefineCoreType(string type) { struct Faulty { static int x; static void instance() { x = 3; } X164!() xxx; } } mixin DefineCoreType!(""); mixin template A164() { static this() { } } struct X164() { mixin A164!(); } /***************************************************/ // 9428 void test9428() { int[2][] items = [[1, 2]]; int[2] x = [3, 4]; auto r1 = items ~ [x]; assert(r1.length == 2); assert(r1[0][0] == 1); assert(r1[0][1] == 2); assert(r1[1][0] == 3); assert(r1[1][1] == 4); auto r2 = items ~ x; assert(r2.length == 2); assert(r2[0][0] == 1); assert(r2[0][1] == 2); assert(r2[1][0] == 3); assert(r2[1][1] == 4); auto r3 = [x] ~ items; assert(r3.length == 2); assert(r3[0][0] == 3); assert(r3[0][1] == 4); assert(r3[1][0] == 1); assert(r3[1][1] == 2); auto r4 = x ~ items; assert(r4.length == 2); assert(r4[0][0] == 3); assert(r4[0][1] == 4); assert(r4[1][0] == 1); assert(r4[1][1] == 2); } /***************************************************/ // 9477 template Tuple9477(T...) { alias T Tuple9477; } template Select9477(bool b, T, U) { static if (b) alias T Select9477; else alias U Select9477; } void test9477() { static bool isEq (T1, T2)(T1 s1, T2 s2) { return s1 == s2; } static bool isNeq(T1, T2)(T1 s1, T2 s2) { return s1 != s2; } // Must be outside the loop due to http://d.puremagic.com/issues/show_bug.cgi?id=9748 int order; // Must be outside the loop due to http://d.puremagic.com/issues/show_bug.cgi?id=9756 auto checkOrder(bool dyn, uint expected)() { assert(order==expected); order++; // Use temporary ("v") to work around http://d.puremagic.com/issues/show_bug.cgi?id=9402 auto v = cast(Select9477!(dyn, string, char[1]))"a"; return v; } foreach (b1; Tuple9477!(false, true)) foreach (b2; Tuple9477!(false, true)) { version (D_PIC) {} else // Work around http://d.puremagic.com/issues/show_bug.cgi?id=9754 { assert( isEq (cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[0]))"" )); assert(!isNeq(cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[0]))"" )); assert(!isEq (cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[1]))"a" )); assert( isNeq(cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[1]))"a" )); } assert( isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"a" )); assert(!isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"a" )); assert(!isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"b" )); assert( isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"b" )); assert(!isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[2]))"aa")); assert( isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[2]))"aa")); // Note: order of evaluation was not followed before this patch // (thus, the test below will fail without the patch). // Although the specification mentions that as implementation-defined behavior, // I understand that this isn't by design, but rather an inconvenient aspect of DMD // that has been moved to the specification. order = 0; bool result = checkOrder!(b1, 0)() == checkOrder!(b2, 1)(); assert(result); assert(order == 2); } // need largest natural alignment to avoid unaligned access on // some architectures, double in this case. align(8) ubyte[64] a1, a2; foreach (T; Tuple9477!(void, ubyte, ushort, uint, ulong, char, wchar, dchar, float, double)) { auto s1 = cast(T[])(a1[]); auto s2 = cast(T[])(a2[]); assert(s1 == s2); a2[$-1]++; assert(s1 != s2); assert(s1[0..$-1]==s2[0..$-1]); a2[$-1]--; } } /***************************************************/ // 9504 struct Bar9504 { template Abc(T) { T y; } enum size_t num = 123; class Def {} } template GetSym9504(alias sym) { static assert(__traits(isSame, sym, Bar9504.Abc)); } template GetExp9504(size_t n) { static assert(n == Bar9504.num); } template GetTyp9504(T) { static assert(is(T == Bar9504.Def)); } alias GetSym9504!(typeof(Bar9504.init).Abc) X9504; // NG alias GetExp9504!(typeof(Bar9504.init).num) Y9504; // NG alias GetTyp9504!(typeof(Bar9504.init).Def) Z9504; Bar9504 test9504() { alias GetSym9504!(typeof(return).Abc) V9504; // NG alias GetExp9504!(typeof(return).num) W9504; // NG alias GetTyp9504!(typeof(return).Def) X9504; return Bar9504(); } /***************************************************/ // 9538 void test9538() { void*[1] x; auto ti = typeid(x.ptr); } /***************************************************/ // 9539 void test9539() { void f(int** ptr) { assert(**ptr == 10); } int* p = new int; *p = 10; int*[1] x = [p]; f(&x[0]); int*[] arr = [null]; static assert(!__traits(compiles, p = arr)); // bad! } /***************************************************/ // 9700 mixin template Proxy9700(alias a) { auto ref opOpAssign(string op, V)(V v) { return a += v; } // NG //auto ref opOpAssign(string op, V)(V v) { a += v; } // OK } struct MyInt9700 { int value; invariant() { assert(value >= 0); } mixin Proxy9700!value; } void test9700() { MyInt9700 a = { 2 }; a *= 3; // object.Error: Access Violation } /***************************************************/ // 9834 struct Event9834 { void delegate() dg; void set(void delegate() h) pure { dg = h; } // AV occurs void call() { dg(); } } void test9834() { Event9834 ev; auto a = new class { Object o; this() { o = new Object; ev.set((){ o.toString(); }); } }; ev.call(); } /***************************************************/ // 9859 void test9859(inout int[] arr) { auto dg1 = { foreach (i, e; arr) { } }; dg1(); void foo() { auto v = arr; auto w = arr[0]; } void bar(inout int i) { auto v = arr[i]; } auto dg2 = { auto dg = { void foo(T)() { auto dg = { auto dg = { auto v = arr; }; }; } foo!int; }; }; void qux(T)() { auto v = arr; auto dg1 = { auto v = arr; }; auto dg2 = { auto dg = { auto v = arr; }; }; } qux!int; } /***************************************************/ // 9912 template TypeTuple9912(Stuff...) { alias Stuff TypeTuple9912; } struct S9912 { int i; alias TypeTuple9912!i t; void testA() { auto x = t; } void testB() { auto x = t; } } /***************************************************/ // 9883 struct S9883 { @property size_t p9883(T)() { return 0; } } @property size_t p9883(T)() { return 0; } void test9883() { S9883 s; auto n1 = p9883!int; // OK auto n2 = s.p9883!int; // OK auto a1 = new int[p9883!int]; // Error: need size of rightmost array, not type p!(int) auto a2 = new int[s.p9883!int]; // Error: no property 'p!(int)' for type 'S' } /***************************************************/ // 10091 struct S10091 { enum e = "a"; } void test10091() { auto arr = cast(ubyte[1]) S10091.e; } /***************************************************/ void test12824() { label: static if (0) { } } /***************************************************/ // 9130 class S9130 { void bar() { } } import core.stdc.stdio : printf; struct Function { int[] ai = [1,2,3]; } @property void meta(alias m)() { static Function md; printf("length = %d\n", md.ai.length); printf("ptr = %p\n", md.ai.ptr); md.ai[0] = 0; } void test9130() { meta!(__traits(getOverloads, S9130, "bar")[0]); meta!(S9130.bar); } /***************************************************/ // 10390 class C10390 { this() { this.c = this; } C10390 c; } const c10390 = new C10390(); pragma(msg, c10390); /***************************************************/ // 10542 class B10542 { this() nothrow pure @safe { } } class D10542 : B10542 { } void test10542() nothrow pure @safe { new D10542; } /***************************************************/ // 10539 void test10539() { int[2][2] a; int* p1 = a.ptr.ptr; // OK <- error int* p2 = (*a.ptr).ptr; // OK assert(p1 is p2); } /***************************************************/ struct TimeOfDay { ubyte h, m, s; } __gshared byte glob; struct DateTime { this(ubyte _d, ubyte _m, ubyte _y, TimeOfDay _tod = TimeOfDay.init) { d = _d; m = _m; y = _y; tod = _tod; } TimeOfDay tod; ubyte d, m, y; } void test10634() { glob = 123; DateTime date1 = DateTime(0, 0, 0); DateTime date2; assert(date1 == date2); } /***************************************************/ immutable(char)[4] bar7254(int i) { if (i) { immutable(char)[4] r; return r; } else return "1234"; } void test7254() { assert(bar7254(0) == "1234"); } /***************************************************/ struct S11075() { int x = undefined_expr; } class C11075() { int x = undefined_expr; } interface I11075() { enum int x = undefined_expr; } void test11075() { static assert(!is(typeof(S11075!().x))); static assert(!is(typeof(S11075!().x))); static assert(!is(typeof(C11075!().x))); static assert(!is(typeof(C11075!().x))); static assert(!is(typeof(I11075!().x))); static assert(!is(typeof(I11075!().x))); } /***************************************************/ // 11181 void test11181() { auto a = ["a", "b"]; static assert(!is(typeof([a, "x"]))); static assert(!is(typeof(true ? a : "x"))); static assert(!is(typeof(true ? a[0 .. $] : "x"))); static assert(!is(typeof([a[0 .. $], "x"]))); } /***************************************************/ // 11317 void test11317() { auto ref uint fun() { return 0; } void test(ref uint x) {} static assert(!__traits(compiles, test(fun()))); assert(fun() == 0); } /***************************************************/ // 11888 void test11888() { static long val; static ubyte* foo(size_t* len) { *len = val.sizeof; return cast(ubyte*)&val; } size_t size; ubyte[] t = foo(&size)[0..size]; assert(t.ptr is cast(void*)&val); assert(t.length == 8); // regression test int[3] sa1 = [1,2,3]; int[1] sa2 = sa1[1..2]; // convert slice to Tsarray assert(sa2.length == 1); assert(sa2[0] == 2); } /***************************************************/ // 12036 template T12036(alias a) { string value; } struct S12036 { auto fun() { } mixin T12036!fun; } void test12036() { S12036 s; assert(s.value == ""); } /***************************************************/ // 12153 void test12153() { int[1] i, j; bool b = true; (b ? i : j)[] = [4]; assert(i == [4]); // regression test int[1][1] k, l; (b ? k : l)[0..1][0..1] = [4]; assert(k == [[4]]); } /***************************************************/ // 12498 string a12498() { string b; while (b) { } for (; b; ) { } return ""; } void test12498() { enum t = a12498(); string x = t; } /***************************************************/ // 12900 struct A12900 { char[1] b; } void test12900() { A12900 c; if (*c.b.ptr) return; } /***************************************************/ // 12937 void test12937() { void[1] sa2 = cast(void[])[cast(ubyte)1]; // ICE! assert((cast(ubyte[])sa2[])[0] == 1); } /***************************************************/ // 13154 void test13154() { int[3] ints = [2 , 1 , 0 , 1 ][0..3]; float[3] floats0 = [2f , 1f , 0f , 1f ][0..3]; float[3] floats1 = [2.0 , 1.0 , 0.0 , 1.0 ][0..3]; // fails! float[3] floats2 = [2.0f, 1.0f, 0.0f, 1.0f][0..3]; assert(ints == [2, 1, 0]); assert(floats0 == [2, 1, 0]); assert(floats1 == [2, 1, 0]); // fail! assert(floats1 != [0, 0, 0]); // fail! assert(floats2 == [2, 1, 0]); } /***************************************************/ // 13437 ubyte[4] foo13437() { return [1,2,3,4]; } void test13437() { auto n = cast(ubyte[4])foo13437()[]; // OK <- ICE: e2ir.c 4616 static assert(is(typeof(n) == ubyte[4])); assert(n == [1,2,3,4]); } /***************************************************/ // 13472 class A13472 { int a; } void test13472() { A13472[] test; test.length = 4; auto b = test[0..2] ~ null ~ test[2..$]; assert(b.length == 5); } /***************************************************/ // 13476 template ParameterTypeTuple13476(func...) { static if (is(typeof(*func[0]) P == function)) alias ParameterTypeTuple13476 = P; else static assert(0, "argument has no parameters"); } int flag13476; __gshared extern(C) void function(int) nothrow someFunc13476 = &Stub13476!someFunc13476; extern(C) auto Stub13476(alias func)(ParameterTypeTuple13476!func args) { ++flag13476; extern(C) void function(int) nothrow impl = (i) { }; return (func = impl)(args); } __gshared extern(C) void function(int) nothrow someFunc13476Alt = &Stub13476Alt!someFunc13476AltP; __gshared extern(C) void function(int) nothrow* someFunc13476AltP = &someFunc13476Alt; extern(C) auto Stub13476Alt(alias func)(int args) nothrow { ++flag13476; extern(C) void function(int) nothrow impl = (i) {}; return (*func = impl)(args); } void test13476() { assert(flag13476 == 0); someFunc13476(42); assert(flag13476 == 1); someFunc13476(43); assert(flag13476 == 1); someFunc13476Alt(42); assert(flag13476 == 2); someFunc13476Alt(43); assert(flag13476 == 2); } /***************************************************/ // 14038 static immutable ubyte[string] wordsAA14038; static this() { wordsAA14038["zero"] = 0; } /***************************************************/ // 14192 void test14192() { shared int[int] map; map[1] = 1; } /***************************************************/ // 13720 struct FracSec13720 { this(int hnsecs) {} } struct SysTime13720 { this(TimeOfDay13720 dateTime, FracSec13720 fracSec) { } } struct TimeOfDay13720 { ~this() { } } void assertThrown13720(T)(lazy T) {} void test13720() { assertThrown13720(SysTime13720(TimeOfDay13720.init, FracSec13720(-1))); } /***************************************************/ // 13952 struct Reg13952 { ubyte type; ubyte regNo; ushort size; } struct Imm13952 { ulong imm; } struct Opnd13952 { union { Reg13952 reg; // size == 4 Imm13952 imm; // size == 8 } ubyte tag; this(Reg13952 r) { reg = r; } } Opnd13952 opnd13952(Reg13952 reg) { return Opnd13952(reg); } void test13952() { Reg13952 reg; auto op = opnd13952(reg); auto buf = (cast(ubyte*)&op)[0 .. op.sizeof]; //debug //{ // import std.stdio; // writefln("op.reg = [%(%02x %)]", (cast(ubyte*)&op.reg)[0 .. Reg13952.sizeof]); // writefln("op.imm = [%(%02x %)]", (cast(ubyte*)&op.imm)[0 .. Imm13952.sizeof]); //} foreach (e; buf) assert(e == 0); } /***************************************************/ // 14165 class Foo14165 { @disable this(); this(int i) {} } /***************************************************/ // 13985 interface I13985 { void m1(); void m2(); void m3(); final void mf() { m3(); } } class C13985 : I13985 { void m1() {} void m2() {} void m3() {} } class D13985 : C13985 { void ml() { super.mf(); } } void test13985() { auto d = new D13985(); d.ml(); } /***************************************************/ // 14211 extern(C++) // all derived classes won't have invariants class B14211 { void func() { } } final class C14211 : B14211 { } void test14211() { auto c = new C14211(); *cast(void**)c = null; c.func(); // called without vtbl access } /***************************************************/ // 14552 template map14552(fun...) { template AppliedReturnType(alias f) { alias typeof(f(0)) AppliedReturnType; } auto map14552(int[] r) { assert(!is(AppliedReturnType!fun)); return MapResult14552!fun(); } } struct MapResult14552(alias fun) { @property front() { fun(0); } } class Outer14552 { auto test() { [1].map14552!(j => new Inner); } class Inner {} } /***************************************************/ // 14853 struct Queue14853(T) { struct Node { T mfPayload = T.init; union { typeof(this)* mfPrev; shared(typeof(this)*) mfShPrev; } union { typeof(this)* mfNext; shared(typeof(this)*) mfShNext; } } Node root; void pfPut(T v, Node* r = null) { shared n = new Node(v); // problem! } } void test14853() { auto b1 = new Queue14853!uint; } /***************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test18(); test19(); test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); test28(); test29(); test30(); test31(); test32(); test33(); test34(); test35(); test36(); test37(); test38(); test39(); test40(); test41(); test42(); test43(); test44(); test45(); test46(); test47(); test48(); test49(); test796(); test50(); test51(); test52(); test53(); test54(); test55(); test56(); test57(); test58(); test60(); test61(); test62(); test63(); test64(); test65(); test66(); test67(); test68(); test69(); test70(); test5785(); test72(); test73(); test74(); test75(); test76(); test77(); test78(); test79(); test80(); test81(); test82(); test83(); test3559(); test84(); test85(); test2006(); test8442(); test86(); test87(); test2486(); test5554(); test88(); test7545(); test89(); test90(); test91(); test92(); test4536(); test93(); test94(); test95(); test5403(); test96(); test97(); test98(); test99(); test100(); test101(); test103(); test104(); test105(); test3927(); test107(); test109(); test111(); test113(); test115(); test116(); test117(); test3822(); test6545(); test118(); test5081(); test120(); test10724(); test122(); test123(); test124(); test125(); test6763(); test127(); test128(); test1891(); test129(); test130(); test1064(); test131(); test132(); test133(); test134(); test135(); test136(); test137(); test138(); test1962(); test139(); test140(); test141(); test6317(); test142(); test143(); test144(); test145(); test146(); test147(); test6685(); test148(); test149(); test2356(); test11238(); test2540(); test14348(); test150(); test151(); test152(); test153(); test154(); test155(); test156(); test658(); test4258(); test4539(); test4963(); test4031(); test5437(); test6230(); test6264(); test6284(); test6295(); test6293(); test5046(); test1471(); test6335(); test1687(); test6228(); test3733(); test4392(); test7942(); test6220(); test5799(); test157(); test6473(); test6630(); test6690(); test2953(); test2997(); test4423(); test4647(); test5696(); test6084(); test6488(); test6565(); test6836(); test6837(); test6927(); test6733(); test6813(); test6859(); test3022(); test6910(); test6902(); test6330(); test6868(); test2856(); test3091(); test6056(); test6356(); test7073(); test7104(); test7150(); test7160(); test7168(); test7170(); test7196(); test7285(); test14737(); test7321(); test3282(); test7534(); test7534cov(); test7618(); test7621(); test11417(); test7682(); test7735(); test7823(); test7871(); test7906(); test7907(); test12503(); test8004(); test8064(); test8105(); test159(); test12824(); test8283(); test13182(); test8269(); test8395(); test13427(); test5749(); test8396(); test160(); test8665(); test8108(); test8360(); test9577(); test6141(); test199(); test8526(); test161(); test7175(); test8819(); test8917(); test8945(); test11805(); test14192(); test163(); test9428(); test9477(); test9538(); test9700(); test9834(); test13947(); test9883(); test10091(); test9130(); test10542(); test10539(); test10634(); test7254(); test13468(); test11075(); test11181(); test11317(); test11888(); test12036(); test12153(); test12937(); test13154(); test13437(); test13472(); test13476(); test13720(); test13952(); test13985(); test14211(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link14198b.sh0000755000175000017500000000146213200164642023457 0ustar matthiasmatthias#!/usr/bin/env bash src=runnable${SEP}extra-files dir=${RESULTS_DIR}${SEP}runnable output_file=${dir}/link14198b.sh.out rm -f ${output_file} if [ $OS == "win32" -o $OS == "win64" ]; then LIBEXT=.lib else LIBEXT=.a fi libname=${dir}${SEP}lib14198b${LIBEXT} # Do not link failure even without library file. $DMD -m${MODEL} -I${src} -of${dir}${SEP}test14198b${EXE} ${src}${SEP}test14198.d > ${output_file} 2>&1 grep -q "_D8std141984conv11__T2toTAyaZ9__T2toTbZ2toFNaNbNiNfbZAya" ${output_file} && exit 1 $DMD -m${MODEL} -I${src} -of${dir}${SEP}test14198b${EXE} -version=bug14198 ${src}${SEP}test14198.d > ${output_file} 2>&1 grep -q "_D8std141984conv11__T2toTAyaZ9__T2toTbZ2toFNaNbNiNfbZAya" ${output_file} && exit 1 rm ${dir}/{test14198b${OBJ},test14198b${EXE}} echo Success > ${output_file} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/Same.d0000644000175000017500000000024713200164642022444 0ustar matthiasmatthias// EXTRA_SOURCES: imports/Other.d // PERMUTE_ARGS: module Same; // makes no difference if removed import core.stdc.stdio; class Same { this() { printf("Same\n"); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/gdb4149.d0000644000175000017500000000030313200164642022626 0ustar matthiasmatthias/* REQUIRED_ARGS: -g PERMUTE_ARGS: GDB_SCRIPT: --- b 17 r echo RESULT= p x --- GDB_MATCH: RESULT=.*33 */ void foo(ref int x) { ++x; // BP } void main() { auto x = 32; foo(x); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test21.d0000644000175000017500000000016313200164642022676 0ustar matthiasmatthias// EXTRA_SOURCES: imports/test21a.d import imports.test21a; int main() { TA!(int) variable; return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ice4481.d0000644000175000017500000000031013200164642022627 0ustar matthiasmatthias// EXTRA_SOURCES: imports/ice4481a.d // EXTRA_SOURCES: imports/ice4481b.d import imports.ice4481a; import imports.ice4481b; void main() { auto f = new Font(); assert(f.textHeight("str")); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/structlit.d0000644000175000017500000007676313200164642023634 0ustar matthiasmatthiasimport std.stdio; struct S { int x; int y; } /********************************************/ void test1() { S s = S(1,2); assert(s.x == 1); assert(s.y == 2); } /********************************************/ void foo2(S s) { assert(s.x == 1); assert(s.y == 2); } void test2() { foo2( S(1,2) ); } /********************************************/ S foo3() { return S(1, 2); } void test3() { S s = foo3(); assert(s.x == 1); assert(s.y == 2); } /********************************************/ struct S4 { long x; long y; long z; } S4 foo4() { return S4(1, 2, 3); } void test4() { S4 s = foo4(); assert(s.x == 1); assert(s.y == 2); assert(s.z == 3); } /********************************************/ struct S5 { long x; char y; long z; } S5 foo5() { return S5(1, 2, 3); } void test5() { S5 s = foo5(); assert(s.x == 1); assert(s.y == 2); assert(s.z == 3); } /********************************************/ struct S6 { long x; char y; long z; } void test6() { S6 s1 = S6(1,2,3); S6 s2 = S6(1,2,3); assert(s1 == s2); s1 = S6(4,5,6); s2 = S6(4,5,6); assert(s1 == s2); S6* p1 = &s1; S6* p2 = &s2; *p1 = S6(7,8,9); *p2 = S6(7,8,9); assert(*p1 == *p2); } /********************************************/ struct S7 { long x; char y; long z; } void test7() { static S7 s1 = S7(1,2,3); static S7 s2 = S7(1,2,3); assert(s1 == s2); } /********************************************/ struct S8 { int i; string s; } void test8() { S8 s = S8(3, "hello"); assert(s.i == 3); assert(s.s == "hello"); static S8 t = S8(4, "betty"); assert(t.i == 4); assert(t.s == "betty"); S8 u = S8(3, ['h','e','l','l','o']); assert(u.i == 3); assert(u.s == "hello"); static S8 v = S8(4, ['b','e','t','t','y']); assert(v.i == 4); assert(v.s == "betty"); } /********************************************/ struct S9 { int i; char[5] s; } void test9() { S9 s = S9(3, "hello"); assert(s.i == 3); assert(s.s == "hello"); static S9 t = S9(4, "betty"); assert(t.i == 4); assert(t.s == "betty"); S9 u = S9(3, ['h','e','l','l','o']); assert(u.i == 3); assert(u.s == "hello"); static S9 v = S9(4, ['b','e','t','t','y']); assert(v.i == 4); assert(v.s == "betty"); } /********************************************/ alias int myint10; struct S10 { int i; union { int x = 2; int y; } int j = 3; myint10 k = 4; } void test10() { S10 s = S10( 1 ); assert(s.i == 1); assert(s.x == 2); assert(s.y == 2); assert(s.j == 3); assert(s.k == 4); static S10 t = S10( 1 ); assert(t.i == 1); assert(t.x == 2); assert(t.y == 2); assert(t.j == 3); assert(t.k == 4); S10 u = S10( 1, 5 ); assert(u.i == 1); assert(u.x == 5); assert(u.y == 5); assert(u.j == 3); assert(u.k == 4); static S10 v = S10( 1, 6 ); assert(v.i == 1); assert(v.x == 6); assert(v.y == 6); assert(v.j == 3); assert(v.k == 4); } /********************************************/ struct S11 { int i; int j = 3; } void test11() { static const s = S11( 1, 5 ); static const i = s.i; assert(i == 1); static assert(s.j == 5); } /********************************************/ struct S12 { int[5] x; int[5] y = 3; } void test12() { S12 s = S12(); foreach (v; s.x) assert(v == 0); foreach (v; s.y) assert(v == 3); } /********************************************/ struct S13 { int[5] x; int[5] y; int[6][3] z; } void test13() { S13 s = S13(0,3,4); foreach (v; s.x) assert(v == 0); foreach (v; s.y) assert(v == 3); for (int i = 0; i < 6; i++) { for (int j = 0; j < 3; j++) { assert(s.z[j][i] == 4); } } } /********************************************/ struct S14a { int n; } struct S14b { this(int n){} } void foo14(ref S14a s) {} void foo14(ref S14b s) {} void hoo14()(ref S14a s) {} void hoo14()(ref S14b s) {} void poo14(S)(ref S s) {} void bar14(S14a s) {} void bar14(S14b s) {} void var14()(S14a s) {} void var14()(S14b s) {} void war14(S)(S s) {} int baz14( S14a s) { return 1; } int baz14(ref S14a s) { return 2; } int baz14( S14b s) { return 1; } int baz14(ref S14b s) { return 2; } int vaz14()( S14a s) { return 1; } int vaz14()(ref S14a s) { return 2; } int vaz14()( S14b s) { return 1; } int vaz14()(ref S14b s) { return 2; } int waz14(S)( S s) { return 1; } int waz14(S)(ref S s) { return 2; } void test14() { // can not bind rvalue-sl with ref static assert(!__traits(compiles, foo14(S14a(0)))); static assert(!__traits(compiles, foo14(S14b(0)))); static assert(!__traits(compiles, hoo14(S14a(0)))); static assert(!__traits(compiles, hoo14(S14b(0)))); static assert(!__traits(compiles, poo14(S14a(0)))); static assert(!__traits(compiles, poo14(S14b(0)))); // still can bind rvalue-sl with non-ref bar14(S14a(0)); bar14(S14b(0)); var14(S14a(0)); var14(S14b(0)); war14(S14a(0)); war14(S14b(0)); // preferred binding of rvalue-sl in overload resolution assert(baz14(S14a(0)) == 1); assert(baz14(S14b(0)) == 1); assert(vaz14(S14a(0)) == 1); assert(vaz14(S14b(0)) == 1); assert(waz14(S14a(0)) == 1); assert(waz14(S14b(0)) == 1); } /********************************************/ void check15(T, ubyte results, A...)(A args) { // m c i s sc enum m = (results & 0b_1_0_0_0_0) != 0; enum c = (results & 0b_0_1_0_0_0) != 0; enum i = (results & 0b_0_0_1_0_0) != 0; enum s = (results & 0b_0_0_0_1_0) != 0; enum sc = (results & 0b_0_0_0_0_1) != 0; // allocation on stack static assert((is(typeof( T(args) ) U) && is(U == T )) == m); static assert((is(typeof( const T(args) ) U) && is(U == const(T) )) == c); static assert((is(typeof( immutable T(args) ) U) && is(U == immutable(T) )) == i); static assert((is(typeof( shared T(args) ) U) && is(U == shared(T) )) == s); static assert((is(typeof( shared const T(args) ) U) && is(U == shared(const T) )) == sc); // allocation on heap static assert((is(typeof( new T(args) ) U) && is(U == T *)) == m); static assert((is(typeof( new const T(args) ) U) && is(U == const(T)*)) == c); static assert((is(typeof( new immutable T(args) ) U) && is(U == immutable(T)*)) == i); static assert((is(typeof( new shared T(args) ) U) && is(U == shared(T)*)) == s); static assert((is(typeof( new shared const T(args) ) U) && is(U == shared(const T)*)) == sc); } void test15a() { static struct Foo1 { this(int v) {} int value; } static struct Boo1 { this(int v) const {} int[] value; } static struct Bar1 { this(int[] v) {} int[] value; } static struct Baz1 { this(const int[] v) pure {} int[] value; } // unique ctor static struct Coo1 { this(int[] v) immutable {} int[] value; } static struct Car1 { this(int[] v) immutable {} immutable(int)[] value; } check15!(Foo1, 0b_1_1_0_0_0)(1); check15!(Boo1, 0b_0_1_0_0_0)(1); check15!(Bar1, 0b_1_1_0_0_0)(null); check15!(Baz1, 0b_1_1_1_1_1)(null); check15!(Coo1, 0b_0_1_1_0_1)(null); check15!(Car1, 0b_0_1_1_0_1)(null); // m c i s sc // Template constructor should work as same as non-template ones static struct Foo2 { this()(int v) {} int value; } static struct Boo2 { this()(int v) const {} int[] value; } static struct Bar2 { this()(int[] v) {} int[] value; } // has mutable indieection static struct Baz2 { this()(const int[] v) pure {} int[] value; } // unique ctor static struct Coo2 { this()(int[] v) immutable {} int[] value; } static struct Car2 { this()(int[] v) immutable {} immutable(int)[] value; } check15!(Foo2, 0b_1_1_0_0_0)(1); check15!(Boo2, 0b_0_1_0_0_0)(1); check15!(Bar2, 0b_1_1_0_0_0)(null); check15!(Baz2, 0b_1_1_1_1_1)(null); check15!(Coo2, 0b_0_1_1_0_1)(null); check15!(Car2, 0b_0_1_1_0_1)(null); // m c i s sc // Except Bar!().__ctor, their constructors are inferred to pure, then they become unique ctors. static struct Foo3() { this(int v) {} int value; } static struct Boo3() { this(int v) const {} int[] value; } static struct Bar3() { this(int[] v) {} int[] value; } // has mutable indieection static struct Baz3() { this(const int[] v) pure {} int[] value; } // unique ctor static struct Coo3() { this(int[] v) immutable {} int[] value; } static struct Car3() { this(int[] v) immutable {} immutable(int)[] value; } check15!(Foo3!(), 0b_1_1_1_1_1)(1); check15!(Boo3!(), 0b_1_1_1_1_1)(1); check15!(Bar3!(), 0b_1_1_0_0_0)(null); check15!(Baz3!(), 0b_1_1_1_1_1)(null); check15!(Coo3!(), 0b_1_1_1_1_1)(null); check15!(Car3!(), 0b_1_1_1_1_1)(null); // m c i s sc } // inout constructor works as like unique constructor in many cases void test15b() { static struct Nullable1 { private int[] _value; private bool _isNull = true; this(inout int[] v) inout //pure { _value = v; //static int g; auto x = g; // impure access _isNull = false; } } static assert( __traits(compiles, Nullable1([1,2,3]))); static assert(!__traits(compiles, Nullable1([1,2,3].idup))); static assert(!__traits(compiles, immutable Nullable1([1,2,3]))); static assert( __traits(compiles, immutable Nullable1([1,2,3].idup))); static assert(!__traits(compiles, shared Nullable1([1,2,3]))); static assert(!__traits(compiles, shared Nullable1([1,2,3].idup))); static struct Nullable2(T) { private T _value; private bool _isNull = true; this(inout T v) inout //pure { _value = v; //static int g; auto x = g; // impure access _isNull = false; } } static assert( __traits(compiles, Nullable2!(int[])([1,2,3]))); static assert(!__traits(compiles, Nullable2!(int[])([1,2,3].idup))); static assert(!__traits(compiles, immutable Nullable2!(int[])([1,2,3]))); static assert( __traits(compiles, immutable Nullable2!(int[])([1,2,3].idup))); static assert(!__traits(compiles, shared Nullable2!(int[])([1,2,3]))); static assert(!__traits(compiles, shared Nullable2!(int[])([1,2,3].idup))); // ctor is inout pure, but cannot create unique object. struct S { int[] marr; const int[] carr; immutable int[] iarr; this(int[] m, const int[] c, immutable int[] i) inout pure { static assert(!__traits(compiles, marr = m)); static assert(!__traits(compiles, carr = c)); // cannot implicitly convertible const(int[]) to inout(const(int[])) iarr = i; } } static assert(!__traits(compiles, { int[] ma; immutable int[] ia; auto m = S(ma, ma, ia); })); static assert( __traits(compiles, { int[] ma; immutable int[] ia; auto c = const S(ma, ma, ia); })); static assert(!__traits(compiles, { int[] ma; immutable int[] ia; auto i = immutable S(ma, ma, ia); })); } // TemplateThisParameter with constructor should work void test15c() { static class C { this(this This)() { static assert(is(This == immutable C)); } this(T = void, this This)(int) { static assert(is(This == immutable C)); } } auto c1 = new immutable C; auto c2 = new immutable C(1); } void test15d() // Bugzilla 9974 { class CM { this() {} } auto cm = new CM(); const class CC { this() {} } const cc = new const CC(); immutable class CI { this() {} } immutable ci = new immutable CI(); shared class CS { this() {} } shared cs = new shared CS(); shared const class CSC { this() {} } shared const csc = new shared const CSC(); struct SM { this(int) {} } auto sm = new SM(1); const struct SC { this(int) {} } const sc = new const SC(1); immutable struct SI { this(int) {} } immutable si = new immutable SI(1); shared struct SS { this(int) {} } shared ss = new shared SS(1); shared const struct SSC { this(int) {} } shared const ssc = new shared const SSC(1); } void test15e() // Bugzilla 10005 { // struct literal static struct S { int[] a; } int[] marr = [1,2,3]; static assert( __traits(compiles, { S m = S(marr); })); static assert( __traits(compiles, { const S c = S(marr); })); static assert(!__traits(compiles, { immutable S i = S(marr); })); immutable int[] iarr = [1,2,3]; static assert(!__traits(compiles, { S m = immutable S(iarr); })); static assert( __traits(compiles, { const S c = immutable S(iarr); })); static assert( __traits(compiles, { immutable S i = immutable S(iarr); })); // mutable constructor static struct MS { int[] a; this(int n) { a = new int[](n); } } static assert( __traits(compiles, { MS m = MS(3); })); static assert( __traits(compiles, { const MS c = MS(3); })); static assert(!__traits(compiles, { immutable MS i = MS(3); })); static assert(!__traits(compiles, { MS m = immutable MS(3); })); static assert(!__traits(compiles, { const MS c = immutable MS(3); })); static assert(!__traits(compiles, { immutable MS i = immutable MS(3); })); // immutable constructor static struct IS { int[] a; this(int n) immutable { a = new int[](n); } } static assert(!__traits(compiles, { IS m = IS(3); })); static assert(!__traits(compiles, { const IS c = IS(3); })); static assert(!__traits(compiles, { immutable IS i = IS(3); })); static assert(!__traits(compiles, { IS m = immutable IS(3); })); static assert( __traits(compiles, { const IS c = immutable IS(3); })); static assert( __traits(compiles, { immutable IS i = immutable IS(3); })); } struct Foo9984 { int[] p; // Prefix storage class and tempalte constructor inout this()(inout int[] a) { p = a; } auto foo() inout { return inout(Foo9984)(p); } } void test9993a() { static class A { int x; this() { x = 13; } this() immutable { x = 42; } } A ma = new A; assert(ma.x == 13); immutable A ia = new immutable A; assert(ia.x == 42); static assert(!__traits(compiles, { immutable A ia = new A; })); static class B { int x; this() { x = 13; } this() const { x = 42; } } const B mb = new B; assert(mb.x == 13); const B cb = new const B; assert(cb.x == 42); static assert(!__traits(compiles, { immutable B ib = new B; })); static class C { int x; this() const { x = 13; } this() immutable { x = 42; } } const C cc = new const C; assert(cc.x == 13); immutable C ic = new immutable C; assert(ic.x == 42); static assert(!__traits(compiles, { C mc = new C; })); } void test9993b() { static class A { int x; this()() { x = 13; } this()() immutable { x = 42; } } A ma = new A; assert(ma.x == 13); immutable A ia = new immutable A; assert(ia.x == 42); static assert(__traits(compiles, { immutable A ia = new A; })); static class B { int x; this()() { x = 13; } this()() const { x = 42; } } const B mb = new B; assert(mb.x == 13); const B cb = new const B; assert(cb.x == 42); static assert(__traits(compiles, { immutable B ib = new B; })); static class C { int x; this()() const { x = 13; } this()() immutable { x = 42; } } const C cc = new const C; assert(cc.x == 13); immutable C ic = new immutable C; assert(ic.x == 42); static assert(!__traits(compiles, { C mc = new C; })); } /********************************************/ // 1914 struct Bug1914a { const char[10] i = [1,0,0,0,0,0,0,0,0,0]; char[10] x = i; int y=5; } struct Bug1914b { const char[10] i = [0,0,0,0,0,0,0,0,0,0]; char[10] x = i; int y=5; } struct Bug1914c { const char[2] i = ['a', 'b']; const char[2][3] j = [['x', 'y'], ['p', 'q'], ['r', 's']]; const char[2][3] k = ["cd", "ef", "gh"]; const char[2][3] l = [['x', 'y'], ['p'], ['h', 'k']]; char[2][3] x = i; int y = 5; char[2][3] z = j; char[2][3] w = k; int v=27; char[2][3] u = l; int t = 718; } struct T3198 { int g = 1; } class Foo3198 { int[5] x = 6; T3198[5] y = T3198(4); } void test3198and1914() { Bug1914a a; assert(a.y==5, "bug 1914, non-zero init"); Bug1914b b; assert(b.y==5, "bug 1914, zero init"); Bug1914c c; assert(c.y==5, "bug 1914, multilevel init"); assert(c.v==27, "bug 1914, multilevel init2"); assert(c.x[2][1]=='b'); assert(c.t==718, "bug 1914, multi3"); assert(c.u[1][0]=='p'); assert(c.u[1][1]==char.init); auto f = new Foo3198(); assert(f.x[0]==6); assert(f.y[0].g==4, "bug 3198"); } /********************************************/ // 2427 void test2427() { struct S { int x; } int foo(int i) { return i; } int i; S s = { foo(i) }; } /********************************************/ struct T5885 { uint a, b; } double mulUintToDouble(T5885 t, double m) { return t.a * m; } void test5885() { enum ae = mulUintToDouble(T5885(10, 0), 10.0); enum be = mulUintToDouble(T5885(10, 20), 10.0); static assert(ae == be); auto a = mulUintToDouble(T5885(10, 0), 10.0); auto b = mulUintToDouble(T5885(10, 20), 10.0); assert(a == b); } /********************************************/ // 5889 struct S5889a { int n; } struct S5889b { this(int n){} } bool isLvalue(S)(auto ref S s){ return __traits(isRef, s); } int foo(ref S5889a s) { return 1; } int foo( S5889a s) { return 2; } int foo(ref S5889b s) { return 1; } int foo( S5889b s) { return 2; } int goo(ref const(S5889a) s) { return 1; } int goo( const(S5889a) s) { return 2; } int goo(ref const(S5889b) s) { return 1; } int goo( const(S5889b) s) { return 2; } int too(S)(ref S s) { return 1; } int too(S)( S s) { return 2; } S makeRvalue(S)(){ S s; return s; } void test5889() { S5889a sa; S5889b sb; assert( isLvalue(sa)); assert( isLvalue(sb)); assert(!isLvalue(S5889a(0))); assert(!isLvalue(S5889b(0))); assert(!isLvalue(makeRvalue!S5889a())); assert(!isLvalue(makeRvalue!S5889b())); assert(foo(sa) == 1); assert(foo(sb) == 1); assert(foo(S5889a(0)) == 2); assert(foo(S5889b(0)) == 2); assert(foo(makeRvalue!S5889a()) == 2); assert(foo(makeRvalue!S5889b()) == 2); assert(goo(sa) == 1); assert(goo(sb) == 1); assert(goo(S5889a(0)) == 2); assert(goo(S5889b(0)) == 2); assert(goo(makeRvalue!S5889a()) == 2); assert(goo(makeRvalue!S5889b()) == 2); assert(too(sa) == 1); assert(too(sb) == 1); assert(too(S5889a(0)) == 2); assert(too(S5889b(0)) == 2); assert(too(makeRvalue!S5889a()) == 2); assert(too(makeRvalue!S5889b()) == 2); } /********************************************/ // 4147 struct S4247 { int n = 1024; this(int x) { n = x; } } void test4247() { auto p1 = S4247(); assert(p1.n == 1024); auto p2 = S4247(1); assert(p2.n == 1); } /********************************************/ // 6937 void test6937() { static struct S { int x, y; } auto s1 = S(1, 2); auto ps1 = new S(1, 2); assert(ps1.x == 1); assert(ps1.y == 2); assert(*ps1 == s1); auto ps2 = new S(1); assert(ps2.x == 1); assert(ps2.y == 0); assert(*ps2 == S(1, 0)); static assert(!__traits(compiles, new S(1,2,3))); int v = 0; struct NS { int x; void foo() { v = x; } } auto ns = NS(1); ns.foo(); assert(ns.x == 1); assert(v == 1); auto pns = new NS(2); assert(pns.x == 2); pns.foo(); assert(v == 2); pns.x = 1; assert(*pns == ns); static struct X { int v; this(this) { ++v; } } static struct Y { X x; } Y y = Y(X(1)); assert(y.x.v == 1); auto py1 = new Y(X(1)); assert(py1.x.v == 1); assert(*py1 == y); auto py2 = new Y(y.x); assert(py2.x.v == 2); } /********************************************/ // 12681 struct HasUnion12774 { union { int a, b; } } bool test12681() { immutable int x = 42; static struct S1 { immutable int *p; } immutable s1 = new S1(&x); assert(s1.p == &x); struct S2 { immutable int *p; void foo() {} } auto s2 = new S2(&x); assert(s2.p == &x); struct S3 { immutable int *p; int foo() { return x; } } auto s3 = new S3(&x); assert(s3.p == &x); assert(s3.foo() == 42); auto x12774 = new HasUnion12774(); return true; } static assert(test12681()); /********************************************/ // 3991 union X3991 { int a = void; dchar b = void; } union Y3991 { int a = void; dchar b = 'a'; } union Z3991 { int a = 123; dchar b = void; } void test3991() { X3991 x; Y3991 y; assert(y.b == 'a'); Z3991 z; assert(z.a == 123); } /********************************************/ // 7727 union U7727A1 { int i; double d; } union U7727A2 { int i = 123; double d; } //union U7727A3 { int i; double d = 2.5; } union U7727B1 { double d; int i; } union U7727B2 { double d = 2.5; int i; } //union U7727B3 { double d; int i = 123; } void test7727() { import core.stdc.math : isnan; { U7727A1 u; assert(u.i == 0); } { U7727A1 u = { i: 1024 }; assert(u.i == 1024); } { U7727A1 u = { d: 1.225 }; assert(u.d == 1.225); } static assert(!__traits(compiles, { U7727A1 u = { i: 1024, d: 1.225 }; } )); { U7727A2 u; assert(u.i == 123); } { U7727A2 u = { i: 1024 }; assert(u.i == 1024); } { U7727A2 u = { d: 1.225 }; assert(u.d == 1.225); } static assert(!__traits(compiles, { U7727A2 u = { i: 1024, d: 1.225 }; } )); // Blocked by issue 1432 // { U7727A3 u; assert(u.d == 2.5); } // { U7727A3 u = { i: 1024 }; assert(u.i == 1024); } // { U7727A3 u = { d: 1.225 }; assert(u.d == 1.225); } // static assert(!__traits(compiles, // { U7727A3 u = { i: 1024, d: 1.225 }; } // )); { U7727B1 u; assert(isnan(u.d)); } { U7727B1 u = { i: 1024 }; assert(u.i == 1024); } { U7727B1 u = { d: 1.225 }; assert(u.d == 1.225); } static assert(!__traits(compiles, { U7727B1 u = { i: 1024, d: 1.225 }; } )); { U7727B2 u; assert(u.d == 2.5); } { U7727B2 u = { i: 1024 }; assert(u.i == 1024); } { U7727B2 u = { d: 1.225 }; assert(u.d == 1.225); } static assert(!__traits(compiles, { U7727B2 u = { i: 1024, d: 1.225 }; } )); // Blocked by issue 1432 // { U7727B3 u; assert(u.i == 123); } // { U7727B3 u = { i: 1024 }; assert(u.i == 1024); } // { U7727B3 u = { d: 1.225 }; assert(u.d == 1.225); } // static assert(!__traits(compiles, // { U7727B3 u = { i: 1024, d: 1.225 }; } // )); test7727a(); test7727b(); } // -------- struct Foo7727a { ushort bar2; } struct Foo7727b { union { ubyte[2] bar1; ushort bar2; } } void test7727a() { immutable Foo7727a foo1 = { bar2: 100 }; // OK immutable Foo7727b foo2 = { bar2: 100 }; // OK <-- error } // -------- struct S7727 { int i; double d; } union U7727 { int i; double d; } void test7727b() { S7727 s = { d: 5 }; // OK U7727 u = { d: 5 }; // OK <-- Error: is not a static and cannot have static initializer } /********************************************/ // 7929 void test7929() { static struct S { int [] numbers; } const int [] numbers = new int[2]; const S si = {numbers}; // Error: cannot implicitly convert expression (numbers) of type const(int[]) to int[] const S se = const(S)(numbers); // OK } /********************************************/ // 7021 struct S7021 { @disable this(); } void test7021() { static assert(!is(typeof({ auto s = S7021(); }))); } /********************************************/ // 8738 void test8738() { int[3] a = [1, 2, 3]; struct S { int a, b, c; } S s = S(1, 2, 3); a = [4, a[0], 6]; s = S(4, s.a, 6); assert(a == [4, 1, 6]); assert(s == S(4, 1, 6)); } /********************************************/ // 8763 void test8763() { struct S { this(int) {} } void foo(T, Args...)(Args args) { T t = T(args); // Error: constructor main.S.this (int) is not callable using argument types () } S t = S(); // OK, initialize to S.init foo!S(); } /********************************************/ // 8902 union U8902 { int a, b; } enum U8902 u8902a = U8902.init; // No errors U8902 u8902b; // No errors U8902 u8902c = U8902.init; // Error: duplicate union initialization for b void test8902() { U8902 u8902d = U8902.init; // No errors immutable U8902 u8902e = U8902.init; // No errors immutable static U8902 u8902f = U8902.init; // Error: duplicate union... static U8902 u8902g = u8902e; // Error: duplicate union... static U8902 u8902h = U8902.init; // Error: duplicate union... } /********************************************/ // 9116 void test9116() { static struct X { int v; this(this) { ++v; } } static struct Y { X x; } X x = X(1); assert(x.v == 1); Y y = Y(X(1)); //printf("y.x.v = %d\n", y.x.v); // print 2, but should 1 assert(y.x.v == 1); // fails } /********************************************/ // 9293 void test9293() { static struct A { // enum A zero = A(); // This works as expected enum A zero = {}; // Note the difference here int opCmp(const ref A a) const { assert(0); } int opCmp(const A a) const { return 0; } } A a; auto b = a >= A.zero; // Error: A() is not an lvalue } /********************************************/ // 9566 void test9566() { static struct ExpandData { ubyte[4096] window = 0; } ExpandData a; auto b = ExpandData.init; // bug } /********************************************/ // 9775 enum Month9775 : ubyte { jan = 1, } struct Date9775 { this(int year, int month, int day) pure { _year = cast(short)year; _month = cast(Month9775)month; _day = cast(ubyte)day; } short _year = 1; Month9775 _month = Month9775.jan; ubyte _day = 1; } const Date9775 date9775c1 = Date9775(2012, 12, 21); const date9775c2 = Date9775(2012, 12, 21); enum Date9775 date9775e1 = Date9775(2012, 12, 21); enum date9775e2 = Date9775(2012, 12, 21); /********************************************/ // 11105 struct S11105 { int[2][1] a21; } void test11105() { S11105 s = S11105([1, 2]); } /********************************************/ // 11147 struct V11147 { union { struct { float x = 0; float y = 0; float z = 0; } struct { float r; float g; float b; } } } void test11147() { auto v = V11147.init; assert(v.x == 0f); assert(v.y == 0f); assert(v.z == 0f); assert(v.r == 0f); assert(v.g == 0f); assert(v.b == 0f); } /********************************************/ // 11256 struct S11256 { @disable this(); } struct Z11256a(Ranges...) { Ranges ranges; this(Ranges rs) { ranges = rs; } } struct Z11256b(Ranges...) { Ranges ranges = Ranges.init; // Internal error: e2ir.c 5321 this(Ranges rs) { ranges = rs; } } struct Z11256c(Ranges...) { Ranges ranges = void; // todt.c(475) v->type->ty == Tsarray && vsz == 0 this(Ranges rs) { ranges = rs; } } struct F11256(alias pred) { this(int[] = null) { } } Z!Ranges z11256(alias Z, Ranges...)(Ranges ranges) { return Z!Ranges(ranges); } void test11256() { z11256!Z11256a(S11256.init, F11256!(gv => true)()); z11256!Z11256b(S11256.init, F11256!(gv => true)()); z11256!Z11256c(S11256.init, F11256!(gv => true)()); } /********************************************/ // 11269 struct Atom { union { int i; struct { ulong first, rest; } struct { uint a, b; } } } void test11269() { Atom a1; Atom a2 = {i:1, rest:10, b:2}; } /********************************************/ // 11427 struct S11427 { union { ubyte a; int x; } void[] arr; } int foo11427() @safe { S11427 s1 = S11427(); S11427 s2; return 0; } /********************************************/ // 12011 struct S12011a { int f() { return i; } enum e = this.init.f(); int i = 1, j = 2; } struct S12011b { int f() { return i; } enum e = S12011b().f(); int i = 1, j = 2; } void test12011() { static assert(S12011a.e == 1); static assert(S12011b.e == 1); } /********************************************/ // 13021 void test13021() { static union U1 { float a; int b; } static union U2 { double a; long b; } static union U3 { real a; struct B { long b1, b2; } // ICE happens only if B.sizeof == real.sizeof B b; } static union U4 { real a; long[2] b; // ditto } auto f = U1(1.0); auto ok = f.b; auto fail1 = U1(1.0).b; // OK <- Internal error: e2ir.c 1162 auto fail2 = U2(1.0).b; // OK <- Internal error: e2ir.c 1162 auto fail3 = U3(1.0).b; // OK <- Internal error: e2ir.c 1162 auto fail4 = U4(1.0).b; // OK <- Internal error: backend/el.c 2904 } /********************************************/ // 14556 enum E14556 { a = 1 } struct S14556a { this(int) {} E14556[1] data; } struct S14556b { this(int) {} void[1] data; } void test14556() { auto sa = S14556a(0); assert(sa.data == [E14556.a]); auto sb = S14556b(0); assert(sb.data[] == cast(ubyte[1])[0]); } /********************************************/ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15a(); test15b(); test15c(); test15d(); test15e(); test9993a(); test9993b(); test3198and1914(); test2427(); test5885(); test5889(); test4247(); test6937(); test12681(); test3991(); test7727(); test7929(); test7021(); test8738(); test8763(); test8902(); test9116(); test9293(); test9566(); test11105(); test11147(); test11256(); test13021(); test14556(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link12010.d0000644000175000017500000000024713200164642023100 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/a12010.d // REQUIRED_ARGS: -release // -release is necessary to avoid __assert. import imports.a12010; void main() {} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/ldc_github_131_1.d0000644000175000017500000000017513200164642024467 0ustar matthiasmatthias// EXTRA_SOURCES: imports/ldc_github_131_1a.d import imports.ldc_github_131_1a; void main() { auto a = dirEntries(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test31.d0000644000175000017500000000036513200164642022703 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test31a.d // PERMUTE_ARGS: import imports.test31a; class Foo { mixin Baz!(); void testfunc() { privfunc(); // Error: .privfunc is private } } int main() { return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/complex.d0000644000175000017500000001334613200164642023232 0ustar matthiasmatthias// PERMUTE_ARGS: import std.stdio; import std.math; import core.stdc.stdio; /***************************************/ void test1() { creal c = 3.0 + 4.0i; c = sqrt(c); printf("re = %Lg, im = %Lg\n", c.re, c.im); assert(c.re == 2.0); assert(c.im == 1.0); float f = sqrt(25.0f); assert(f == 5.0); double d = sqrt(4.0); assert(d == 2.0); real r = sqrt(9.0L); assert(r == 3.0); } /***************************************/ ireal f2() { return 1i; } void test2() { creal v = 0+0i; v += f2(); assert(v == 0 + 1i); v = v + f2(); assert(v == 0 + 2i); } /***************************************/ cdouble[1] a3; cdouble[1] b3; cdouble[] concat3() { return a3~b3; } void test3() { a3[]=0.5+1.0i; b3[]=0.5+3.0i; cdouble[] arr=concat3(); assert(arr.length==2); assert(arr[0]==0.5+1.0i); assert(arr[1]==0.5+3.0i); } /***************************************/ creal[1] a4; creal[1] b4; creal[] concat4() { return a4~b4; } void test4() { a4[]=0.5+1.0i; b4[]=0.5+3.0i; creal[] arr=concat4(); assert(arr.length==2); assert(arr[0]==0.5+1.0i); assert(arr[1]==0.5+3.0i); } /***************************************/ void test5() { ifloat i=1.0fi; // i += 2.2; // assert(i == 1i); } /***************************************/ void test6() { float i=1.0f; // i /= 2.2fi; // assert(i == 0); } /***************************************/ void test7() { creal x=1.0i+2.0; creal[] arr; arr = arr ~ x; assert(arr.length==1); assert(arr[0]==1.0i+2.0); x=0.0i+5.0; assert(arr[0]==1.0i+2.0); } /****************************************/ creal[1] a8; creal[1] b8; creal[] concat8() { return a8 ~ b8; } void test8() { a8[]=0.5L+1.0Li; b8[]=0.5L+3.0Li; creal[] arr=concat8(); assert(arr.length==2); assert(arr[0]==0.5L+1.0Li); assert(arr[1]==0.5L+3.0Li); } /***************************************/ creal[1] a9; creal[1] b9; creal[] concat9() { return a9~b9; } void test9() { a9[]=0.5L+1.0Li; b9[]=0.5L+3.0Li; creal[] arr=concat9(); assert(arr.length==2); assert(arr[0]==0.5L+1.0Li); assert(arr[1]==0.5L+3.0Li); } /***************************************/ void test10() { ifloat a = 1.0i; assert(a.im == 1.0); const ifloat b = 2.0i; static assert(b.im == 2.0); // FAIL } /***************************************/ void test11() { real r = real.nan; assert( r!=0 ); if (r==0) assert(0); ireal ir = ireal.nan; assert( ir!=0 ); assert( ir!=0i ); if (ir==0) assert(0); if (ir==0i) assert(0); creal cr = creal.nan; assert( cr!=0 ); assert( cr!=0i ); if (cr==0) assert(0); if (cr==0i) assert(0); double d = double.nan; assert( d!=0 ); if (d==0) assert(0); idouble id = idouble.nan; assert( id!=0 ); assert( id!=0i ); if (id==0) assert(0); if (id==0i) assert(0); cdouble cd = cdouble.nan; assert( cd!=0 ); assert( cd!=0i ); if (cd==0) assert(0); if (cd==0i) assert(0); float f = float.nan; assert( f!=0 ); if (f==0) assert(0); ifloat ifx = ifloat.nan; assert( ifx!=0 ); assert( ifx!=0i ); if (ifx==0) assert(0); if (ifx==0i) assert(0); cfloat cf = cfloat.nan; assert( cf!=0 ); assert( cf!=0i ); if (cf==0) assert(0); if (cf==0i) assert(0); } /***************************************/ void test12() { real x = 3; creal a = (2 + 4i) % 3; writeln(a); assert(a == 2 + 1i); creal b = (2 + 4i) % x; writeln(b); assert(b == a); } /***************************************/ void test13() { ireal a = 5i; ireal b = a % 2; writeln(b); assert(b == 1i); } /***************************************/ cdouble inv( cdouble expr ) { return (1.0 + 0.0i) / expr; } /***************************************/ void test14() { cfloat c; cfloat d; assert(c != d); cdouble e; cdouble f; assert(e != f); creal g; creal h; assert(g != h); } /***************************************/ void test7581() { cfloat a() { return cfloat.nan; } assert(a() != 0); } /***************************************/ float f() { return 1.0f; } ifloat i() { return 1.0fi; } void test7594() { assert(f() + i() == 1.0f + 1.0fi); } /***************************************/ cdouble conv(cfloat a) { return a; } void test7593() { assert(conv(1.0f+1.0fi) == 1.0+1.0i); } /***************************************/ cfloat get() { return cfloat.nan; } void test7591() { assert(!(get() == 0)); } /***************************************/ void foo8966(cfloat x) { assert(x.re == 3.0f); } __gshared cfloat[] a8966; void test8966() { a8966 = new cfloat[2]; a8966[0] = 3.0f + 1.0fi; foo8966(a8966[0]); } /***************************************/ void formatTest2(cfloat s, double re, double im) { assert(s.re == re); assert(s.im == im); } cfloat getcf() { return 2 + 1i; } void test10677() { formatTest2( getcf(), 2, 1 ); } /***************************************/ void test7806() { for (idouble i = -2i; i <= 2i; i += .125i) for (double r = -2; r <= 2; r += .0625) { cdouble c = r + i; printf("%g %gi\n", c.re, c.im); } } /***************************************/ void test7976() { creal[] a = new creal[2]; auto b = a[0] = a[1]; } /***************************************/ int main(char[][] args) { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test7581(); test7594(); test7593(); test7591(); test8966(); test10677(); test7806(); test7976(); printf("Success!\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testformat.d0000644000175000017500000000574213200164642023754 0ustar matthiasmatthias// PERMUTE_ARGS: import std.stdio; import std.string; /*************************************************************/ void test1() { double x = 1e6; float f; double d; real r; while (x > 1e-5) { double y = x / 101.0; std.stdio.writef("x = %g\t%f\t%e\n",x/101.0,x/101.0,x/101.0); x /= 10.0; } double a = 123456789.0; for (int i = 20; i--; a /= 10) std.stdio.writef("%20.6g|%20.6e|%20.6f\n",a,a,a); std.stdio.writef("%e %e %e %e\n",float.nan,double.nan,real.nan,double.infinity); std.stdio.writef("%e %e %e\n",-float.nan,-double.nan,-double.infinity); std.stdio.writef("%-5E %5E %E\n",float.nan,double.nan,double.infinity); std.stdio.writef("%f %f %f\n",float.nan,double.nan,double.infinity); std.stdio.writef("%f %f %f\n",-float.nan,-double.nan,-double.infinity); std.stdio.writef("%+F %+ F %F\n",float.nan,double.nan,double.infinity); std.stdio.writef("%g %g %g\n",float.nan,double.nan,double.infinity); std.stdio.writef("%g %g %g\n",-float.nan,-double.nan,-double.infinity); std.stdio.writef("% G %G %G\n",float.nan,double.nan,double.infinity); r = 0x1.AAp+3L; std.stdio.writef(" r = %g\n", r); std.stdio.writef(" r = %a\n", r); std.stdio.writef(" r = %A\n", r); d = 0x1.AAp+3; std.stdio.writef(" d = %.5a\n", d); std.stdio.writef(" d = %A\n", d); f = 0x1.AAp+3f; std.stdio.writef(" f = %a\n", f); std.stdio.writef(" f = %A\n", f); f = 0x1.FFp+3f; std.stdio.writef(" f = %.1a\n", f); std.stdio.writef(" f = %A\n", f); r = 0; std.stdio.writef(" r = %a\n", r); std.stdio.writef(" r = %A\n", r); std.stdio.writef("%e\n", 1e+300); std.stdio.writef("%.0f\n%.307f\n", 1e+300, 1e-300); std.stdio.writef("%.0A\n%.307A\n", 1e+300, 1e-300); } /*************************************************************/ void test2() { writefln("%o", 9); assert(std.string.format("%o", 9) == "11"); assert(std.string.format("%o", 10) == "12"); assert(std.string.format("%b", 9) == "1001"); assert(std.string.format("%b", 10) == "1010"); } /*************************************************************/ void test3() { Object e = new Exception("hello"); writeln(e.toString()); //assert(e.toString() == "object.Exception: hello"); //assert(format(e) == "object.Exception: hello"); alias char[] xstring; assert(format(cast(xstring)"world") == "world"); } /*************************************************************/ void test4() { const char[][] x = ["%s","123"]; writeln(x); assert(std.string.format("%s", x) == `["%s", "123"]`); } /*************************************************************/ void test5() { int[int] foo; foo[1] = 2; foo[7] = 28; writefln("%s", foo); void[0] v; assert(format("%s", v) == "[]"); } /*************************************************************/ int main() { test1(); test2(); test3(); test4(); test5(); std.stdio.writefln("Success"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link11127.d0000644000175000017500000000007713200164642023111 0ustar matthiasmatthiasimport imports.link11127a; void main() { cycle([1, 2]); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link12037.d0000644000175000017500000000013713200164642023107 0ustar matthiasmatthiasimport imports.a12037; alias CustomFloat!(10, 5) Float16; void main() { Float16 f = 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test3449.d0000644000175000017500000000606413200164642023065 0ustar matthiasmatthias /******************************************/ // 3449 template TypeTuple(T...) { alias TypeTuple = T; } // If module variable has no explicit initializer, // constant folding is not allowed for that. int mg1; const int cg1; immutable int ig1; static this() { mg1 = 10; cg1 = 10; ig1 = 10; } static assert(!__traits(compiles, { static assert(mg1 == 0); })); static assert(!__traits(compiles, { static assert(cg1 == 0); })); static assert(!__traits(compiles, { static assert(ig1 == 0); })); // But, if module variable has explicit initializer and // non-mutable type, constant folding is allowed for that.. int mg2 = 1; const int cg2 = 1; immutable int ig2 = 1; static this() { mg2 = 11; static assert(!__traits(compiles, cg2 = 11)); // not allowed for constant folding static assert(!__traits(compiles, ig2 = 11)); // not allowed for constant folding } static assert(!__traits(compiles, { static assert(mg2 == 1); })); static assert(cg2 == 1); // possible static assert(ig2 == 1); // possible // For aggregate fields, compiler behavior will be changed. void test3449() { static struct S(T) { T field1; // doesn't have explicit initializer T field2 = 1; // has explicit initializer this(int n) { field1 = n; // allowed field2 = n; // NEW! re-assigning during construction is allowed for any qualified fields. } } foreach (T; TypeTuple!(int, const int, immutable int)) { alias S!T ST; auto s1 = ST(); // default construction assert(s1.field1 == 0); // == T.init assert(s1.field2 == 1); // == specified initializer // Getting address for non-mutable field is allowed. T* s1p1 = &s1.field1; T* s1p2 = &s1.field2; assert(*s1p1 == 0); assert(*s1p2 == 1); static if (is(T == int)) { // If T is mutable, // modification through indirection is allowed *s1p1 = 100, *s1p2 = 101; assert(*s1p1 == 100); assert(*s1p2 == 101); } else { // If T is not mutable, modification is not allowed static assert(!__traits(compiles, *s1p1 = 100)); static assert(!__traits(compiles, *s1p2 = 100)); } // Access to non-static non-mutable field is // now correctly rejected by "need this" error. static assert(!__traits(compiles, ST.field1 == 1)); static assert(!__traits(compiles, ST.field2 == 0)); // So, re-assignment of non-mutable fields // during construction is enough acceptable. auto s2 = ST(10); assert(s2.field1 == 10); assert(s2.field2 == 10); } } /******************************************/ // 10643 struct S10643 { const int[1000] x = void; this(int n) { x[] = n; } } static assert(S10643.sizeof == int.sizeof * 1000); /******************************************/ int main() { test3449(); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link11931.d0000644000175000017500000000035513200164642023113 0ustar matthiasmatthias// REQUIRED_ARGS: -g // PERMUTE_ARGS: // EXTRA_SOURCES: imports/test11931a.d // EXTRA_SOURCES: imports/test11931b.d // EXTRA_SOURCES: imports/test11931c.d // EXTRA_SOURCES: imports/test11931d.d // COMPILE_SEPARATELY: -g void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test38.d0000644000175000017500000000033213200164642022704 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test38a.d // PERMUTE_ARGS: import std.stdio; import imports.test38a; void main() { static b = bar(7); printf("b = %d, %d\n", b, bar(7)); assert(b == 49); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/iasm.d0000644000175000017500000035370513200164642022522 0ustar matthiasmatthias// PERMUTE_ARGS: // Copyright (c) 1999-2012 by Digital Mars // All Rights Reserved // written by Walter Bright // http://www.digitalmars.com import std.stdio; version (D_PIC) { int main() { return 0; } } else version (D_InlineAsm_X86) { struct M128 { int a,b,c,d; }; struct M64 { int a,b; }; /****************************************************/ void test1() { int foo; int bar; static const int x = 4; asm { align x; ; mov EAX, __LOCAL_SIZE ; mov foo[EBP], EAX ; } assert(foo == 8); } /****************************************************/ void test2() { int foo; int bar; asm { even ; mov EAX,0 ; inc EAX ; mov foo[EBP], EAX ; } assert(foo == 1); } /****************************************************/ void test3() { int foo; int bar; asm { mov EAX,5 ; jmp $ + 1 ; db 0x40,0x48 ; // inc EAX, dec EAX mov foo[EBP],EAX ; } assert(foo == 4); } /****************************************************/ void test4() { int foo; int bar; asm { xor EAX,EAX ; add EAX,5 ; jne L1 ; db 0x40,0x48 ; // inc EAX, dec EAX L1: db 0x48 ; mov foo[EBP],EAX ; } assert(foo == 4); } /****************************************************/ void test5() { int foo; ubyte *p; ushort *w; uint *u; ulong *ul; float *f; double *d; real *e; static float fs = 1.1; static double ds = 1.2; static real es = 1.3; asm { call L1 ; db 0x40,0x48 ; // inc EAX, dec EAX db "abc" ; ds "def" ; di "ghi" ; dl 0x12345678ABCDEF ; df 1.1 ; dd 1.2 ; de 1.3 ; L1: pop EBX ; mov p[EBP],EBX ; } assert(p[0] == 0x40); assert(p[1] == 0x48); assert(p[2] == 'a'); assert(p[3] == 'b'); assert(p[4] == 'c'); w = cast(ushort *)(p + 5); assert(w[0] == 'd'); assert(w[1] == 'e'); assert(w[2] == 'f'); u = cast(uint *)(w + 3); assert(u[0] == 'g'); assert(u[1] == 'h'); assert(u[2] == 'i'); ul = cast(ulong *)(u + 3); assert(ul[0] == 0x12345678ABCDEF); f = cast(float *)(ul + 1); assert(*f == fs); d = cast(double *)(f + 1); assert(*d == ds); e = cast(real *)(d + 1); assert(*e == es); } /****************************************************/ void test6() { ubyte *p; static ubyte data[] = [ 0x8B, 0x01, // mov EAX,[ECX] 0x8B, 0x04, 0x19, // mov EAX,[EBX][ECX] 0x8B, 0x04, 0x4B, // mov EAX,[ECX*2][EBX] 0x8B, 0x04, 0x5A, // mov EAX,[EBX*2][EDX] 0x8B, 0x04, 0x8E, // mov EAX,[ECX*4][ESI] 0x8B, 0x04, 0xF9, // mov EAX,[EDI*8][ECX] 0x2B, 0x1C, 0x19, // sub EBX,[EBX][ECX] 0x3B, 0x0C, 0x4B, // cmp ECX,[ECX*2][EBX] 0x03, 0x14, 0x5A, // add EDX,[EBX*2][EDX] 0x33, 0x34, 0x8E, // xor ESI,[ECX*4][ESI] 0x29, 0x1C, 0x19, // sub [EBX][ECX],EBX 0x39, 0x0C, 0x4B, // cmp [ECX*2][EBX],ECX 0x01, 0x24, 0x5A, // add [EBX*2][EDX],ESP 0x31, 0x2C, 0x8E, // xor [ECX*4][ESI],EBP 0xA8, 0x03, // test AL,3 0x66, 0xA9, 0x04, 0x00, // test AX,4 0xA9, 0x05, 0x00, 0x00, 0x00, // test EAX,5 0x85, 0x3C, 0xF9, // test [EDI*8][ECX],EDI ]; int i; asm { call L1 ; mov EAX,[ECX] ; mov EAX,[ECX][EBX] ; mov EAX,[ECX*2][EBX] ; mov EAX,[EDX][EBX*2] ; mov EAX,[ECX*4][ESI] ; mov EAX,[ECX][EDI*8] ; sub EBX,[ECX][EBX] ; cmp ECX,[ECX*2][EBX] ; add EDX,[EDX][EBX*2] ; xor ESI,[ECX*4][ESI] ; sub [ECX][EBX],EBX ; cmp [ECX*2][EBX],ECX ; add [EDX][EBX*2],ESP ; xor [ECX*4][ESI],EBP ; test AL,3 ; test AX,4 ; test EAX,5 ; test [ECX][EDI*8],EDI ; L1: pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test7() { ubyte *p; static ubyte data[] = [ 0x26,0xA1,0x24,0x13,0x00,0x00, // mov EAX,ES:[01324h] 0x36,0x66,0xA1,0x78,0x56,0x00,0x00, // mov AX,SS:[05678h] 0xA0,0x78,0x56,0x00,0x00, // mov AL,[05678h] 0x2E,0x8A,0x25,0x78,0x56,0x00,0x00, // mov AH,CS:[05678h] 0x64,0x8A,0x1D,0x78,0x56,0x00,0x00, // mov BL,FS:[05678h] 0x65,0x8A,0x3D,0x78,0x56,0x00,0x00, // mov BH,GS:[05678h] ]; int i; asm { call L1 ; mov EAX,ES:[0x1324] ; mov AX,SS:[0x5678] ; mov AL,DS:[0x5678] ; mov AH,CS:[0x5678] ; mov BL,FS:[0x5678] ; mov BH,GS:[0x5678] ; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test8() { ubyte *p; static ubyte data[] = [ 0x8C,0xD0, // mov AX,SS 0x8C,0xDB, // mov BX,DS 0x8C,0xC1, // mov CX,ES 0x8C,0xCA, // mov DX,CS 0x8C,0xE6, // mov SI,FS 0x8C,0xEF, // mov DI,GS 0x8E,0xD0, // mov SS,AX 0x8E,0xDB, // mov DS,BX 0x8E,0xC1, // mov ES,CX 0x8E,0xCA, // mov CS,DX 0x8E,0xE6, // mov FS,SI 0x8E,0xEF, // mov GS,DI 0x0F,0x22,0xC0, // mov CR0,EAX 0x0F,0x22,0xD3, // mov CR2,EBX 0x0F,0x22,0xD9, // mov CR3,ECX 0x0F,0x22,0xE2, // mov CR4,EDX 0x0F,0x20,0xC0, // mov EAX,CR0 0x0F,0x20,0xD3, // mov EBX,CR2 0x0F,0x20,0xD9, // mov ECX,CR3 0x0F,0x20,0xE2, // mov EDX,CR4 0x0F,0x23,0xC0, // mov DR0,EAX 0x0F,0x23,0xCE, // mov DR1,ESI 0x0F,0x23,0xD3, // mov DR2,EBX 0x0F,0x23,0xD9, // mov DR3,ECX 0x0F,0x23,0xE2, // mov DR4,EDX 0x0F,0x23,0xEF, // mov DR5,EDI 0x0F,0x23,0xF4, // mov DR6,ESP 0x0F,0x23,0xFD, // mov DR7,EBP 0x0F,0x21,0xC4, // mov ESP,DR0 0x0F,0x21,0xCD, // mov EBP,DR1 0x0F,0x21,0xD0, // mov EAX,DR2 0x0F,0x21,0xDB, // mov EBX,DR3 0x0F,0x21,0xE1, // mov ECX,DR4 0x0F,0x21,0xEA, // mov EDX,DR5 0x0F,0x21,0xF6, // mov ESI,DR6 0x0F,0x21,0xFF, // mov EDI,DR7 0xA4, // movsb 0x66,0xA5, // movsw 0xA5, // movsd ]; int i; asm { call L1 ; mov AX,SS ; mov BX,DS ; mov CX,ES ; mov DX,CS ; mov SI,FS ; mov DI,GS ; mov SS,AX ; mov DS,BX ; mov ES,CX ; mov CS,DX ; mov FS,SI ; mov GS,DI ; mov CR0,EAX ; mov CR2,EBX ; mov CR3,ECX ; mov CR4,EDX ; mov EAX,CR0 ; mov EBX,CR2 ; mov ECX,CR3 ; mov EDX,CR4 ; mov DR0,EAX ; mov DR1,ESI ; mov DR2,EBX ; mov DR3,ECX ; mov DR4,EDX ; mov DR5,EDI ; mov DR6,ESP ; mov DR7,EBP ; mov ESP,DR0 ; mov EBP,DR1 ; mov EAX,DR2 ; mov EBX,DR3 ; mov ECX,DR4 ; mov EDX,DR5 ; mov ESI,DR6 ; mov EDI,DR7 ; movsb ; movsw ; movsd ; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test9() { ubyte *p; static ubyte data[] = [ 0x67,0x66,0x8B,0x00, // mov AX,[BX+SI] 0x67,0x66,0x8B,0x01, // mov AX,[BX+DI] 0x67,0x66,0x8B,0x02, // mov AX,[BP+SI] 0x67,0x66,0x8B,0x03, // mov AX,[BP+DI] 0x67,0x66,0x8B,0x04, // mov AX,[SI] 0x67,0x66,0x8B,0x05, // mov AX,[DI] 0x66,0xB8,0xD2,0x04, // mov AX,04D2h 0x67,0x66,0x8B,0x07, // mov AX,[BX] 0x67,0x66,0x8B,0x40,0x01, // mov AX,1[BX+SI] 0x67,0x66,0x8B,0x41,0x02, // mov AX,2[BX+DI] 0x67,0x66,0x8B,0x42,0x03, // mov AX,3[BP+SI] 0x67,0x66,0x8B,0x43,0x04, // mov AX,4[BP+DI] 0x67,0x66,0x8B,0x44,0x05, // mov AX,5[SI] 0x67,0x66,0x8B,0x45,0x06, // mov AX,6[DI] 0x67,0x66,0x8B,0x43,0x07, // mov AX,7[BP+DI] 0x67,0x66,0x8B,0x47,0x08, // mov AX,8[BX] 0x67,0x8B,0x80,0x21,0x01, // mov EAX,0121h[BX+SI] 0x67,0x66,0x8B,0x81,0x22,0x01, // mov AX,0122h[BX+DI] 0x67,0x66,0x8B,0x82,0x43,0x23, // mov AX,02343h[BP+SI] 0x67,0x66,0x8B,0x83,0x54,0x45, // mov AX,04554h[BP+DI] 0x67,0x66,0x8B,0x84,0x45,0x66, // mov AX,06645h[SI] 0x67,0x66,0x8B,0x85,0x36,0x12, // mov AX,01236h[DI] 0x67,0x66,0x8B,0x86,0x67,0x45, // mov AX,04567h[BP] 0x67,0x8A,0x87,0x08,0x01, // mov AL,0108h[BX] ]; int i; asm { call L1 ; mov AX,[BX+SI] ; mov AX,[BX+DI] ; mov AX,[BP+SI] ; mov AX,[BP+DI] ; mov AX,[SI] ; mov AX,[DI] ; mov AX,[1234] ; mov AX,[BX] ; mov AX,1[BX+SI] ; mov AX,2[BX+DI] ; mov AX,3[BP+SI] ; mov AX,4[BP+DI] ; mov AX,5[SI] ; mov AX,6[DI] ; mov AX,7[DI+BP] ; mov AX,8[BX] ; mov EAX,0x121[BX+SI] ; mov AX,0x122[BX+DI] ; mov AX,0x2343[BP+SI] ; mov AX,0x4554[BP+DI] ; mov AX,0x6645[SI] ; mov AX,0x1236[DI] ; mov AX,0x4567[BP] ; mov AL,0x108[BX] ; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ shared int bar10 = 78; shared int baz10[2]; void test10() { ubyte *p; int foo; static ubyte data[] = [ ]; int i; asm { mov bar10,0x12 ; mov baz10,0x13 ; mov ESI,1 ; mov baz10[ESI*4],0x14 ; } assert(bar10 == 0x12); assert(baz10[0] == 0x13); assert(baz10[1] == 0x14); } /****************************************************/ struct Foo11 { int c; int a; int b; } void test11() { ubyte *p; int x1; int x2; int x3; int x4; asm { mov x1,Foo11.a.sizeof ; mov x2,Foo11.b.offsetof ; mov x3,Foo11.sizeof ; mov x4,Foo11.sizeof + 7 ; } assert(x1 == int.sizeof); assert(x2 == 8); assert(x3 == 12); assert(x4 == 19); } /****************************************************/ void test12() { ubyte *p; static ubyte data[] = [ 0x37, // aaa 0xD5,0x0A, // aad 0xD4,0x0A, // aam 0x3F, // aas 0x67,0x63,0x3C, // arpl [SI],DI 0x14,0x05, // adc AL,5 0x83,0xD0,0x14, // adc EAX,014h 0x80,0x55,0xF8,0x17, // adc byte ptr -8[EBP],017h 0x83,0x55,0xFC,0x17, // adc dword ptr -4[EBP],017h 0x81,0x55,0xFC,0x34,0x12,0x00,0x00, // adc dword ptr -4[EBP],01234h 0x10,0x7D,0xF8, // adc -8[EBP],BH 0x11,0x5D,0xFC, // adc -4[EBP],EBX 0x12,0x5D,0xF8, // adc BL,-8[EBP] 0x13,0x55,0xFC, // adc EDX,-4[EBP] 0x04,0x05, // add AL,5 0x83,0xC0,0x14, // add EAX,014h 0x80,0x45,0xF8,0x17, // add byte ptr -8[EBP],017h 0x83,0x45,0xFC,0x17, // add dword ptr -4[EBP],017h 0x81,0x45,0xFC,0x34,0x12,0x00,0x00, // add dword ptr -4[EBP],01234h 0x00,0x7D,0xF8, // add -8[EBP],BH 0x01,0x5D,0xFC, // add -4[EBP],EBX 0x02,0x5D,0xF8, // add BL,-8[EBP] 0x03,0x55,0xFC, // add EDX,-4[EBP] 0x24,0x05, // and AL,5 0x83,0xE0,0x14, // and EAX,014h 0x80,0x65,0xF8,0x17, // and byte ptr -8[EBP],017h 0x83,0x65,0xFC,0x17, // and dword ptr -4[EBP],017h 0x81,0x65,0xFC,0x34,0x12,0x00,0x00, // and dword ptr -4[EBP],01234h 0x20,0x7D,0xF8, // and -8[EBP],BH 0x21,0x5D,0xFC, // and -4[EBP],EBX 0x22,0x5D,0xF8, // and BL,-8[EBP] 0x23,0x55,0xFC, // and EDX,-4[EBP] 0x3C,0x05, // cmp AL,5 0x83,0xF8,0x14, // cmp EAX,014h 0x80,0x7D,0xF8,0x17, // cmp byte ptr -8[EBP],017h 0x83,0x7D,0xFC,0x17, // cmp dword ptr -4[EBP],017h 0x81,0x7D,0xFC,0x34,0x12,0x00,0x00, // cmp dword ptr -4[EBP],01234h 0x38,0x7D,0xF8, // cmp -8[EBP],BH 0x39,0x5D,0xFC, // cmp -4[EBP],EBX 0x3A,0x5D,0xF8, // cmp BL,-8[EBP] 0x3B,0x55,0xFC, // cmp EDX,-4[EBP] 0x0C,0x05, // or AL,5 0x83,0xC8,0x14, // or EAX,014h 0x80,0x4D,0xF8,0x17, // or byte ptr -8[EBP],017h 0x83,0x4D,0xFC,0x17, // or dword ptr -4[EBP],017h 0x81,0x4D,0xFC,0x34,0x12,0x00,0x00, // or dword ptr -4[EBP],01234h 0x08,0x7D,0xF8, // or -8[EBP],BH 0x09,0x5D,0xFC, // or -4[EBP],EBX 0x0A,0x5D,0xF8, // or BL,-8[EBP] 0x0B,0x55,0xFC, // or EDX,-4[EBP] 0x1C,0x05, // sbb AL,5 0x83,0xD8,0x14, // sbb EAX,014h 0x80,0x5D,0xF8,0x17, // sbb byte ptr -8[EBP],017h 0x83,0x5D,0xFC,0x17, // sbb dword ptr -4[EBP],017h 0x81,0x5D,0xFC,0x34,0x12,0x00,0x00, // sbb dword ptr -4[EBP],01234h 0x18,0x7D,0xF8, // sbb -8[EBP],BH 0x19,0x5D,0xFC, // sbb -4[EBP],EBX 0x1A,0x5D,0xF8, // sbb BL,-8[EBP] 0x1B,0x55,0xFC, // sbb EDX,-4[EBP] 0x2C,0x05, // sub AL,5 0x83,0xE8,0x14, // sub EAX,014h 0x80,0x6D,0xF8,0x17, // sub byte ptr -8[EBP],017h 0x83,0x6D,0xFC,0x17, // sub dword ptr -4[EBP],017h 0x81,0x6D,0xFC,0x34,0x12,0x00,0x00, // sub dword ptr -4[EBP],01234h 0x28,0x7D,0xF8, // sub -8[EBP],BH 0x29,0x5D,0xFC, // sub -4[EBP],EBX 0x2A,0x5D,0xF8, // sub BL,-8[EBP] 0x2B,0x55,0xFC, // sub EDX,-4[EBP] 0xA8,0x05, // test AL,5 0xA9,0x14,0x00,0x00,0x00, // test EAX,014h 0xF6,0x45,0xF8,0x17, // test byte ptr -8[EBP],017h 0xF7,0x45,0xFC,0x17,0x00,0x00,0x00, // test dword ptr -4[EBP],017h 0xF7,0x45,0xFC,0x34,0x12,0x00,0x00, // test dword ptr -4[EBP],01234h 0x84,0x7D,0xF8, // test -8[EBP],BH 0x85,0x5D,0xFC, // test -4[EBP],EBX 0x34,0x05, // xor AL,5 0x83,0xF0,0x14, // xor EAX,014h 0x80,0x75,0xF8,0x17, // xor byte ptr -8[EBP],017h 0x83,0x75,0xFC,0x17, // xor dword ptr -4[EBP],017h 0x81,0x75,0xFC,0x34,0x12,0x00,0x00, // xor dword ptr -4[EBP],01234h 0x30,0x7D,0xF8, // xor -8[EBP],BH 0x31,0x5D,0xFC, // xor -4[EBP],EBX 0x32,0x5D,0xF8, // xor BL,-8[EBP] 0x33,0x55,0xFC, // xor EDX,-4[EBP] ]; int i; byte rm8; int rm32; static int m32; asm { call L1 ; aaa ; aad ; aam ; aas ; arpl [SI],DI ; adc AL,5 ; adc EAX,20 ; adc rm8[EBP],23 ; adc rm32[EBP],23 ; adc rm32[EBP],0x1234 ; adc rm8[EBP],BH ; adc rm32[EBP],EBX ; adc BL,rm8[EBP] ; adc EDX,rm32[EBP] ; add AL,5 ; add EAX,20 ; add rm8[EBP],23 ; add rm32[EBP],23 ; add rm32[EBP],0x1234 ; add rm8[EBP],BH ; add rm32[EBP],EBX ; add BL,rm8[EBP] ; add EDX,rm32[EBP] ; and AL,5 ; and EAX,20 ; and rm8[EBP],23 ; and rm32[EBP],23 ; and rm32[EBP],0x1234 ; and rm8[EBP],BH ; and rm32[EBP],EBX ; and BL,rm8[EBP] ; and EDX,rm32[EBP] ; cmp AL,5 ; cmp EAX,20 ; cmp rm8[EBP],23 ; cmp rm32[EBP],23 ; cmp rm32[EBP],0x1234 ; cmp rm8[EBP],BH ; cmp rm32[EBP],EBX ; cmp BL,rm8[EBP] ; cmp EDX,rm32[EBP] ; or AL,5 ; or EAX,20 ; or rm8[EBP],23 ; or rm32[EBP],23 ; or rm32[EBP],0x1234 ; or rm8[EBP],BH ; or rm32[EBP],EBX ; or BL,rm8[EBP] ; or EDX,rm32[EBP] ; sbb AL,5 ; sbb EAX,20 ; sbb rm8[EBP],23 ; sbb rm32[EBP],23 ; sbb rm32[EBP],0x1234 ; sbb rm8[EBP],BH ; sbb rm32[EBP],EBX ; sbb BL,rm8[EBP] ; sbb EDX,rm32[EBP] ; sub AL,5 ; sub EAX,20 ; sub rm8[EBP],23 ; sub rm32[EBP],23 ; sub rm32[EBP],0x1234 ; sub rm8[EBP],BH ; sub rm32[EBP],EBX ; sub BL,rm8[EBP] ; sub EDX,rm32[EBP] ; test AL,5 ; test EAX,20 ; test rm8[EBP],23 ; test rm32[EBP],23 ; test rm32[EBP],0x1234 ; test rm8[EBP],BH ; test rm32[EBP],EBX ; xor AL,5 ; xor EAX,20 ; xor rm8[EBP],23 ; xor rm32[EBP],23 ; xor rm32[EBP],0x1234 ; xor rm8[EBP],BH ; xor rm32[EBP],EBX ; xor BL,rm8[EBP] ; xor EDX,rm32[EBP] ; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { //printf("p[%d] = x%02x, data = x%02x\n", i, p[i], data[i]); assert(p[i] == data[i]); } } /****************************************************/ void test13() { int m32; long m64; M128 m128; ubyte *p; static ubyte data[] = [ 0x0F,0x0B, // ud2 0x0F,0x05, // syscall 0x0F,0x34, // sysenter 0x0F,0x35, // sysexit 0x0F,0x07, // sysret 0x0F,0xAE,0xE8, // lfence 0x0F,0xAE,0xF0, // mfence 0x0F,0xAE,0xF8, // sfence 0x0F,0xAE,0x00, // fxsave [EAX] 0x0F,0xAE,0x08, // fxrstor [EAX] 0x0F,0xAE,0x10, // ldmxcsr [EAX] 0x0F,0xAE,0x18, // stmxcsr [EAX] 0x0F,0xAE,0x38, // clflush [EAX] 0x0F,0x58,0x08, // addps XMM1,[EAX] 0x0F,0x58,0xCA, // addps XMM1,XMM2 0x66, 0x0F,0x58,0x03, // addpd XMM0,[EBX] 0x66, 0x0F,0x58,0xD1, // addpd XMM2,XMM1 0xF2,0x0F,0x58,0x08, // addsd XMM1,[EAX] 0xF2,0x0F,0x58,0xCA, // addsd XMM1,XMM2 0xF3,0x0F,0x58,0x2E, // addss XMM5,[ESI] 0xF3,0x0F,0x58,0xF7, // addss XMM6,XMM7 0x0F,0x54,0x08, // andps XMM1,[EAX] 0x0F,0x54,0xCA, // andps XMM1,XMM2 0x66, 0x0F,0x54,0x03, // andpd XMM0,[EBX] 0x66, 0x0F,0x54,0xD1, // andpd XMM2,XMM1 0x0F,0x55,0x08, // andnps XMM1,[EAX] 0x0F,0x55,0xCA, // andnps XMM1,XMM2 0x66, 0x0F,0x55,0x03, // andnpd XMM0,[EBX] 0x66, 0x0F,0x55,0xD1, // andnpd XMM2,XMM1 0xA7, // cmpsd 0x0F,0xC2,0x08,0x01, // cmpps XMM1,[EAX],1 0x0F,0xC2,0xCA,0x02, // cmpps XMM1,XMM2,2 0x66, 0x0F,0xC2,0x03,0x03, // cmppd XMM0,[EBX],3 0x66, 0x0F,0xC2,0xD1,0x04, // cmppd XMM2,XMM1,4 0xF2,0x0F,0xC2,0x08,0x05, // cmpsd XMM1,[EAX],5 0xF2,0x0F,0xC2,0xCA,0x06, // cmpsd XMM1,XMM2,6 0xF3,0x0F,0xC2,0x2E,0x07, // cmpss XMM5,[ESI],7 0xF3,0x0F,0xC2,0xF7,0x00, // cmpss XMM6,XMM7,0 0x66, 0x0F,0x2F,0x08, // comisd XMM1,[EAX] 0x66, 0x0F,0x2F,0x4D,0xE0, // comisd XMM1,-020h[EBP] 0x66, 0x0F,0x2F,0xCA, // comisd XMM1,XMM2 0x0F,0x2F,0x2E, // comiss XMM5,[ESI] 0x0F,0x2F,0xF7, // comiss XMM6,XMM7 0xF3,0x0F,0xE6,0xDC, // cvtdq2pd XMM3,XMM4 0xF3,0x0F,0xE6,0x5D,0xE0, // cvtdq2pd XMM3,-020h[EBP] 0x0F,0x5B,0xDC, // cvtdq2ps XMM3,XMM4 0x0F,0x5B,0x5D,0xE8, // cvtdq2ps XMM3,-018h[EBP] 0xF2,0x0F,0xE6,0xDC, // cvtpd2dq XMM3,XMM4 0xF2,0x0F,0xE6,0x5D,0xE8, // cvtpd2dq XMM3,-018h[EBP] 0x66, 0x0F,0x2D,0xDC, // cvtpd2pi MM3,XMM4 0x66, 0x0F,0x2D,0x5D,0xE8, // cvtpd2pi MM3,-018h[EBP] 0x66, 0x0F,0x5A,0xDC, // cvtpd2ps XMM3,XMM4 0x66, 0x0F,0x5A,0x5D,0xE8, // cvtpd2ps XMM3,-018h[EBP] 0x66, 0x0F,0x2A,0xDC, // cvtpi2pd XMM3,MM4 0x66, 0x0F,0x2A,0x5D,0xE0, // cvtpi2pd XMM3,-020h[EBP] 0x0F,0x2A,0xDC, // cvtpi2ps XMM3,MM4 0x0F,0x2A,0x5D,0xE0, // cvtpi2ps XMM3,-020h[EBP] 0x66, 0x0F,0x5B,0xDC, // cvtps2dq XMM3,XMM4 0x66, 0x0F,0x5B,0x5D,0xE8, // cvtps2dq XMM3,-018h[EBP] 0x0F,0x5A,0xDC, // cvtps2pd XMM3,XMM4 0x0F,0x5A,0x5D,0xE0, // cvtps2pd XMM3,-020h[EBP] 0x0F,0x2D,0xDC, // cvtps2pi MM3,XMM4 0x0F,0x2D,0x5D,0xE0, // cvtps2pi MM3,-020h[EBP] 0xF2,0x0F,0x2D,0xCC, // cvtsd2si XMM1,XMM4 0xF2,0x0F,0x2D,0x55,0xE0, // cvtsd2si XMM2,-020h[EBP] 0xF2,0x0F,0x5A,0xDC, // cvtsd2ss XMM3,XMM4 0xF2,0x0F,0x5A,0x5D,0xE0, // cvtsd2ss XMM3,-020h[EBP] 0xF2,0x0F,0x2A,0xDA, // cvtsi2sd XMM3,EDX 0xF2,0x0F,0x2A,0x5D,0xD8, // cvtsi2sd XMM3,-028h[EBP] 0xF3,0x0F,0x2A,0xDA, // cvtsi2ss XMM3,EDX 0xF3,0x0F,0x2A,0x5D,0xD8, // cvtsi2ss XMM3,-028h[EBP] 0xF3,0x0F,0x5A,0xDC, // cvtss2sd XMM3,XMM4 0xF3,0x0F,0x5A,0x5D,0xD8, // cvtss2sd XMM3,-028h[EBP] 0xF3,0x0F,0x2D,0xFC, // cvtss2si XMM7,XMM4 0xF3,0x0F,0x2D,0x7D,0xD8, // cvtss2si XMM7,-028h[EBP] 0x66, 0x0F,0x2C,0xDC, // cvttpd2pi MM3,XMM4 0x66, 0x0F,0x2C,0x7D,0xE8, // cvttpd2pi MM7,-018h[EBP] 0x66, 0x0F,0xE6,0xDC, // cvttpd2dq XMM3,XMM4 0x66, 0x0F,0xE6,0x7D,0xE8, // cvttpd2dq XMM7,-018h[EBP] 0xF3,0x0F,0x5B,0xDC, // cvttps2dq XMM3,XMM4 0xF3,0x0F,0x5B,0x7D,0xE8, // cvttps2dq XMM7,-018h[EBP] 0x0F,0x2C,0xDC, // cvttps2pi MM3,XMM4 0x0F,0x2C,0x7D,0xE0, // cvttps2pi MM7,-020h[EBP] 0xF2,0x0F,0x2C,0xC4, // cvttsd2si EAX,XMM4 0xF2,0x0F,0x2C,0x4D,0xE8, // cvttsd2si ECX,-018h[EBP] 0xF3,0x0F,0x2C,0xC4, // cvttss2si EAX,XMM4 0xF3,0x0F,0x2C,0x4D,0xD8, // cvttss2si ECX,-028h[EBP] 0x66, 0x0F,0x5E,0xE8, // divpd XMM5,XMM0 0x66, 0x0F,0x5E,0x6D,0xE8, // divpd XMM5,-018h[EBP] 0x0F,0x5E,0xE8, // divps XMM5,XMM0 0x0F,0x5E,0x6D,0xE8, // divps XMM5,-018h[EBP] 0xF2,0x0F,0x5E,0xE8, // divsd XMM5,XMM0 0xF2,0x0F,0x5E,0x6D,0xE0, // divsd XMM5,-020h[EBP] 0xF3,0x0F,0x5E,0xE8, // divss XMM5,XMM0 0xF3,0x0F,0x5E,0x6D,0xD8, // divss XMM5,-028h[EBP] 0x66, 0x0F,0xF7,0xD1, // maskmovdqu XMM2,XMM1 0x0F,0xF7,0xE3, // maskmovq MM4,MM3 0x66, 0x0F,0x5F,0xC0, // maxpd XMM0,XMM0 0x66, 0x0F,0x5F,0x4D,0xE8, // maxpd XMM1,-018h[EBP] 0x0F,0x5F,0xD1, // maxps XMM2,XMM1 0x0F,0x5F,0x5D,0xE8, // maxps XMM3,-018h[EBP] 0xF2,0x0F,0x5F,0xE2, // maxsd XMM4,XMM2 0xF2,0x0F,0x5F,0x6D,0xE0, // maxsd XMM5,-020h[EBP] 0xF3,0x0F,0x5F,0xF3, // maxss XMM6,XMM3 0xF3,0x0F,0x5F,0x7D,0xD8, // maxss XMM7,-028h[EBP] 0x66, 0x0F,0x5D,0xC0, // minpd XMM0,XMM0 0x66, 0x0F,0x5D,0x4D,0xE8, // minpd XMM1,-018h[EBP] 0x0F,0x5D,0xD1, // minps XMM2,XMM1 0x0F,0x5D,0x5D,0xE8, // minps XMM3,-018h[EBP] 0xF2,0x0F,0x5D,0xE2, // minsd XMM4,XMM2 0xF2,0x0F,0x5D,0x6D,0xE0, // minsd XMM5,-020h[EBP] 0xF3,0x0F,0x5D,0xF3, // minss XMM6,XMM3 0xF3,0x0F,0x5D,0x7D,0xD8, // minss XMM7,-028h[EBP] 0x66, 0x0F,0x28,0xCA, // movapd XMM1,XMM2 0x66, 0x0F,0x28,0x5D,0xE8, // movapd XMM3,-018h[EBP] 0x66, 0x0F,0x29,0x65,0xE8, // movapd -018h[EBP],XMM4 0x0F,0x28,0xCA, // movaps XMM1,XMM2 0x0F,0x28,0x5D,0xE8, // movaps XMM3,-018h[EBP] 0x0F,0x29,0x65,0xE8, // movaps -018h[EBP],XMM4 0x0F,0x6E,0xCB, // movd MM1,EBX 0x0F,0x6E,0x55,0xD8, // movd MM2,-028h[EBP] 0x0F,0x7E,0xDB, // movd EBX,MM3 0x0F,0x7E,0x65,0xD8, // movd -028h[EBP],MM4 0x66, 0x0F,0x6E,0xCB, // movd XMM1,EBX 0x66, 0x0F,0x6E,0x55,0xD8, // movd XMM2,-028h[EBP] 0x66, 0x0F,0x7E,0xDB, // movd EBX,XMM3 0x66, 0x0F,0x7E,0x65,0xD8, // movd -028h[EBP],XMM4 0x66, 0x0F,0x6F,0xCA, // movdqa XMM1,XMM2 0x66, 0x0F,0x6F,0x55,0xE8, // movdqa XMM2,-018h[EBP] 0x66, 0x0F,0x7F,0x65,0xE8, // movdqa -018h[EBP],XMM4 0xF3,0x0F,0x6F,0xCA, // movdqu XMM1,XMM2 0xF3,0x0F,0x6F,0x55,0xE8, // movdqu XMM2,-018h[EBP] 0xF3,0x0F,0x7F,0x65,0xE8, // movdqu -018h[EBP],XMM4 0xF2,0x0F,0xD6,0xDC, // movdq2q MM4,XMM3 0x0F,0x12,0xDC, // movhlps XMM4,XMM3 0x66, 0x0F,0x16,0x55,0xE0, // movhpd XMM2,-020h[EBP] 0x66, 0x0F,0x17,0x7D,0xE0, // movhpd -020h[EBP],XMM7 0x0F,0x16,0x55,0xE0, // movhps XMM2,-020h[EBP] 0x0F,0x17,0x7D,0xE0, // movhps -020h[EBP],XMM7 0x0F,0x16,0xDC, // movlhps XMM4,XMM3 0x66, 0x0F,0x12,0x55,0xE0, // movlpd XMM2,-020h[EBP] 0x66, 0x0F,0x13,0x7D,0xE0, // movlpd -020h[EBP],XMM7 0x0F,0x12,0x55,0xE0, // movlps XMM2,-020h[EBP] 0x0F,0x13,0x7D,0xE0, // movlps -020h[EBP],XMM7 0x66, 0x0F,0x50,0xF3, // movmskpd ESI,XMM3 0x0F,0x50,0xF3, // movmskps ESI,XMM3 0x66, 0x0F,0x59,0xC0, // mulpd XMM0,XMM0 0x66, 0x0F,0x59,0x4D,0xE8, // mulpd XMM1,-018h[EBP] 0x0F,0x59,0xD1, // mulps XMM2,XMM1 0x0F,0x59,0x5D,0xE8, // mulps XMM3,-018h[EBP] 0xF2,0x0F,0x59,0xE2, // mulsd XMM4,XMM2 0xF2,0x0F,0x59,0x6D,0xE0, // mulsd XMM5,-020h[EBP] 0xF3,0x0F,0x59,0xF3, // mulss XMM6,XMM3 0xF3,0x0F,0x59,0x7D,0xD8, // mulss XMM7,-028h[EBP] 0x66, 0x0F,0x51,0xC4, // sqrtpd XMM0,XMM4 0x66, 0x0F,0x51,0x4D,0xE8, // sqrtpd XMM1,-018h[EBP] 0x0F,0x51,0xD5, // sqrtps XMM2,XMM5 0x0F,0x51,0x5D,0xE8, // sqrtps XMM3,-018h[EBP] 0xF2,0x0F,0x51,0xE6, // sqrtsd XMM4,XMM6 0xF2,0x0F,0x51,0x6D,0xE0, // sqrtsd XMM5,-020h[EBP] 0xF3,0x0F,0x51,0xF7, // sqrtss XMM6,XMM7 0xF3,0x0F,0x51,0x7D,0xD8, // sqrtss XMM7,-028h[EBP] 0x66, 0x0F,0x5C,0xC4, // subpd XMM0,XMM4 0x66, 0x0F,0x5C,0x4D,0xE8, // subpd XMM1,-018h[EBP] 0x0F,0x5C,0xD5, // subps XMM2,XMM5 0x0F,0x5C,0x5D,0xE8, // subps XMM3,-018h[EBP] 0xF2,0x0F,0x5C,0xE6, // subsd XMM4,XMM6 0xF2,0x0F,0x5C,0x6D,0xE0, // subsd XMM5,-020h[EBP] 0xF3,0x0F,0x5C,0xF7, // subss XMM6,XMM7 0xF3,0x0F,0x5C,0x7D,0xD8, // subss XMM7,-028h[EBP] 0x0F,0x01,0xE0, // smsw EAX ]; int i; asm { call L1 ; ud2 ; syscall ; sysenter ; sysexit ; sysret ; lfence ; mfence ; sfence ; fxsave [EAX] ; fxrstor [EAX] ; ldmxcsr [EAX] ; stmxcsr [EAX] ; clflush [EAX] ; addps XMM1,[EAX] ; addps XMM1,XMM2 ; addpd XMM0,[EBX] ; addpd XMM2,XMM1 ; addsd XMM1,[EAX] ; addsd XMM1,XMM2 ; addss XMM5,[ESI] ; addss XMM6,XMM7 ; andps XMM1,[EAX] ; andps XMM1,XMM2 ; andpd XMM0,[EBX] ; andpd XMM2,XMM1 ; andnps XMM1,[EAX] ; andnps XMM1,XMM2 ; andnpd XMM0,[EBX] ; andnpd XMM2,XMM1 ; cmpsd ; cmpps XMM1,[EAX],1 ; cmpps XMM1,XMM2,2 ; cmppd XMM0,[EBX],3 ; cmppd XMM2,XMM1,4 ; cmpsd XMM1,[EAX],5 ; cmpsd XMM1,XMM2,6 ; cmpss XMM5,[ESI],7 ; cmpss XMM6,XMM7,0 ; comisd XMM1,[EAX] ; comisd XMM1,m64[EBP] ; comisd XMM1,XMM2 ; comiss XMM5,[ESI] ; comiss XMM6,XMM7 ; cvtdq2pd XMM3,XMM4 ; cvtdq2pd XMM3,m64[EBP] ; cvtdq2ps XMM3,XMM4 ; cvtdq2ps XMM3,m128[EBP] ; cvtpd2dq XMM3,XMM4 ; cvtpd2dq XMM3,m128[EBP] ; cvtpd2pi MM3,XMM4 ; cvtpd2pi MM3,m128[EBP] ; cvtpd2ps XMM3,XMM4 ; cvtpd2ps XMM3,m128[EBP] ; cvtpi2pd XMM3,MM4 ; cvtpi2pd XMM3,m64[EBP] ; cvtpi2ps XMM3,MM4 ; cvtpi2ps XMM3,m64[EBP] ; cvtps2dq XMM3,XMM4 ; cvtps2dq XMM3,m128[EBP] ; cvtps2pd XMM3,XMM4 ; cvtps2pd XMM3,m64[EBP] ; cvtps2pi MM3,XMM4 ; cvtps2pi MM3,m64[EBP] ; cvtsd2si ECX,XMM4 ; cvtsd2si EDX,m64[EBP] ; cvtsd2ss XMM3,XMM4 ; cvtsd2ss XMM3,m64[EBP] ; cvtsi2sd XMM3,EDX ; cvtsi2sd XMM3,m32[EBP] ; cvtsi2ss XMM3,EDX ; cvtsi2ss XMM3,m32[EBP] ; cvtss2sd XMM3,XMM4 ; cvtss2sd XMM3,m32[EBP] ; cvtss2si EDI,XMM4 ; cvtss2si EDI,m32[EBP] ; cvttpd2pi MM3,XMM4 ; cvttpd2pi MM7,m128[EBP] ; cvttpd2dq XMM3,XMM4 ; cvttpd2dq XMM7,m128[EBP] ; cvttps2dq XMM3,XMM4 ; cvttps2dq XMM7,m128[EBP] ; cvttps2pi MM3,XMM4 ; cvttps2pi MM7,m64[EBP] ; cvttsd2si EAX,XMM4 ; cvttsd2si ECX,m128[EBP] ; cvttss2si EAX,XMM4 ; cvttss2si ECX,m32[EBP] ; divpd XMM5,XMM0 ; divpd XMM5,m128[EBP] ; divps XMM5,XMM0 ; divps XMM5,m128[EBP] ; divsd XMM5,XMM0 ; divsd XMM5,m64[EBP] ; divss XMM5,XMM0 ; divss XMM5,m32[EBP] ; maskmovdqu XMM1,XMM2 ; maskmovq MM3,MM4 ; maxpd XMM0,XMM0 ; maxpd XMM1,m128[EBP] ; maxps XMM2,XMM1 ; maxps XMM3,m128[EBP] ; maxsd XMM4,XMM2 ; maxsd XMM5,m64[EBP] ; maxss XMM6,XMM3 ; maxss XMM7,m32[EBP] ; minpd XMM0,XMM0 ; minpd XMM1,m128[EBP] ; minps XMM2,XMM1 ; minps XMM3,m128[EBP] ; minsd XMM4,XMM2 ; minsd XMM5,m64[EBP] ; minss XMM6,XMM3 ; minss XMM7,m32[EBP] ; movapd XMM1,XMM2 ; movapd XMM3,m128[EBP] ; movapd m128[EBP],XMM4 ; movaps XMM1,XMM2 ; movaps XMM3,m128[EBP] ; movaps m128[EBP],XMM4 ; movd MM1,EBX ; movd MM2,m32[EBP] ; movd EBX,MM3 ; movd m32[EBP],MM4 ; movd XMM1,EBX ; movd XMM2,m32[EBP] ; movd EBX,XMM3 ; movd m32[EBP],XMM4 ; movdqa XMM1,XMM2 ; movdqa XMM2,m128[EBP] ; movdqa m128[EBP],XMM4 ; movdqu XMM1,XMM2 ; movdqu XMM2,m128[EBP] ; movdqu m128[EBP],XMM4 ; movdq2q MM3,XMM4 ; movhlps XMM3,XMM4 ; movhpd XMM2,m64[EBP] ; movhpd m64[EBP],XMM7 ; movhps XMM2,m64[EBP] ; movhps m64[EBP],XMM7 ; movlhps XMM3,XMM4 ; movlpd XMM2,m64[EBP] ; movlpd m64[EBP],XMM7 ; movlps XMM2,m64[EBP] ; movlps m64[EBP],XMM7 ; movmskpd ESI,XMM3 ; movmskps ESI,XMM3 ; mulpd XMM0,XMM0 ; mulpd XMM1,m128[EBP] ; mulps XMM2,XMM1 ; mulps XMM3,m128[EBP] ; mulsd XMM4,XMM2 ; mulsd XMM5,m64[EBP] ; mulss XMM6,XMM3 ; mulss XMM7,m32[EBP] ; sqrtpd XMM0,XMM4 ; sqrtpd XMM1,m128[EBP] ; sqrtps XMM2,XMM5 ; sqrtps XMM3,m128[EBP] ; sqrtsd XMM4,XMM6 ; sqrtsd XMM5,m64[EBP] ; sqrtss XMM6,XMM7 ; sqrtss XMM7,m32[EBP] ; subpd XMM0,XMM4 ; subpd XMM1,m128[EBP] ; subps XMM2,XMM5 ; subps XMM3,m128[EBP] ; subsd XMM4,XMM6 ; subsd XMM5,m64[EBP] ; subss XMM6,XMM7 ; subss XMM7,m32[EBP] ; smsw EAX ; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { //printf("[%d] = %02x %02x\n", i, p[i], data[i]); assert(p[i] == data[i]); } } /****************************************************/ void test14() { byte m8; short m16; int m32; long m64; M128 m128; ubyte *p; static ubyte data[] = [ 0x66, 0x0F,0x50,0xF3, // movmskpd ESI,XMM3 0x0F,0x50,0xF3, // movmskps ESI,XMM3 0x66, 0x0F,0xE7,0x55,0xE8, // movntdq -018h[EBP],XMM2 0x0F,0xC3,0x4D,0xDC, // movnti -024h[EBP],ECX 0x66, 0x0F,0x2B,0x5D,0xE8, // movntpd -018h[EBP],XMM3 0x0F,0x2B,0x65,0xE8, // movntps -018h[EBP],XMM4 0x0F,0xE7,0x6D,0xE0, // movntq -020h[EBP],MM5 0x0F,0x6F,0xCA, // movq MM1,MM2 0x0F,0x6F,0x55,0xE0, // movq MM2,-020h[EBP] 0x0F,0x7F,0x5D,0xE0, // movq -020h[EBP],MM3 0xF3,0x0F,0x7E,0xCA, // movq XMM1,XMM2 0xF3,0x0F,0x7E,0x55,0xE0, // movq XMM2,-020h[EBP] 0x66, 0x0F,0xD6,0x5D,0xE0, // movq -020h[EBP],XMM3 0xF3,0x0F,0xD6,0xDA, // movq2dq XMM3,MM2 0xA5, // movsd 0xF2,0x0F,0x10,0xCA, // movsd XMM1,XMM2 0xF2,0x0F,0x10,0x5D,0xE0, // movsd XMM3,-020h[EBP] 0xF2,0x0F,0x11,0x65,0xE0, // movsd -020h[EBP],XMM4 0xF3,0x0F,0x10,0xCA, // movss XMM1,XMM2 0xF3,0x0F,0x10,0x5D,0xDC, // movss XMM3,-024h[EBP] 0xF3,0x0F,0x11,0x65,0xDC, // movss -024h[EBP],XMM4 0x66, 0x0F,0x10,0xCA, // movupd XMM1,XMM2 0x66, 0x0F,0x10,0x5D,0xE8, // movupd XMM3,-018h[EBP] 0x66, 0x0F,0x11,0x65,0xE8, // movupd -018h[EBP],XMM4 0x0F,0x10,0xCA, // movups XMM1,XMM2 0x0F,0x10,0x5D,0xE8, // movups XMM3,-018h[EBP] 0x0F,0x11,0x65,0xE8, // movups -018h[EBP],XMM4 0x66, 0x0F,0x56,0xCA, // orpd XMM1,XMM2 0x66, 0x0F,0x56,0x5D,0xE8, // orpd XMM3,-018h[EBP] 0x0F,0x56,0xCA, // orps XMM1,XMM2 0x0F,0x56,0x5D,0xE8, // orps XMM3,-018h[EBP] 0x0F,0x63,0xCA, // packsswb MM1,MM2 0x0F,0x63,0x5D,0xE0, // packsswb MM3,-020h[EBP] 0x66, 0x0F,0x63,0xCA, // packsswb XMM1,XMM2 0x66, 0x0F,0x63,0x5D,0xE8, // packsswb XMM3,-018h[EBP] 0x0F,0x6B,0xCA, // packssdw MM1,MM2 0x0F,0x6B,0x5D,0xE0, // packssdw MM3,-020h[EBP] 0x66, 0x0F,0x6B,0xCA, // packssdw XMM1,XMM2 0x66, 0x0F,0x6B,0x5D,0xE8, // packssdw XMM3,-018h[EBP] 0x0F,0x67,0xCA, // packuswb MM1,MM2 0x0F,0x67,0x5D,0xE0, // packuswb MM3,-020h[EBP] 0x66, 0x0F,0x67,0xCA, // packuswb XMM1,XMM2 0x66, 0x0F,0x67,0x5D,0xE8, // packuswb XMM3,-018h[EBP] 0x0F,0xFC,0xCA, // paddb MM1,MM2 0x0F,0xFC,0x5D,0xE0, // paddb MM3,-020h[EBP] 0x66, 0x0F,0xFC,0xCA, // paddb XMM1,XMM2 0x66, 0x0F,0xFC,0x5D,0xE8, // paddb XMM3,-018h[EBP] 0x0F,0xFD,0xCA, // paddw MM1,MM2 0x0F,0xFD,0x5D,0xE0, // paddw MM3,-020h[EBP] 0x66, 0x0F,0xFD,0xCA, // paddw XMM1,XMM2 0x66, 0x0F,0xFD,0x5D,0xE8, // paddw XMM3,-018h[EBP] 0x0F,0xFE,0xCA, // paddd MM1,MM2 0x0F,0xFE,0x5D,0xE0, // paddd MM3,-020h[EBP] 0x66, 0x0F,0xFE,0xCA, // paddd XMM1,XMM2 0x66, 0x0F,0xFE,0x5D,0xE8, // paddd XMM3,-018h[EBP] 0x0F,0xD4,0xCA, // paddq MM1,MM2 0x0F,0xD4,0x5D,0xE0, // paddq MM3,-020h[EBP] 0x66, 0x0F,0xD4,0xCA, // paddq XMM1,XMM2 0x66, 0x0F,0xD4,0x5D,0xE8, // paddq XMM3,-018h[EBP] 0x0F,0xEC,0xCA, // paddsb MM1,MM2 0x0F,0xEC,0x5D,0xE0, // paddsb MM3,-020h[EBP] 0x66, 0x0F,0xEC,0xCA, // paddsb XMM1,XMM2 0x66, 0x0F,0xEC,0x5D,0xE8, // paddsb XMM3,-018h[EBP] 0x0F,0xED,0xCA, // paddsw MM1,MM2 0x0F,0xED,0x5D,0xE0, // paddsw MM3,-020h[EBP] 0x66, 0x0F,0xED,0xCA, // paddsw XMM1,XMM2 0x66, 0x0F,0xED,0x5D,0xE8, // paddsw XMM3,-018h[EBP] 0x0F,0xDC,0xCA, // paddusb MM1,MM2 0x0F,0xDC,0x5D,0xE0, // paddusb MM3,-020h[EBP] 0x66, 0x0F,0xDC,0xCA, // paddusb XMM1,XMM2 0x66, 0x0F,0xDC,0x5D,0xE8, // paddusb XMM3,-018h[EBP] 0x0F,0xDD,0xCA, // paddusw MM1,MM2 0x0F,0xDD,0x5D,0xE0, // paddusw MM3,-020h[EBP] 0x66, 0x0F,0xDD,0xCA, // paddusw XMM1,XMM2 0x66, 0x0F,0xDD,0x5D,0xE8, // paddusw XMM3,-018h[EBP] 0x0F,0xDB,0xCA, // pand MM1,MM2 0x0F,0xDB,0x5D,0xE0, // pand MM3,-020h[EBP] 0x66, 0x0F,0xDB,0xCA, // pand XMM1,XMM2 0x66, 0x0F,0xDB,0x5D,0xE8, // pand XMM3,-018h[EBP] 0x0F,0xDF,0xCA, // pandn MM1,MM2 0x0F,0xDF,0x5D,0xE0, // pandn MM3,-020h[EBP] 0x66, 0x0F,0xDF,0xCA, // pandn XMM1,XMM2 0x66, 0x0F,0xDF,0x5D,0xE8, // pandn XMM3,-018h[EBP] 0x0F,0xE0,0xCA, // pavgb MM1,MM2 0x0F,0xE0,0x5D,0xE0, // pavgb MM3,-020h[EBP] 0x66, 0x0F,0xE0,0xCA, // pavgb XMM1,XMM2 0x66, 0x0F,0xE0,0x5D,0xE8, // pavgb XMM3,-018h[EBP] 0x0F,0xE3,0xCA, // pavgw MM1,MM2 0x0F,0xE3,0x5D,0xE0, // pavgw MM3,-020h[EBP] 0x66, 0x0F,0xE3,0xCA, // pavgw XMM1,XMM2 0x66, 0x0F,0xE3,0x5D,0xE8, // pavgw XMM3,-018h[EBP] 0x0F,0x74,0xCA, // pcmpeqb MM1,MM2 0x0F,0x74,0x5D,0xE0, // pcmpeqb MM3,-020h[EBP] 0x66, 0x0F,0x74,0xCA, // pcmpeqb XMM1,XMM2 0x66, 0x0F,0x74,0x5D,0xE8, // pcmpeqb XMM3,-018h[EBP] 0x0F,0x75,0xCA, // pcmpeqw MM1,MM2 0x0F,0x75,0x5D,0xE0, // pcmpeqw MM3,-020h[EBP] 0x66, 0x0F,0x75,0xCA, // pcmpeqw XMM1,XMM2 0x66, 0x0F,0x75,0x5D,0xE8, // pcmpeqw XMM3,-018h[EBP] 0x0F,0x76,0xCA, // pcmpeqd MM1,MM2 0x0F,0x76,0x5D,0xE0, // pcmpeqd MM3,-020h[EBP] 0x66, 0x0F,0x76,0xCA, // pcmpeqd XMM1,XMM2 0x66, 0x0F,0x76,0x5D,0xE8, // pcmpeqd XMM3,-018h[EBP] 0x0F,0x64,0xCA, // pcmpgtb MM1,MM2 0x0F,0x64,0x5D,0xE0, // pcmpgtb MM3,-020h[EBP] 0x66, 0x0F,0x64,0xCA, // pcmpgtb XMM1,XMM2 0x66, 0x0F,0x64,0x5D,0xE8, // pcmpgtb XMM3,-018h[EBP] 0x0F,0x65,0xCA, // pcmpgtw MM1,MM2 0x0F,0x65,0x5D,0xE0, // pcmpgtw MM3,-020h[EBP] 0x66, 0x0F,0x65,0xCA, // pcmpgtw XMM1,XMM2 0x66, 0x0F,0x65,0x5D,0xE8, // pcmpgtw XMM3,-018h[EBP] 0x0F,0x66,0xCA, // pcmpgtd MM1,MM2 0x0F,0x66,0x5D,0xE0, // pcmpgtd MM3,-020h[EBP] 0x66, 0x0F,0x66,0xCA, // pcmpgtd XMM1,XMM2 0x66, 0x0F,0x66,0x5D,0xE8, // pcmpgtd XMM3,-018h[EBP] 0x0F,0xC5,0xD6,0x07, // pextrw EDX,MM6,7 0x66, 0x0F,0xC5,0xD6,0x07, // pextrw EDX,XMM6,7 0x0F,0xC4,0xF2,0x07, // pinsrw MM6,EDX,7 0x0F,0xC4,0x75,0xDA,0x07, // pinsrw MM6,-026h[EBP],7 0x66, 0x0F,0xC4,0xF2,0x07, // pinsrw XMM6,EDX,7 0x66, 0x0F,0xC4,0x75,0xDA,0x07, // pinsrw XMM6,-026h[EBP],7 0x0F,0xF5,0xCA, // pmaddwd MM1,MM2 0x0F,0xF5,0x5D,0xE0, // pmaddwd MM3,-020h[EBP] 0x66, 0x0F,0xF5,0xCA, // pmaddwd XMM1,XMM2 0x66, 0x0F,0xF5,0x5D,0xE8, // pmaddwd XMM3,-018h[EBP] 0x0F,0xEE,0xCA, // pmaxsw MM1,XMM2 0x0F,0xEE,0x5D,0xE0, // pmaxsw MM3,-020h[EBP] 0x66, 0x0F,0xEE,0xCA, // pmaxsw XMM1,XMM2 0x66, 0x0F,0xEE,0x5D,0xE8, // pmaxsw XMM3,-018h[EBP] 0x0F,0xDE,0xCA, // pmaxub MM1,XMM2 0x0F,0xDE,0x5D,0xE0, // pmaxub MM3,-020h[EBP] 0x66, 0x0F,0xDE,0xCA, // pmaxub XMM1,XMM2 0x66, 0x0F,0xDE,0x5D,0xE8, // pmaxub XMM3,-018h[EBP] 0x0F,0xEA,0xCA, // pminsw MM1,MM2 0x0F,0xEA,0x5D,0xE0, // pminsw MM3,-020h[EBP] 0x66, 0x0F,0xEA,0xCA, // pminsw XMM1,XMM2 0x66, 0x0F,0xEA,0x5D,0xE8, // pminsw XMM3,-018h[EBP] 0x0F,0xDA,0xCA, // pminub MM1,MM2 0x0F,0xDA,0x5D,0xE0, // pminub MM3,-020h[EBP] 0x66, 0x0F,0xDA,0xCA, // pminub XMM1,XMM2 0x66, 0x0F,0xDA,0x5D,0xE8, // pminub XMM3,-018h[EBP] 0x0F,0xD7,0xC8, // pmovmskb ECX,MM0 0x66, 0x0F,0xD7,0xCE, // pmovmskb ECX,XMM6 0x0F,0xE4,0xCA, // pmulhuw MM1,MM2 0x0F,0xE4,0x5D,0xE0, // pmulhuw MM3,-020h[EBP] 0x66, 0x0F,0xE4,0xCA, // pmulhuw XMM1,XMM2 0x66, 0x0F,0xE4,0x5D,0xE8, // pmulhuw XMM3,-018h[EBP] 0x0F,0xE5,0xCA, // pmulhw MM1,MM2 0x0F,0xE5,0x5D,0xE0, // pmulhw MM3,-020h[EBP] 0x66, 0x0F,0xE5,0xCA, // pmulhw XMM1,XMM2 0x66, 0x0F,0xE5,0x5D,0xE8, // pmulhw XMM3,-018h[EBP] 0x0F,0xD5,0xCA, // pmullw MM1,MM2 0x0F,0xD5,0x5D,0xE0, // pmullw MM3,-020h[EBP] 0x66, 0x0F,0xD5,0xCA, // pmullw XMM1,XMM2 0x66, 0x0F,0xD5,0x5D,0xE8, // pmullw XMM3,-018h[EBP] 0x0F,0xF4,0xCA, // pmuludq MM1,MM2 0x0F,0xF4,0x5D,0xE0, // pmuludq MM3,-020h[EBP] 0x66, 0x0F,0xF4,0xCA, // pmuludq XMM1,XMM2 0x66, 0x0F,0xF4,0x5D,0xE8, // pmuludq XMM3,-018h[EBP] 0x0F,0xEB,0xCA, // por MM1,MM2 0x0F,0xEB,0x5D,0xE0, // por MM3,-020h[EBP] 0x66, 0x0F,0xEB,0xCA, // por XMM1,XMM2 0x66, 0x0F,0xEB,0x5D,0xE8, // por XMM3,-018h[EBP] 0x0F,0x18,0x4D,0xD8, // prefetcht0 -028h[EBP] 0x0F,0x18,0x55,0xD8, // prefetcht1 -028h[EBP] 0x0F,0x18,0x5D,0xD8, // prefetcht2 -028h[EBP] 0x0F,0x18,0x45,0xD8, // prefetchnta -028h[EBP] 0x0F,0xF6,0xCA, // psadbw MM1,MM2 0x0F,0xF6,0x5D,0xE0, // psadbw MM3,-020h[EBP] 0x66, 0x0F,0xF6,0xCA, // psadbw XMM1,XMM2 0x66, 0x0F,0xF6,0x5D,0xE8, // psadbw XMM3,-018h[EBP] 0x66, 0x0F,0x70,0xCA,0x03, // pshufd XMM1,XMM2 0x66, 0x0F,0x70,0x5D,0xE8,0x03, // pshufd XMM3,-018h[EBP] 0xF3,0x0F,0x70,0xCA,0x03, // pshufhw XMM1,XMM2 0xF3,0x0F,0x70,0x5D,0xE8,0x03, // pshufhw XMM3,-018h[EBP] 0xF2,0x0F,0x70,0xCA,0x03, // pshuflw XMM1,XMM2 0xF2,0x0F,0x70,0x5D,0xE8,0x03, // pshuflw XMM3,-018h[EBP] 0x0F,0x70,0xCA,0x03, // pshufw MM1,MM2 0x0F,0x70,0x5D,0xE0,0x03, // pshufw MM3,-020h[EBP] 0x66, 0x0F,0x73,0xF9,0x18, // pslldq XMM1,018h 0x0F,0xF1,0xCA, // psllw MM1,MM2 0x0F,0xF1,0x4D,0xE0, // psllw MM1,-020h[EBP] 0x66, 0x0F,0xF1,0xCA, // psllw XMM1,XMM2 0x66, 0x0F,0xF1,0x4D,0xE8, // psllw XMM1,-018h[EBP] 0x0F,0x71,0xF1,0x15, // psraw MM1,015h 0x66, 0x0F,0x71,0xF1,0x15, // psraw XMM1,015h 0x0F,0xF2,0xCA, // pslld MM1,MM2 0x0F,0xF2,0x4D,0xE0, // pslld MM1,-020h[EBP] 0x66, 0x0F,0xF2,0xCA, // pslld XMM1,XMM2 0x66, 0x0F,0xF2,0x4D,0xE8, // pslld XMM1,-018h[EBP] 0x0F,0x72,0xF1,0x15, // psrad MM1,015h 0x66, 0x0F,0x72,0xF1,0x15, // psrad XMM1,015h 0x0F,0xF3,0xCA, // psllq MM1,MM2 0x0F,0xF3,0x4D,0xE0, // psllq MM1,-020h[EBP] 0x66, 0x0F,0xF3,0xCA, // psllq XMM1,XMM2 0x66, 0x0F,0xF3,0x4D,0xE8, // psllq XMM1,-018h[EBP] 0x0F,0x73,0xF1,0x15, // psllq MM1,015h 0x66, 0x0F,0x73,0xF1,0x15, // psllq XMM1,015h 0x0F,0xE1,0xCA, // psraw MM1,MM2 0x0F,0xE1,0x4D,0xE0, // psraw MM1,-020h[EBP] 0x66, 0x0F,0xE1,0xCA, // psraw XMM1,XMM2 0x66, 0x0F,0xE1,0x4D,0xE8, // psraw XMM1,-018h[EBP] 0x0F,0x71,0xE1,0x15, // psraw MM1,015h 0x66, 0x0F,0x71,0xE1,0x15, // psraw XMM1,015h 0x0F,0xE2,0xCA, // psrad MM1,MM2 0x0F,0xE2,0x4D,0xE0, // psrad MM1,-020h[EBP] 0x66, 0x0F,0xE2,0xCA, // psrad XMM1,XMM2 0x66, 0x0F,0xE2,0x4D,0xE8, // psrad XMM1,-018h[EBP] 0x0F,0x72,0xE1,0x15, // psrad MM1,015h 0x66, 0x0F,0x72,0xE1,0x15, // psrad XMM1,015h 0x66, 0x0F,0x73,0xD9,0x18, // psrldq XMM1,018h 0x0F,0xD1,0xCA, // psrlw MM1,MM2 0x0F,0xD1,0x4D,0xE0, // psrlw MM1,-020h[EBP] 0x66, 0x0F,0xD1,0xCA, // psrlw XMM1,XMM2 0x66, 0x0F,0xD1,0x4D,0xE8, // psrlw XMM1,-018h[EBP] 0x0F,0x71,0xD1,0x15, // psrlw MM1,015h 0x66, 0x0F,0x71,0xD1,0x15, // psrlw XMM1,015h 0x0F,0xD2,0xCA, // psrld MM1,MM2 0x0F,0xD2,0x4D,0xE0, // psrld MM1,-020h[EBP] 0x66, 0x0F,0xD2,0xCA, // psrld XMM1,XMM2 0x66, 0x0F,0xD2,0x4D,0xE8, // psrld XMM1,-018h[EBP] 0x0F,0x72,0xD1,0x15, // psrld MM1,015h 0x66, 0x0F,0x72,0xD1,0x15, // psrld XMM1,015h 0x0F,0xD3,0xCA, // psrlq MM1,MM2 0x0F,0xD3,0x4D,0xE0, // psrlq MM1,-020h[EBP] 0x66, 0x0F,0xD3,0xCA, // psrlq XMM1,XMM2 0x66, 0x0F,0xD3,0x4D,0xE8, // psrlq XMM1,-018h[EBP] 0x0F,0x73,0xD1,0x15, // psrlq MM1,015h 0x66, 0x0F,0x73,0xD1,0x15, // psrlq XMM1,015h 0x0F,0xF8,0xCA, // psubb MM1,MM2 0x0F,0xF8,0x4D,0xE0, // psubb MM1,-020h[EBP] 0x66, 0x0F,0xF8,0xCA, // psubb XMM1,XMM2 0x66, 0x0F,0xF8,0x4D,0xE8, // psubb XMM1,-018h[EBP] 0x0F,0xF9,0xCA, // psubw MM1,MM2 0x0F,0xF9,0x4D,0xE0, // psubw MM1,-020h[EBP] 0x66, 0x0F,0xF9,0xCA, // psubw XMM1,XMM2 0x66, 0x0F,0xF9,0x4D,0xE8, // psubw XMM1,-018h[EBP] 0x0F,0xFA,0xCA, // psubd MM1,MM2 0x0F,0xFA,0x4D,0xE0, // psubd MM1,-020h[EBP] 0x66, 0x0F,0xFA,0xCA, // psubd XMM1,XMM2 0x66, 0x0F,0xFA,0x4D,0xE8, // psubd XMM1,-018h[EBP] 0x0F,0xFB,0xCA, // psubq MM1,MM2 0x0F,0xFB,0x4D,0xE0, // psubq MM1,-020h[EBP] 0x66, 0x0F,0xFB,0xCA, // psubq XMM1,XMM2 0x66, 0x0F,0xFB,0x4D,0xE8, // psubq XMM1,-018h[EBP] 0x0F,0xE8,0xCA, // psubsb MM1,MM2 0x0F,0xE8,0x4D,0xE0, // psubsb MM1,-020h[EBP] 0x66, 0x0F,0xE8,0xCA, // psubsb XMM1,XMM2 0x66, 0x0F,0xE8,0x4D,0xE8, // psubsb XMM1,-018h[EBP] 0x0F,0xE9,0xCA, // psubsw MM1,MM2 0x0F,0xE9,0x4D,0xE0, // psubsw MM1,-020h[EBP] 0x66, 0x0F,0xE9,0xCA, // psubsw XMM1,XMM2 0x66, 0x0F,0xE9,0x4D,0xE8, // psubsw XMM1,-018h[EBP] 0x0F,0xD8,0xCA, // psubusb MM1,MM2 0x0F,0xD8,0x4D,0xE0, // psubusb MM1,-020h[EBP] 0x66, 0x0F,0xD8,0xCA, // psubusb XMM1,XMM2 0x66, 0x0F,0xD8,0x4D,0xE8, // psubusb XMM1,-018h[EBP] 0x0F,0xD9,0xCA, // psubusw MM1,MM2 0x0F,0xD9,0x4D,0xE0, // psubusw MM1,-020h[EBP] 0x66, 0x0F,0xD9,0xCA, // psubusw XMM1,XMM2 0x66, 0x0F,0xD9,0x4D,0xE8, // psubusw XMM1,-018h[EBP] 0x0F,0x68,0xCA, // punpckhbw MM1,MM2 0x0F,0x68,0x4D,0xE0, // punpckhbw MM1,-020h[EBP] 0x66, 0x0F,0x68,0xCA, // punpckhbw XMM1,XMM2 0x66, 0x0F,0x68,0x4D,0xE8, // punpckhbw XMM1,-018h[EBP] 0x0F,0x69,0xCA, // punpckhwd MM1,MM2 0x0F,0x69,0x4D,0xE0, // punpckhwd MM1,-020h[EBP] 0x66, 0x0F,0x69,0xCA, // punpckhwd XMM1,XMM2 0x66, 0x0F,0x69,0x4D,0xE8, // punpckhwd XMM1,-018h[EBP] 0x0F,0x6A,0xCA, // punpckhdq MM1,MM2 0x0F,0x6A,0x4D,0xE0, // punpckhdq MM1,-020h[EBP] 0x66, 0x0F,0x6A,0xCA, // punpckhdq XMM1,XMM2 0x66, 0x0F,0x6A,0x4D,0xE8, // punpckhdq XMM1,-018h[EBP] 0x66, 0x0F,0x6D,0xCA, // punpckhqdq XMM1,XMM2 0x66, 0x0F,0x6D,0x4D,0xE8, // punpckhqdq XMM1,-018h[EBP] 0x0F,0x60,0xCA, // punpcklbw MM1,MM2 0x0F,0x60,0x4D,0xE0, // punpcklbw MM1,-020h[EBP] 0x66, 0x0F,0x60,0xCA, // punpcklbw XMM1,XMM2 0x66, 0x0F,0x60,0x4D,0xE8, // punpcklbw XMM1,-018h[EBP] 0x0F,0x61,0xCA, // punpcklwd MM1,MM2 0x0F,0x61,0x4D,0xE0, // punpcklwd MM1,-020h[EBP] 0x66, 0x0F,0x61,0xCA, // punpcklwd XMM1,XMM2 0x66, 0x0F,0x61,0x4D,0xE8, // punpcklwd XMM1,-018h[EBP] 0x0F,0x62,0xCA, // punpckldq MM1,MM2 0x0F,0x62,0x4D,0xE0, // punpckldq MM1,-020h[EBP] 0x66, 0x0F,0x62,0xCA, // punpckldq XMM1,XMM2 0x66, 0x0F,0x62,0x4D,0xE8, // punpckldq XMM1,-018h[EBP] 0x66, 0x0F,0x6C,0xCA, // punpcklqdq XMM1,XMM2 0x66, 0x0F,0x6C,0x4D,0xE8, // punpcklqdq XMM1,-018h[EBP] 0x0F,0xEF,0xCA, // pxor MM1,MM2 0x0F,0xEF,0x4D,0xE0, // pxor MM1,-020h[EBP] 0x66, 0x0F,0xEF,0xCA, // pxor XMM1,XMM2 0x66, 0x0F,0xEF,0x4D,0xE8, // pxor XMM1,-018h[EBP] 0x0F,0x53,0xCA, // rcpps XMM1,XMM2 0x0F,0x53,0x4D,0xE8, // rcpps XMM1,-018h[EBP] 0xF3,0x0F,0x53,0xCA, // rcpss XMM1,XMM2 0xF3,0x0F,0x53,0x4D,0xDC, // rcpss XMM1,-024h[EBP] 0x0F,0x52,0xCA, // rsqrtps XMM1,XMM2 0x0F,0x52,0x4D,0xE8, // rsqrtps XMM1,-018h[EBP] 0xF3,0x0F,0x52,0xCA, // rsqrtss XMM1,XMM2 0xF3,0x0F,0x52,0x4D,0xDC, // rsqrtss XMM1,-024h[EBP] 0x66, 0x0F,0xC6,0xCA,0x03, // shufpd XMM1,XMM2,3 0x66, 0x0F,0xC6,0x4D,0xE8,0x04, // shufpd XMM1,-018h[EBP],4 0x0F,0xC6,0xCA,0x03, // shufps XMM1,XMM2,3 0x0F,0xC6,0x4D,0xE8,0x04, // shufps XMM1,-018h[EBP],4 0x66, 0x0F,0x2E,0xE6, // ucimisd XMM4,XMM6 0x66, 0x0F,0x2E,0x6D,0xE0, // ucimisd XMM5,-020h[EBP] 0x0F,0x2E,0xF7, // ucomiss XMM6,XMM7 0x0F,0x2E,0x7D,0xDC, // ucomiss XMM7,-024h[EBP] 0x66, 0x0F,0x15,0xE6, // uppckhpd XMM4,XMM6 0x66, 0x0F,0x15,0x6D,0xE8, // uppckhpd XMM5,-018h[EBP] 0x0F,0x15,0xE6, // unpckhps XMM4,XMM6 0x0F,0x15,0x6D,0xE8, // unpckhps XMM5,-018h[EBP] 0x66, 0x0F,0x14,0xE6, // uppcklpd XMM4,XMM6 0x66, 0x0F,0x14,0x6D,0xE8, // uppcklpd XMM5,-018h[EBP] 0x0F,0x14,0xE6, // unpcklps XMM4,XMM6 0x0F,0x14,0x6D,0xE8, // unpcklps XMM5,-018h[EBP] 0x66, 0x0F,0x57,0xCA, // xorpd XMM1,XMM2 0x66, 0x0F,0x57,0x4D,0xE8, // xorpd XMM1,-018h[EBP] 0x0F,0x57,0xCA, // xorps XMM1,XMM2 0x0F,0x57,0x4D,0xE8, // xorps XMM1,-018h[EBP] ]; int i; asm { call L1 ; movmskpd ESI,XMM3 ; movmskps ESI,XMM3 ; movntdq m128[EBP],XMM2 ; movnti m32[EBP],ECX ; movntpd m128[EBP],XMM3 ; movntps m128[EBP],XMM4 ; movntq m64[EBP],MM5 ; movq MM1,MM2 ; movq MM2,m64[EBP] ; movq m64[EBP],MM3 ; movq XMM1,XMM2 ; movq XMM2,m64[EBP] ; movq m64[EBP],XMM3 ; movq2dq XMM3,MM2 ; movsd ; movsd XMM1,XMM2 ; movsd XMM3,m64[EBP] ; movsd m64[EBP],XMM4 ; movss XMM1,XMM2 ; movss XMM3,m32[EBP] ; movss m32[EBP],XMM4 ; movupd XMM1,XMM2 ; movupd XMM3,m128[EBP] ; movupd m128[EBP],XMM4 ; movups XMM1,XMM2 ; movups XMM3,m128[EBP] ; movups m128[EBP],XMM4 ; orpd XMM1,XMM2 ; orpd XMM3,m128[EBP] ; orps XMM1,XMM2 ; orps XMM3,m128[EBP] ; packsswb MM1,MM2 ; packsswb MM3,m64[EBP] ; packsswb XMM1,XMM2 ; packsswb XMM3,m128[EBP] ; packssdw MM1,MM2 ; packssdw MM3,m64[EBP] ; packssdw XMM1,XMM2 ; packssdw XMM3,m128[EBP] ; packuswb MM1,MM2 ; packuswb MM3,m64[EBP] ; packuswb XMM1,XMM2 ; packuswb XMM3,m128[EBP] ; paddb MM1,MM2 ; paddb MM3,m64[EBP] ; paddb XMM1,XMM2 ; paddb XMM3,m128[EBP] ; paddw MM1,MM2 ; paddw MM3,m64[EBP] ; paddw XMM1,XMM2 ; paddw XMM3,m128[EBP] ; paddd MM1,MM2 ; paddd MM3,m64[EBP] ; paddd XMM1,XMM2 ; paddd XMM3,m128[EBP] ; paddq MM1,MM2 ; paddq MM3,m64[EBP] ; paddq XMM1,XMM2 ; paddq XMM3,m128[EBP] ; paddsb MM1,MM2 ; paddsb MM3,m64[EBP] ; paddsb XMM1,XMM2 ; paddsb XMM3,m128[EBP] ; paddsw MM1,MM2 ; paddsw MM3,m64[EBP] ; paddsw XMM1,XMM2 ; paddsw XMM3,m128[EBP] ; paddusb MM1,MM2 ; paddusb MM3,m64[EBP] ; paddusb XMM1,XMM2 ; paddusb XMM3,m128[EBP] ; paddusw MM1,MM2 ; paddusw MM3,m64[EBP] ; paddusw XMM1,XMM2 ; paddusw XMM3,m128[EBP] ; pand MM1,MM2 ; pand MM3,m64[EBP] ; pand XMM1,XMM2 ; pand XMM3,m128[EBP] ; pandn MM1,MM2 ; pandn MM3,m64[EBP] ; pandn XMM1,XMM2 ; pandn XMM3,m128[EBP] ; pavgb MM1,MM2 ; pavgb MM3,m64[EBP] ; pavgb XMM1,XMM2 ; pavgb XMM3,m128[EBP] ; pavgw MM1,MM2 ; pavgw MM3,m64[EBP] ; pavgw XMM1,XMM2 ; pavgw XMM3,m128[EBP] ; pcmpeqb MM1,MM2 ; pcmpeqb MM3,m64[EBP] ; pcmpeqb XMM1,XMM2 ; pcmpeqb XMM3,m128[EBP] ; pcmpeqw MM1,MM2 ; pcmpeqw MM3,m64[EBP] ; pcmpeqw XMM1,XMM2 ; pcmpeqw XMM3,m128[EBP] ; pcmpeqd MM1,MM2 ; pcmpeqd MM3,m64[EBP] ; pcmpeqd XMM1,XMM2 ; pcmpeqd XMM3,m128[EBP] ; pcmpgtb MM1,MM2 ; pcmpgtb MM3,m64[EBP] ; pcmpgtb XMM1,XMM2 ; pcmpgtb XMM3,m128[EBP] ; pcmpgtw MM1,MM2 ; pcmpgtw MM3,m64[EBP] ; pcmpgtw XMM1,XMM2 ; pcmpgtw XMM3,m128[EBP] ; pcmpgtd MM1,MM2 ; pcmpgtd MM3,m64[EBP] ; pcmpgtd XMM1,XMM2 ; pcmpgtd XMM3,m128[EBP] ; pextrw EDX,MM6,7 ; pextrw EDX,XMM6,7 ; pinsrw MM6,EDX,7 ; pinsrw MM6,m16[EBP],7 ; pinsrw XMM6,EDX,7 ; pinsrw XMM6,m16[EBP],7 ; pmaddwd MM1,MM2 ; pmaddwd MM3,m64[EBP] ; pmaddwd XMM1,XMM2 ; pmaddwd XMM3,m128[EBP] ; pmaxsw MM1,MM2 ; pmaxsw MM3,m64[EBP] ; pmaxsw XMM1,XMM2 ; pmaxsw XMM3,m128[EBP] ; pmaxub MM1,MM2 ; pmaxub MM3,m64[EBP] ; pmaxub XMM1,XMM2 ; pmaxub XMM3,m128[EBP] ; pminsw MM1,MM2 ; pminsw MM3,m64[EBP] ; pminsw XMM1,XMM2 ; pminsw XMM3,m128[EBP] ; pminub MM1,MM2 ; pminub MM3,m64[EBP] ; pminub XMM1,XMM2 ; pminub XMM3,m128[EBP] ; pmovmskb ECX,MM0 ; pmovmskb ECX,XMM6 ; pmulhuw MM1,MM2 ; pmulhuw MM3,m64[EBP] ; pmulhuw XMM1,XMM2 ; pmulhuw XMM3,m128[EBP] ; pmulhw MM1,MM2 ; pmulhw MM3,m64[EBP] ; pmulhw XMM1,XMM2 ; pmulhw XMM3,m128[EBP] ; pmullw MM1,MM2 ; pmullw MM3,m64[EBP] ; pmullw XMM1,XMM2 ; pmullw XMM3,m128[EBP] ; pmuludq MM1,MM2 ; pmuludq MM3,m64[EBP] ; pmuludq XMM1,XMM2 ; pmuludq XMM3,m128[EBP] ; por MM1,MM2 ; por MM3,m64[EBP] ; por XMM1,XMM2 ; por XMM3,m128[EBP] ; prefetcht0 m8[EBP] ; prefetcht1 m8[EBP] ; prefetcht2 m8[EBP] ; prefetchnta m8[EBP] ; psadbw MM1,MM2 ; psadbw MM3,m64[EBP] ; psadbw XMM1,XMM2 ; psadbw XMM3,m128[EBP] ; pshufd XMM1,XMM2,3 ; pshufd XMM3,m128[EBP],3 ; pshufhw XMM1,XMM2,3 ; pshufhw XMM3,m128[EBP],3 ; pshuflw XMM1,XMM2,3 ; pshuflw XMM3,m128[EBP],3 ; pshufw MM1,MM2,3 ; pshufw MM3,m64[EBP],3 ; pslldq XMM1,0x18 ; psllw MM1,MM2 ; psllw MM1,m64[EBP] ; psllw XMM1,XMM2 ; psllw XMM1,m128[EBP] ; psllw MM1,0x15 ; psllw XMM1,0x15 ; pslld MM1,MM2 ; pslld MM1,m64[EBP] ; pslld XMM1,XMM2 ; pslld XMM1,m128[EBP] ; pslld MM1,0x15 ; pslld XMM1,0x15 ; psllq MM1,MM2 ; psllq MM1,m64[EBP] ; psllq XMM1,XMM2 ; psllq XMM1,m128[EBP] ; psllq MM1,0x15 ; psllq XMM1,0x15 ; psraw MM1,MM2 ; psraw MM1,m64[EBP] ; psraw XMM1,XMM2 ; psraw XMM1,m128[EBP] ; psraw MM1,0x15 ; psraw XMM1,0x15 ; psrad MM1,MM2 ; psrad MM1,m64[EBP] ; psrad XMM1,XMM2 ; psrad XMM1,m128[EBP] ; psrad MM1,0x15 ; psrad XMM1,0x15 ; psrldq XMM1,0x18 ; psrlw MM1,MM2 ; psrlw MM1,m64[EBP] ; psrlw XMM1,XMM2 ; psrlw XMM1,m128[EBP] ; psrlw MM1,0x15 ; psrlw XMM1,0x15 ; psrld MM1,MM2 ; psrld MM1,m64[EBP] ; psrld XMM1,XMM2 ; psrld XMM1,m128[EBP] ; psrld MM1,0x15 ; psrld XMM1,0x15 ; psrlq MM1,MM2 ; psrlq MM1,m64[EBP] ; psrlq XMM1,XMM2 ; psrlq XMM1,m128[EBP] ; psrlq MM1,0x15 ; psrlq XMM1,0x15 ; psubb MM1,MM2 ; psubb MM1,m64[EBP] ; psubb XMM1,XMM2 ; psubb XMM1,m128[EBP] ; psubw MM1,MM2 ; psubw MM1,m64[EBP] ; psubw XMM1,XMM2 ; psubw XMM1,m128[EBP] ; psubd MM1,MM2 ; psubd MM1,m64[EBP] ; psubd XMM1,XMM2 ; psubd XMM1,m128[EBP] ; psubq MM1,MM2 ; psubq MM1,m64[EBP] ; psubq XMM1,XMM2 ; psubq XMM1,m128[EBP] ; psubsb MM1,MM2 ; psubsb MM1,m64[EBP] ; psubsb XMM1,XMM2 ; psubsb XMM1,m128[EBP] ; psubsw MM1,MM2 ; psubsw MM1,m64[EBP] ; psubsw XMM1,XMM2 ; psubsw XMM1,m128[EBP] ; psubusb MM1,MM2 ; psubusb MM1,m64[EBP] ; psubusb XMM1,XMM2 ; psubusb XMM1,m128[EBP] ; psubusw MM1,MM2 ; psubusw MM1,m64[EBP] ; psubusw XMM1,XMM2 ; psubusw XMM1,m128[EBP] ; punpckhbw MM1,MM2 ; punpckhbw MM1,m64[EBP] ; punpckhbw XMM1,XMM2 ; punpckhbw XMM1,m128[EBP] ; punpckhwd MM1,MM2 ; punpckhwd MM1,m64[EBP] ; punpckhwd XMM1,XMM2 ; punpckhwd XMM1,m128[EBP] ; punpckhdq MM1,MM2 ; punpckhdq MM1,m64[EBP] ; punpckhdq XMM1,XMM2 ; punpckhdq XMM1,m128[EBP] ; punpckhqdq XMM1,XMM2 ; punpckhqdq XMM1,m128[EBP] ; punpcklbw MM1,MM2 ; punpcklbw MM1,m64[EBP] ; punpcklbw XMM1,XMM2 ; punpcklbw XMM1,m128[EBP] ; punpcklwd MM1,MM2 ; punpcklwd MM1,m64[EBP] ; punpcklwd XMM1,XMM2 ; punpcklwd XMM1,m128[EBP] ; punpckldq MM1,MM2 ; punpckldq MM1,m64[EBP] ; punpckldq XMM1,XMM2 ; punpckldq XMM1,m128[EBP] ; punpcklqdq XMM1,XMM2 ; punpcklqdq XMM1,m128[EBP] ; pxor MM1,MM2 ; pxor MM1,m64[EBP] ; pxor XMM1,XMM2 ; pxor XMM1,m128[EBP] ; rcpps XMM1,XMM2 ; rcpps XMM1,m128[EBP] ; rcpss XMM1,XMM2 ; rcpss XMM1,m32[EBP] ; rsqrtps XMM1,XMM2 ; rsqrtps XMM1,m128[EBP] ; rsqrtss XMM1,XMM2 ; rsqrtss XMM1,m32[EBP] ; shufpd XMM1,XMM2,3 ; shufpd XMM1,m128[EBP],4 ; shufps XMM1,XMM2,3 ; shufps XMM1,m128[EBP],4 ; ucomisd XMM4,XMM6 ; ucomisd XMM5,m64[EBP] ; ucomiss XMM6,XMM7 ; ucomiss XMM7,m32[EBP] ; unpckhpd XMM4,XMM6 ; unpckhpd XMM5,m128[EBP] ; unpckhps XMM4,XMM6 ; unpckhps XMM5,m128[EBP] ; unpcklpd XMM4,XMM6 ; unpcklpd XMM5,m128[EBP] ; unpcklps XMM4,XMM6 ; unpcklps XMM5,m128[EBP] ; xorpd XMM1,XMM2 ; xorpd XMM1,m128[EBP] ; xorps XMM1,XMM2 ; xorps XMM1,m128[EBP] ; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test15() { int m32; long m64; M128 m128; ubyte *p; static ubyte data[] = [ 0x0F,0x0F,0xDC,0xBF, // pavgusb MM3,MM4 0x0F,0x0F,0x5D,0xE0,0xBF, // pavgusb MM3,-020h[EBP] 0x0F,0x0F,0xDC,0x1D, // pf2id MM3,MM4 0x0F,0x0F,0x5D,0xE0,0x1D, // pf2id MM3,-020h[EBP] 0x0F,0x0F,0xDC,0xAE, // pfacc MM3,MM4 0x0F,0x0F,0x5D,0xE0,0xAE, // pfacc MM3,-020h[EBP] 0x0F,0x0F,0xDC,0x9E, // pfadd MM3,MM4 0x0F,0x0F,0x5D,0xE0,0x9E, // pfadd MM3,-020h[EBP] 0x0F,0x0F,0xDC,0xB0, // pfcmpeq MM3,MM4 0x0F,0x0F,0x5D,0xE0,0xB0, // pfcmpeq MM3,-020h[EBP] 0x0F,0x0F,0xDC,0x90, // pfcmpge MM3,MM4 0x0F,0x0F,0x5D,0xE0,0x90, // pfcmpge MM3,-020h[EBP] 0x0F,0x0F,0xDC,0xA0, // pfcmpgt MM3,MM4 0x0F,0x0F,0x5D,0xE0,0xA0, // pfcmpgt MM3,-020h[EBP] 0x0F,0x0F,0xDC,0xA4, // pfmax MM3,MM4 0x0F,0x0F,0x5D,0xE0,0x94, // pfmin MM3,-020h[EBP] 0x0F,0x0F,0xDC,0xB4, // pfmul MM3,MM4 0x0F,0x0F,0x5D,0xE0,0xB4, // pfmul MM3,-020h[EBP] 0x0F,0x0F,0xDC,0x8A, // pfnacc MM3,MM4 0x0F,0x0F,0x5D,0xE0,0x8E, // pfpnacc MM3,-020h[EBP] 0x0F,0x0F,0xDC,0x96, // pfrcp MM3,MM4 0x0F,0x0F,0x5D,0xE0,0x96, // pfrcp MM3,-020h[EBP] 0x0F,0x0F,0xDC,0xA6, // pfrcpit1 MM3,MM4 0x0F,0x0F,0x5D,0xE0,0xA6, // pfrcpit1 MM3,-020h[EBP] 0x0F,0x0F,0xDC,0xB6, // pfrcpit2 MM3,MM4 0x0F,0x0F,0x5D,0xE0,0xB6, // pfrcpit2 MM3,-020h[EBP] 0x0F,0x0F,0xDC,0x97, // pfrsqrt MM3,MM4 0x0F,0x0F,0x5D,0xE0,0xA7, // pfrsqit1 MM3,-020h[EBP] 0x0F,0x0F,0xDC,0x9A, // pfsub MM3,MM4 0x0F,0x0F,0x5D,0xE0,0x9A, // pfsub MM3,-020h[EBP] 0x0F,0x0F,0xDC,0xAA, // pfsubr MM3,MM4 0x0F,0x0F,0x5D,0xE0,0xAA, // pfsubr MM3,-020h[EBP] 0x0F,0x0F,0xDC,0x0D, // pi2fd MM3,MM4 0x0F,0x0F,0x5D,0xE0,0x0D, // pi2fd MM3,-020h[EBP] 0x0F,0x0F,0xDC,0xB7, // pmulhrw MM3,MM4 0x0F,0x0F,0x5D,0xE0,0xB7, // pmulhrw MM3,-020h[EBP] 0x0F,0x0F,0xDC,0xBB, // pswapd MM3,MM4 0x0F,0x0F,0x5D,0xE0,0xBB, // pswapd MM3,-020h[EBP] ]; int i; asm { call L1 ; pavgusb MM3,MM4 ; pavgusb MM3,m64[EBP] ; pf2id MM3,MM4 ; pf2id MM3,m64[EBP] ; pfacc MM3,MM4 ; pfacc MM3,m64[EBP] ; pfadd MM3,MM4 ; pfadd MM3,m64[EBP] ; pfcmpeq MM3,MM4 ; pfcmpeq MM3,m64[EBP] ; pfcmpge MM3,MM4 ; pfcmpge MM3,m64[EBP] ; pfcmpgt MM3,MM4 ; pfcmpgt MM3,m64[EBP] ; pfmax MM3,MM4 ; pfmin MM3,m64[EBP] ; pfmul MM3,MM4 ; pfmul MM3,m64[EBP] ; pfnacc MM3,MM4 ; pfpnacc MM3,m64[EBP] ; pfrcp MM3,MM4 ; pfrcp MM3,m64[EBP] ; pfrcpit1 MM3,MM4 ; pfrcpit1 MM3,m64[EBP] ; pfrcpit2 MM3,MM4 ; pfrcpit2 MM3,m64[EBP] ; pfrsqrt MM3,MM4 ; pfrsqit1 MM3,m64[EBP] ; pfsub MM3,MM4 ; pfsub MM3,m64[EBP] ; pfsubr MM3,MM4 ; pfsubr MM3,m64[EBP] ; pi2fd MM3,MM4 ; pi2fd MM3,m64[EBP] ; pmulhrw MM3,MM4 ; pmulhrw MM3,m64[EBP] ; pswapd MM3,MM4 ; pswapd MM3,m64[EBP] ; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ struct S17 { char x[6]; } __gshared S17 xx17; void test17() { ubyte *p; static ubyte data[] = [ 0x0F, 0x01, 0x10, // lgdt [EAX] 0x0F, 0x01, 0x18, // lidt [EAX] 0x0F, 0x01, 0x00, // sgdt [EAX] 0x0F, 0x01, 0x08, // sidt [EAX] ]; int i; asm { call L1 ; lgdt [EAX] ; lidt [EAX] ; sgdt [EAX] ; sidt [EAX] ; lgdt xx17 ; lidt xx17 ; sgdt xx17 ; sidt xx17 ; L1: pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test18() { ubyte *p; static ubyte data[] = [ 0xDB, 0xF1, // fcomi ST,ST(1) 0xDB, 0xF0, // fcomi ST,ST(0) 0xDB, 0xF2, // fcomi ST,ST(2) 0xDF, 0xF1, // fcomip ST,ST(1) 0xDF, 0xF0, // fcomip ST,ST(0) 0xDF, 0xF2, // fcomip ST,ST(2) 0xDB, 0xE9, // fucomi ST,ST(1) 0xDB, 0xE8, // fucomi ST,ST(0) 0xDB, 0xEB, // fucomi ST,ST(3) 0xDF, 0xE9, // fucomip ST,ST(1) 0xDF, 0xED, // fucomip ST,ST(5) 0xDF, 0xEC, // fucomip ST,ST(4) ]; int i; asm { call L1 ; fcomi ; fcomi ST(0) ; fcomi ST,ST(2) ; fcomip ; fcomip ST(0) ; fcomip ST,ST(2) ; fucomi ; fucomi ST(0) ; fucomi ST,ST(3) ; fucomip ; fucomip ST(5) ; fucomip ST,ST(4) ; L1: pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ extern (C) { void foo19() { } } void test19() { void function() fp; int x; int *p; asm { lea EAX, dword ptr [foo19]; mov fp, EAX; mov x, EAX; mov p, EAX; call fp; } (*fp)(); } /****************************************************/ void test20() { ubyte *p; static ubyte data[] = [ 0x9B, 0xDB, 0xE0, // feni 0xDB, 0xE0, // fneni 0x9B, 0xDB, 0xE1, // fdisi 0xDB, 0xE1, // fndisi 0x9B, 0xDB, 0xE2, // fclex 0xDB, 0xE2, // fnclex 0x9B, 0xDB, 0xE3, // finit 0xDB, 0xE3, // fninit 0xDB, 0xE4, // fsetpm ]; int i; asm { call L1 ; feni ; fneni ; fdisi ; fndisi ; finit ; fninit ; fclex ; fnclex ; finit ; fninit ; fsetpm ; L1: pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test21() { ubyte *p; static ubyte data[] = [ 0xE4, 0x06, // in AL,6 0x66, 0xE5, 0x07, // in AX,7 0xE5, 0x08, // in EAX,8 0xEC, // in AL,DX 0x66, 0xED, // in AX,DX 0xED, // in EAX,DX 0xE6, 0x06, // out 6,AL 0x66, 0xE7, 0x07, // out 7,AX 0xE7, 0x08, // out 8,EAX 0xEE, // out DX,AL 0x66, 0xEF, // out DX,AX 0xEF, // out DX,EAX ]; int i; asm { call L1 ; in AL,6 ; in AX,7 ; in EAX,8 ; in AL,DX ; in AX,DX ; in EAX,DX ; out 6,AL ; out 7,AX ; out 8,EAX ; out DX,AL ; out DX,AX ; out DX,EAX ; L1: pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test22() { ubyte *p; static ubyte data[] = [ 0x0F, 0xC7, 0x4D, 0xF8 // cmpxchg8b ]; int i; M64 m64; asm { call L1 ; cmpxchg8b m64 ; L1: pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test23() { short m16; int m32; long m64; M128 m128; ubyte *p; static ubyte data[] = [ 0xD9, 0xC9, // fxch ST(1), ST(0) 0xDF, 0x5D, 0xD8, // fistp word ptr -018h[EBP] 0xDB, 0x5D, 0xDC, // fistp dword ptr -014h[EBP] 0xDF, 0x7D, 0xE0, // fistp long64 ptr -010h[EBP] 0xDF, 0x4D, 0xD8, // fisttp short ptr -018h[EBP] 0xDB, 0x4D, 0xDC, // fisttp word ptr -014h[EBP] 0xDD, 0x4D, 0xE0, // fisttp long64 ptr -010h[EBP] 0x0F, 0x01, 0xC8, // monitor 0x0F, 0x01, 0xC9, // mwait 0x0F, 0x01, 0xD0, // xgetbv 0x66, 0x0F, 0xD0, 0xCA, // addsubpd XMM1,XMM2 0x66, 0x0F, 0xD0, 0x4D, 0xE8, // addsubpd XMM1,-010h[EBP] 0xF2, 0x0F, 0xD0, 0xCA, // addsubps XMM1,XMM2 0xF2, 0x0F, 0xD0, 0x4D, 0xE8, // addsubps XMM1,-010h[EBP] 0x66, 0x0F, 0x7C, 0xCA, // haddpd XMM1,XMM2 0x66, 0x0F, 0x7C, 0x4D, 0xE8, // haddpd XMM1,-010h[EBP] 0xF2, 0x0F, 0x7C, 0xCA, // haddps XMM1,XMM2 0xF2, 0x0F, 0x7C, 0x4D, 0xE8, // haddps XMM1,-010h[EBP] 0x66, 0x0F, 0x7D, 0xCA, // hsubpd XMM1,XMM2 0x66, 0x0F, 0x7D, 0x4D, 0xE8, // hsubpd XMM1,-010h[EBP] 0xF2, 0x0F, 0x7D, 0xCA, // hsubps XMM1,XMM2 0xF2, 0x0F, 0x7D, 0x4D, 0xE8, // hsubps XMM1,-010h[EBP] 0xF2, 0x0F, 0xF0, 0x4D, 0xE8, // lddqu XMM1,-010h[EBP] 0xF2, 0x0F, 0x12, 0xCA, // movddup XMM1,XMM2 0xF2, 0x0F, 0x12, 0x4D, 0xE0, // movddup XMM1,-018h[EBP] 0xF3, 0x0F, 0x16, 0xCA, // movshdup XMM1,XMM2 0xF3, 0x0F, 0x16, 0x4D, 0xE8, // movshdup XMM1,-010h[EBP] 0xF3, 0x0F, 0x12, 0xCA, // movsldup XMM1,XMM2 0xF3, 0x0F, 0x12, 0x4D, 0xE8, // movsldup XMM1,-010h[EBP] ]; int i; asm { call L1 ; fxch ST(1), ST(0) ; fistp m16[EBP] ; fistp m32[EBP] ; fistp m64[EBP] ; fisttp m16[EBP] ; fisttp m32[EBP] ; fisttp m64[EBP] ; monitor ; mwait ; xgetbv ; addsubpd XMM1,XMM2 ; addsubpd XMM1,m128[EBP] ; addsubps XMM1,XMM2 ; addsubps XMM1,m128[EBP] ; haddpd XMM1,XMM2 ; haddpd XMM1,m128[EBP] ; haddps XMM1,XMM2 ; haddps XMM1,m128[EBP] ; hsubpd XMM1,XMM2 ; hsubpd XMM1,m128[EBP] ; hsubps XMM1,XMM2 ; hsubps XMM1,m128[EBP] ; lddqu XMM1,m128[EBP] ; movddup XMM1,XMM2 ; movddup XMM1,m64[EBP] ; movshdup XMM1,XMM2 ; movshdup XMM1,m128[EBP] ; movsldup XMM1,XMM2 ; movsldup XMM1,m128[EBP] ; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test24() { version(D_InlineAsm) { ushort i; asm { lea AX, i; mov i, AX; } assert(cast(ushort)&i == i); } } /****************************************************/ void test25() { short m16; int m32; long m64; M128 m128; ubyte *p; static ubyte data[] = [ 0x66, 0x0F, 0x7E, 0xC1, // movd ECX,XMM0 0x66, 0x0F, 0x7E, 0xC9, // movd ECX,XMM1 0x66, 0x0F, 0x7E, 0xD1, // movd ECX,XMM2 0x66, 0x0F, 0x7E, 0xD9, // movd ECX,XMM3 0x66, 0x0F, 0x7E, 0xE1, // movd ECX,XMM4 0x66, 0x0F, 0x7E, 0xE9, // movd ECX,XMM5 0x66, 0x0F, 0x7E, 0xF1, // movd ECX,XMM6 0x66, 0x0F, 0x7E, 0xF9, // movd ECX,XMM7 0x0F, 0x7E, 0xC1, // movd ECX,MM0 0x0F, 0x7E, 0xC9, // movd ECX,MM1 0x0F, 0x7E, 0xD1, // movd ECX,MM2 0x0F, 0x7E, 0xD9, // movd ECX,MM3 0x0F, 0x7E, 0xE1, // movd ECX,MM4 0x0F, 0x7E, 0xE9, // movd ECX,MM5 0x0F, 0x7E, 0xF1, // movd ECX,MM6 0x0F, 0x7E, 0xF9, // movd ECX,MM7 0x66, 0x0F, 0x6E, 0xC1, // movd XMM0,ECX 0x66, 0x0F, 0x6E, 0xC9, // movd XMM1,ECX 0x66, 0x0F, 0x6E, 0xD1, // movd XMM2,ECX 0x66, 0x0F, 0x6E, 0xD9, // movd XMM3,ECX 0x66, 0x0F, 0x6E, 0xE1, // movd XMM4,ECX 0x66, 0x0F, 0x6E, 0xE9, // movd XMM5,ECX 0x66, 0x0F, 0x6E, 0xF1, // movd XMM6,ECX 0x66, 0x0F, 0x6E, 0xF9, // movd XMM7,ECX 0x0F, 0x6E, 0xC1, // movd MM0,ECX 0x0F, 0x6E, 0xC9, // movd MM1,ECX 0x0F, 0x6E, 0xD1, // movd MM2,ECX 0x0F, 0x6E, 0xD9, // movd MM3,ECX 0x0F, 0x6E, 0xE1, // movd MM4,ECX 0x0F, 0x6E, 0xE9, // movd MM5,ECX 0x0F, 0x6E, 0xF1, // movd MM6,ECX 0x0F, 0x6E, 0xF9, // movd MM7,ECX 0x66, 0x0F, 0x7E, 0xC8, // movd EAX,XMM1 0x66, 0x0F, 0x7E, 0xCB, // movd EBX,XMM1 0x66, 0x0F, 0x7E, 0xC9, // movd ECX,XMM1 0x66, 0x0F, 0x7E, 0xCA, // movd EDX,XMM1 0x66, 0x0F, 0x7E, 0xCE, // movd ESI,XMM1 0x66, 0x0F, 0x7E, 0xCF, // movd EDI,XMM1 0x66, 0x0F, 0x7E, 0xCD, // movd EBP,XMM1 0x66, 0x0F, 0x7E, 0xCC, // movd ESP,XMM1 0x0F, 0x7E, 0xC8, // movd EAX,MM1 0x0F, 0x7E, 0xCB, // movd EBX,MM1 0x0F, 0x7E, 0xC9, // movd ECX,MM1 0x0F, 0x7E, 0xCA, // movd EDX,MM1 0x0F, 0x7E, 0xCE, // movd ESI,MM1 0x0F, 0x7E, 0xCF, // movd EDI,MM1 0x0F, 0x7E, 0xCD, // movd EBP,MM1 0x0F, 0x7E, 0xCC, // movd ESP,MM1 0x66, 0x0F, 0x6E, 0xC8, // movd XMM1,EAX 0x66, 0x0F, 0x6E, 0xCB, // movd XMM1,EBX 0x66, 0x0F, 0x6E, 0xC9, // movd XMM1,ECX 0x66, 0x0F, 0x6E, 0xCA, // movd XMM1,EDX 0x66, 0x0F, 0x6E, 0xCE, // movd XMM1,ESI 0x66, 0x0F, 0x6E, 0xCF, // movd XMM1,EDI 0x66, 0x0F, 0x6E, 0xCD, // movd XMM1,EBP 0x66, 0x0F, 0x6E, 0xCC, // movd XMM1,ESP 0x0F, 0x6E, 0xC8, // movd MM1,EAX 0x0F, 0x6E, 0xCB, // movd MM1,EBX 0x0F, 0x6E, 0xC9, // movd MM1,ECX 0x0F, 0x6E, 0xCA, // movd MM1,EDX 0x0F, 0x6E, 0xCE, // movd MM1,ESI 0x0F, 0x6E, 0xCF, // movd MM1,EDI 0x0F, 0x6E, 0xCD, // movd MM1,EBP 0x0F, 0x6E, 0xCC, // movd MM1,ESP ]; int i; asm { call L1 ; movd ECX, XMM0; movd ECX, XMM1; movd ECX, XMM2; movd ECX, XMM3; movd ECX, XMM4; movd ECX, XMM5; movd ECX, XMM6; movd ECX, XMM7; movd ECX, MM0; movd ECX, MM1; movd ECX, MM2; movd ECX, MM3; movd ECX, MM4; movd ECX, MM5; movd ECX, MM6; movd ECX, MM7; movd XMM0, ECX; movd XMM1, ECX; movd XMM2, ECX; movd XMM3, ECX; movd XMM4, ECX; movd XMM5, ECX; movd XMM6, ECX; movd XMM7, ECX; movd MM0, ECX; movd MM1, ECX; movd MM2, ECX; movd MM3, ECX; movd MM4, ECX; movd MM5, ECX; movd MM6, ECX; movd MM7, ECX; movd EAX, XMM1; movd EBX, XMM1; movd ECX, XMM1; movd EDX, XMM1; movd ESI, XMM1; movd EDI, XMM1; movd EBP, XMM1; movd ESP, XMM1; movd EAX, MM1; movd EBX, MM1; movd ECX, MM1; movd EDX, MM1; movd ESI, MM1; movd EDI, MM1; movd EBP, MM1; movd ESP, MM1; movd XMM1, EAX; movd XMM1, EBX; movd XMM1, ECX; movd XMM1, EDX; movd XMM1, ESI; movd XMM1, EDI; movd XMM1, EBP; movd XMM1, ESP; movd MM1, EAX; movd MM1, EBX; movd MM1, ECX; movd MM1, EDX; movd MM1, ESI; movd MM1, EDI; movd MM1, EBP; movd MM1, ESP; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void fn26(ref byte val) { asm { mov EAX, val; inc byte ptr [EAX]; } } void test26() { byte b; //printf( "%i\n", b ); assert(b == 0); fn26(b); //printf( "%i\n", b ); assert(b == 1); } /****************************************************/ void test27() { static const ubyte[16] a = [0, 1, 2, 3, 4, 5, 6, 7, 8 ,9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF]; version (Windows) { asm { movdqu XMM0, a; pslldq XMM0, 2; } } } /****************************************************/ /* PASS: cfloat z; cfloat[1] z; double z; double[1] b; long z; long[1] z; FAIL: (bad type/size of operands 'movq') byte[8] z; char[8] z; dchar[2] z; float[2] z; int[2] z; short[4] z; wchar[4] z; XPASS: (too small, but accecpted by DMD) cfloat[0] z; double[0] z; long[0] z; */ void test28() { version (Windows) { cfloat[4] z; static const ubyte[8] A = [3, 4, 9, 0, 1, 3, 7, 2]; ubyte[8] b; asm{ movq MM0, z; movq MM0, A; movq b, MM0; } for(size_t i = 0; i < A.length; i++) { if(A[i] != b[i]) { assert(0); } } } } /****************************************************/ shared int[5] bar29 = [3, 4, 5, 6, 7]; void test29() { int* x; asm { push offsetof bar29; pop EAX; mov x, EAX; } assert(*x == 3); asm { mov EAX, offsetof bar29; mov x, EAX; } assert(*x == 3); } /****************************************************/ const int CONST_OFFSET30 = 10; void foo30() { asm { mov EDX, 10; mov EAX, [EDX + CONST_OFFSET30]; } } void test30() { } /****************************************************/ void test31() { ubyte *p; static ubyte data[] = [ 0xF7, 0xD8, // neg EAX 0x74, 0x04, // je L8 0xF7, 0xD8, // neg EAX 0x75, 0xFC, // jne L4 0x40, // inc EAX ]; int i; asm { call L1 ; neg EAX; je L2; L3: neg EAX; jne L3; L2: inc EAX; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void infiniteAsmLoops() { /* This crashes DMD 0.162: */ for (;;) asm { inc EAX; } /* It doesn't seem to matter what you use. These all crash: */ //for (;;) asm { mov EAX, EBX; } //for (;;) asm { xor EAX, EAX; } //for (;;) asm { push 0; pop EAX; } //for (;;) asm { jmp infiniteAsmLoops; } /* This is a workaround: */ for (bool a = true; a;) asm { hlt; } // compiles /* But this isn't: */ //for (const bool a = true; a;) asm{ hlt; } // crashes DMD /* It's not restricted to for-statements: */ //while(1) asm { hlt; } // crashes DMD /* This compiles: */ { bool a = true; while(a) asm { hlt; } } /* But again, this doesn't: */ /* { const bool a = true; // note the const while(a) asm { hlt; } } //*/ //do { asm { hlt; } } while (1); // crashes DMD /* This, of course, compiles: */ { bool a = true; do asm { hlt; } while (a); } /* But predicably, this doesn't: */ /* { const bool a = true; do asm { hlt; } while (a); } //**/ /* Not even hand-coding the loop works: */ /* { label: asm { hlt; } // commenting out this line to make it compile goto label; } //*/ /* Unless you go all the way: (i.e. this compiles) */ asm { L1: hlt; jmp L1; } /* or like this (also compiles): */ static void test() { asm { naked; hlt; jmp test; } } test(); /* Wait... it gets weirder: */ /* This also doesn't compile: */ /* for (;;) { writef(""); asm { hlt; } } //*/ /* But this does: */ //* for (;;) { asm { hlt; } writef(""); } //*/ /* The same loop that doesn't compile above * /does/ compile after previous one: */ //* for (;;) { writef(""); asm { hlt; } } //*/ /* Note: this one is at the end because it seems to also trigger the * "now it works" event of the loop above. */ /* There has to be /something/ in that asm block: */ for (;;) asm {} // compiles } void test32() { } /****************************************************/ void test33() { int x = 1; alias x y; asm { mov EAX, x; mov EAX, y; } } /****************************************************/ int test34() { asm{ jmp label; } return 0; label: return 1; } /****************************************************/ void foo35() { printf("hello\n"); } void test35() { void function() p; uint q; asm { mov ECX, foo35 ; mov q, ECX ; lea EDX, foo35 ; mov p, EDX ; } assert(p == &foo35); assert(q == *cast(uint *)p); } /****************************************************/ void func36() { } int test36() { void* a = &func36; uint* b = cast(uint*) a; uint f = *b; uint g; asm{ mov EAX, func36; mov g, EAX; } if(f != g){ assert(0); } } /****************************************************/ void a37(X...)(X expr) { alias expr[0] var1; asm { fld double ptr expr[0]; fstp double ptr var1; } } void test37() { a37(3.6); } /****************************************************/ int f38(X...)(X x) { asm { mov EAX, int ptr x[1]; } } int g38(X...)(X x) { asm { mov EAX, x[1]; } } void test38() { assert(456 == f38(123, 456)); assert(456 == g38(123, 456)); } /****************************************************/ void test39() { const byte z = 35; goto end; asm { db z; } end: ; } /****************************************************/ void test40() { printf(""); const string s = "abcdefghi"; asm { jmp L1; ds s; L1:; } end: ; } /****************************************************/ void test41() { ubyte *p; static ubyte data[] = [ 0x66,0x0F,0x28,0x0C,0x06, // movapd XMM1,[EAX][ESI] 0x66,0x0F,0x28,0x0C,0x06, // movapd XMM1,[EAX][ESI] 0x66,0x0F,0x28,0x0C,0x46, // movapd XMM1,[EAX*2][ESI] 0x66,0x0F,0x28,0x0C,0x86, // movapd XMM1,[EAX*4][ESI] 0x66,0x0F,0x28,0x0C,0xC6, // movapd XMM1,[EAX*8][ESI] ]; int i; asm { call L1 ; movapd XMM1, [ESI+EAX]; movapd XMM1, [ESI+1*EAX]; movapd XMM1, [ESI+2*EAX]; movapd XMM1, [ESI+4*EAX]; movapd XMM1, [ESI+8*EAX]; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ enum { enumeration42 = 1, } void test42() { asm { mov EAX, enumeration42; } } /****************************************************/ void foo43() { asm {lea EAX, [0*4+EAX]; } asm {lea EAX, [4*0+EAX]; } asm {lea EAX, [EAX+4*0]; } asm {lea EAX, [0+EAX]; } asm {lea EAX, [7*7+EAX]; } } void test43() { } /****************************************************/ enum n1 = 42; enum { n2 = 42 } uint retN1() { asm { mov EAX,n1; // No! - mov EAX,-4[EBP] } } uint retN2() { asm { mov EAX,n2; // OK - mov EAX,02Ah } } void test44() { assert(retN1() == 42); assert(retN2() == 42); } /****************************************************/ void test45() { ubyte *p; static ubyte data[] = [ 0xDA, 0xC0, // fcmovb ST(0) 0xDA, 0xC1, // fcmovb 0xDA, 0xCA, // fcmove ST(2) 0xDA, 0xD3, // fcmovbe ST(3) 0xDA, 0xDC, // fcmovu ST(4) 0xDB, 0xC5, // fcmovnb ST(5) 0xDB, 0xCE, // fcmovne ST(6) 0xDB, 0xD7, // fcmovnbe ST(7) 0xDB, 0xD9, // fcmovnu ]; int i; asm { call L1 ; fcmovb ST, ST(0); fcmovb ST, ST(1); fcmove ST, ST(2); fcmovbe ST, ST(3); fcmovu ST, ST(4); fcmovnb ST, ST(5); fcmovne ST, ST(6); fcmovnbe ST, ST(7); fcmovnu ST, ST(1); L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test46() { ubyte *p; static ubyte data[] = [ 0x66, 0x0F, 0x3A, 0x41, 0xCA, 0x08, // dppd XMM1,XMM2,8 0x66, 0x0F, 0x3A, 0x40, 0xDC, 0x07, // dpps XMM3,XMM4,7 0x66, 0x0F, 0x50, 0xF3, // movmskpd ESI,XMM3 0x66, 0x0F, 0x50, 0xC7, // movmskpd EAX,XMM7 0x0F, 0x50, 0xC7, // movmskps EAX,XMM7 0x0F, 0xD7, 0xC7, // pmovmskb EAX,MM7 0x66, 0x0F, 0xD7, 0xC7, // pmovmskb EAX,XMM7 ]; int i; asm { call L1 ; dppd XMM1,XMM2,8 ; dpps XMM3,XMM4,7 ; movmskpd ESI,XMM3 ; movmskpd EAX,XMM7 ; movmskps EAX,XMM7 ; pmovmskb EAX,MM7 ; pmovmskb EAX,XMM7 ; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ struct Foo47 { float x,y; } void bar47(Foo47 f) { int i; asm { mov EAX, offsetof f; mov i, EAX; } assert(i == 8); } void test47() { Foo47 f; bar47(f); } /****************************************************/ void func48(void delegate () callback) { callback(); } void test48() { func48(() { asm{ mov EAX,EAX; }; }); } /****************************************************/ void test49() { ubyte *p; static ubyte data[] = [ 0x00, 0xC0, // add AL,AL 0x00, 0xD8, // add AL,BL 0x00, 0xC8, // add AL,CL 0x00, 0xD0, // add AL,DL 0x00, 0xE0, // add AL,AH 0x00, 0xF8, // add AL,BH 0x00, 0xE8, // add AL,CH 0x00, 0xF0, // add AL,DH 0x00, 0xC4, // add AH,AL 0x00, 0xDC, // add AH,BL 0x00, 0xCC, // add AH,CL 0x00, 0xD4, // add AH,DL 0x00, 0xE4, // add AH,AH 0x00, 0xFC, // add AH,BH 0x00, 0xEC, // add AH,CH 0x00, 0xF4, // add AH,DH 0x00, 0xC3, // add BL,AL 0x00, 0xDB, // add BL,BL 0x00, 0xCB, // add BL,CL 0x00, 0xD3, // add BL,DL 0x00, 0xE3, // add BL,AH 0x00, 0xFB, // add BL,BH 0x00, 0xEB, // add BL,CH 0x00, 0xF3, // add BL,DH 0x00, 0xC7, // add BH,AL 0x00, 0xDF, // add BH,BL 0x00, 0xCF, // add BH,CL 0x00, 0xD7, // add BH,DL 0x00, 0xE7, // add BH,AH 0x00, 0xFF, // add BH,BH 0x00, 0xEF, // add BH,CH 0x00, 0xF7, // add BH,DH 0x00, 0xC1, // add CL,AL 0x00, 0xD9, // add CL,BL 0x00, 0xC9, // add CL,CL 0x00, 0xD1, // add CL,DL 0x00, 0xE1, // add CL,AH 0x00, 0xF9, // add CL,BH 0x00, 0xE9, // add CL,CH 0x00, 0xF1, // add CL,DH 0x00, 0xC5, // add CH,AL 0x00, 0xDD, // add CH,BL 0x00, 0xCD, // add CH,CL 0x00, 0xD5, // add CH,DL 0x00, 0xE5, // add CH,AH 0x00, 0xFD, // add CH,BH 0x00, 0xED, // add CH,CH 0x00, 0xF5, // add CH,DH 0x00, 0xC2, // add DL,AL 0x00, 0xDA, // add DL,BL 0x00, 0xCA, // add DL,CL 0x00, 0xD2, // add DL,DL 0x00, 0xE2, // add DL,AH 0x00, 0xFA, // add DL,BH 0x00, 0xEA, // add DL,CH 0x00, 0xF2, // add DL,DH 0x00, 0xC6, // add DH,AL 0x00, 0xDE, // add DH,BL 0x00, 0xCE, // add DH,CL 0x00, 0xD6, // add DH,DL 0x00, 0xE6, // add DH,AH 0x00, 0xFE, // add DH,BH 0x00, 0xEE, // add DH,CH 0x00, 0xF6, // add DH,DH 0x66, 0x01, 0xC0, // add AX,AX 0x66, 0x01, 0xD8, // add AX,BX 0x66, 0x01, 0xC8, // add AX,CX 0x66, 0x01, 0xD0, // add AX,DX 0x66, 0x01, 0xF0, // add AX,SI 0x66, 0x01, 0xF8, // add AX,DI 0x66, 0x01, 0xE8, // add AX,BP 0x66, 0x01, 0xE0, // add AX,SP 0x66, 0x01, 0xC3, // add BX,AX 0x66, 0x01, 0xDB, // add BX,BX 0x66, 0x01, 0xCB, // add BX,CX 0x66, 0x01, 0xD3, // add BX,DX 0x66, 0x01, 0xF3, // add BX,SI 0x66, 0x01, 0xFB, // add BX,DI 0x66, 0x01, 0xEB, // add BX,BP 0x66, 0x01, 0xE3, // add BX,SP 0x66, 0x01, 0xC1, // add CX,AX 0x66, 0x01, 0xD9, // add CX,BX 0x66, 0x01, 0xC9, // add CX,CX 0x66, 0x01, 0xD1, // add CX,DX 0x66, 0x01, 0xF1, // add CX,SI 0x66, 0x01, 0xF9, // add CX,DI 0x66, 0x01, 0xE9, // add CX,BP 0x66, 0x01, 0xE1, // add CX,SP 0x66, 0x01, 0xC2, // add DX,AX 0x66, 0x01, 0xDA, // add DX,BX 0x66, 0x01, 0xCA, // add DX,CX 0x66, 0x01, 0xD2, // add DX,DX 0x66, 0x01, 0xF2, // add DX,SI 0x66, 0x01, 0xFA, // add DX,DI 0x66, 0x01, 0xEA, // add DX,BP 0x66, 0x01, 0xE2, // add DX,SP 0x66, 0x01, 0xC6, // add SI,AX 0x66, 0x01, 0xDE, // add SI,BX 0x66, 0x01, 0xCE, // add SI,CX 0x66, 0x01, 0xD6, // add SI,DX 0x66, 0x01, 0xF6, // add SI,SI 0x66, 0x01, 0xFE, // add SI,DI 0x66, 0x01, 0xEE, // add SI,BP 0x66, 0x01, 0xE6, // add SI,SP 0x66, 0x01, 0xC7, // add DI,AX 0x66, 0x01, 0xDF, // add DI,BX 0x66, 0x01, 0xCF, // add DI,CX 0x66, 0x01, 0xD7, // add DI,DX 0x66, 0x01, 0xF7, // add DI,SI 0x66, 0x01, 0xFF, // add DI,DI 0x66, 0x01, 0xEF, // add DI,BP 0x66, 0x01, 0xE7, // add DI,SP 0x66, 0x01, 0xC5, // add BP,AX 0x66, 0x01, 0xDD, // add BP,BX 0x66, 0x01, 0xCD, // add BP,CX 0x66, 0x01, 0xD5, // add BP,DX 0x66, 0x01, 0xF5, // add BP,SI 0x66, 0x01, 0xFD, // add BP,DI 0x66, 0x01, 0xED, // add BP,BP 0x66, 0x01, 0xE5, // add BP,SP 0x66, 0x01, 0xC4, // add SP,AX 0x66, 0x01, 0xDC, // add SP,BX 0x66, 0x01, 0xCC, // add SP,CX 0x66, 0x01, 0xD4, // add SP,DX 0x66, 0x01, 0xF4, // add SP,SI 0x66, 0x01, 0xFC, // add SP,DI 0x66, 0x01, 0xEC, // add SP,BP 0x66, 0x01, 0xE4, // add SP,SP 0x01, 0xC0, // add EAX,EAX 0x01, 0xD8, // add EAX,EBX 0x01, 0xC8, // add EAX,ECX 0x01, 0xD0, // add EAX,EDX 0x01, 0xF0, // add EAX,ESI 0x01, 0xF8, // add EAX,EDI 0x01, 0xE8, // add EAX,EBP 0x01, 0xE0, // add EAX,ESP 0x01, 0xC3, // add EBX,EAX 0x01, 0xDB, // add EBX,EBX 0x01, 0xCB, // add EBX,ECX 0x01, 0xD3, // add EBX,EDX 0x01, 0xF3, // add EBX,ESI 0x01, 0xFB, // add EBX,EDI 0x01, 0xEB, // add EBX,EBP 0x01, 0xE3, // add EBX,ESP 0x01, 0xC1, // add ECX,EAX 0x01, 0xD9, // add ECX,EBX 0x01, 0xC9, // add ECX,ECX 0x01, 0xD1, // add ECX,EDX 0x01, 0xF1, // add ECX,ESI 0x01, 0xF9, // add ECX,EDI 0x01, 0xE9, // add ECX,EBP 0x01, 0xE1, // add ECX,ESP 0x01, 0xC2, // add EDX,EAX 0x01, 0xDA, // add EDX,EBX 0x01, 0xCA, // add EDX,ECX 0x01, 0xD2, // add EDX,EDX 0x01, 0xF2, // add EDX,ESI 0x01, 0xFA, // add EDX,EDI 0x01, 0xEA, // add EDX,EBP 0x01, 0xE2, // add EDX,ESP 0x01, 0xC6, // add ESI,EAX 0x01, 0xDE, // add ESI,EBX 0x01, 0xCE, // add ESI,ECX 0x01, 0xD6, // add ESI,EDX 0x01, 0xF6, // add ESI,ESI 0x01, 0xFE, // add ESI,EDI 0x01, 0xEE, // add ESI,EBP 0x01, 0xE6, // add ESI,ESP 0x01, 0xC7, // add EDI,EAX 0x01, 0xDF, // add EDI,EBX 0x01, 0xCF, // add EDI,ECX 0x01, 0xD7, // add EDI,EDX 0x01, 0xF7, // add EDI,ESI 0x01, 0xFF, // add EDI,EDI 0x01, 0xEF, // add EDI,EBP 0x01, 0xE7, // add EDI,ESP 0x01, 0xC5, // add EBP,EAX 0x01, 0xDD, // add EBP,EBX 0x01, 0xCD, // add EBP,ECX 0x01, 0xD5, // add EBP,EDX 0x01, 0xF5, // add EBP,ESI 0x01, 0xFD, // add EBP,EDI 0x01, 0xED, // add EBP,EBP 0x01, 0xE5, // add EBP,ESP 0x01, 0xC4, // add ESP,EAX 0x01, 0xDC, // add ESP,EBX 0x01, 0xCC, // add ESP,ECX 0x01, 0xD4, // add ESP,EDX 0x01, 0xF4, // add ESP,ESI 0x01, 0xFC, // add ESP,EDI 0x01, 0xEC, // add ESP,EBP 0x01, 0xE4, // add ESP,ESP ]; int i; asm { call L1 ; add AL,AL ; add AL,BL ; add AL,CL ; add AL,DL ; add AL,AH ; add AL,BH ; add AL,CH ; add AL,DH ; add AH,AL ; add AH,BL ; add AH,CL ; add AH,DL ; add AH,AH ; add AH,BH ; add AH,CH ; add AH,DH ; add BL,AL ; add BL,BL ; add BL,CL ; add BL,DL ; add BL,AH ; add BL,BH ; add BL,CH ; add BL,DH ; add BH,AL ; add BH,BL ; add BH,CL ; add BH,DL ; add BH,AH ; add BH,BH ; add BH,CH ; add BH,DH ; add CL,AL ; add CL,BL ; add CL,CL ; add CL,DL ; add CL,AH ; add CL,BH ; add CL,CH ; add CL,DH ; add CH,AL ; add CH,BL ; add CH,CL ; add CH,DL ; add CH,AH ; add CH,BH ; add CH,CH ; add CH,DH ; add DL,AL ; add DL,BL ; add DL,CL ; add DL,DL ; add DL,AH ; add DL,BH ; add DL,CH ; add DL,DH ; add DH,AL ; add DH,BL ; add DH,CL ; add DH,DL ; add DH,AH ; add DH,BH ; add DH,CH ; add DH,DH ; add AX,AX ; add AX,BX ; add AX,CX ; add AX,DX ; add AX,SI ; add AX,DI ; add AX,BP ; add AX,SP ; add BX,AX ; add BX,BX ; add BX,CX ; add BX,DX ; add BX,SI ; add BX,DI ; add BX,BP ; add BX,SP ; add CX,AX ; add CX,BX ; add CX,CX ; add CX,DX ; add CX,SI ; add CX,DI ; add CX,BP ; add CX,SP ; add DX,AX ; add DX,BX ; add DX,CX ; add DX,DX ; add DX,SI ; add DX,DI ; add DX,BP ; add DX,SP ; add SI,AX ; add SI,BX ; add SI,CX ; add SI,DX ; add SI,SI ; add SI,DI ; add SI,BP ; add SI,SP ; add DI,AX ; add DI,BX ; add DI,CX ; add DI,DX ; add DI,SI ; add DI,DI ; add DI,BP ; add DI,SP ; add BP,AX ; add BP,BX ; add BP,CX ; add BP,DX ; add BP,SI ; add BP,DI ; add BP,BP ; add BP,SP ; add SP,AX ; add SP,BX ; add SP,CX ; add SP,DX ; add SP,SI ; add SP,DI ; add SP,BP ; add SP,SP ; add EAX,EAX ; add EAX,EBX ; add EAX,ECX ; add EAX,EDX ; add EAX,ESI ; add EAX,EDI ; add EAX,EBP ; add EAX,ESP ; add EBX,EAX ; add EBX,EBX ; add EBX,ECX ; add EBX,EDX ; add EBX,ESI ; add EBX,EDI ; add EBX,EBP ; add EBX,ESP ; add ECX,EAX ; add ECX,EBX ; add ECX,ECX ; add ECX,EDX ; add ECX,ESI ; add ECX,EDI ; add ECX,EBP ; add ECX,ESP ; add EDX,EAX ; add EDX,EBX ; add EDX,ECX ; add EDX,EDX ; add EDX,ESI ; add EDX,EDI ; add EDX,EBP ; add EDX,ESP ; add ESI,EAX ; add ESI,EBX ; add ESI,ECX ; add ESI,EDX ; add ESI,ESI ; add ESI,EDI ; add ESI,EBP ; add ESI,ESP ; add EDI,EAX ; add EDI,EBX ; add EDI,ECX ; add EDI,EDX ; add EDI,ESI ; add EDI,EDI ; add EDI,EBP ; add EDI,ESP ; add EBP,EAX ; add EBP,EBX ; add EBP,ECX ; add EBP,EDX ; add EBP,ESI ; add EBP,EDI ; add EBP,EBP ; add EBP,ESP ; add ESP,EAX ; add ESP,EBX ; add ESP,ECX ; add ESP,EDX ; add ESP,ESI ; add ESP,EDI ; add ESP,EBP ; add ESP,ESP ; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ void test50() { ubyte *p; static ubyte data[] = [ 0x66, 0x98, // cbw 0xF8, // clc 0xFC, // cld 0xFA, // cli 0xF5, // cmc 0xA6, // cmpsb 0x66, 0xA7, // cmpsw 0xA7, // cmpsd 0x66, 0x99, // cwd 0x27, // daa 0x2F, // das 0x48, // dec EAX 0xF6, 0xF1, // div CL 0x66, 0xF7, 0xF3, // div BX 0xF7, 0xF2, // div EDX 0xF4, // hlt 0xF6, 0xFB, // idiv BL 0x66, 0xF7, 0xFA, // idiv DX 0xF7, 0xFE, // idiv ESI 0xF6, 0xEB, // imul BL 0x66, 0xF7, 0xEA, // imul DX 0xF7, 0xEE, // imul ESI 0xEC, // in AL,DX 0x66, 0xED, // in AX,DX 0x43, // inc EBX 0xCC, // int 3 0xCD, 0x67, // int 067h 0xCE, // into 0x66, 0xCF, // iret 0x77, 0xFC, // ja L30 0x77, 0xFA, // ja L30 0x73, 0xF8, // jae L30 0x73, 0xF6, // jae L30 0x73, 0xF4, // jae L30 0x72, 0xF2, // jb L30 0x72, 0xF0, // jb L30 0x76, 0xEE, // jbe L30 0x76, 0xEC, // jbe L30 0x72, 0xEA, // jb L30 0x67, 0xE3, 0xE7, // jcxz L30 0x74, 0xE5, // je L30 0x74, 0xE3, // je L30 0x7F, 0xE1, // jg L30 0x7F, 0xDF, // jg L30 0x7D, 0xDD, // jge L30 0x7D, 0xDB, // jge L30 0x7C, 0xD9, // jl L30 0x7C, 0xD7, // jl L30 0x7E, 0xD5, // jle L30 0x7E, 0xD3, // jle L30 0xEB, 0xD1, // jmp short L30 0x75, 0xCF, // jne L30 0x75, 0xCD, // jne L30 0x71, 0xCB, // jno L30 0x79, 0xC9, // jns L30 0x7B, 0xC7, // jnp L30 0x7B, 0xC5, // jnp L30 0x70, 0xC3, // jo L30 0x7A, 0xC1, // jp L30 0x7A, 0xBF, // jp L30 0x78, 0xBD, // js L30 0x9F, // lahf 0xC5, 0x30, // lds ESI,[EAX] 0x8B, 0xFB, // mov EDI,EBX 0xC4, 0x29, // les EBP,[ECX] 0xF0, // lock 0xAC, // lodsb 0x66, 0xAD, // lodsw 0xAD, // lodsd 0xE2, 0xAF, // loop L30 0xE1, 0xAD, // loope L30 0xE1, 0xAB, // loope L30 0xE0, 0xA9, // loopne L30 0xE0, 0xA7, // loopne L30 0xA4, // movsb 0x66, 0xA5, // movsw 0xA5, // movsd 0xF6, 0xE4, // mul AH 0x66, 0xF7, 0xE1, // mul CX 0xF7, 0xE5, // mul EBP 0x90, // nop 0xF7, 0xD7, // not EDI 0x66, 0xE7, 0x44, // out 044h,AX 0xEE, // out DX,AL 0x66, 0x9D, // popf 0x66, 0x9C, // pushf 0xD1, 0xDB, // rcr EBX,1 0xF3, // rep 0xF3, // rep 0xF2, // repne 0xF3, // rep 0xF2, // repne 0xC3, // ret 0xC2, 0x04, 0x00, // ret 4 0xD1, 0xC1, // rol ECX,1 0xD1, 0xCA, // ror EDX,1 0x9E, // sahf 0xD1, 0xE5, // shl EBP,1 0xD1, 0xE4, // shl ESP,1 0xD1, 0xFF, // sar EDI,1 0xAE, // scasb 0x66, 0xAF, // scasw 0xAF, // scasd 0xD1, 0xEE, // shr ESI,1 0xFD, // std 0xF9, // stc 0xFB, // sti 0xAA, // stosb 0x66, 0xAB, // stosw 0xAB, // stosd 0x9B, // wait 0x91, // xchg EAX,ECX 0xD7, // xlat ]; int i; asm { call L1 ; cbw ; clc ; cld ; cli ; cmc ; cmpsb ; cmpsw ; cmpsd ; cwd ; daa ; das ; dec EAX ; div CL ; div BX ; div EDX ; hlt ; idiv BL ; idiv DX ; idiv ESI ; imul BL ; imul DX ; imul ESI ; in AL,DX ; in AX,DX ; inc EBX ; int 3 ; int 0x67 ; into ; L10: iret ; ja L10 ; jnbe L10 ; jae L10 ; jnb L10 ; jnc L10 ; jb L10 ; jnae L10 ; jbe L10 ; jna L10 ; jc L10 ; jcxz L10 ; je L10 ; jz L10 ; jg L10 ; jnle L10 ; jge L10 ; jnl L10 ; jl L10 ; jnge L10 ; jle L10 ; jng L10 ; jmp short L10 ; jne L10 ; jnz L10 ; jno L10 ; jns L10 ; jnp L10 ; jpo L10 ; jo L10 ; jp L10 ; jpe L10 ; js L10 ; lahf ; lds ESI,[EAX] ; lea EDI,[EBX] ; les EBP,[ECX] ; lock ; lodsb ; lodsw ; lodsd ; loop L10 ; loope L10 ; loopz L10 ; loopnz L10 ; loopne L10 ; movsb ; movsw ; movsd ; mul AH ; mul CX ; mul EBP ; nop ; not EDI ; out 0x44,AX ; out DX,AL ; popf ; pushf ; rcr EBX,1 ; rep ; repe ; repne ; repz ; repnz ; ret ; ret 4 ; rol ECX,1 ; ror EDX,1 ; sahf ; sal EBP,1 ; shl ESP,1 ; sar EDI,1 ; scasb ; scasw ; scasd ; shr ESI,1 ; std ; stc ; sti ; stosb ; stosw ; stosd ; wait ; xchg EAX,ECX ; xlat ; L1: ; pop EBX ; mov p[EBP],EBX ; } for (i = 0; i < data.length; i++) { assert(p[i] == data[i]); } } /****************************************************/ class Test51 { void test(int n) { asm { mov EAX, this; } } } /****************************************************/ void test52() { int x; ubyte* p; static ubyte data[] = [ 0xF6, 0xD8, // neg AL 0x66, 0xF7, 0xD8, // neg AX 0xF7, 0xD8, // neg EAX 0xF6, 0xDC, // neg AH 0xF7, 0x5D, 0xe8, // neg dword ptr -8[EBP] 0xF6, 0x1B, // neg byte ptr [EBX] ]; asm { call L1 ; neg AL ; neg AX ; neg EAX ; neg AH ; // neg b ; // neg w ; // neg i ; // neg l ; neg x ; neg [EBX] ; L1: pop EAX ; mov p[EBP],EAX ; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ void test53() { int x; ubyte* p; static ubyte data[] = [ 0x8D, 0x04, 0x00, // lea EAX,[EAX][EAX] 0x8D, 0x04, 0x08, // lea EAX,[ECX][EAX] 0x8D, 0x04, 0x10, // lea EAX,[EDX][EAX] 0x8D, 0x04, 0x18, // lea EAX,[EBX][EAX] 0x8D, 0x04, 0x28, // lea EAX,[EBP][EAX] 0x8D, 0x04, 0x30, // lea EAX,[ESI][EAX] 0x8D, 0x04, 0x38, // lea EAX,[EDI][EAX] 0x8D, 0x04, 0x00, // lea EAX,[EAX][EAX] 0x8D, 0x04, 0x01, // lea EAX,[EAX][ECX] 0x8D, 0x04, 0x02, // lea EAX,[EAX][EDX] 0x8D, 0x04, 0x03, // lea EAX,[EAX][EBX] 0x8D, 0x04, 0x04, // lea EAX,[EAX][ESP] 0x8D, 0x44, 0x05, 0x00, // lea EAX,0[EAX][EBP] 0x8D, 0x04, 0x06, // lea EAX,[EAX][ESI] 0x8D, 0x04, 0x07, // lea EAX,[EAX][EDI] 0x8D, 0x44, 0x01, 0x12, // lea EAX,012h[EAX][ECX] 0x8D, 0x84, 0x01, 0x34, 0x12, 0x00, 0x00, // lea EAX,01234h[EAX][ECX] 0x8D, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, // lea EAX,012345678h[EAX][ECX] 0x8D, 0x44, 0x05, 0x12, // lea EAX,012h[EAX][EBP] 0x8D, 0x84, 0x05, 0x34, 0x12, 0x00, 0x00, // lea EAX,01234h[EAX][EBP] 0x8D, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, // lea EAX,012345678h[EAX][EBP] ]; asm { call L1 ; // Right lea EAX, [EAX+EAX]; lea EAX, [EAX+ECX]; lea EAX, [EAX+EDX]; lea EAX, [EAX+EBX]; //lea EAX, [EAX+ESP]; ESP can't be on the right lea EAX, [EAX+EBP]; lea EAX, [EAX+ESI]; lea EAX, [EAX+EDI]; // Left lea EAX, [EAX+EAX]; lea EAX, [ECX+EAX]; lea EAX, [EDX+EAX]; lea EAX, [EBX+EAX]; lea EAX, [ESP+EAX]; lea EAX, [EBP+EAX]; // Good gets disp+8 correctly lea EAX, [ESI+EAX]; lea EAX, [EDI+EAX]; // Disp8/32 checks lea EAX, [ECX+EAX+0x12]; lea EAX, [ECX+EAX+0x1234]; lea EAX, [ECX+EAX+0x1234_5678]; lea EAX, [EBP+EAX+0x12]; lea EAX, [EBP+EAX+0x1234]; lea EAX, [EBP+EAX+0x1234_5678]; L1: pop EAX ; mov p[EBP],EAX ; } foreach (i,b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ void test54() { int x; ubyte* p; static ubyte data[] = [ 0xFE, 0xC8, // dec AL 0xFE, 0xCC, // dec AH 0x66, 0x48, // dec AX 0x48, // dec EAX 0xFE, 0xC0, // inc AL 0xFE, 0xC4, // inc AH 0x66, 0x40, // inc AX 0x40, // inc EAX 0x66, 0x0F, 0xA4, 0xC8, 0x04, // shld AX, CX, 4 0x66, 0x0F, 0xA5, 0xC8, // shld AX, CX, CL 0x0F, 0xA4, 0xC8, 0x04, // shld EAX, ECX, 4 0x0F, 0xA5, 0xC8, // shld EAX, ECX, CL 0x66, 0x0F, 0xAC, 0xC8, 0x04, // shrd AX, CX, 4 0x66, 0x0F, 0xAD, 0xC8, // shrd AX, CX, CL 0x0F, 0xAC, 0xC8, 0x04, // shrd EAX, ECX, 4 0x0F, 0xAD, 0xC8, // shrd EAX, ECX, CL ]; asm { call L1; dec AL; dec AH; dec AX; dec EAX; inc AL; inc AH; inc AX; inc EAX; shld AX, CX, 4; shld AX, CX, CL; shld EAX, ECX, 4; shld EAX, ECX, CL; shrd AX, CX, 4; shrd AX, CX, CL; shrd EAX, ECX, 4; shrd EAX, ECX, CL; L1: pop EAX; mov p[EBP],EAX; } foreach (i,b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ void test55() { int x; ubyte* p; enum NOP = 0x9090_9090_9090_9090; static ubyte data[] = [ 0x0F, 0x87, 0xFF, 0xFF, 0, 0, // ja $ + 0xFFFF 0x72, 0x18, // jb Lb 0x0F, 0x82, 0x92, 0x00, 0, 0, // jc Lc 0x0F, 0x84, 0x0C, 0x01, 0, 0, // je Le 0xEB, 0x0A, // jmp Lb 0xE9, 0x85, 0x00, 0x00, 0, // jmp Lc 0xE9, 0x00, 0x01, 0x00, 0, // jmp Le ]; asm { call L1; ja $+0x0_FFFF; jb Lb; jc Lc; je Le; jmp Lb; jmp Lc; jmp Le; Lb: dq NOP,NOP,NOP,NOP; // 32 dq NOP,NOP,NOP,NOP; // 64 dq NOP,NOP,NOP,NOP; // 96 dq NOP,NOP,NOP,NOP; // 128 Lc: dq NOP,NOP,NOP,NOP; // 160 dq NOP,NOP,NOP,NOP; // 192 dq NOP,NOP,NOP,NOP; // 224 dq NOP,NOP,NOP,NOP; // 256 Le: nop; L1: pop EAX; mov p[EBP],EAX; } foreach (i,b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ void test56() { int x; x = foo56(); assert(x == 42); } int foo56() { asm { naked; xor EAX,EAX; jz bar56; ret; } } void bar56() { asm { naked; mov EAX, 42; ret; } } /****************************************************/ /* ======================= SSSE3 ======================= */ void test57() { ubyte* p; M64 m64; M128 m128; static ubyte data[] = [ 0x0F, 0x3A, 0x0F, 0xCA, 0x03, // palignr MM1, MM2, 3 0x66, 0x0F, 0x3A, 0x0F, 0xCA, 0x03, // palignr XMM1, XMM2, 3 0x0F, 0x3A, 0x0F, 0x5D, 0xD8, 0x03, // palignr MM3, -0x28[EBP], 3 0x66, 0x0F, 0x3A, 0x0F, 0x5D, 0xE0, 0x03, // palignr XMM3, -0x20[EBP], 3 0x0F, 0x38, 0x02, 0xCA, // phaddd MM1, MM2 0x66, 0x0F, 0x38, 0x02, 0xCA, // phaddd XMM1, XMM2 0x0F, 0x38, 0x02, 0x5D, 0xD8, // phaddd MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x02, 0x5D, 0xE0, // phaddd XMM3, -0x20[EBP] 0x0F, 0x38, 0x01, 0xCA, // phaddw MM1, MM2 0x66, 0x0F, 0x38, 0x01, 0xCA, // phaddw XMM1, XMM2 0x0F, 0x38, 0x01, 0x5D, 0xD8, // phaddw MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x01, 0x5D, 0xE0, // phaddw XMM3, -0x20[EBP] 0x0F, 0x38, 0x03, 0xCA, // phaddsw MM1, MM2 0x66, 0x0F, 0x38, 0x03, 0xCA, // phaddsw XMM1, XMM2 0x0F, 0x38, 0x03, 0x5D, 0xD8, // phaddsw MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x03, 0x5D, 0xE0, // phaddsw XMM3, -0x20[EBP] 0x0F, 0x38, 0x06, 0xCA, // phsubd MM1, MM2 0x66, 0x0F, 0x38, 0x06, 0xCA, // phsubd XMM1, XMM2 0x0F, 0x38, 0x06, 0x5D, 0xD8, // phsubd MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x06, 0x5D, 0xE0, // phsubd XMM3, -0x20[EBP] 0x0F, 0x38, 0x05, 0xCA, // phsubw MM1, MM2 0x66, 0x0F, 0x38, 0x05, 0xCA, // phsubw XMM1, XMM2 0x0F, 0x38, 0x05, 0x5D, 0xD8, // phsubw MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x05, 0x5D, 0xE0, // phsubw XMM3, -0x20[EBP] 0x0F, 0x38, 0x07, 0xCA, // phsubsw MM1, MM2 0x66, 0x0F, 0x38, 0x07, 0xCA, // phsubsw XMM1, XMM2 0x0F, 0x38, 0x07, 0x5D, 0xD8, // phsubsw MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x07, 0x5D, 0xE0, // phsubsw XMM3, -0x20[EBP] 0x0F, 0x38, 0x04, 0xCA, // pmaddubsw MM1, MM2 0x66, 0x0F, 0x38, 0x04, 0xCA, // pmaddubsw XMM1, XMM2 0x0F, 0x38, 0x04, 0x5D, 0xD8, // pmaddubsw MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x04, 0x5D, 0xE0, // pmaddubsw XMM3, -0x20[EBP] 0x0F, 0x38, 0x0B, 0xCA, // pmulhrsw MM1, MM2 0x66, 0x0F, 0x38, 0x0B, 0xCA, // pmulhrsw XMM1, XMM2 0x0F, 0x38, 0x0B, 0x5D, 0xD8, // pmulhrsw MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x0B, 0x5D, 0xE0, // pmulhrsw XMM3, -0x20[EBP] 0x0F, 0x38, 0x00, 0xCA, // pshufb MM1, MM2 0x66, 0x0F, 0x38, 0x00, 0xCA, // pshufb XMM1, XMM2 0x0F, 0x38, 0x00, 0x5D, 0xD8, // pshufb MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x00, 0x5D, 0xE0, // pshufb XMM3, -0x20[EBP] 0x0F, 0x38, 0x1C, 0xCA, // pabsb MM1, MM2 0x66, 0x0F, 0x38, 0x1C, 0xCA, // pabsb XMM1, XMM2 0x0F, 0x38, 0x1C, 0x5D, 0xD8, // pabsb MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x1C, 0x5D, 0xE0, // pabsb XMM3, -0x20[EBP] 0x0F, 0x38, 0x1E, 0xCA, // pabsd MM1, MM2 0x66, 0x0F, 0x38, 0x1E, 0xCA, // pabsd XMM1, XMM2 0x0F, 0x38, 0x1E, 0x5D, 0xD8, // pabsd MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x1E, 0x5D, 0xE0, // pabsd XMM3, -0x20[EBP] 0x0F, 0x38, 0x1D, 0xCA, // pabsw MM1, MM2 0x66, 0x0F, 0x38, 0x1D, 0xCA, // pabsw XMM1, XMM2 0x0F, 0x38, 0x1D, 0x5D, 0xD8, // pabsw MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x1D, 0x5D, 0xE0, // pabsw XMM3, -0x20[EBP] 0x0F, 0x38, 0x08, 0xCA, // psignb MM1, MM2 0x66, 0x0F, 0x38, 0x08, 0xCA, // psignb XMM1, XMM2 0x0F, 0x38, 0x08, 0x5D, 0xD8, // psignb MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x08, 0x5D, 0xE0, // psignb XMM3, -0x20[EBP] 0x0F, 0x38, 0x0A, 0xCA, // psignd MM1, MM2 0x66, 0x0F, 0x38, 0x0A, 0xCA, // psignd XMM1, XMM2 0x0F, 0x38, 0x0A, 0x5D, 0xD8, // psignd MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x0A, 0x5D, 0xE0, // psignd XMM3, -0x20[EBP] 0x0F, 0x38, 0x09, 0xCA, // psignw MM1, MM2 0x66, 0x0F, 0x38, 0x09, 0xCA, // psignw XMM1, XMM2 0x0F, 0x38, 0x09, 0x5D, 0xD8, // psignw MM3, -0x28[EBP] 0x66, 0x0F, 0x38, 0x09, 0x5D, 0xE0, // psignw XMM3, -0x20[EBP] ]; asm { call L1; palignr MM1, MM2, 3; palignr XMM1, XMM2, 3; palignr MM3, m64 , 3; palignr XMM3, m128, 3; phaddd MM1, MM2; phaddd XMM1, XMM2; phaddd MM3, m64; phaddd XMM3, m128; phaddw MM1, MM2; phaddw XMM1, XMM2; phaddw MM3, m64; phaddw XMM3, m128; phaddsw MM1, MM2; phaddsw XMM1, XMM2; phaddsw MM3, m64; phaddsw XMM3, m128; phsubd MM1, MM2; phsubd XMM1, XMM2; phsubd MM3, m64; phsubd XMM3, m128; phsubw MM1, MM2; phsubw XMM1, XMM2; phsubw MM3, m64; phsubw XMM3, m128; phsubsw MM1, MM2; phsubsw XMM1, XMM2; phsubsw MM3, m64; phsubsw XMM3, m128; pmaddubsw MM1, MM2; pmaddubsw XMM1, XMM2; pmaddubsw MM3, m64; pmaddubsw XMM3, m128; pmulhrsw MM1, MM2; pmulhrsw XMM1, XMM2; pmulhrsw MM3, m64; pmulhrsw XMM3, m128; pshufb MM1, MM2; pshufb XMM1, XMM2; pshufb MM3, m64; pshufb XMM3, m128; pabsb MM1, MM2; pabsb XMM1, XMM2; pabsb MM3, m64; pabsb XMM3, m128; pabsd MM1, MM2; pabsd XMM1, XMM2; pabsd MM3, m64; pabsd XMM3, m128; pabsw MM1, MM2; pabsw XMM1, XMM2; pabsw MM3, m64; pabsw XMM3, m128; psignb MM1, MM2; psignb XMM1, XMM2; psignb MM3, m64; psignb XMM3, m128; psignd MM1, MM2; psignd XMM1, XMM2; psignd MM3, m64; psignd XMM3, m128; psignw MM1, MM2; psignw XMM1, XMM2; psignw MM3, m64; psignw XMM3, m128; L1: pop EAX; mov p[EBP],EAX; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ /* ======================= SSE4.1 ======================= */ void test58() { ubyte* p; byte m8; short m16; int m32; M64 m64; M128 m128; static ubyte data[] = [ 0x66, 0x0F, 0x3A, 0x0D, 0xCA, 3,// blendpd XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x0D, 0x5D, 0xE0, 3,// blendpd XMM3,XMMWORD PTR [RBP-0x20],0x3 0x66, 0x0F, 0x3A, 0x0C, 0xCA, 3,// blendps XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x0C, 0x5D, 0xE0, 3,// blendps XMM3,XMMWORD PTR [RBP-0x20],0x3 0x66, 0x0F, 0x38, 0x15, 0xCA, // blendvpd XMM1,XMM2,XMM0 0x66, 0x0F, 0x38, 0x15, 0x5D, 0xE0, // blendvpd XMM3,XMMWORD PTR [RBP-0x20],XMM0 0x66, 0x0F, 0x38, 0x14, 0xCA, // blendvps XMM1,XMM2,XMM0 0x66, 0x0F, 0x38, 0x14, 0x5D, 0xE0, // blendvps XMM3,XMMWORD PTR [RBP-0x20],XMM0 0x66, 0x0F, 0x3A, 0x41, 0xCA, 3,// dppd XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x41, 0x5D, 0xE0, 3,// dppd XMM3,XMMWORD PTR [RBP-0x20],0x3 0x66, 0x0F, 0x3A, 0x40, 0xCA, 3,// dpps XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x40, 0x5D, 0xE0, 3,// dpps XMM3,XMMWORD PTR [RBP-0x20],0x3 0x66, 0x0F, 0x3A, 0x17, 0xD2, 3,// extractps EDX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x17, 0x55, 0xC8, 3,// extractps DWORD PTR [RBP-0x38],XMM2,0x3 0x66, 0x0F, 0x3A, 0x21, 0xCA, 3,// insertps XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x21, 0x5D, 0xC8, 3,// insertps XMM3,DWORD PTR [RBP-0x38],0x3 0x66, 0x0F, 0x38, 0x2A, 0x4D, 0xE0, // movntdqa XMM1,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x3A, 0x42, 0xCA, 3,// mpsadbw XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x42, 0x5D, 0xE0, 3,// mpsadbw XMM3,XMMWORD PTR [RBP-0x20],0x3 0x66, 0x0F, 0x38, 0x2B, 0xCA, // packusdw XMM1,XMM2 0x66, 0x0F, 0x38, 0x2B, 0x5D, 0xE0, // packusdw XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x38, 0x10, 0xCA, // pblendvb XMM1,XMM2,XMM0 0x66, 0x0F, 0x38, 0x10, 0x5D, 0xE0, // pblendvb XMM3,XMMWORD PTR [RBP-0x20],XMM0 0x66, 0x0F, 0x3A, 0x0E, 0xCA, 3,// pblendw XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x0E, 0x5D, 0xE0, 3,// pblendw XMM3,XMMWORD PTR [RBP-0x20],0x3 0x66, 0x0F, 0x38, 0x29, 0xCA, // pcmpeqq XMM1,XMM2 0x66, 0x0F, 0x38, 0x29, 0x5D, 0xE0, // pcmpeqq XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x3A, 0x14, 0xD0, 3,// pextrb EAX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x14, 0xD3, 3,// pextrb EBX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x14, 0xD1, 3,// pextrb ECX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x14, 0xD2, 3,// pextrb EDX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x14, 0x5D, 0xC4, 3,// pextrb BYTE PTR [RBP-0x3C],XMM3,0x3 0x66, 0x0F, 0x3A, 0x16, 0xD0, 3,// pextrd EAX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x16, 0xD3, 3,// pextrd EBX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x16, 0xD1, 3,// pextrd ECX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x16, 0xD2, 3,// pextrd EDX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x16, 0x5D, 0xC8, 3,// pextrd DWORD PTR [RBP-0x38],XMM3,0x3 0x66, 0x0F, 0xC5, 0xC2, 3,// pextrw EAX,XMM2,0x3 0x66, 0x0F, 0xC5, 0xDA, 3,// pextrw EBX,XMM2,0x3 0x66, 0x0F, 0xC5, 0xCA, 3,// pextrw ECX,XMM2,0x3 0x66, 0x0F, 0xC5, 0xD2, 3,// pextrw EDX,XMM2,0x3 0x66, 0x0F, 0x3A, 0x15, 0x5D, 0xC6, 3,// pextrw WORD PTR [RBP-0x3A],XMM3,0x3 0x66, 0x0F, 0x38, 0x41, 0xCA, // phminposuw XMM1,XMM2 0x66, 0x0F, 0x38, 0x41, 0x5D, 0xE0, // phminposuw XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x3A, 0x20, 0xC8, 3,// pinsrb XMM1,EAX,0x3 0x66, 0x0F, 0x3A, 0x20, 0xCB, 3,// pinsrb XMM1,EBX,0x3 0x66, 0x0F, 0x3A, 0x20, 0xC9, 3,// pinsrb XMM1,ECX,0x3 0x66, 0x0F, 0x3A, 0x20, 0xCA, 3,// pinsrb XMM1,EDX,0x3 0x66, 0x0F, 0x3A, 0x20, 0x5D, 0xC4, 3,// pinsrb XMM3,BYTE PTR [RBP-0x3C],0x3 0x66, 0x0F, 0x3A, 0x22, 0xC8, 3,// pinsrd XMM1,EAX,0x3 0x66, 0x0F, 0x3A, 0x22, 0xCB, 3,// pinsrd XMM1,EBX,0x3 0x66, 0x0F, 0x3A, 0x22, 0xC9, 3,// pinsrd XMM1,ECX,0x3 0x66, 0x0F, 0x3A, 0x22, 0xCA, 3,// pinsrd XMM1,EDX,0x3 0x66, 0x0F, 0x3A, 0x22, 0x5D, 0xC8, 3,// pinsrd XMM3,DWORD PTR [RBP-0x38],0x3 0x66, 0x0F, 0x38, 0x3C, 0xCA, // pmaxsb XMM1,XMM2 0x66, 0x0F, 0x38, 0x3C, 0x5D, 0xE0, // pmaxsb XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x38, 0x3D, 0xCA, // pmaxsd XMM1,XMM2 0x66, 0x0F, 0x38, 0x3D, 0x5D, 0xE0, // pmaxsd XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x38, 0x3F, 0xCA, // pmaxud XMM1,XMM2 0x66, 0x0F, 0x38, 0x3F, 0x5D, 0xE0, // pmaxud XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x38, 0x3E, 0xCA, // pmaxuw XMM1,XMM2 0x66, 0x0F, 0x38, 0x3E, 0x5D, 0xE0, // pmaxuw XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x38, 0x38, 0xCA, // pminsb XMM1,XMM2 0x66, 0x0F, 0x38, 0x38, 0x5D, 0xE0, // pminsb XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x38, 0x39, 0xCA, // pminsd XMM1,XMM2 0x66, 0x0F, 0x38, 0x39, 0x5D, 0xE0, // pminsd XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x38, 0x3B, 0xCA, // pminud XMM1,XMM2 0x66, 0x0F, 0x38, 0x3B, 0x5D, 0xE0, // pminud XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x38, 0x3A, 0xCA, // pminuw XMM1,XMM2 0x66, 0x0F, 0x38, 0x3A, 0x5D, 0xE0, // pminuw XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x38, 0x20, 0xCA, // pmovsxbw XMM1,XMM2 0x66, 0x0F, 0x38, 0x20, 0x5D, 0xD0, // pmovsxbw XMM3,QWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x21, 0xCA, // pmovsxbd XMM1,XMM2 0x66, 0x0F, 0x38, 0x21, 0x5D, 0xC8, // pmovsxbd XMM3,DWORD PTR [RBP-0x38] 0x66, 0x0F, 0x38, 0x22, 0xCA, // pmovsxbq XMM1,XMM2 0x66, 0x0F, 0x38, 0x22, 0x5D, 0xC6, // pmovsxbq XMM3,WORD PTR [RBP-0x3A] 0x66, 0x0F, 0x38, 0x23, 0xCA, // pmovsxwd XMM1,XMM2 0x66, 0x0F, 0x38, 0x23, 0x5D, 0xD0, // pmovsxwd XMM3,QWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x24, 0xCA, // pmovsxwq XMM1,XMM2 0x66, 0x0F, 0x38, 0x24, 0x5D, 0xC8, // pmovsxwq XMM3,DWORD PTR [RBP-0x38] 0x66, 0x0F, 0x38, 0x25, 0xCA, // pmovsxdq XMM1,XMM2 0x66, 0x0F, 0x38, 0x25, 0x5D, 0xD0, // pmovsxdq XMM3,QWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x30, 0xCA, // pmovzxbw XMM1,XMM2 0x66, 0x0F, 0x38, 0x30, 0x5D, 0xD0, // pmovzxbw XMM3,QWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x31, 0xCA, // pmovzxbd XMM1,XMM2 0x66, 0x0F, 0x38, 0x31, 0x5D, 0xC8, // pmovzxbd XMM3,DWORD PTR [RBP-0x38] 0x66, 0x0F, 0x38, 0x32, 0xCA, // pmovzxbq XMM1,XMM2 0x66, 0x0F, 0x38, 0x32, 0x5D, 0xC6, // pmovzxbq XMM3,WORD PTR [RBP-0x3A] 0x66, 0x0F, 0x38, 0x33, 0xCA, // pmovzxwd XMM1,XMM2 0x66, 0x0F, 0x38, 0x33, 0x5D, 0xD0, // pmovzxwd XMM3,QWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x34, 0xCA, // pmovzxwq XMM1,XMM2 0x66, 0x0F, 0x38, 0x34, 0x5D, 0xC8, // pmovzxwq XMM3,DWORD PTR [RBP-0x38] 0x66, 0x0F, 0x38, 0x35, 0xCA, // pmovzxdq XMM1,XMM2 0x66, 0x0F, 0x38, 0x35, 0x5D, 0xD0, // pmovzxdq XMM3,QWORD PTR [RBP-0x30] 0x66, 0x0F, 0x38, 0x28, 0xCA, // pmuldq XMM1,XMM2 0x66, 0x0F, 0x38, 0x28, 0x5D, 0xE0, // pmuldq XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x38, 0x40, 0xCA, // pmulld XMM1,XMM2 0x66, 0x0F, 0x38, 0x40, 0x5D, 0xE0, // pmulld XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x38, 0x17, 0xCA, // ptest XMM1,XMM2 0x66, 0x0F, 0x38, 0x17, 0x5D, 0xE0, // ptest XMM3,XMMWORD PTR [RBP-0x20] 0x66, 0x0F, 0x3A, 0x09, 0xCA, 3,// roundpd XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x09, 0x5D, 0xE0, 3,// roundpd XMM3,XMMWORD PTR [RBP-0x20],0x3 0x66, 0x0F, 0x3A, 0x08, 0xCA, 3,// roundps XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x08, 0x5D, 0xE0, 3,// roundps XMM3,XMMWORD PTR [RBP-0x20],0x3 0x66, 0x0F, 0x3A, 0x0B, 0xCA, 3,// roundsd XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x0B, 0x5D, 0xD0, 3,// roundsd XMM3,QWORD PTR [RBP-0x30],0x3 0x66, 0x0F, 0x3A, 0x0A, 0xCA, 3,// roundss XMM1,XMM2,0x3 0x66, 0x0F, 0x3A, 0x0A, 0x4D, 0xC8, 3,// roundss xmm1,dword ptr [rbp-0x38],0x3 ]; asm { call L1; blendpd XMM1, XMM2, 3; blendpd XMM3, m128, 3; blendps XMM1, XMM2, 3; blendps XMM3, m128, 3; blendvpd XMM1, XMM2, XMM0; blendvpd XMM3, m128, XMM0; blendvps XMM1, XMM2, XMM0; blendvps XMM3, m128, XMM0; dppd XMM1, XMM2, 3; dppd XMM3, m128, 3; dpps XMM1, XMM2, 3; dpps XMM3, m128, 3; extractps EDX, XMM2, 3; extractps m32, XMM2, 3; insertps XMM1, XMM2, 3; insertps XMM3, m32, 3; movntdqa XMM1, m128; mpsadbw XMM1, XMM2, 3; mpsadbw XMM3, m128, 3; packusdw XMM1, XMM2; packusdw XMM3, m128; pblendvb XMM1, XMM2, XMM0; pblendvb XMM3, m128, XMM0; pblendw XMM1, XMM2, 3; pblendw XMM3, m128, 3; pcmpeqq XMM1, XMM2; pcmpeqq XMM3, m128; pextrb EAX, XMM2, 3; pextrb EBX, XMM2, 3; pextrb ECX, XMM2, 3; pextrb EDX, XMM2, 3; pextrb m8, XMM3, 3; pextrd EAX, XMM2, 3; pextrd EBX, XMM2, 3; pextrd ECX, XMM2, 3; pextrd EDX, XMM2, 3; pextrd m32, XMM3, 3; pextrw EAX, XMM2, 3; pextrw EBX, XMM2, 3; pextrw ECX, XMM2, 3; pextrw EDX, XMM2, 3; pextrw m16, XMM3, 3; phminposuw XMM1, XMM2; phminposuw XMM3, m128; pinsrb XMM1, EAX, 3; pinsrb XMM1, EBX, 3; pinsrb XMM1, ECX, 3; pinsrb XMM1, EDX, 3; pinsrb XMM3, m8, 3; pinsrd XMM1, EAX, 3; pinsrd XMM1, EBX, 3; pinsrd XMM1, ECX, 3; pinsrd XMM1, EDX, 3; pinsrd XMM3, m32, 3; pmaxsb XMM1, XMM2; pmaxsb XMM3, m128; pmaxsd XMM1, XMM2; pmaxsd XMM3, m128; pmaxud XMM1, XMM2; pmaxud XMM3, m128; pmaxuw XMM1, XMM2; pmaxuw XMM3, m128; pminsb XMM1, XMM2; pminsb XMM3, m128; pminsd XMM1, XMM2; pminsd XMM3, m128; pminud XMM1, XMM2; pminud XMM3, m128; pminuw XMM1, XMM2; pminuw XMM3, m128; pmovsxbw XMM1, XMM2; pmovsxbw XMM3, m64; pmovsxbd XMM1, XMM2; pmovsxbd XMM3, m32; pmovsxbq XMM1, XMM2; pmovsxbq XMM3, m16; pmovsxwd XMM1, XMM2; pmovsxwd XMM3, m64; pmovsxwq XMM1, XMM2; pmovsxwq XMM3, m32; pmovsxdq XMM1, XMM2; pmovsxdq XMM3, m64; pmovzxbw XMM1, XMM2; pmovzxbw XMM3, m64; pmovzxbd XMM1, XMM2; pmovzxbd XMM3, m32; pmovzxbq XMM1, XMM2; pmovzxbq XMM3, m16; pmovzxwd XMM1, XMM2; pmovzxwd XMM3, m64; pmovzxwq XMM1, XMM2; pmovzxwq XMM3, m32; pmovzxdq XMM1, XMM2; pmovzxdq XMM3, m64; pmuldq XMM1, XMM2; pmuldq XMM3, m128; pmulld XMM1, XMM2; pmulld XMM3, m128; ptest XMM1, XMM2; ptest XMM3, m128; roundpd XMM1, XMM2, 3; roundpd XMM3, m128, 3; roundps XMM1, XMM2, 3; roundps XMM3, m128, 3; roundsd XMM1, XMM2, 3; roundsd XMM3, m64, 3; roundss XMM1, XMM2, 3; roundss XMM1, m32, 3; L1: pop EAX; mov p[EBP],EAX; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /****************************************************/ /* ======================= SSE4.2 ======================= */ void test59() { ubyte* p; byte m8; short m16; int m32; M64 m64; M128 m128; static ubyte data[] = [ 0xF2, 0x0F, 0x38, 0xF0, 0xC1, // crc32 EAX, CL 0x66, 0xF2, 0x0F, 0x38, 0xF1, 0xC1, // crc32 EAX, CX 0xF2, 0x0F, 0x38, 0xF1, 0xC1, // crc32 EAX, ECX 0xF2, 0x0F, 0x38, 0xF0, 0x55, 0xC4, // crc32 EDX, byte ptr [RBP-0x3C] 0x66, 0xF2, 0x0F, 0x38, 0xF1, 0x55, 0xC6, // crc32 EDX, word ptr [RBP-0x3A] 0xF2, 0x0F, 0x38, 0xF1, 0x55, 0xC8, // crc32 EDX,dword ptr [RBP-0x38] 0x66, 0x0F, 0x3A, 0x61, 0xCA, 2, // pcmpestri XMM1,XMM2, 2 0x66, 0x0F, 0x3A, 0x61, 0x5D, 0xE0, 2, // pcmpestri XMM3,xmmword ptr [RBP-0x20], 2 0x66, 0x0F, 0x3A, 0x60, 0xCA, 2, // pcmpestrm XMM1,XMM2, 2 0x66, 0x0F, 0x3A, 0x60, 0x5D, 0xE0, 2, // pcmpestrm XMM3,xmmword ptr [RBP-0x20], 2 0x66, 0x0F, 0x3A, 0x63, 0xCA, 2, // pcmpistri XMM1,XMM2, 2 0x66, 0x0F, 0x3A, 0x63, 0x5D, 0xE0, 2, // pcmpistri XMM3,xmmword ptr [RBP-0x20], 2 0x66, 0x0F, 0x3A, 0x62, 0xCA, 2, // pcmpistrm XMM1,XMM2, 2 0x66, 0x0F, 0x3A, 0x62, 0x5D, 0xE0, 2, // pcmpistrm XMM3,xmmword ptr [RBP-0x20], 2 0x66, 0x0F, 0x38, 0x37, 0xCA, // pcmpgtq XMM1,XMM2 0x66, 0x0F, 0x38, 0x37, 0x5D, 0xE0, // pcmpgtq XMM3,xmmword ptr [RBP-0x20] 0x66, 0xF3, 0x0F, 0xB8, 0xC1, // popcnt AX, CX 0xF3, 0x0F, 0xB8, 0xC1, // popcnt EAX, ECX 0x66, 0xF3, 0x0F, 0xB8, 0x55, 0xC6, // popcnt DX, word ptr [RBP-0x3A] 0xF3, 0x0F, 0xB8, 0x55, 0xC8, // popcnt EDX,dword ptr [RBP-0x38] ]; asm { call L1; crc32 EAX, CL; crc32 EAX, CX; crc32 EAX, ECX; crc32 EDX, m8; crc32 EDX, m16; crc32 EDX, m32; pcmpestri XMM1, XMM2, 2; pcmpestri XMM3, m128, 2; pcmpestrm XMM1, XMM2, 2; pcmpestrm XMM3, m128, 2; pcmpistri XMM1, XMM2, 2; pcmpistri XMM3, m128, 2; pcmpistrm XMM1, XMM2, 2; pcmpistrm XMM3, m128, 2; pcmpgtq XMM1, XMM2; pcmpgtq XMM3, m128; popcnt AX, CX; popcnt EAX, ECX; popcnt DX, m16; popcnt EDX, m32; L1: pop EAX; mov p[EBP],EAX; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } /* ======================= SHA ========================== */ void test60() { ubyte* p; byte m8; short m16; int m32; M64 m64; M128 m128; static ubyte data[] = [ 0x0F, 0x3A, 0xCC, 0xD1, 0x01, // sha1rnds4 XMM2, XMM1, 1; 0x0F, 0x3A, 0xCC, 0x10, 0x01, // sha1rnds4 XMM2, [RAX], 1; 0x0F, 0x38, 0xC8, 0xD1, // sha1nexte XMM2, XMM1; 0x0F, 0x38, 0xC8, 0x10, // sha1nexte XMM2, [RAX]; 0x0F, 0x38, 0xC9, 0xD1, // sha1msg1 XMM2, XMM1; 0x0F, 0x38, 0xC9, 0x10, // sha1msg1 XMM2, [RAX]; 0x0F, 0x38, 0xCA, 0xD1, // sha1msg2 XMM2, XMM1; 0x0F, 0x38, 0xCA, 0x10, // sha1msg2 XMM2, [RAX]; 0x0F, 0x38, 0xCB, 0xD1, // sha256rnds2 XMM2, XMM1; 0x0F, 0x38, 0xCB, 0x10, // sha256rnds2 XMM2, [RAX]; 0x0F, 0x38, 0xCC, 0xD1, // sha256msg1 XMM2, XMM1; 0x0F, 0x38, 0xCC, 0x10, // sha256msg1 XMM2, [RAX]; 0x0F, 0x38, 0xCD, 0xD1, // sha256msg2 XMM2, XMM1; 0x0F, 0x38, 0xCD, 0x10, // sha256msg2 XMM2, [RAX]; ]; asm { call L1; sha1rnds4 XMM2, XMM1, 1; sha1rnds4 XMM2, [EAX], 1; sha1nexte XMM2, XMM1; sha1nexte XMM2, [EAX]; sha1msg1 XMM2, XMM1; sha1msg1 XMM2, [EAX]; sha1msg2 XMM2, XMM1; sha1msg2 XMM2, [EAX]; sha256rnds2 XMM2, XMM1; sha256rnds2 XMM2, [EAX]; sha256msg1 XMM2, XMM1; sha256msg1 XMM2, [EAX]; sha256msg2 XMM2, XMM1; sha256msg2 XMM2, [EAX]; L1: pop EAX; mov p[EBP],EAX; } foreach (ref i, b; data) { //printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } } void test9866() { ubyte* p; static ubyte data[] = [ 0x66, 0x0f, 0xbe, 0xc0, // movsx AX, AL; 0x66, 0x0f, 0xbe, 0x00, // movsx AX, byte ptr [EAX]; 0x0f, 0xbe, 0xc0, // movsx EAX, AL; 0x0f, 0xbe, 0x00, // movsx EAX, byte ptr [EAX]; 0x66, 0x0f, 0xbf, 0xc0, // movsx AX, AX; 0x66, 0x0f, 0xbf, 0x00, // movsx AX, word ptr [EAX]; 0x0f, 0xbf, 0xc0, // movsx EAX, AX; 0x0f, 0xbf, 0x00, // movsx EAX, word ptr [EAX]; 0x66, 0x0f, 0xb6, 0xc0, // movzx AX, AL; 0x66, 0x0f, 0xb6, 0x00, // movzx AX, byte ptr [EAX]; 0x0f, 0xb6, 0xc0, // movzx EAX, AL; 0x0f, 0xb6, 0x00, // movzx EAX, byte ptr [EAX]; 0x66, 0x0f, 0xb7, 0xc0, // movzx AX, AX; 0x66, 0x0f, 0xb7, 0x00, // movzx AX, word ptr [EAX]; 0x0f, 0xb7, 0xc0, // movzx EAX, AX; 0x0f, 0xb7, 0x00, // movzx EAX, word ptr [EAX]; ]; asm { call L1; movsx AX, AL; movsx AX, byte ptr [EAX]; movsx EAX, AL; movsx EAX, byte ptr [EAX]; movsx AX, AX; movsx AX, word ptr [EAX]; movsx EAX, AX; movsx EAX, word ptr [EAX]; movzx AX, AL; movzx AX, byte ptr [EAX]; movzx EAX, AL; movzx EAX, byte ptr [EAX]; movzx AX, AX; movzx AX, word ptr [EAX]; movzx EAX, AX; movzx EAX, word ptr [EAX]; L1: pop EAX; mov p[EBP],EAX; } foreach (ref i, b; data) { // printf("data[%d] = 0x%02x, should be 0x%02x\n", i, p[i], b); assert(p[i] == b); } assert(p[data.length] == 0x58); // pop EAX } /****************************************************/ void test5012() { void bar() {} asm { mov EAX, bar; } } /****************************************************/ int main() { printf("Testing iasm.d\n"); test1(); test2(); test3(); test4(); version (OSX) { } else { test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); //test16(); // add this one from \cbx\test\iasm.c ? test17(); test18(); test19(); //test20(); test21(); test22(); test23(); test24(); test25(); test26(); test27(); test28(); test29(); test30(); test31(); test32(); test33(); test34(); test35(); test36(); test37(); test38(); test39(); test40(); test41(); test42(); test43(); test44(); test45(); test46(); test47(); test48(); test49(); test50(); //Test51 test52(); test53(); test54(); test55(); test56(); test57(); test58(); test59(); test60(); test9866(); } printf("Success\n"); return 0; } } else { int main() { return 0; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/xtest55.d0000644000175000017500000000065213200164642023100 0ustar matthiasmatthias// PERMUTE_ARGS: import core.memory, std.stdio; Stuff* stuff1; struct Stuff { uint num; } int main() { stuff1 = new Stuff; stuff1.num = 1; auto bar = new byte[1024 * 1024]; auto stuff2 = new Stuff; stuff2.num = 2; writeln(stuff1, "\t", stuff2); // Same address. assert(stuff1 != stuff2); writeln(stuff1.num, "\t", stuff2.num); // Both 2. assert(stuff1.num == 1); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/test27.d0000644000175000017500000000026413200164642022706 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/test27a.d // PERMUTE_ARGS: import imports.test27a; int main() { auto v = new myClass!(int)(); v.func(5); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/casting.d0000644000175000017500000001032013200164642023200 0ustar matthiasmatthiasextern(C) int printf(const char*, ...); template Seq(T...) { alias T Seq; } /***************************************************/ // 3133 void test3133() { short[2] x = [1, 2]; auto y = cast(int[1])x; // no error } /***************************************************/ // 7504 void test7504() pure nothrow @safe { auto n = null; char[] k = n; assert(k.ptr == null); assert(k.length == 0); double[] l; l = n; assert(l.ptr == null); assert(l.length == 0); immutable(int[]) m = n; assert(m.ptr == null); assert(m.length == 0); const(float)[] o; o = n; assert(o.ptr == null); assert(o.length == 0); auto c = create7504(null, null); assert(c.k.ptr == null); assert(c.k.length == 0); assert(c.l.ptr == null); assert(c.l.length == 0); } class C7504 { int[] k; string l; } C7504 create7504(T...)(T input) { auto obj = new C7504; obj.tupleof = input; return obj; } /***************************************************/ // 8119 struct S8119; void test8119() { void* v; auto sp1 = cast(S8119*)v; int* i; auto sp2 = cast(S8119*)i; S8119* s; auto ip = cast(int*)s; } /***************************************************/ // 8645 template TypeTuple8645(TL...) { alias TL TypeTuple8645; } void test8645() { alias TypeTuple8645!(int) Foo; int bar; static assert(!is(typeof( cast(Foo)bar ))); } /***************************************************/ // 10497 struct S10497; void test10497(S10497** s) { void* ptr; *s = cast(S10497*)ptr; } /***************************************************/ // 10793 struct RealFoo10793 { int i; } struct Foo10793; void test10793() { auto rf = RealFoo10793(10); void* prf = cast(void*)&rf; Foo10793* f = cast(Foo10793*)prf; } /***************************************************/ // 10834 void test10834() { struct S { int i; } S s; cast(void)s; class C { int i; } C c; cast(void)c; enum E { a, b } E e; cast(void)e; int[] ia; cast(void)ia; } /***************************************************/ // 10842 template Test10842(F, T) { bool res; F from() { res = true; return F.init; } T to() { // The cast operand had incorrectly been eliminated return cast(T)from(); } bool test() { res = false; to(); return res; } } void test10842() { foreach (From; Seq!(bool, byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real)) { foreach (To; Seq!(ifloat, idouble, ireal)) { if (!Test10842!(From, To).test()) assert(0); } } foreach (From; Seq!(ifloat, idouble, ireal)) { foreach (To; Seq!(/*bool*, */byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real)) { if (!Test10842!(From, To).test()) assert(0); } } if (!Test10842!(typeof(null), string).test()) // 10842 assert(0); } /***************************************************/ // 11722 class C11722 { T opCast(T)() { assert(0); } } void test11722() { C11722 c = new C11722(); shared C11722 sc = cast(shared)c; } /***************************************************/ // 14218 void test14218() { foreach (To; Seq!( byte, short, int, long, ubyte, ushort, uint, ulong, char, wchar, dchar, bool)) { auto x = cast(To)null; assert(x == 0); // false, '0x00' } // Questionable but currently accepted foreach (To; Seq!( float, double, real, ifloat, idouble, ireal)) { auto x = cast(To)null; assert(x == 0); // 0i } // Internal error: backend/el.c in el_long() //foreach (To; Seq!(cfloat, cdouble, creal)) //{ // static assert(!__traits(compiles, { auto x = cast(To)null; })); //} } /***************************************************/ int main() { test3133(); test7504(); test8119(); test8645(); test10793(); test10834(); test10842(); test11722(); test14218(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/testsafe.d0000644000175000017500000002526213200164642023401 0ustar matthiasmatthias// PERMUTE_ARGS: //http://d.puremagic.com/issues/show_bug.cgi?id=5415 @safe void pointercast() { int* a; void* b; static assert( __traits(compiles, cast(void*)a)); static assert(!__traits(compiles, cast(int*)b)); static assert(!__traits(compiles, cast(int*)b)); static assert(!__traits(compiles, cast(short*)b)); static assert( __traits(compiles, cast(byte*)b)); static assert( __traits(compiles, cast(short*)a)); static assert( __traits(compiles, cast(byte*)a)); } @safe void pointercast2() { size_t a; int b; Object c; static assert(!__traits(compiles, cast(void*)a)); static assert(!__traits(compiles, cast(void*)b)); static assert(!__traits(compiles, cast(void*)c)); } @safe void pointerarithmetic() {//http://d.puremagic.com/issues/show_bug.cgi?id=4132 void* a; int b; static assert(!__traits(compiles, a + b)); static assert(!__traits(compiles, a - b)); static assert(!__traits(compiles, a += b)); static assert(!__traits(compiles, a -= b)); static assert(!__traits(compiles, a++)); static assert(!__traits(compiles, a--)); static assert(!__traits(compiles, ++a)); static assert(!__traits(compiles, --a)); static assert( __traits(compiles, a + 0)); static assert( __traits(compiles, a - 0)); static assert( __traits(compiles, 0 + a)); static assert(!__traits(compiles, a + 1)); static assert(!__traits(compiles, a - 1)); static assert(!__traits(compiles, 1 + a)); static assert( __traits(compiles, a += 0)); static assert( __traits(compiles, a -= 0)); static assert(!__traits(compiles, a += 1)); static assert(!__traits(compiles, a -= 1)); } union SafeUnion1 { int a; struct { int b; int* c; } } union SafeUnion2 { int a; struct { int b; int c; } } union UnsafeUnion1 { int a; int* c; } union UnsafeUnion2 { int a; align(1) struct { byte b; int* c; } } union UnsafeUnion3 { int a; Object c; } union UnsafeUnion4 { int a; align(1) struct { byte b; Object c; } } struct pwrapper { int* a; } union UnsafeUnion5 { SafeUnion2 x; pwrapper b; } union uA { struct { int* a; void* b; } } struct uB { uA a; } struct uC { uB a; } struct uD { uC a; } @safe void safeunions() // improved for issue 11510 { SafeUnion1 su1; SafeUnion2 su2; UnsafeUnion1 uu1; UnsafeUnion2 uu2; UnsafeUnion3 uu3; UnsafeUnion4 uu4; UnsafeUnion5 uu5; uD uud; int n; void* p; Object o; // Writing field is always allowed, even if it is overlapped. su1.a = 7, su1.b = 8, su1.c = null; su2.a = 7, su2.b = 8, su2.c = 9; uu1.a = 7, uu1.c = null; uu2.a = 7; uu2.b = 8, uu2.c = null; uu3.a = 7; uu3.c = null; uu4.a = 7; uu4.b = 8, uu4.c = null; uu5.x.a = 7; uu5.x.b = 8, uu5.x.c = 9; uud.a.a.a.a = null, uud.a.a.a.b = null; // Reading field is allowed, if it is not overlapped or has no pointers. n = su1.a, n = su1.b, p = su1.c; n = su2.a, n = su2.b, n = su2.c; n = uu1.a; n = uu2.a, n = uu2.b; n = uu3.a; n = uu4.a, n = uu4.b; n = uu5.x.a, n = uu5.x.b, n = uu5.x.c; p = uud.a.a.a.a, p = uud.a.a.a.b; // Reading overlapped pointer field is not allowed. static assert(!__traits(compiles, { auto p = uu1.c; })); static assert(!__traits(compiles, { auto p = uu2.c; })); static assert(!__traits(compiles, { auto c = uu3.c; })); static assert(!__traits(compiles, { auto c = uu4.c; })); static assert(!__traits(compiles, { auto p = uu5.b.a; })); } @safe void safeexception() { try {} catch(Exception e) {} static assert(!__traits(compiles, { try {} catch(Error e) {} })); static assert(!__traits(compiles, { try {} catch(Throwable e) {} })); static assert(!__traits(compiles, { try {} catch {} })); } version (D_InlineAsm_X86) version = DMD_InlineAsm; version (D_InlineAsm_X86_64) version = DMD_InlineAsm; version (DMD_InlineAsm) { @safe void inlineasm() { static assert(!__traits(compiles, { asm { int 3; } }() )); } } version (LDC) { @safe void ldc_inlineasm() { import ldc.llvmasm; static assert(!__traits(compiles, { __asm("", ""); }() )); } } @safe void multablecast() { Object m; const(Object) c; immutable(Object) i; static assert( __traits(compiles, cast(const(Object))m)); static assert( __traits(compiles, cast(const(Object))i)); static assert(!__traits(compiles, cast(immutable(Object))m)); static assert(!__traits(compiles, cast(immutable(Object))c)); static assert(!__traits(compiles, cast(Object)c)); static assert(!__traits(compiles, cast(Object)i)); void* mp; const(void)* cp; immutable(void)* ip; static assert( __traits(compiles, cast(const(void)*)mp)); static assert( __traits(compiles, cast(const(void)*)ip)); static assert(!__traits(compiles, cast(immutable(void)*)mp)); static assert(!__traits(compiles, cast(immutable(void)*)cp)); static assert(!__traits(compiles, cast(void*)cp)); static assert(!__traits(compiles, cast(void*)ip)); } @safe void sharedcast() { Object local; shared(Object) xshared; immutable(Object) ishared; static assert(!__traits(compiles, cast()xshared)); static assert(!__traits(compiles, cast(shared)local)); static assert(!__traits(compiles, cast(immutable)xshared)); static assert(!__traits(compiles, cast(shared)ishared)); } int threadlocalvar; @safe void takeaddr() { static assert(!__traits(compiles, (int x) { auto y = &x; } )); static assert(!__traits(compiles, { int x; auto y = &x; } )); static assert( __traits(compiles, { static int x; auto y = &x; } )); static assert( __traits(compiles, { auto y = &threadlocalvar; } )); } __gshared int gsharedvar; @safe void use__gshared() { static assert(!__traits(compiles, { int x = gsharedvar; } )); } @safe void voidinitializers() {//http://d.puremagic.com/issues/show_bug.cgi?id=4885 static assert(!__traits(compiles, { uint* ptr = void; } )); static assert( __traits(compiles, { uint i = void; } )); static assert( __traits(compiles, { uint[2] a = void; } )); struct ValueStruct { int a; } struct NonValueStruct { int* a; } static assert( __traits(compiles, { ValueStruct a = void; } )); static assert(!__traits(compiles, { NonValueStruct a = void; } )); static assert(!__traits(compiles, { uint[] a = void; } )); static assert(!__traits(compiles, { int** a = void; } )); static assert(!__traits(compiles, { int[int] a = void; } )); } @safe void pointerindex() {//http://d.puremagic.com/issues/show_bug.cgi?id=9195 static assert(!__traits(compiles, { int* p; auto a = p[30]; })); static assert( __traits(compiles, { int* p; auto a = p[0]; })); } @safe void basiccast() {//http://d.puremagic.com/issues/show_bug.cgi?id=5088 auto a = cast(int)cast(const int)1; auto b = cast(real)cast(const int)1; auto c = cast(real)cast(const real)2.0; } @safe void arraycast() { int[] x; void[] y = x; static assert( __traits(compiles, cast(void[])x)); static assert( __traits(compiles, cast(int[])y)); static assert(!__traits(compiles, cast(int*[])y)); static assert(!__traits(compiles, cast(void[][])y)); int[3] a; int[] b = cast(int[])a; uint[3] c = cast(uint[3])a; const char[] cc; static assert( __traits(compiles, cast(const(ubyte)[])cc)); static assert( __traits(compiles, cast(const(ubyte[]))cc)); static assert(!__traits(compiles, cast(shared(ubyte)[])cc)); shared char[] sc; static assert( __traits(compiles, cast(shared(ubyte)[])sc)); static assert( __traits(compiles, cast(shared(ubyte[]))sc)); static assert(!__traits(compiles, cast(const(ubyte)[])sc)); } @safe void structcast() { struct A { ptrdiff_t x; } struct B { size_t x; } struct C { void* x; } A a; B b; C c; static assert( __traits(compiles, a = cast(A)b)); static assert( __traits(compiles, a = cast(A)c)); static assert( __traits(compiles, b = cast(B)a)); static assert( __traits(compiles, b = cast(B)c)); static assert(!__traits(compiles, c = cast(C)a)); static assert(!__traits(compiles, c = cast(C)b)); } @safe void test6497() { int n; (0 ? n : n) = 3; } @safe void varargs() { static void fun(string[] val...) {} fun("a"); } extern(C++) interface E {} extern(C++) interface F : E {} @safe void classcast() { class A {}; class B : A {}; A a; B b; static assert( __traits(compiles, cast(A)a)); static assert( __traits(compiles, cast(B)a)); static assert( __traits(compiles, cast(A)b)); static assert( __traits(compiles, cast(B)b)); const A ca; const B cb; static assert( __traits(compiles, cast(const(A))ca)); static assert( __traits(compiles, cast(const(B))ca)); static assert( __traits(compiles, cast(const(A))cb)); static assert( __traits(compiles, cast(const(B))cb)); static assert(!__traits(compiles, cast(A)ca)); static assert(!__traits(compiles, cast(B)ca)); static assert(!__traits(compiles, cast(A)cb)); static assert(!__traits(compiles, cast(B)cb)); interface C {}; interface D : C {}; C c; D d; static assert( __traits(compiles, cast(C)c)); static assert( __traits(compiles, cast(D)c)); static assert( __traits(compiles, cast(C)d)); static assert( __traits(compiles, cast(D)d)); E e; F f; static assert( __traits(compiles, cast(E)e)); static assert(!__traits(compiles, cast(F)e)); static assert( __traits(compiles, cast(E)f)); static assert( __traits(compiles, cast(F)f)); } /***************************************************/ // 6278 @safe { class A6278 { int test() in { assert(0); } body { return 1; } } class B6278 : A6278 { override int test() in { assert(0); } body { return 1; } } } /***************************************************/ // 7803 @safe int f7803() { scope(success) {/* ... */} return 3; } nothrow int g7803() { scope(success) {/* ... */} return 3; } /***************************************************/ // 6405 void foo6405(int[][] args...) @trusted { } void test6405() @safe { foo6405([1,2,3], [1,2,3]); } /***************************************************/ // 12502 void test12502() @safe { const char[1] arr; auto ax = cast(const(char) []) arr[]; // ok auto a1 = cast(const(ubyte)[]) arr[]; // ok auto a2 = cast(const(char) []) arr; // ok auto a3 = cast(const(ubyte)[]) arr; // ok <- error } /***************************************************/ void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/link11069b.d0000644000175000017500000000042013200164642023250 0ustar matthiasmatthias// COMPILE_SEPARATELY // EXTRA_SOURCES: imports/link11069x.d // EXTRA_SOURCES: imports/link11069y.d // EXTRA_SOURCES: imports/link11069z.d import imports.link11069y; import imports.link11069z; void foo() { Vector2 rsm; readWriteVariable(rsm); } void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/0000755000175000017500000000000013200164642023632 5ustar matthiasmatthiasldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/hello-profile-postscript.sh0000755000175000017500000000110613200164642031140 0ustar matthiasmatthias#!/usr/bin/env bash # strip out Dmain since it's symbol differs between windows and non-windows grep -v Dmain ${RESULTS_DIR}/runnable/hello-profile.d.trace.def > ${RESULTS_DIR}/runnable/hello-profile.d.trace.def2 diff --strip-trailing-cr runnable/extra-files/hello-profile.d.trace.def ${RESULTS_DIR}/runnable/hello-profile.d.trace.def2 if [ $? -ne 0 ]; then exit 1; fi tracelog=${RESULTS_DIR}/runnable/hello-profile.d.trace.log if [ ! -f ${tracelog} ]; then echo "missing file: ${tracelog}" exit 1 fi rm ${RESULTS_DIR}/runnable/hello-profile.d.trace.{def,def2,log} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/test_shared.d0000644000175000017500000000002013200164642026274 0ustar matthiasmatthiasvoid main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/linkdebug_uni.d0000644000175000017500000000065313200164642026622 0ustar matthiasmatthiasmodule linkdebug_uni; import linkdebug_range; struct GcPolicy {} alias CodepointSet = InversionList!(); struct InversionList(SP = GcPolicy) { @trusted: size_t addInterval(int a, int b, size_t hint = 0) { auto data = new uint[](0); // affects to the number of missimg symbol auto range = assumeSorted(data[]); // NG //SortedRange!(uint[], "a < b") SR; // OK return 1; } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/test2.d0000644000175000017500000001357513200164642025053 0ustar matthiasmatthias import object; import core.stdc.stdio; import std.algorithm; /* ================================ */ class Foo { int foo(int x) { return x + 3; } } class Bar : Foo { override int foo(int y) { return y + 4; } } void test1() { Bar e; assert(e is null); e = new Bar(); assert(e.foo(5) == 9); } /* ================================ */ class Foo2 { int foo(int x) { return x + 3; } } class Bar2 : Foo2 { override int foo(int y) { assert(Foo2.foo(2) == 5); return y + 4; } } void test2() { Bar2 e; assert(e is null); e = new Bar2(); assert(e.foo(5) == 9); assert(e.Foo2.foo(10) == 13); } /* ================================ */ void test3() { debug printf("debug\n"); debug(1) printf("debug(1)\n"); debug(2) printf("debug(2)\n"); debug(3) printf("debug(3)\n"); debug(bar) printf("debug(bar)\n"); debug(10) assert(0); debug(1) { int d1 = 3; printf("debug(1) { }\n"); } debug(2) { printf("debug(2): d1 = %d\n", d1); } } /* ================================ */ int x1; int x2; class Foo4 { static this() { x1 = 3; printf("Foo4 ctor()\n"); } static ~this() { x1 = 4; printf("Foo4 dtor()\n"); } } static this() { x2 = 5; printf("ctor()\n"); } static ~this() { x2 = 6; printf("dtor()\n"); } void test4() { printf("x1 = %d, x2 = %d\n", x1, x2); assert(x1 == 3); assert(x2 == 5); } /* ================================ */ void test5() { printf("test5()\n"); static uint foo; static uint x = 3; static uint len = 32; version (D_Bits) { bit[] bits; bits = (cast(bit *)&foo)[0..len]; bits[6] = true; assert(foo == (1 << 6)); } } /* ================================ */ int[] test6_1(int[] a) { a.length = 6; return a; } void test6() { printf("test6()\n"); int b[3]; int a[]; b[0] = 0; b[1] = 1; b[2] = 2; assert(b.length == 3); a = test6_1(b); a[2] = 2; assert(a.length == 6); } /* ================================ */ class OutBuffer7 { char data[]; uint offset; void write(const(char) *p, uint nbytes) { data[offset .. offset + nbytes] = (cast(char *)p)[0 .. nbytes]; } } void test7() { printf("test7()\n"); int i; OutBuffer7 ob = new OutBuffer7; ob.data = new char[10]; printf("ob.data.length = %d\n", ob.data.length); assert(ob.data.length == 10); for (i = 0; i < 10; i++) assert(ob.data[i] == char.init); printf("test7.1()\n"); ob.data[] = '-'; printf("test7.2()\n"); printf("ob.data[] = '%.*s'\n", cast(int)ob.data.length, ob.data.ptr); for (i = 0; i < 10; i++) assert(ob.data[i] == '-'); ob.offset = 3; ob.write("foo", 3); printf("ob.data.length = %d\n", ob.data.length); printf("ob.data[] = '%.*s'\n", cast(int)ob.data.length, ob.data.ptr); for (i = 0; i < 10; i++) { if (i < 3 || i >= 6) assert(ob.data[i] == '-'); } assert(ob.data[3] == 'f'); assert(ob.data[4] == 'o'); assert(ob.data[5] == 'o'); } /* ================================ */ class A8 { enum { bar = 8, baz } int foo; } void test8() { printf("test8()\n"); A8 a; a = new A8(); a.foo = A8.bar; assert(a.foo == 8); } /* ================================ */ int z9; unittest { printf("module unittest 9\n"); z9 = 3; } void test9() { assert(z9 == 3); } /* ================================ */ void test10() { printf("test10()\n"); const int i = 8000; assert(i == 8000); static int j = 78; assert(j == 78); } /* ================================ */ Object test11_a() { return null; } void test11() { assert(test11_a() is null); } /* ================================ */ class A12 { } class B12 { } int testx(A12 a) { return 1; } int testx(B12 b) { return 2; } void test12() { A12 a = new A12(); B12 b = new B12(); assert(testx(a) == 1); assert(testx(b) == 2); } /* ================================ */ char[] tolower13(ref char[] s) { int i; for (i = 0; i < s.length; i++) { char c = s[i]; if ('A' <= c && c <= 'Z') s[i] = cast(char)(c + (cast(char)'a' - 'A')); } return s; } void test13() { auto s1 = "FoL".dup; char[] s2; s2 = tolower13(s1); assert(std.algorithm.cmp(s2, "fol") == 0); assert(s2 == s1); } /* ================================ */ alias ABC14* LPABC14; class ABC14 { } alias DEF14* LPDEF14; DEF14[3] foo; struct DEF14 { int x; } void test14() { assert(foo.sizeof == int.sizeof * 3); } /* ================================ */ class bits15 { bool a = true, b = true, c = true; void dump() { printf("%d %d %d\n", a, b, c); } } void test15() { bits15 k = new bits15; k.a = true; k.dump(); k.b = true; k.dump(); k.c = true; k.dump(); assert(k.a == true); assert(k.b == true); assert(k.c == true); } /* ================================ */ align(4) struct foo16 { short s; int i; } void test16() { assert(foo16.sizeof == 8); } /* ================================ */ enum Color { red, blue, green }; int[Color.max+1] colors1 = [ Color.blue:6, Color.green:2, Color.red:5 ]; enum { red, blue, green }; int[3] colors2 = [ blue:6, green:2, red:5 ]; void test17() { assert(colors1.length == 3); assert(colors1[0] == 5); assert(colors1[1] == 6); assert(colors1[2] == 2); assert(colors2[0] == 5); assert(colors2[1] == 6); assert(colors2[2] == 2); } /* ================================ */ class Test19 { struct { int a, b, c; } } void test19() { Test19 t = new Test19(); t.a = 3; assert(t.a == 3); } /* ================================ */ int main() { test1(); test2(); test3(); test4(); test5(); test6(); test7(); test8(); test9(); test10(); test11(); test12(); test13(); test14(); test15(); test16(); test17(); test19(); printf("Success\n"); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/test14198.d0000644000175000017500000000173513200164642025373 0ustar matthiasmatthiasmodule test14198; import std14198.conv; struct S { ptrdiff_t function() fptr = &handler; static ptrdiff_t handler() pure @safe { static if (is(typeof(to!string(false)))) { to!string(false); // [1] to!string(bool src) should be deduced to pure @safe, and the function will be mangled to: // --> _D8std141984conv11__T2toTAyaZ9__T2toTbZ2toFNaNbNiNfbZAya // [2] its object code would be stored in the library file, because it's instantiated in std14188.uni: // --> FormatSpec!char --> to!string(bool src) in FormatSpec!char.toString() // But semanti3 of FormatSpec!char.toString() won't get called from this module compilation, // so the instantiaion is invisible. // Then, the object code is also stored in test14198.obj, and the link will succeed. } else static assert(0); return 0; } } void main() { } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/multi9377.d0000644000175000017500000000025413200164642025464 0ustar matthiasmatthiasimport core.stdc.stdio; import mul9377a, mul9377b; int main() { printf("main\n"); abc(); def!().mem(); pragma(msg, def!().mem.mangleof); return 0; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/objc_self_test.m0000644000175000017500000000035713200164642027002 0ustar matthiasmatthias#import @interface objc_self_test : NSObject -(int) getValue; @end @implementation objc_self_test -(int) getValue { return 3; } @end int getValue () { return [[[objc_self_test alloc] init] getValue]; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/cppmangle1.cpp0000644000175000017500000000004313200164642026362 0ustar matthiasmatthiasint test0(int x) { return x; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/bug9010-postscript.sh0000755000175000017500000000103313200164642027465 0ustar matthiasmatthias#!/usr/bin/env bash # trim off the last line which contains the path of the file which differs between windows and non-windows LINE_COUNT_MINUS_1=$(( `wc -l < ${RESULTS_DIR}/runnable/runnable-bug9010.lst` - 1 )) head -n${LINE_COUNT_MINUS_1} ${RESULTS_DIR}/runnable/runnable-bug9010.lst > ${RESULTS_DIR}/runnable/runnable-bug9010.lst2 diff --strip-trailing-cr runnable/extra-files/runnable-bug9010.lst ${RESULTS_DIR}/runnable/runnable-bug9010.lst2 if [ $? -ne 0 ]; then exit 1 fi rm ${RESULTS_DIR}/runnable/runnable-bug9010.lst{,2} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/test35.d0000644000175000017500000000016413200164642025127 0ustar matthiasmatthiasimport imports.test35a; void main() { auto num = removeIf( "abcdef".dup, ( char c ) { return c == 'c'; } ); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/test13666.d0000644000175000017500000000006013200164642025360 0ustar matthiasmatthiasimport lib13666; int main() { return foo(); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/test10386.d0000644000175000017500000000027113200164642025360 0ustar matthiasmatthiasmodule test10386; // import lib.foo.bar; // ok import lib10386.foo; // linker failure void main() { static assert(foo.mangleof == "_D8lib103863foo3bar3fooFiZv"); foo(1); } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/linkdebug.d0000644000175000017500000000040413200164642025741 0ustar matthiasmatthiasmodule linkdebug; void main() { import linkdebug_uni; import linkdebug_range; // OK //SortedRangeX!(uint[], "a <= b") SR; CodepointSet set; set.addInterval(1, 2); // NG, order dependent. SortedRange!(uint[], "a <= b") SR; } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/a20-postscript.sh0000755000175000017500000000107113200164642026762 0ustar matthiasmatthias#!/usr/bin/env bash # trim off the last line which contains the path of the file which differs between windows and non-windows LINE_COUNT_MINUS_1=$(( `wc -l < ${RESULTS_DIR}/runnable/runnable-a20.lst` - 1 )) head -n${LINE_COUNT_MINUS_1} ${RESULTS_DIR}/runnable/runnable-a20.lst > ${RESULTS_DIR}/runnable/runnable-a20.lst2 diff --strip-trailing-cr runnable/extra-files/runnable-a20.lst ${RESULTS_DIR}/runnable/runnable-a20.lst2 if [ $? -ne 0 ]; then exit 1; fi rm ${RESULTS_DIR}/runnable/runnable-a20.lst{,2} rm ${RESULTS_DIR}/runnable/runnable-imports-a20a.lst ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/untag.html0000644000175000017500000025445113200164642025651 0ustar matthiasmatthias Abbott and Costello Meet Frankenstein - Wikipedia, the free encyclopedia

Abbott and Costello Meet Frankenstein

From Wikipedia, the free encyclopedia

Abbott and Costello Meet Frankenstein

Abbott and Costello Meet Frankenstein Theatrical Poster
Directed by Charles Barton
Produced by Robert Arthur
Written by Robert Lees
Frederic I. Rinaldo
John Grant
Starring Bud Abbott
Lou Costello
Lon Chaney, Jr.
Bela Lugosi
Glenn Strange
Music by Frank Skinner
Editing by Frank Gross
Distributed by Universal International
Release date(s) June 15, 1948 (U.S. release)
Running time 83 min.
Language English
Budget $760,000
Preceded by House of Dracula (1945)
The Invisible Man's Revenge (1944)
The Noose Hangs High (1948)
Followed by Mexican Hayride (1948)
Abbott and Costello Meet the Invisible Man (1951)

Abbott and Costello Meet Frankenstein (onscreen title: Bud Abbott Lou Costello Meet Frankenstein) is a 1948 comedy/horror film directed by Charles Barton and starring the comedy team of Abbott and Costello.

This is the first of several films where the comedy duo meets classic characters from Universal's film stable. In the film, they encounter Dracula, Frankenstein's monster, and the Wolf Man. Subsequent films pair the duo with the Mummy, the Keystone Kops, and the Invisible Man. On a TV special in the early 1950s, the comedy duo did a sketch where they interacted with the latest original Universal Studios monster being promoted at the time, the Creature from the Black Lagoon.

The film is considered the swan song for the "Big Three" Universal horror monsters – Dracula, the Wolf Man and Frankenstein's monster – although it does not appear to fit within the loose continuity of the earlier films.

The film was re-released in 1956 along with Abbott and Costello Meet the Killer, Boris Karloff.

In 2001, the United States Library of Congress deemed this film "culturally, historically, or aesthetically significant" and selected it for preservation in the National Film Registry.

In September 2007, Reader’s Digest selected the movie as one of the top 100 funniest films of all time.

Contents

[edit] Plot

Chick Young (Bud Abbott) and Wilbur Grey (Lou Costello) work as baggage clerks in LaMirada, Florida. When Wilbur mishandles two crates belonging to 'MacDougal's House of Horrors' museum, Mr. MacDougal (Frank Ferguson) demands that they deliver them in person so that they can be inspected by an insurance agent. MacDougal boasts to Wilbur's girlfriend, Dr. Sandra Mornay (Lénore Aubert), that the crates contain "the remains of the original Count Dracula" (Bela Lugosi) and "the body of the Frankenstein Monster" (Glenn Strange).

Dracula awakens, hypnotizes Wilbur, and spirits away his own coffin (and the revived Monster) before anyone else sees them. MacDougal then arrives with the insurance agent. Finding the storage crates empty, he accuses the boys of theft and has them arrested.

Mornay receives Dracula and the Monster at her island castle. Sandra is a gifted surgeon who has studied Dr. Frankenstein's notebooks, and has been posing as Wilbur's girlfriend as part of Dracula's scheme to replace the Monster's brutish brain with one more pliable — Wilbur's.

Wilbur and Chick are bailed out of jail and mistakenly believe Sandra to be their benefactor. Actually Joan Raymond (Jane Randolph), who also seems to like Wilbur, is responsible for the good deed. Joan is secretly working for the company that is processing MacDougal's insurance claim, and hopes Wilbur will lead her to the missing 'exhibits'.

Meanwhile, Larry Talbot (Lon Chaney, Jr.) has taken the apartment across the hall from Wilbur and Chick. He has tracked Dracula and the Monster from Europe, and knows them to be alive. Talbot asks the boys to help him find and destroy the villains. Wilbur is amenable to the plan, but Chick thinks both of them are crazy. Talbot's desperate insistence that he be locked in his room before moonrise impresses Chick even less.

The following night, Wilbur, Chick and Joan go to Sandra's castle to pick her up for a costume ball. Sandra has told Wilbur to come alone, and receives the extra guests rather icily.

While the ladies powder their noses, Wilbur answers a telephone call from someone wanting to speak to a 'Dr Lejos'. It is Talbot, who informs them that they are in the "house of Dracula". Wilbur reluctantly agrees to search the castle with Chick, and soon stumbles upon an underground passageway, complete with boat and dock. Behind a secret revolving wall, Wilbur again encounters Dracula and the Monster, but escapes. Wilbur's every attempt to get Chick to witness the villains fails - thanks to the revolving wall. Meanwhile, Joan has discovered Dr Frankenstein's notebook in Sandra's bureau, while Sandra has discovered Joan's employee I.D. in her bag.

Suavely reattired, Dracula (a.k.a. Dr. Lejos) is introduced by Sandra to Joan and the boys. He commends Sandra on her 'choice', expertly massaging the ego of Wilbur, who does not realize the true context of the remark. Also working at the castle is the naive Dr. Stevens (Charles Bradstreet), who questions some of the specialized equipment that has arrived. Dracula manages to deflect Dr. Stevens' questions by pairing him with Joan and shooing off the 'young people' to their ball. Sandra claims to have a sudden splitting headache and will not be able to attend the event. When Dracula consults Sandra in private, she admits that Dr. Stevens' questions, Joan's insurance credentials and Wilbur's inquiries have made her nervous, and wants to postpone the experiments. Impatient, Dracula asserts his will by hypnotizing her, and biting her in the throat.

At the ball, the boys encounter Talbot and MacDougal. Dracula arrives unexpectedly with Sandra, now under his spell. Dracula easily deflects Talbot's accusations, making the man appear disturbed. Dracula takes Joan for a dance while Sandra lures Wilbur to a quiet spot. Just before she can bite Wilbur's neck, Chick and Larry approach looking for Joan, and Sandra flees. As they search the grounds, Talbot transforms into the Wolf Man. Wilbur escapes, but the Wolf Man finds and injures MacDougal. Later noting that Chick is costumed as a werewolf, MacDougal concludes that Chick attacked him for revenge. (The fact that Chick is dressed like Talbot certainly does not help the situation). Chick manages to slip away, only to witness Dracula hypnotizing Wilbur. Chick becomes somewhat hypnotized himself, while Wilbur and an entranced Joan are brought back to the castle by Dracula and Sandra. The next morning, Chick is still on the lam when he finds Larry, who confesses that he was MacDougal's attacker. Now finally convinced, Chick agrees to help Larry rescue Wilbur and Joan.

While Wilbur is being held in a pillory, Sandra finally explains to him the plan to transplant his brain into the Monster. She and Dracula leave him to prepare the Monster for the operation. Chick and Talbot arrive, free Wilbur, and head off to save Joan. Wilbur, meanwhile, is lured back to the castle by Dracula, who easily overpowers his mind.

While the Monster receives an electrical boost in the lab, Sandra is about to open Wilbur's skull when Talbot storms in and casts her aside. Chick fends off Dracula with a chair, lifting it over his head to swing it at the vampire and inadvertently knocking out Sandra in the process. But just as Talbot is about to untie Wilbur, he once again transforms into the Wolf Man.

Dracula returns to the scene, only to have a tug-of-war with the Wolf Man over Wilbur's gurney. Dracula flees, with the Wolf Man giving chase. Chick arrives to untie Wilbur just as the Monster, now fully recovered, breaks his own restraints and rises from his stretcher. Sandra attempts to order him back as Dracula does, but the Monster defiantly tosses her out a window.

Dr. Stevens, meanwhile, has managed to find Joan and gets her to the boat. Dracula, in an attempt to escape, transforms into a bat, but the Wolf Man snares him and both fall over a balcony and into the rocky seas below. Joan abruptly wakes from her trance, while the boys escape the castle and head to the pier, with the Monster in pursuit. Once again Chick and Wilbur encounter Mr. MacDougal, who still insists that he wants his exhibits. They loudly reply, "..here comes one of them now!" When the Monster appears, MacDougal and his partner jump off the pier. Chick and Wilbur attempt to escape in a rowboat that is securely tied to the pier. The Monster throws barrels at them, in a series of near misses. Wilbur finally unties the boat, while Stevens and Joan arrive and set the pier ablaze. The Monster turns around and marches into the flames, slowing and succumbing as the pier collapses into the water.

Just as Chick and Wilbur relax, they hear a disembodied voice (Vincent Price) and see a cigarette floating in the air: "Allow me to introduce myself, I'm the Invisible Man!" The boys jump off the boat and swim away as the Invisible Man lights his cigarette and laughs. (This scene presaged 1951's Abbott and Costello Meet the Invisible Man, though Price did not star, and all characters were different.

[edit] Cast

[edit] Production

The film was originally intended to be titled The Brain of Frankenstein, but its name was changed prior to the filming schedule, which ran from February 5 through March 20, 1948.

Walter Lantz, noted for the creation of Woody Woodpecker, provided the animation for Dracula's transformations.

In a 1996 documentary, 100 Years of Horror, hosted by Christopher Lee, it was revealed that the studio hired two additional comedians to add laughs between takes on the set.

Costello hated the script for Abbott and Costello Meet Frankenstein.[2] He said that his five-year-old daughter could have written something better, but later warmed to the film during production.

During the filming of Abbott and Costello Meet Frankenstein, Glenn Strange found Costello so funny he would often break up laughing, necessitating many retakes. There were several pie fights between takes as well, but Abbott and Costello respected the three monsters (Chaney as the Wolfman, Lugosi as Dracula and Strange as the Monster) and made sure no pies were flung at the heavily made-up actors.

Boris Karloff was originally approached to play the monster once again, but declined. He did, however, help promote the movie and can be seen in several publicity photos, including one where he is buying a ticket, even though he refused to actually see the film (considering it an insult).

The Australian film board required that almost every scene involving a monster should be removed before release.[3]

[edit] Film mistakes

At one point in the film, where Abbott and Costello's characters are going through the revolving panel, Costello calls Abbott by his real name instead of his character's name. In addition, although the film is titled Abbott and Costello Meet Frankenstein, there is no character named Frankenstein in this movie. He is referenced for his work in bringing his creature to life, but the character himself does not appear. In addition, Dracula's reflection can be seen in the mirror when he makes the nurse his next victim. The studio intended to remove the reflection, but failed to do before the theatrical release, and to this day can still be seen in the movie.

[edit] Cultural references

  • In a 2006 episode of Iconoclasts on the Sundance Channel, Quentin Tarantino cited the film as his favorite childhood movie because "when it was supposed to be funny, it was really funny, and when it was supposed to be scary, it was really scary."
  • The film was unofficially remade in Mexico as Frankenstein, el Vampiro y Compañía (1962) and in Egypt as Haram Alek (1953).[4]
  • In the Star Trek: Enterprise episode "Horizon", Trip Tucker wanted to show the film.
  • In an episode of Home Improvement in which Mark is putting together a project for film class, after Tim tells his other sons that film was something he himself appreciated in school, Randy sarcastically quips back that his favorite movie was Abbott and Costello Meet Frankenstein.[citation needed]
  • In 1954, an Egyptian film studio created Ismil and Abdel Meet Frankenstein, a scene-for-scene remake of the 1948 classic. This version is not commercially available on DVD, but is scheduled for a public film showing at the Mid-Atlantic Nostalgia Convention in September 2008.

[edit] Routines

The Moving Candle routine previously used in Hold That Ghost was utilized again in this film.

[edit] DVD releases

[edit] Notes

  1. ^ The monster is actually played by two actors. Glenn Strange plays him for most of the film, but when he broke his foot during production, Lon Chaney, Jr. (who previously played the monster in The Ghost of Frankenstein), took over the role for a portion of the laboratory battle sequence.
  2. ^ Furmanek, Bob and Ron Palumbo (1991). Abbott and Costello in Hollywood. New York: Perigee Books. ISBN 0-399-51605-0
  3. ^ Furmanek, Bob and Ron Palumbo (1991). Abbott and Costello in Hollywood. New York: Perigee Books. ISBN 0-399-51605-0
  4. ^ Frankensteinia: The Frankenstein Blog: Frankenstein Gets Knocked-Off

[edit] External links

ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/cabi2.cpp0000644000175000017500000000704413200164642025323 0ustar matthiasmatthias #include #include #include #if __cplusplus extern "C" { #endif struct Foo1 { char c; }; struct Foo1 ctest1() { struct Foo1 f; f.c = 3; return f; } struct Foo2 { short s; }; struct Foo2 ctest2() { struct Foo2 f; f.s = 0x1234; return f; } struct Foo3 { char c; short s; }; struct Foo3 ctest3() { struct Foo3 f; f.s = 0x5678; return f; } struct Foo4 { int i; }; struct Foo4 ctest4() { struct Foo4 f; f.i = 0x12345678; return f; } struct Foo5 { int i, j; }; struct Foo5 ctest5() { struct Foo5 f; f.i = 0x12345678; f.j = 0x21436587; return f; } struct Foo6 { int i, j, k; }; struct Foo6 ctest6() { struct Foo6 f; f.i = 0x12345678; f.j = 0x21463587; f.k = 0x24163857; return f; } struct S7 { float a,b; }; struct S7 ctest10() { struct S7 f; f.a = 2.5; f.b = 1.5; return f; } // ================================= char ctest7(char c) { return c + 1; } unsigned char ctest8(unsigned char c) { return c + 1; } signed char ctest9(signed char c) { return c + 1; } /***********************************************/ void ctestrir(int x1, int x2, int x3, int x4, int x5, int x6, long double a, int b, long double c) { assert(a == 100.0); assert(b == 67); assert(c == 200.0); } /***********************************************/ extern void dtestrir(int x1, int x2, int x3, int x4, int x5, int x6, long double a, int b, long double c); void test4() { dtestrir(1,2,3,4,5,6, 300.0, 68, 401.0); } /**********************************************/ typedef struct S11 { char a; char b; char c; } S11; S11 ctest11(char x, S11 s, char y) { printf("C sz = %d\n", (int)sizeof(S11)); assert(sizeof(S11) == 3); printf("x = %d\n", (int)x); printf("s.a = %d\n", (int)s.a); printf("s.b = %d\n", (int)s.b); printf("s.c = %d\n", (int)s.c); printf("y = %d\n", (int)y); return s; } /**********************************************/ typedef struct S12 { char a,d; char b,e; char c; } S12; S12 ctest12(char x, S12 s, char y) { printf("C sz = %d\n", (int)sizeof(S12)); assert(sizeof(S12) == 5); printf("x = %d\n", (int)x); printf("s.a = %d\n", (int)s.a); printf("s.b = %d\n", (int)s.b); printf("s.c = %d\n", (int)s.c); printf("y = %d\n", (int)y); return s; } /**********************************************/ typedef struct S13 { short a; short b; short c; } S13; S13 ctest13(char x, S13 s, char y) { printf("C sz = %d\n", (int)sizeof(S13)); assert(sizeof(S13) == 6); printf("x = %d\n", (int)x); printf("s.a = %d\n", (int)s.a); printf("s.b = %d\n", (int)s.b); printf("s.c = %d\n", (int)s.c); printf("y = %d\n", (int)y); return s; } /**********************************************/ typedef struct S14 { char a,d,e,f; char b,g; char c; } S14; S14 ctest14(char x, S14 s, char y) { printf("C sz = %d\n", (int)sizeof(S14)); assert(sizeof(S14) == 7); printf("x = %d\n", (int)x); printf("s.a = %d\n", (int)s.a); printf("s.b = %d\n", (int)s.b); printf("s.c = %d\n", (int)s.c); printf("y = %d\n", (int)y); return s; } /**********************************************/ typedef struct S15 { char a,d,e,f; char b,g,h,i; char c; } S15; S15 ctest15(char x, S15 s, char y) { printf("C sz = %d\n", (int)sizeof(S15)); assert(sizeof(S15) == 9); printf("x = %d\n", (int)x); printf("s.a = %d\n", (int)s.a); printf("s.b = %d\n", (int)s.b); printf("s.c = %d\n", (int)s.c); printf("y = %d\n", (int)y); return s; } #if __cplusplus } #endif ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/ldc_cabi2.cpp0000644000175000017500000002451613200164642026150 0ustar matthiasmatthias#include #include #include // ldc_cabi1 defines these extern int8_t a, b, c, d, e, f, g, h; extern uint32_t errors; #define TEST(b) \ if (!(b)) (++errors, printf("%s:%u: failed check\n", __FILE__, __LINE__)) static bool testar(int8_t* a, size_t len, int8_t a0) { for (size_t i = 0; i < len; ++i) { if (a[i] != (int8_t)(a0+i)) { return false; } } return true; } extern "C" { struct EMPTY {}; struct B1 {int8_t a;}; struct B2 {int8_t a, b;}; struct I1 {int a;}; struct I2 {int a, b;}; union UI1 {int a; short b; int8_t c;}; union UI1a {short a; int8_t b; int c;}; struct NI1 {I1 a;}; struct NUI1 {UI1 a;}; union UNI1 {UI1 a; NI1 b; int c;}; struct S3 {char a; short b;}; struct S6 {char a; int b; char c;}; struct S9 {char a; double b;}; struct S19 {char a; double b, c;}; struct F2 {float a, b;}; struct F4 {float a, b, c, d;}; struct D1 {double a;}; struct D2 {double a, b;}; struct D4 {double a, b, c, d;}; struct D5 {double a, b, c, d, e;}; struct D8 {double a, b, c, d, e, f, g, h;}; union UD4 {D1 a; D2 b; D4 c; double e;}; struct DA0 {double a[0];}; struct DA4 {double a[4];}; struct DA5 {double a[5];}; struct DA8 {double a[8];}; struct CA4 {char a[4];}; struct DHFA1 {EMPTY a; double d;}; //struct DHFA1 {EMPTY a; EMPTY b; double c[0]; double d;}; struct DHFA2 {double a; D1 b;}; struct DHFA2a {D1 a; double b;}; struct DHFA4x {D2 a[2];}; struct S1 {int8_t a;}; struct S2 {int8_t a;}; struct SA64 {int8_t a[64];}; struct SA65 {int8_t a[65];}; void dvfun(int s, ...); B1 dretb1(B1 x); B1 cretb1(B1 x) { TEST(x.a == a); B1 r = {++a}; return r; } B2 dretb2(B2 x); B2 cretb2(B2 x) { TEST(x.a == a); TEST(x.b == b); B2 r = {++a, ++b}; return r; } I1 dreti1(I1 x); I1 creti1(I1 x) { TEST(x.a == a); I1 r = {++a}; return r; } I2 dreti2(I2 x); I2 creti2(I2 x) { TEST(x.a == a); TEST(x.b == b); I2 r = {++a, ++b}; return r; } UI1a dretui1a(UI1a x); UI1a cretui1a(UI1a x) { TEST(x.c == a); UI1a r; r.c = ++a; return r; } UNI1 dretuni1(UNI1 x); UNI1 cretuni1(UNI1 x) { TEST(x.a.a == a); UNI1 r = {{++a}}; return r; } F4 dretf4(F4 x); F4 cretf4(F4 x) { TEST(x.a == a); TEST(x.b == b); TEST(x.c == c); TEST(x.d == d); F4 r = {(float)++a, (float)++b, (float)++c, (float)++d}; return r; } D4 dretd4(D4 x); D4 cretd4(D4 x) { TEST(x.a == a); TEST(x.b == b); TEST(x.c == c); TEST(x.d == d); D4 r = {(double)++a, (double)++b, (double)++c, (double)++d}; return r; } D5 dretd5(D5 x); D5 cretd5(D5 x) { TEST(x.a == a); TEST(x.b == b); TEST(x.c == c); TEST(x.d == d); TEST(x.e == e); D5 r = {(double)++a, (double)++b, (double)++c, (double)++d, (double)++e}; return r; } D8 dretd8(D8 x); D8 cretd8(D8 x) { TEST(x.a == a); TEST(x.b == b); TEST(x.c == c); TEST(x.d == d); TEST(x.e == e); TEST(x.f == f); TEST(x.g == g); TEST(x.h == h); D8 r = {(double)++a, (double)++b, (double)++c, (double)++d, (double)++e, (double)++f, (double)++g, (double)++h}; return r; } UD4 dretud4(UD4 x); UD4 cretud4(UD4 x) { TEST(x.c.a == a); TEST(x.c.b == b); TEST(x.c.c == c); TEST(x.c.d == d); UD4 r; D4 d4 = {(double)++a, (double)++b, (double)++c, (double)++d}; r.c = d4; return r; } DA0 dretda0(DA0 x); DA0 cretda0(DA0 x) { DA0 r; return r; } DA4 dretda4(DA4 x); DA4 cretda4(DA4 x) { TEST(x.a[0] == a); TEST(x.a[1] == b); TEST(x.a[2] == c); TEST(x.a[3] == d); DA4 r = {(double)++a, (double)++b, (double)++c, (double)++d}; return r; } DA5 dretda5(DA5 x); DA5 cretda5(DA5 x) { TEST(x.a[0] == a); TEST(x.a[1] == b); TEST(x.a[2] == c); TEST(x.a[3] == d); TEST(x.a[4] == e); DA5 r = {(double)++a, (double)++b, (double)++c, (double)++d, (double)++e}; return r; } DA8 dretda8(DA8 x); DA8 cretda8(DA8 x) { TEST(x.a[0] == a); TEST(x.a[1] == b); TEST(x.a[2] == c); TEST(x.a[3] == d); TEST(x.a[4] == e); TEST(x.a[5] == f); TEST(x.a[6] == g); TEST(x.a[7] == h); DA8 r = {(double)++a, (double)++b, (double)++c, (double)++d, (double)++e, (double)++f, (double)++g, (double)++h}; return r; } DHFA1 dretdhfa1(DHFA1 x); DHFA1 cretdhfa1(DHFA1 x) { TEST(x.d == a); DHFA1 r; r.d = ++a; return r; } DHFA2 dretdhfa2(DHFA2 x); DHFA2 cretdhfa2(DHFA2 x) { TEST(x.a == a); TEST(x.b.a == b); DHFA2 r = {(double)++a, {(double)++b}}; return r; } DHFA2a dretdhfa2a(DHFA2a x); DHFA2a cretdhfa2a(DHFA2a x) { TEST(x.a.a == a); TEST(x.b == b); DHFA2a r = {{(double)++a}, (double)++b}; return r; } DHFA4x dretdhfa4x(DHFA4x x); DHFA4x cretdhfa4x(DHFA4x x) { TEST(x.a[0].a == a); TEST(x.a[0].b == b); TEST(x.a[1].a == c); TEST(x.a[1].b == d); DHFA4x r = {{{(double)++a, (double)++b}, {(double)++c, (double)++d}}}; return r; } S1 drets1(S1 x); S1 crets1(S1 x) { TEST(x.a == a); S1 r = {++a}; return r; } S2 drets2(S2 x); S2 crets2(S2 x) { TEST(x.a == a); S2 r = {++a}; return r; } double dretdouble(double x); double cretdouble(double x) { TEST(x == a); double r = ++a; return r; } long long dretlonglong(long long x); long long cretlonglong(long long x) { TEST(x == a); long long r = ++a; return r; } S9 drets9(S9 x); S9 crets9(S9 x) { TEST(x.a == a); TEST(x.b == b); S9 r = {++a, (double)(++b)}; return r; } SA64 dretsa64(SA64 x); SA64 cretsa64(SA64 x) { TEST(testar(x.a, 64, a)); SA64 r; ++a; for (int i = 0; i < 64; ++i) { r.a[i] = a+i; } return r; } SA65 dretsa65(SA65 x); SA65 cretsa65(SA65 x) { TEST(testar(x.a, 65, a)); SA65 r; ++a; for (int i = 0; i < 65; ++i) { r.a[i] = a+i; } return r; } void cvfun(int s, ...) { va_list args; va_start(args, s); switch (s) { case 0: cretb1(va_arg(args,B1)); break; case 1: cretb2(va_arg(args,B2)); break; case 2: creti2(va_arg(args,I2)); break; case 3: cretf4(va_arg(args,F4)); break; case 4: cretd4(va_arg(args,D4)); break; case 5: cretdhfa2(va_arg(args,DHFA2)); break; case 6: cretdhfa2a(va_arg(args,DHFA2a)); break; case 7: cretuni1(va_arg(args,UNI1)); break; case 8: cretdouble(va_arg(args,double)); break; case 9: cretlonglong(va_arg(args,long long)); break; case 10: crets9(va_arg(args,S9)); break; } } void ccall() { B1 b1 = {++a}; B1 b1r = dretb1(b1); TEST(b1r.a == a); B2 b2 = {++a,++b}; B2 b2r = dretb2(b2); TEST(b2r.a == a); TEST(b2r.b == b); I2 i2 = {++a,++b}; I2 i2r = dreti2(i2); TEST(i2r.a == a); TEST(i2r.b == b); UNI1 uni1i = {{++a}}; UNI1 uni1 = dretuni1(uni1i); TEST(uni1.a.a == a); F4 f4 = {(float)++a, (float)++b, (float)++c, (float)++d}; F4 f4r = dretf4(f4); TEST(f4r.a == a); TEST(f4r.b == b); TEST(f4r.c == c); TEST(f4r.d == d); D4 d4 = {(double)++a, (double)++b, (double)++c, (double)++d}; D4 d4r = dretd4(d4); TEST(d4r.a == a); TEST(d4r.b == b); TEST(d4r.c == c); TEST(d4r.d == d); D5 d5 = {(double)++a, (double)++b, (double)++c, (double)++d, (double)++e}; D5 d5r = dretd5(d5); TEST(d5r.a == a); TEST(d5r.b == b); TEST(d5r.c == c); TEST(d5r.d == d); TEST(d5r.e == e); D8 d8 = {(double)++a, (double)++b, (double)++c, (double)++d, (double)++e, (double)++f, (double)++g, (double)++h}; D8 d8r = dretd8(d8); TEST(d8r.a == a); TEST(d8r.b == b); TEST(d8r.c == c); TEST(d8r.d == d); TEST(d8r.e == e); TEST(d8r.f == f); TEST(d8r.g == g); TEST(d8r.h == h); UD4 ud4; D4 d4x = {(double)++a, (double)++b, (double)++c, (double)++d}; ud4.c = d4x; UD4 ud4r = dretud4(ud4); TEST(ud4r.c.a == a); TEST(ud4r.c.b == b); TEST(ud4r.c.c == c); TEST(ud4r.c.d == d); DA4 da4 = {(double)++a, (double)++b, (double)++c, (double)++d}; DA4 da4r = dretda4(da4); TEST(da4r.a[0] == a); TEST(da4r.a[1] == b); TEST(da4r.a[2] == c); TEST(da4r.a[3] == d); DA5 da5 = {(double)++a, (double)++b, (double)++c, (double)++d, (double)++e}; DA5 da5r = dretda5(da5); TEST(da5r.a[0] == a); TEST(da5r.a[1] == b); TEST(da5r.a[2] == c); TEST(da5r.a[3] == d); TEST(da5r.a[4] == e); DA8 da8 = {(double)++a, (double)++b, (double)++c, (double)++d, (double)++e, (double)++f, (double)++g, (double)++h}; DA8 da8r = dretda8(da8); TEST(da8r.a[0] == a); TEST(da8r.a[1] == b); TEST(da8r.a[2] == c); TEST(da8r.a[3] == d); TEST(da8r.a[4] == e); TEST(da8r.a[5] == f); TEST(da8r.a[6] == g); TEST(da8r.a[7] == h); DHFA2 dhfa2i = {(double)++a, {(double)++b}}; DHFA2 dhfa2 = dretdhfa2(dhfa2i); TEST(dhfa2.a == a); TEST(dhfa2.b.a == b); DHFA2a dhfa2ai = {{(double)++a}, (double)++b}; DHFA2a dhfa2a = dretdhfa2a(dhfa2ai); TEST(dhfa2a.a.a == a); TEST(dhfa2a.b == b); DHFA4x dhfa4xi = {{{(double)++a, (double)++b}, {(double)++c, (double)++d}}}; DHFA4x dhfa4x = dretdhfa4x(dhfa4xi); TEST(dhfa4x.a[0].a == a); TEST(dhfa4x.a[0].b == b); TEST(dhfa4x.a[1].a == c); TEST(dhfa4x.a[1].b == d); // structs with postblit or dtor may not be passed like a similar POD // struct. #if 0 S1 s1 = {++a}; S1 s1r = drets1(s1); TEST(s1r.a == a); S2 s2 = {++a}; S2 s2r = drets2(s2); TEST(s2r.a == a); #endif SA64 s64; ++a; for (int i = 0; i < 64; ++i) { s64.a[i] = a+i; } SA64 s64r = dretsa64(s64); TEST(testar(s64r.a, 64, a)); SA65 s65; ++a; for (int i = 0; i < 65; ++i) { s65.a[i] = a+i; } SA65 s65r = dretsa65(s65); TEST(testar(s65r.a, 65, a)); b1.a = ++a; dvfun(0, b1); b2.a = ++a; b2.b = ++b; dvfun(1, b2); i2.a = ++a; i2.b = ++b; dvfun(2, i2); uni1.a.a = ++a; cvfun(7, uni1); // TODO: type-oh? Should be dvfun? f4.a = ++a; f4.b = ++b; f4.c = ++c; f4.d = ++d; dvfun(3, f4); d4.a = ++a; d4.b = ++b; d4.c = ++c; d4.d = ++d; dvfun(4, d4); dhfa2.a = ++a; dhfa2.b.a = ++b; dvfun(5, dhfa2); dhfa2a.a.a = ++a; dhfa2a.b = ++b; dvfun(6, dhfa2a); } } // extern "C" ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/link14834b.d0000644000175000017500000000015213200164642025500 0ustar matthiasmatthiasimport link14834a; void main() { foreach (n; dirEntries(".")) { assert(n == 10); } } ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/teststdio.txt0000644000175000017500000000002613200164642026413 0ustar matthiasmatthiasasdfasdf a sdf asdf ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/mul9377b.d0000644000175000017500000000067613200164642025301 0ustar matthiasmatthiasmodule mul9377b; import core.stdc.stdio; int j; int foo()() { printf("foo()\n"); static int z = 7; assert(z != 10); return ++z; } void bar() { assert(j == 7); foo(); printf("bar\n"); } template def() { alias int defint; static this() { printf("def.static this()\n"); j = 7; } //void mem(int){} void mem() { printf("def().mem()\n"); } } def!().defint x; ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/cov2-postscript.sh0000755000175000017500000000101113200164642027243 0ustar matthiasmatthias#!/usr/bin/env bash # trim off the last line which contains the path of the file which differs between windows and non-windows LINE_COUNT_MINUS_1=$(( `wc -l < ${RESULTS_DIR}/runnable/runnable-cov2.lst` - 1 )) head -n${LINE_COUNT_MINUS_1} ${RESULTS_DIR}/runnable/runnable-cov2.lst > ${RESULTS_DIR}/runnable/runnable-cov2.lst2 diff --strip-trailing-cr runnable/extra-files/runnable-cov2.lst ${RESULTS_DIR}/runnable/runnable-cov2.lst2 if [ $? -ne 0 ]; then exit 1 fi rm ${RESULTS_DIR}/runnable/runnable-cov2.lst{,2} ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/runnable-cov2.lst0000644000175000017500000000312613200164642027035 0ustar matthiasmatthias |// PERMUTE_ARGS: |// POST_SCRIPT: runnable/extra-files/cov2-postscript.sh |// REQUIRED_ARGS: -cov |// EXECUTE_ARGS: ${RESULTS_DIR}/runnable | |extern(C) void dmd_coverDestPath(string pathname); | |/***************************************************/ | |void test1() |{ 1| int counter = 20; | do { 20| --counter; | } 20| while(counter > 0); |} | |/***************************************************/ | |struct S2 |{ 2| this(this) { int x = 1; } 3| ~this() { int x = 1; } 00000000| ref S2 opAssign(S2) { return this; } 1| bool opEquals(ref const S2) const { return true; } |} |struct T2 |{ | S2 s; | 2| this(this) { int x = 1; } 3| ~this() { int x = 1; } |} |void test2() |{ 2| T2 ta; 2| T2 tb = ta; 1| tb = ta; 1| typeid(T2).equals(&ta, &tb); |} | |/***************************************************/ | |void test3() |{ 1| long total = 0; 20000002| for (size_t i = 0; i < 10_000_000; i++) 10000000| total += i; |} | |/***************************************************/ | |int main(string[] args) |{ 1| dmd_coverDestPath(args[1]); 1| test1(); 1| test2(); 1| test3(); 1| return 0; |} | ldc-0.17.5-src/tests/d2/dmd-testsuite/runnable/extra-files/externmangle2.cpp0000644000175000017500000000336113200164642027114 0ustar matthiasmatthias struct Test32NS1 { template struct Foo { X *v; }; template struct Bar { X *v; }; }; struct Test32NS2 { template struct Foo { X *v; }; }; template