summaryrefslogtreecommitdiff
path: root/libstdc++-v3/src
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2019-05-04 15:35:33 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2019-05-04 15:35:33 +0100
commit854a5c7722041c3c37ac68eca357bac225e58b88 (patch)
treed345f7c0c2d3d13cf33bd877b2e10ba9ddb45322 /libstdc++-v3/src
parent2f7f1aca2959712d4d66f1409719a5bde871a626 (diff)
PR libstdc++/90299 make filesystem::absolute overloads consistent
In this implementation it is an error to pass the empty path to absolute, because the empty path doesn't represent any file in the filesystem so the function cannot meet its postcondition. Currently the absolute(const path&, error_code&) overload reports an error for the empty path, but using errc::no_such_file_or_directory, and the other overload does not report an error. This patch makes them consistntly report an errc::invalid_argument error for the empty path. PR libstdc++/90299 * src/c++17/fs_ops.cc (absolute(const path&)): Report an error if the argument is an empty path. (absolute(const path&, error_code&)): Use invalid_argument as error code instead of no_such_file_or_directory. * testsuite/27_io/filesystem/operations/absolute.cc: Check handling of non-existent paths and empty paths with both overloads of absolute. From-SVN: r270874
Diffstat (limited to 'libstdc++-v3/src')
-rw-r--r--libstdc++-v3/src/c++17/fs_ops.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc
index 5ca523826cb..2d13b172d69 100644
--- a/libstdc++-v3/src/c++17/fs_ops.cc
+++ b/libstdc++-v3/src/c++17/fs_ops.cc
@@ -72,6 +72,9 @@ fs::absolute(const path& p)
ec));
return ret;
#else
+ if (p.empty())
+ _GLIBCXX_THROW_OR_ABORT(filesystem_error("cannot make absolute path", p,
+ make_error_code(std::errc::invalid_argument)));
return current_path() / p;
#endif
}
@@ -82,7 +85,7 @@ fs::absolute(const path& p, error_code& ec)
path ret;
if (p.empty())
{
- ec = make_error_code(std::errc::no_such_file_or_directory);
+ ec = make_error_code(std::errc::invalid_argument);
return ret;
}
ec.clear();