Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LWG-3699 lexically_relative on UNC drive paths (\\?\C:\...) results in a default-constructed value #2867

Merged
merged 4 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
switch to the decision we made
  • Loading branch information
strega-nil committed Jul 20, 2022
commit d22b9655a72cb28e6691e683647e9f1c473b375f
7 changes: 4 additions & 3 deletions stl/inc/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -1693,9 +1693,10 @@ namespace filesystem {
// LWG-3699: `lexically_relative` on UNC drive paths (`\\?\C:\...`) results in a default-constructed value
// This avoids doing any unnecessary copies;
// the return value of `relative_path()` is lifetime-extended if necessary.
const path& _This = _Is_drive_prefix_with_slash_slash_question(_Text) ? relative_path() : *this;
const path& _Base =
_Is_drive_prefix_with_slash_slash_question(_Base_raw._Text) ? _Base_raw.relative_path() : _Base_raw;
const bool _Both_unc_paths = _Is_drive_prefix_with_slash_slash_question(_Text)
&& _Is_drive_prefix_with_slash_slash_question(_Base_raw._Text);
const path& _This = _Both_unc_paths ? relative_path() : *this;
const path& _Base = _Both_unc_paths ? _Base_raw.relative_path() : _Base_raw;

path _Result;

Expand Down
8 changes: 5 additions & 3 deletions tests/std/tests/P0218R1_filesystem/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3148,9 +3148,11 @@ void test_lexically_relative() {

// LWG-3699
EXPECT(path(LR"(\\?\a:\meow)"sv).lexically_relative(LR"(\\?\a:\meow)"sv).native() == LR"(.)"sv);
EXPECT(path(LR"(a:\meow)"sv).lexically_relative(LR"(\\?\a:\meow)"sv).native() == LR"(.)"sv);
EXPECT(path(LR"(\\?\a:\meow)"sv).lexically_relative(LR"(a:\meow)"sv).native() == LR"(.)"sv);
EXPECT(path(LR"(\\?\a:\meow\purr\nyan)"sv).lexically_relative(LR"(a:\meow)"sv).native() == LR"(purr\nyan)"sv);
EXPECT(path(LR"(\\?\a:\meow\purr\nyan)"sv).lexically_relative(LR"(\\?\a:\meow)"sv).native() == LR"(purr\nyan)"sv);
EXPECT(path(LR"(\\?\a:\meow)"sv).lexically_relative(LR"(\\?\a:\meow\purr\nyan)"sv).native() == LR"(..\..)"sv);
// UNC/DOS together should return an empty path
EXPECT(path(LR"(a:\meow)"sv).lexically_relative(LR"(\\?\a:\meow)"sv).native().empty());
EXPECT(path(LR"(\\?\a:\meow)"sv).lexically_relative(LR"(a:\meow)"sv).native().empty());
}

void test_lexically_proximate() {
Expand Down