From 625d8965bfb00e7e749b90024e48c8be1cb079d5 Mon Sep 17 00:00:00 2001 From: Junyoung Lee Date: Mon, 2 Mar 2026 16:05:30 -0600 Subject: [PATCH 1/2] Make `fs::absolute("", ec)` set the error code. --- stl/inc/filesystem | 20 +++++++++----------- tests/libcxx/expected_results.txt | 5 ++--- tests/std/tests/P0218R1_filesystem/test.cpp | 8 ++++++++ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 7d838ea2d17..b9cc15336ea 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -3013,17 +3013,15 @@ namespace filesystem { // calls GetFullPathNameW _Ec.clear(); // for exception safety path _Result; - if (!_Input._Text.empty()) { - _Result._Text.resize(__std_fs_max_path); - for (;;) { - const auto _Requested_size = static_cast(_Result._Text.size()); - const auto _Full_path_result = - __std_fs_get_full_path_name(_Input._Text.c_str(), _Requested_size, _Result._Text.data()); - _Result._Text.resize(_Full_path_result._Size); - if (_Full_path_result._Size < _Requested_size) { - _Ec = _Make_ec(_Full_path_result._Error); - break; - } + _Result._Text.resize(__std_fs_max_path); + for (;;) { + const auto _Requested_size = static_cast(_Result._Text.size()); + const auto _Full_path_result = + __std_fs_get_full_path_name(_Input._Text.c_str(), _Requested_size, _Result._Text.data()); + _Result._Text.resize(_Full_path_result._Size); + if (_Full_path_result._Size < _Requested_size) { + _Ec = _Make_ec(_Full_path_result._Error); + break; } } return _Result; diff --git a/tests/libcxx/expected_results.txt b/tests/libcxx/expected_results.txt index 971a27c8889..cdccea195d3 100644 --- a/tests/libcxx/expected_results.txt +++ b/tests/libcxx/expected_results.txt @@ -714,6 +714,8 @@ std/iterators/iterator.requirements/iterator.assoc.types/readable.traits/indirec # Not analyzed, likely bogus test. constexpr fails with "vector iterators incompatible". std/ranges/range.adaptors/range.join.with/range.join.with.iterator/ctor.default.pass.cpp FAIL +# libc++ treats `fs::absolute("", ec)` as a success case, whereas we emit an error and return an empty `path`. +std/input.output/filesystems/fs.op.funcs/fs.op.absolute/absolute.pass.cpp FAIL # *** LIKELY STL BUGS *** # Not analyzed, likely STL bugs. Various assertions. @@ -1122,9 +1124,6 @@ std/input.output/filesystems/class.path/path.member/path.generic.obs/generic_str # Not analyzed. Assertion failed: std::equal(p.begin(), p.end(), TC.elements.begin(), ComparePathExact()) std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp FAIL -# Not analyzed. Assertion failed: ret.is_absolute() -std/input.output/filesystems/fs.op.funcs/fs.op.absolute/absolute.pass.cpp FAIL - # Not analyzed. Assertion failed: ret == TC.p std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp FAIL diff --git a/tests/std/tests/P0218R1_filesystem/test.cpp b/tests/std/tests/P0218R1_filesystem/test.cpp index de836655bc4..76b4c25c323 100644 --- a/tests/std/tests/P0218R1_filesystem/test.cpp +++ b/tests/std/tests/P0218R1_filesystem/test.cpp @@ -1537,6 +1537,14 @@ void test_absolute() { longPath.resize(260); expect_absolute(longPath, longPath); + EXPECT(absolute(L"", ec).empty()); + if (ec.value() != 123) { + wcerr << L"Warning: Expected absolute on an empty path to report ERROR_INVALID_NAME, " + L"but it reported " + << ec.value() << L"\n"; + } + EXPECT(ec.category() == system_category()); + expect_absolute({}, {}); } From 3271d11e057bb7e5df404463bc5b5d19f47bbe87 Mon Sep 17 00:00:00 2001 From: Junyoung Lee Date: Mon, 2 Mar 2026 17:15:50 -0600 Subject: [PATCH 2/2] remove existing empty test --- tests/std/tests/P0218R1_filesystem/test.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/std/tests/P0218R1_filesystem/test.cpp b/tests/std/tests/P0218R1_filesystem/test.cpp index 76b4c25c323..edd4b60ce03 100644 --- a/tests/std/tests/P0218R1_filesystem/test.cpp +++ b/tests/std/tests/P0218R1_filesystem/test.cpp @@ -1544,8 +1544,6 @@ void test_absolute() { << ec.value() << L"\n"; } EXPECT(ec.category() == system_category()); - - expect_absolute({}, {}); } void test_canonical() {