From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7934) id 235E93857C73; Thu, 11 Jan 2024 11:42:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 235E93857C73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704973326; bh=+KwSn1RJBlpPrTz0iPx+P3VkJFLTnuPAQy7LGnxUURY=; h=From:To:Subject:Date:From; b=X/nkVu+PivuOR+xeaD1fqyEd9NHkbo2a3kXGSHT4gSzVmC3FlypQ2hh9GJXMJI7yG adBnYdZy6dteh+6DiorpxDND99yXPA3Ca3SSUYnTiI8iTIM5u+2k2hD3L2i1Rewhud 3SX0vVEPTgeyHWpnspUDNCS9rx6gWl3VRpKkAlI4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Ken Matsui To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-8209] libstdc++: Fix error handling in filesystem::equivalent [PR113250] X-Act-Checkin: gcc X-Git-Author: Ken Matsui X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: c9c8044632ae8548f088ac89db2c83bf993f8fe8 X-Git-Newrev: 3e51890ef351e7fb9e836c6a48f20ca97294dc16 Message-Id: <20240111114206.235E93857C73@sourceware.org> Date: Thu, 11 Jan 2024 11:42:06 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3e51890ef351e7fb9e836c6a48f20ca97294dc16 commit r13-8209-g3e51890ef351e7fb9e836c6a48f20ca97294dc16 Author: Ken Matsui Date: Wed Jan 10 22:08:07 2024 -0800 libstdc++: Fix error handling in filesystem::equivalent [PR113250] This patch made std::filesystem::equivalent correctly throw an exception when either path does not exist as per [fs.op.equivalent]/4. PR libstdc++/113250 libstdc++-v3/ChangeLog: * src/c++17/fs_ops.cc (fs::equivalent): Use || instead of &&. * src/filesystem/ops.cc (fs::equivalent): Likewise. * testsuite/27_io/filesystem/operations/equivalent.cc: Handle error codes. * testsuite/experimental/filesystem/operations/equivalent.cc: Likewise. Signed-off-by: Ken Matsui Reviewed-by: Jonathan Wakely (cherry picked from commit df147e2ee7199d33d66959c6509ce9c21072077f) Diff: --- libstdc++-v3/src/c++17/fs_ops.cc | 2 +- libstdc++-v3/src/filesystem/ops.cc | 2 +- libstdc++-v3/testsuite/27_io/filesystem/operations/equivalent.cc | 4 ++-- .../testsuite/experimental/filesystem/operations/equivalent.cc | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc index 7d55c356882..6d84d4293d2 100644 --- a/libstdc++-v3/src/c++17/fs_ops.cc +++ b/libstdc++-v3/src/c++17/fs_ops.cc @@ -898,7 +898,7 @@ fs::equivalent(const path& p1, const path& p2, error_code& ec) noexcept return st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino; #endif } - else if (!exists(s1) && !exists(s2)) + else if (!exists(s1) || !exists(s2)) ec = std::make_error_code(std::errc::no_such_file_or_directory); else if (err) ec.assign(err, std::generic_category()); diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc index 0102c6705f2..9fa1a685add 100644 --- a/libstdc++-v3/src/filesystem/ops.cc +++ b/libstdc++-v3/src/filesystem/ops.cc @@ -765,7 +765,7 @@ fs::equivalent(const path& p1, const path& p2, error_code& ec) noexcept return false; return st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino; } - else if (!exists(s1) && !exists(s2)) + else if (!exists(s1) || !exists(s2)) ec = std::make_error_code(std::errc::no_such_file_or_directory); else if (err) ec.assign(err, std::generic_category()); diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/equivalent.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/equivalent.cc index ad79239be5c..a301f16fd00 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/equivalent.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/equivalent.cc @@ -34,13 +34,13 @@ test01() bool result; result = equivalent(p1, p2, ec); - VERIFY( ec ); + VERIFY( ec == std::errc::no_such_file_or_directory ); VERIFY( !result ); __gnu_test::scoped_file f1(p1); ec = bad_ec; result = equivalent(p1, p2, ec); - VERIFY( !ec ); + VERIFY( ec == std::errc::no_such_file_or_directory ); VERIFY( !result ); __gnu_test::scoped_file f2(p2); diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/equivalent.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/equivalent.cc index f44d735cbd1..de6a5f62a80 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/equivalent.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/equivalent.cc @@ -35,13 +35,13 @@ test01() bool result; result = equivalent(p1, p2, ec); - VERIFY( ec ); + VERIFY( ec == std::errc::no_such_file_or_directory ); VERIFY( !result ); const auto bad_ec = ec; __gnu_test::scoped_file f1(p1); result = equivalent(p1, p2, ec); - VERIFY( !ec ); + VERIFY( ec == std::errc::no_such_file_or_directory ); VERIFY( !result ); __gnu_test::scoped_file f2(p2);