lexically_relative on UNC drive paths (\\?\C:\...) results in a default-constructed value
Nicole Mazzuca

Created on 2022-05-12.00:00:00 last changed 1 month ago


Date: 2022-05-15.00:00:00

[ 2022-05-17; Reflector poll ]

Set priority to 3 after reflector poll.

Date: 2022-05-12.00:00:00

As a resolution to LWG 3070, in path lexically_relative(const path& base) const, bullet 3.4 was added:

If: […] any filename in relative_path() or base.relative_path() can be interpreted as a root-name, […] returns path().

This resolution was correct when we have really weird paths like abc\X:\c, but the MSVC standard library implementation treats UNC drive-relative paths as:

\\?\C:\foo\bar = { root-name = \\?, root-directory = \, relative-path = C:\foo\bar }

If we were able to go back in time, we might have root-name = \\?\C:, but we can't make that change at that point without silently breaking users; therefore, we believe it would be best to instead change lexically_relative() to work around this issue.

There exists a related github issue.

I don't yet have standard wording, but I think it would be reasonable to do something like:

If relative_path().has_root_path() && base.relative_path().has_root_path(), and relative_path().root_path() == base.relative_path().root_path(), then return relative_path().lexically_relative(base.relative_path()).

Date User Action Args
2022-05-17 11:58:16adminsetmessages: + msg12470
2022-05-12 00:00:00admincreate