```unpsur.d import std.stdio: writeln; import std.utf: byCodeUnit; void main () { wstring w = "\U00010400"; wchar wc = w.byCodeUnit [0]; // take high surrogate writeln (wc); // let it throw a UTFException } ``` Application output std.utf.UTFException@std/stdio.d(2910): unpaired surrogate UTF-16 value ---------------- ??:? @safe void std.stdio.File.LockingTextWriter.highSurrogateShouldBeEmpty() [0x5616f092907f] /dlang/dmd/linux/bin64/../../src/phobos/std/stdio.d:2992 @safe void std.stdio.File.LockingTextWriter.put!(char).put(char) [0x5616f0922407] /dlang/dmd/linux/bin64/../../src/phobos/std/range/primitives.d:277 @safe void std.range.primitives.doPut!(std.stdio.File.LockingTextWriter, char).doPut(ref std.stdio.File.LockingTextWriter, ref char) [0x5616f09223ea] /dlang/dmd/linux/bin64/../../src/phobos/std/range/primitives.d:380 @safe void std.range.primitives.put!(std.stdio.File.LockingTextWriter, char).put(ref std.stdio.File.LockingTextWriter, char) [0x5616f09223bf] /dlang/dmd/linux/bin64/../../src/phobos/std/stdio.d:1567 @safe void std.stdio.File.write!(wchar, char).write(wchar, char) [0x5616f0921bfe] /dlang/dmd/linux/bin64/../../src/phobos/std/stdio.d:3911 @safe void std.stdio.writeln!(wchar).writeln(wchar) [0x5616f0921b82] onlineapp.d:8 _Dmain [0x5616f0921736] std.utf.UTFException@std/stdio.d(2910): unpaired surrogate UTF-16 value ---------------- ??:? @safe void std.stdio.File.LockingTextWriter.highSurrogateShouldBeEmpty() [0x5616f092907f] ??:? @trusted void std.stdio.File.LockingTextWriter.__dtor() [0x5616f0929197] ??:? @trusted void std.stdio.File.LockingTextWriter.__aggrDtor() [0x5616f09291f0] /dlang/dmd/linux/bin64/../../src/phobos/std/stdio.d:1541 @safe void std.stdio.File.write!(wchar, char).write(wchar, char) [0x5616f0921c1d] /dlang/dmd/linux/bin64/../../src/phobos/std/stdio.d:3911 @safe void std.stdio.writeln!(wchar).writeln(wchar) [0x5616f0921b82] onlineapp.d:8 _Dmain [0x5616f0921736] expected: only one trace
The first trace is the expected one, the second trace is created, when the destructor is called.
@aG0aep6G created dlang/phobos pull request #7801 "fix issue 21592 - two stack traces if high surrogate is printed" fixing this issue: - fix issue 21592 - two stack traces if high surrogate is printed https://github.com/dlang/phobos/pull/7801
dlang/phobos pull request #7801 "fix issue 21592 - two stack traces if high surrogate is printed" was merged into master: - 95acbbd658a62d4724abf5b3a53b26430a1bf312 by aG0aep6G: fix issue 21592 - two stack traces if high surrogate is printed https://github.com/dlang/phobos/pull/7801