aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2018-11-28 15:36:56 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2018-11-28 15:36:56 +0000
commitbd6ccc290a624a54f779054205cbfabb4e33a0aa (patch)
tree711247549173e2042ffb21ff6a4bc11eeb148afb
parent24d9b090fb4b9a260fedb4489392ebd509e93202 (diff)
downloadgcc-bd6ccc290a624a54f779054205cbfabb4e33a0aa.zip
gcc-bd6ccc290a624a54f779054205cbfabb4e33a0aa.tar.gz
gcc-bd6ccc290a624a54f779054205cbfabb4e33a0aa.tar.bz2
Apply resolution for LWG DR 3096
Add fix for "path::lexically_relative is confused by trailing slashes". * 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. From-SVN: r266566
-rw-r--r--libstdc++-v3/ChangeLog6
-rw-r--r--libstdc++-v3/doc/xml/manual/intro.xml7
-rw-r--r--libstdc++-v3/src/filesystem/std-path.cc6
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc20
4 files changed, 37 insertions, 2 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index fe0d165..9ef71f1 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,11 @@
2018-11-28 Jonathan Wakely <jwakely@redhat.com>
+ * 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 cb187e1..7159b59 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.
<listitem><para>Change constructors to constrained templates.
</para></listitem></varlistentry>
+ <varlistentry xml:id="manual.bugs.dr3096"><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&DR;#3096">3096</link>:
+ <emphasis><code>path::lexically_relative</code> is confused by trailing slashes
+ </emphasis>
+ </term>
+ <listitem><para>Implement the fix for trailing slashes.
+ </para></listitem></varlistentry>
+
</variablelist>
</section>
diff --git a/libstdc++-v3/src/filesystem/std-path.cc b/libstdc++-v3/src/filesystem/std-path.cc
index fb8898d..06d882c 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 4bc4758..6652c19 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();
}