[PATCH] Make filesystem::path comparison operators hidden friends (LWG 3065)

Jonathan Wakely jwakely@redhat.com
Wed Apr 24 21:35:00 GMT 2019


This change revealed two testsuite bugs where some string comparisons
only compiled by converting the strings to filesystem::path objects.

	* include/bits/fs_path.h (operator<, operator<=, operator>)
	(operator>=, operator==, operator!=): Make hidden friends, as per
	LWG 3065.
	* testsuite/27_io/filesystem/path/native/string-char8_t.cc: Fix
	string type in test.
	* testsuite/27_io/filesystem/path/native/string.cc: Likewise.

Tested powerpc64le-linux, committed to trunk.

-------------- next part --------------
commit bcfec0ca213b70e81e8291b3344ff47fd8eac012
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Apr 24 21:48:17 2019 +0100

    Make filesystem::path comparison operators hidden friends (LWG 3065)
    
    This change revealed two testsuite bugs where some string comparisons
    only compiled by converting the strings to filesystem::path objects.
    
            * include/bits/fs_path.h (operator<, operator<=, operator>)
            (operator>=, operator==, operator!=): Make hidden friends, as per
            LWG 3065.
            * testsuite/27_io/filesystem/path/native/string-char8_t.cc: Fix
            string type in test.
            * testsuite/27_io/filesystem/path/native/string.cc: Likewise.

diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h
index bf7c65c9cad..3674b4391f8 100644
--- a/libstdc++-v3/include/bits/fs_path.h
+++ b/libstdc++-v3/include/bits/fs_path.h
@@ -417,6 +417,40 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 	return __is;
       }
 
+    // non-member operators
+
+    /// Compare paths
+    friend bool operator<(const path& __lhs, const path& __rhs) noexcept
+    { return __lhs.compare(__rhs) < 0; }
+
+    /// Compare paths
+    friend bool operator<=(const path& __lhs, const path& __rhs) noexcept
+    { return !(__rhs < __lhs); }
+
+    /// Compare paths
+    friend bool operator>(const path& __lhs, const path& __rhs) noexcept
+    { return __rhs < __lhs; }
+
+    /// Compare paths
+    friend bool operator>=(const path& __lhs, const path& __rhs) noexcept
+    { return !(__lhs < __rhs); }
+
+    /// Compare paths
+    friend bool operator==(const path& __lhs, const path& __rhs) noexcept
+    { return __lhs.compare(__rhs) == 0; }
+
+    /// Compare paths
+    friend bool operator!=(const path& __lhs, const path& __rhs) noexcept
+    { return !(__lhs == __rhs); }
+
+    /// Append one path to another
+    friend path operator/(const path& __lhs, const path& __rhs)
+    {
+      path __result(__lhs);
+      __result /= __rhs;
+      return __result;
+    }
+
     // Create a basic_string by reading until a null character.
     template<typename _InputIterator,
 	     typename _Traits = std::iterator_traits<_InputIterator>,
@@ -578,38 +612,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 
   size_t hash_value(const path& __p) noexcept;
 
-  /// Compare paths
-  inline bool operator<(const path& __lhs, const path& __rhs) noexcept
-  { return __lhs.compare(__rhs) < 0; }
-
-  /// Compare paths
-  inline bool operator<=(const path& __lhs, const path& __rhs) noexcept
-  { return !(__rhs < __lhs); }
-
-  /// Compare paths
-  inline bool operator>(const path& __lhs, const path& __rhs) noexcept
-  { return __rhs < __lhs; }
-
-  /// Compare paths
-  inline bool operator>=(const path& __lhs, const path& __rhs) noexcept
-  { return !(__lhs < __rhs); }
-
-  /// Compare paths
-  inline bool operator==(const path& __lhs, const path& __rhs) noexcept
-  { return __lhs.compare(__rhs) == 0; }
-
-  /// Compare paths
-  inline bool operator!=(const path& __lhs, const path& __rhs) noexcept
-  { return !(__lhs == __rhs); }
-
-  /// Append one path to another
-  inline path operator/(const path& __lhs, const path& __rhs)
-  {
-    path __result(__lhs);
-    __result /= __rhs;
-    return __result;
-  }
-
   template<typename _InputIterator>
     inline auto
     u8path(_InputIterator __first, _InputIterator __last)
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/native/string-char8_t.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/native/string-char8_t.cc
index 4f187da7804..f5bb1afca5d 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/native/string-char8_t.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/native/string-char8_t.cc
@@ -46,7 +46,7 @@ test02()
   path p(s);
 
   auto str = p.string<char>();
-  VERIFY( str == u"abc" );
+  VERIFY( str == "abc" );
   VERIFY( str == p.string() );
 
   auto strw = p.string<wchar_t>();
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/native/string.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/native/string.cc
index 5417ab4c011..4d45c7e15df 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/native/string.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/native/string.cc
@@ -46,7 +46,7 @@ test02()
   path p(s);
 
   auto str = p.string<char>();
-  VERIFY( str == u"abc" );
+  VERIFY( str == "abc" );
   VERIFY( str == p.string() );
 
   auto strw = p.string<wchar_t>();


More information about the Libstdc++ mailing list