Skip to content

Conversation

@ssam18
Copy link

@ssam18 ssam18 commented Nov 12, 2025

Fixes #3035

Issue

The win32_unicode_path constructor accepts an error_code& parameter but wasn't clearing it on successful path conversion. This led to callers retaining stale error values even when operations succeeded.

Problem

As reported in #3035, when using file.open() with a pre-set error code (e.g., initialized to error::not_found as a default), the error would persist even after successful file operations. This is inconsistent with std::filesystem conventions where error_code parameters are cleared on success.

Solution

Added ec = {}; at the beginning of the constructor to ensure the error_code is always in a known state - either cleared for success or properly set for failure.

This aligns with:

  • The std::filesystem API convention (e.g., std::filesystem::create_directory)
  • The recommendation from @vinniefalco to clear ec immediately upon entry to avoid these kinds of issues
  • Beast's own file_win32::open which already clears ec on line 222

Testing

Windows-specific change. The fix is minimal and follows established error handling patterns in the codebase.

The win32_unicode_path constructor takes an error_code& parameter but
did not clear it on successful path conversion. This left callers with
stale error values even when the operation succeeded.

This is inconsistent with the std::filesystem convention where error_code
parameters are cleared on success (e.g., std::filesystem::create_directory).
It also caused unexpected behavior in file_win32::open() where a default
error_code value set before try/catch would persist even after successful
file operations.

This change adds 'ec = {};' at the beginning of the constructor to ensure
the error_code is always in a known state, either cleared for success or
set for failure.

Fixes boostorg#3035
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

win32_unicode_path fails to clear ec.

1 participant