Fix filesystem::weakly_canonical()
on Win11 24H2
#4844
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have a regression test for DevCom-538510 (internal VSO-850856) "
std::filesystem::weakly_canonical
erroneously throws an exception":STL/tests/std/tests/P0218R1_filesystem/test.cpp
Lines 3233 to 3237 in ecbc1ef
This has regressed on the upcoming Win11 24H2, where we throw an exception (again). The relevant code is:
STL/stl/inc/filesystem
Lines 4127 to 4144 in ecbc1ef
After calling
_Canonical()
, anything other than_Err == __std_win_error::_Success
or__std_is_file_not_found(_Err)
is considered a hard error (which will cause the non-error_code
overload to throw afilesystem_error
).In current OSes, the
fileWithSuffix
scenario results in_Invalid_name
here. (Locally verified on Win11 23H2. Presumably we get the same behavior in the GitHub PR/CI system running Server 2022 21H2, although I didn't verify that.)In Win11 24H2, we get
_Directory_name_is_invalid
, which isn't recognized by__std_is_file_not_found
. 💥The fix is backwards-compatible and a simple one-liner: add this error code enumerator to the list of synonyms that
__std_is_file_not_found
recognizes. The plain meaning of_Directory_name_is_invalid
is clearly a subset of_Invalid_name
.I've manually verified this (with significant but perhaps not surprising logistical difficulty) in an Azure VM with Win11 24H2. Regular test coverage will be provided by the MSVC-internal test harness (which is how we found this), and eventually by the GitHub test harness once Server 2025 24H2 is officially released.
Additionally, this uncaught exception from a non-
error_code
overload manifested itself as anabort()
with no useful logs. To aid in future investigations, I'm including a simple change to the filesystem test. Now, we wrap the whole test intry ... catch
and print the contents of any exception before failing.