]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix error handling in filesystem::equivalent [PR113250]
authorKen Matsui <kmatsui@gcc.gnu.org>
Thu, 11 Jan 2024 06:08:07 +0000 (22:08 -0800)
committerKen Matsui <kmatsui@gcc.gnu.org>
Thu, 11 Jan 2024 11:36:14 +0000 (03:36 -0800)
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 <kmatsui@gcc.gnu.org>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/src/c++17/fs_ops.cc
libstdc++-v3/src/filesystem/ops.cc
libstdc++-v3/testsuite/27_io/filesystem/operations/equivalent.cc
libstdc++-v3/testsuite/experimental/filesystem/operations/equivalent.cc

index e0b308a37ea4fcb0508f4eec514e9f22608f063f..61df19753efad6bc0148cb83a7ff31047cc3e04f 100644 (file)
@@ -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());
index eccdae3d91084046c0aa573fd47910a5fd4b339a..4d23a804da09e79e9f1f98288988af3d8cd666ca 100644 (file)
@@ -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());
index 78f6e3682043b02a74e7609b2513d792cc126cc4..68f32366d65897939991498ea29dd59b6c1fd4fd 100644 (file)
@@ -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);
index 929a6ca860945553eaadef64af44ab5a26fb4b15..5bc477a31cd6136ca9b0861852323f2a0c1957a0 100644 (file)
@@ -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);