The non-Windows paths use `errnoEnforce` that lazily evaluates the messages. The Windows path uses a private function `wenforce` that evaluates its arguments eagerly.
@n8sh created dlang/phobos pull request #7740 "Microsoft Windows std.stdio.File.lock(), tryLock(), unlock(): do not allocate memory for error messages when they are not needed" fixing this issue: - Fix Issue 21523 - Microsoft Windows std.stdio.File.lock(), tryLock(), unlock(): do not allocate memory for error messages when they are not needed https://github.com/dlang/phobos/pull/7740
dlang/phobos pull request #7740 "Microsoft Windows std.stdio.File.lock(), tryLock(), unlock(): do not allocate memory for error messages when they are not needed" was merged into master: - 5aeaa1f873f5c0d04d27816466960d298503491b by Nathan Sashihara: Fix Issue 21523 - Microsoft Windows std.stdio.File.lock(), tryLock(), unlock(): do not allocate memory for error messages when they are not needed https://github.com/dlang/phobos/pull/7740