Skip to content

<filesystem>: Set the error code for fs::absolute("", ec).#6132

Open
leejy12 wants to merge 3 commits intomicrosoft:mainfrom
leejy12:6120-filesystem-absolute
Open

<filesystem>: Set the error code for fs::absolute("", ec).#6132
leejy12 wants to merge 3 commits intomicrosoft:mainfrom
leejy12:6120-filesystem-absolute

Conversation

@leejy12
Copy link
Contributor

@leejy12 leejy12 commented Mar 2, 2026

Closes #6120

fs::absolute("", ec) was returning an empty path, indicating an error has occurred, but didn't set ec to the appropriate error_code.

libstdc++ treats this call as an error, whereas libc++ treats it as a success case.

[fs.op.absolute#1] says the function "Composes an absolute path referencing the same file system location as p according to the operating system". On Windows, GetFullPathNameW(L"", ...) fails, so following libstdc++’s behavior is more consistent with the standard wording.

This change updates the implementation to set ec.value() to 123 (ERROR_INVALID_NAME).

@leejy12 leejy12 requested a review from a team as a code owner March 2, 2026 23:53
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Mar 2, 2026
@YexuanXiao
Copy link
Contributor

The error code for calling CreateFile with an empty string is ERROR_PATH_NOT_FOUND (3). Is it more appropriate to use it? This means the result obtained when not converting it to an absolute path.

@leejy12
Copy link
Contributor Author

leejy12 commented Mar 3, 2026

@YexuanXiao I intended to let __std_fs_get_full_path_name populate it automatically.

STL/stl/src/filesystem.cpp

Lines 156 to 160 in 117ca96

[[nodiscard]] __std_ulong_and_error __stdcall __std_fs_get_full_path_name(_In_z_ const wchar_t* _Source,
_In_ unsigned long _Target_size, _Out_writes_z_(_Target_size) wchar_t* _Target) noexcept { // calls GetFullPathNameW
const auto _Result = GetFullPathNameW(_Source, _Target_size, _Target, nullptr);
return {_Result, _Result == 0 ? __std_win_error{GetLastError()} : __std_win_error::_Success};
}

But libstdc++ sets the error to EINVAL (22), so a better error may be ERROR_INVALID_PARAMETER (87). I think if we just return this when _Input._Text.empty() is true, we can avoid calling the Win32 API.

@StephanTLavavej StephanTLavavej added bug Something isn't working filesystem C++17 filesystem labels Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working filesystem C++17 filesystem

Projects

Status: Initial Review

Development

Successfully merging this pull request may close these issues.

<filesystem>: workaround dubious absolute("", ec) test case in libcxx suite

3 participants