public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Fix error handling for std::filesystem::equivalent [PR113250]
@ 2024-01-11  6:22 Ken Matsui
  2024-01-11  9:40 ` [PATCH v2 1/2] libstdc++: Fix error handling in filesystem::equivalent [PR113250] Ken Matsui
  0 siblings, 1 reply; 19+ messages in thread
From: Ken Matsui @ 2024-01-11  6:22 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Ken Matsui

This patch made std::filesystem::equivalent correctly throw an exception
when either path does not exist as per [fs.op.equivalent]/4.

libstdc++-v3/ChangeLog:

	* src/c++17/fs_ops.cc (equivalent): Use || instead of &&.
	* testsuite/27_io/filesystem/operations/equivalent.cc: Handle
	error codes.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
---
 libstdc++-v3/src/c++17/fs_ops.cc                              | 2 +-
 .../testsuite/27_io/filesystem/operations/equivalent.cc       | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc
index e0b308a37ea..61df19753ef 100644
--- a/libstdc++-v3/src/c++17/fs_ops.cc
+++ b/libstdc++-v3/src/c++17/fs_ops.cc
@@ -897,7 +897,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/testsuite/27_io/filesystem/operations/equivalent.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/equivalent.cc
index 78f6e368204..68f32366d65 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);
-- 
2.43.0


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2024-01-11 12:36 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-11  6:22 [PATCH] libstdc++: Fix error handling for std::filesystem::equivalent [PR113250] Ken Matsui
2024-01-11  9:40 ` [PATCH v2 1/2] libstdc++: Fix error handling in filesystem::equivalent [PR113250] Ken Matsui
2024-01-11  9:40   ` [PATCH v2 2/2] libstdc++: Use using instead of typedef in opts-common.h Ken Matsui
2024-01-11  9:55     ` Jonathan Wakely
2024-01-11 10:10       ` Ken Matsui
2024-01-11 10:50         ` Jonathan Wakely
2024-01-11 11:28           ` Ken Matsui
2024-01-11 12:01             ` Jonathan Wakely
2024-01-11 12:18               ` Ken Matsui
2024-01-11 12:01           ` Jonathan Wakely
2024-01-11 12:19             ` Ken Matsui
2024-01-11 10:12   ` [PATCH v3 " Ken Matsui
2024-01-11 10:46   ` [PATCH v2 1/2] libstdc++: Fix error handling in filesystem::equivalent [PR113250] Jonathan Wakely
2024-01-11 10:55     ` Ken Matsui
2024-01-11 11:14       ` Backporting [was Re: [PATCH v2 1/2] libstdc++: Fix error handling in filesystem::equivalent [PR113250]] Jonathan Wakely
2024-01-11 11:45         ` Ken Matsui
2024-01-11 12:22           ` Ken Matsui
2024-01-11 12:26             ` Jonathan Wakely
2024-01-11 12:35               ` Ken Matsui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).