diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index fe0d1652c2c..9ef71f13897 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,11 @@ 2018-11-28 Jonathan Wakely + * doc/xml/manual/intro.xml: Document LWG 3096 change. + * src/filesystem/std-path.cc (path::lexically_relative(const path&)): + Treat a final empty element equivalently to a final dot element. + * testsuite/27_io/filesystem/path/generation/relative.cc: Add checks + for the examples in the DR. + PR libstdc++/83306 * include/bits/fs_path.h (filesystem_error): Move data members into pimpl class owned by shared_ptr. Remove inline definitions of member diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index cb187e1a2ed..7159b592c9f 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -1194,6 +1194,13 @@ requirements of the license of GCC. Change constructors to constrained templates. + 3096: + path::lexically_relative is confused by trailing slashes + + + Implement the fix for trailing slashes. + + diff --git a/libstdc++-v3/src/filesystem/std-path.cc b/libstdc++-v3/src/filesystem/std-path.cc index fb8898d9040..06d882cf4de 100644 --- a/libstdc++-v3/src/filesystem/std-path.cc +++ b/libstdc++-v3/src/filesystem/std-path.cc @@ -529,10 +529,12 @@ path::lexically_relative(const path& base) const const path& p = *b; if (is_dotdot(p)) --n; - else if (!is_dot(p)) + else if (!p.empty() && !is_dot(p)) ++n; } - if (n >= 0) + if (n == 0 && (a == end() || a->empty())) + ret = "."; + else if (n >= 0) { const path dotdot(".."); while (n--) diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc index 4bc475827b2..6652c196d07 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc @@ -45,6 +45,25 @@ test02() compare_paths( p.lexically_relative(p), "." ); compare_paths( p.lexically_relative("a/../a/b/../b/c/../c/."), "../../b/c" ); compare_paths( p.lexically_relative("../../../"), "" ); + + compare_paths( path("a/./.").lexically_relative("a"), "./." ); +} + +void +test03() +{ + // LWG 3096 + compare_paths( path("/dir").lexically_relative("/dir"), "." ); + compare_paths( path("/dir").lexically_relative("/dir/"), "." ); + compare_paths( path("/dir").lexically_relative("/dir/."), "." ); + + compare_paths( path("/dir/").lexically_relative("/dir"), "." ); + compare_paths( path("/dir/").lexically_relative("/dir/"), "." ); + compare_paths( path("/dir/").lexically_relative("/dir/."), "." ); + + compare_paths( path("/dir/.").lexically_relative("/dir"), "." ); + compare_paths( path("/dir/.").lexically_relative("/dir/"), "." ); + compare_paths( path("/dir/.").lexically_relative("/dir/."), "." ); } int @@ -52,4 +71,5 @@ main() { test01(); test02(); + test03(); }