Bug 24086 – No output or failed function call

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2023-08-15T01:26:07Z
Last change time
2023-08-15T07:20:38Z
Assigned to
No Owner
Creator
apham

Comments

Comment #0 by apz28 — 2023-08-15T01:26:07Z
import std.stdio; import std.bitmanip : bigEndianToNative, nativeToBigEndian; nothrow @safe: struct X(int N) { @nogc nothrow @safe: enum HALFSize = N / 2; alias HALF = makeHALF!HALFSize; version (LittleEndian) { HALF lo; HALF hi; } else { HALF hi; HALF lo; } this(scope const(ubyte)[] bigEndianBytes) pure { } ubyte[] toBigEndianBytes(return ubyte[] bytes) const in { assert(bytes.length == N); } do { debug writeln("toBigEndianBytes: ", Bytes); static if (N <= 4) { bytes[0..HALFSize] = nativeToBigEndian(hi); bytes[HALFSize..N] = nativeToBigEndian(lo); } else { hi.toBigEndianBytes(bytes[0..HALFSize]); lo.toBigEndianBytes(bytes[HALFSize..N]); } return bytes; } } template makeHALF(int N) { static if (N >= 4) alias makeHALF = X!N; else static if (N == 2) alias makeHALF = ushort; else static if (N == 1) alias makeHALF = ubyte; else static assert(0, "Unsupport makeHALF"); } alias x4 = X!4; alias x8 = X!8; static immutable x4[2] x4s = [ x4([1]), x4([2]), ]; static immutable x8[2] x8s = [ x8([3]), x8([4]), ]; void main() { ubyte[4] b4; foreach (i, e; x4s) { debug writeln("x4s: [", i, "] ", e.toBigEndianBytes(b4)); } ubyte[8] b8; foreach (i, e; x8s) { debug writeln("x8s: [", i, "] ", e.toBigEndianBytes(b8)); } }
Comment #1 by b2.temp — 2023-08-15T07:20:38Z
you need to pass the `-debug` argument to DMD. Without, the semantically incorrect code is not analyzed, it's a case of conditional compilation (https://dlang.org/spec/version.html#debug)