libstdc++/71037 Add base path to filesystem::canonical exceptions
authorJonathan Wakely <jwakely@redhat.com>
Tue, 10 May 2016 12:22:32 +0000 (13:22 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 10 May 2016 12:22:32 +0000 (13:22 +0100)
PR libstdc++/71037
* src/filesystem/ops.cc (canonical(const path&, const path&)): Add
base path to exception.
* testsuite/experimental/filesystem/operations/canonical.cc: Test
paths contained in exception.

From-SVN: r236074

libstdc++-v3/ChangeLog
libstdc++-v3/src/filesystem/ops.cc
libstdc++-v3/testsuite/experimental/filesystem/operations/canonical.cc

index 208b8940f5cd64a3e8b8e8e832b74281a5963c97..cf7ce6f5cd13210c9948a8d24e92752949966a50 100644 (file)
@@ -1,5 +1,11 @@
 2016-05-10  Jonathan Wakely  <jwakely@redhat.com>
 
+       PR libstdc++/71037
+       * src/filesystem/ops.cc (canonical(const path&, const path&)): Add
+       base path to exception.
+       * testsuite/experimental/filesystem/operations/canonical.cc: Test
+       paths contained in exception.
+
        * testsuite/experimental/type_erased_allocator/2.cc: Remove unused
        using declaration.
 
index aa26cafa1032657e79861a235f4cbbf5c7e48071..e18c7510c4170b54c9e1a83c6abee105247f61c7 100644 (file)
@@ -220,8 +220,9 @@ fs::canonical(const path& p, const path& base)
 {
   error_code ec;
   path can = canonical(p, base, ec);
-  if (ec.value())
-    _GLIBCXX_THROW_OR_ABORT(filesystem_error("cannot canonicalize", p, ec));
+  if (ec)
+    _GLIBCXX_THROW_OR_ABORT(filesystem_error("cannot canonicalize", p, base,
+                                            ec));
   return can;
 }
 
index e13c4bfe0a53c762d866ee922c3803a540edf62f..5b4c573eebf6d2e5e8c5c0f27438b2f47dd1c95d 100644 (file)
@@ -59,8 +59,28 @@ test01()
   VERIFY( !ec );
 }
 
+void
+test02()
+{
+#if __cpp_exceptions
+  bool test __attribute__((unused)) = false;
+
+  fs::path p = "rel", base = __gnu_test::nonexistent_path();
+  fs::path e1, e2;
+  try {
+    canonical(p, base);
+  } catch (const fs::filesystem_error& e) {
+    e1 = e.path1();
+    e2 = e.path2();
+  }
+  VERIFY( e1 == p );
+  VERIFY( e2 == base );
+#endif
+}
+
 int
 main()
 {
   test01();
+  test02();
 }