mirror of git://gcc.gnu.org/git/gcc.git
Fix std::filesystem::absolute for empty paths
* src/filesystem/std-ops.cc (absolute): Report an error for empty paths. (weakly_canonical(const path&)): Do not call canonical on empty path. (weakly_canonical(const path&, error_code&)): Likewise. * testsuite/27_io/filesystem/operations/absolute.cc: Check for errors. From-SVN: r260441
This commit is contained in:
parent
cc343938cb
commit
8a49324e8a
|
|
@ -1,5 +1,11 @@
|
||||||
2018-05-21 Jonathan Wakely <jwakely@redhat.com>
|
2018-05-21 Jonathan Wakely <jwakely@redhat.com>
|
||||||
|
|
||||||
|
* src/filesystem/std-ops.cc (absolute): Report an error for empty
|
||||||
|
paths.
|
||||||
|
(weakly_canonical(const path&)): Do not call canonical on empty path.
|
||||||
|
(weakly_canonical(const path&, error_code&)): Likewise.
|
||||||
|
* testsuite/27_io/filesystem/operations/absolute.cc: Check for errors.
|
||||||
|
|
||||||
PR libstdc++/85818
|
PR libstdc++/85818
|
||||||
* testsuite/experimental/filesystem/path/preferred_separator.cc: Add
|
* testsuite/experimental/filesystem/path/preferred_separator.cc: Add
|
||||||
dg-require-filesystem-ts.
|
dg-require-filesystem-ts.
|
||||||
|
|
|
||||||
|
|
@ -84,13 +84,20 @@ fs::absolute(const path& p)
|
||||||
fs::path
|
fs::path
|
||||||
fs::absolute(const path& p, error_code& ec)
|
fs::absolute(const path& p, error_code& ec)
|
||||||
{
|
{
|
||||||
|
path ret;
|
||||||
|
if (p.empty())
|
||||||
|
{
|
||||||
|
ec = make_error_code(std::errc::no_such_file_or_directory);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
|
#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
|
||||||
ec = std::make_error_code(errc::not_supported);
|
ec = std::make_error_code(errc::not_supported);
|
||||||
return {};
|
|
||||||
#else
|
#else
|
||||||
ec.clear();
|
ec.clear();
|
||||||
return current_path() / p;
|
ret = current_path();
|
||||||
|
ret /= p;
|
||||||
#endif
|
#endif
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -1513,7 +1520,8 @@ fs::weakly_canonical(const path& p)
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
// canonicalize:
|
// canonicalize:
|
||||||
result = canonical(result);
|
if (!result.empty())
|
||||||
|
result = canonical(result);
|
||||||
// append the non-existing elements:
|
// append the non-existing elements:
|
||||||
while (iter != end)
|
while (iter != end)
|
||||||
result /= *iter++;
|
result /= *iter++;
|
||||||
|
|
@ -1551,7 +1559,7 @@ fs::weakly_canonical(const path& p, error_code& ec)
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
// canonicalize:
|
// canonicalize:
|
||||||
if (!ec)
|
if (!ec && !result.empty())
|
||||||
result = canonical(result, ec);
|
result = canonical(result, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
result.clear();
|
result.clear();
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,11 @@ void
|
||||||
test01()
|
test01()
|
||||||
{
|
{
|
||||||
for (const path& p : __gnu_test::test_paths)
|
for (const path& p : __gnu_test::test_paths)
|
||||||
VERIFY( absolute(p).is_absolute() );
|
{
|
||||||
|
std::error_code ec;
|
||||||
|
path abs = absolute(p, ec);
|
||||||
|
VERIFY( ec || abs.is_absolute() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue