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 <kmatsui@gcc.gnu.org>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
This commit is contained in:
Ken Matsui 2024-01-10 22:08:07 -08:00
parent ea2a9c76a1
commit df147e2ee7
No known key found for this signature in database
4 changed files with 6 additions and 6 deletions

View 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());

View 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());

View 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);

View 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);