]> 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:44:36 +0000 (03:44 -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>
(cherry picked from commit df147e2ee7199d33d66959c6509ce9c21072077f)

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 84737453ada714272c7168adcaf3db72a34b1a1c..9f24bc6462f1d885fb28af2b4758609b25f69016 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 274878e8f6e7a986e15b4078efb09d919fc5c348..d9e300ffe29eca56a2b9e3bb4e9cb277018c5e8c 100644 (file)
@@ -764,7 +764,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 9354de2e796de3ff0e1a797a76a55f6e8985f62f..97d4a48d52339875dafdc006cca12fc4007201d8 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 4e03877a162fbecdc563e0f727f6c8b5cbedab7b..6089b83c4320e9d5a85629110de023a8e18b15db 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);