]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR libstdc++/83025 fix constraints for path overloads in <fstream>
authorJonathan Wakely <jwakely@redhat.com>
Fri, 17 Nov 2017 14:07:58 +0000 (14:07 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 17 Nov 2017 14:07:58 +0000 (14:07 +0000)
PR libstdc++/83025
* include/std/fstream (basic_filebuf::_If_path): Move to
namespace-scope and rename to _If_fs_path.
(basic_filebuf::open): Use new name.
(basic_ifstream(_Path, ios::openmode))
(basic_ifstream::open(_Path, ios::openmode))
(basic_ofstream(_Path, ios::openmode))
(basic_ofstream::open(_Path, ios::openmode))
(basic_fstream(_Path, ios::openmode))
(basic_fstream::open(_Path, ios::openmode)): Use _If_fs_path.
* testsuite/27_io/basic_filebuf/open/char/path.cc: Test with filename
as non-const char*.
* testsuite/27_io/basic_fstream/cons/char/path.cc: Likewise.
* testsuite/27_io/basic_fstream/open/char/path.cc: Likewise.
* testsuite/27_io/basic_ifstream/cons/char/path.cc: Likewise.
* testsuite/27_io/basic_ifstream/open/char/path.cc: Likewise.
* testsuite/27_io/basic_ofstream/cons/char/path.cc: Likewise.
* testsuite/27_io/basic_ofstream/open/char/path.cc: Likewise.

From-SVN: r254871

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/fstream
libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/path.cc
libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/path.cc
libstdc++-v3/testsuite/27_io/basic_fstream/open/char/path.cc
libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/path.cc
libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/path.cc
libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/path.cc
libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/path.cc

index 3c9f3e7569af5c109c00a41322fa82efed770799..3755ce6c53ab6132c85875933ffb70f22fed46f2 100644 (file)
@@ -1,3 +1,25 @@
+2017-11-17  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/83025
+       * include/std/fstream (basic_filebuf::_If_path): Move to
+       namespace-scope and rename to _If_fs_path.
+       (basic_filebuf::open): Use new name.
+       (basic_ifstream(_Path, ios::openmode))
+       (basic_ifstream::open(_Path, ios::openmode))
+       (basic_ofstream(_Path, ios::openmode))
+       (basic_ofstream::open(_Path, ios::openmode))
+       (basic_fstream(_Path, ios::openmode))
+       (basic_fstream::open(_Path, ios::openmode)): Use _If_fs_path.
+       * testsuite/27_io/basic_filebuf/open/char/path.cc: Test with filename
+       as non-const char*.
+       * testsuite/27_io/basic_fstream/cons/char/path.cc: Likewise.
+       * testsuite/27_io/basic_fstream/open/char/path.cc: Likewise.
+       * testsuite/27_io/basic_ifstream/cons/char/path.cc: Likewise.
+       * testsuite/27_io/basic_ifstream/open/char/path.cc: Likewise.
+       * testsuite/27_io/basic_ofstream/cons/char/path.cc: Likewise.
+       * testsuite/27_io/basic_ofstream/open/char/path.cc: Likewise.
+
+
 2017-11-17  Marc Glisse  <marc.glisse@inria.fr>
 
        * include/bits/vector.tcc (vector::_M_realloc_insert): Cache old
index 26176afccd0192eb4a8075e7092fa473efb48eca..503bdd617215c4effc137107f287321d45591ee1 100644 (file)
@@ -48,6 +48,14 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+#if __cplusplus >= 201703L
+  // Enable if _Path is a filesystem::path or experimental::filesystem::path
+  template<typename _Path, typename _Result = _Path, typename _Path2
+          = decltype(std::declval<_Path&>().make_preferred().filename())>
+    using _If_fs_path = enable_if_t<is_same_v<_Path, _Path2>, _Result>;
+#endif // C++17
+
+
   // [27.8.1.1] template class basic_filebuf
   /**
    *  @brief  The actual work of input and output (for files).
@@ -216,12 +224,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          }
       }
 
-#if __cplusplus >= 201703L
-      template<typename _Path, typename _Result = _Path, typename _Path2
-              = decltype(std::declval<_Path&>().make_preferred().native())>
-       using _If_path = enable_if_t<is_same_v<_Path, _Path2>, _Result>;
-#endif // C++17
-
     public:
       // Constructors/destructor:
       /**
@@ -321,7 +323,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  @return  @c this on success, NULL on failure
        */
       template<typename _Path>
-       _If_path<_Path, __filebuf_type*>
+       _If_fs_path<_Path, __filebuf_type*>
        open(const _Path& __s, ios_base::openmode __mode)
        { return open(__s.c_str(), __mode); }
 #endif // C++17
@@ -540,8 +542,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *
        *  @c ios_base::in is automatically included in @a __mode.
        */
-      template<typename _Path, typename = _Require<
-         is_constructible<__filebuf_type, const _Path&, ios_base::openmode>>>
+      template<typename _Path, typename _Require = _If_fs_path<_Path>>
        basic_ifstream(const _Path& __s,
                       ios_base::openmode __mode = ios_base::in)
        : basic_ifstream(__s.c_str(), __mode)
@@ -661,9 +662,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  fails, @c failbit is set in the stream's error state.
        */
       template<typename _Path>
-       auto
+       _If_fs_path<_Path, void>
        open(const _Path& __s, ios_base::openmode __mode = ios_base::in)
-       -> decltype((void)_M_filebuf.open(__s, __mode))
        { open(__s.c_str(), __mode); }
 #endif // C++17
 #endif // C++11
@@ -768,8 +768,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *
        *  @c ios_base::out is automatically included in @a __mode.
        */
-      template<typename _Path, typename = _Require<
-         is_constructible<__filebuf_type, const _Path&, ios_base::openmode>>>
+      template<typename _Path, typename _Require = _If_fs_path<_Path>>
        basic_ofstream(const _Path& __s,
                       ios_base::openmode __mode = ios_base::out)
        : basic_ofstream(__s.c_str(), __mode)
@@ -889,9 +888,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  function fails, @c failbit is set in the stream's error state.
        */
       template<typename _Path>
-       auto
+       _If_fs_path<_Path, void>
        open(const _Path& __s, ios_base::openmode __mode = ios_base::out)
-       -> decltype((void)_M_filebuf.open(__s, __mode))
        { open(__s.c_str(), __mode); }
 #endif // C++17
 #endif // C++11
@@ -992,8 +990,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  @param  __s  filesystem::path specifying the filename.
        *  @param  __mode  Open file in specified mode (see std::ios_base).
        */
-      template<typename _Path, typename = _Require<
-         is_constructible<__filebuf_type, const _Path&, ios_base::openmode>>>
+      template<typename _Path, typename _Require = _If_fs_path<_Path>>
        basic_fstream(const _Path& __s,
                      ios_base::openmode __mode = ios_base::in | ios_base::out)
        : basic_fstream(__s.c_str(), __mode)
@@ -1115,10 +1112,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  function fails, @c failbit is set in the stream's error state.
        */
       template<typename _Path>
-       auto
+       _If_fs_path<_Path, void>
        open(const _Path& __s,
             ios_base::openmode __mode = ios_base::in | ios_base::out)
-       -> decltype((void)_M_filebuf.open(__s, __mode))
        { open(__s.c_str(), __mode); }
 #endif // C++17
 #endif // C++11
index 56fffde5f9ba6b2314200cbc81c3c5260a18590e..51f0839394bcf5f738664340145cf96b60b2b8b8 100644 (file)
@@ -24,7 +24,8 @@
 #include <filesystem>
 #include <testsuite_hooks.h>
 
-const std::filesystem::path filename = "filebuf_members-1.tst";
+char cstr[] = "filebuf_members-1.tst";
+const std::filesystem::path filename = cstr;
 
 void
 test01()
@@ -34,6 +35,13 @@ test01()
   VERIFY( fb.is_open() );
 }
 
+void
+test02() // compile-only
+{
+  std::filebuf fb;
+  fb.open(cstr, std::ios::in); // PR libstdc++/83025
+}
+
 int
 main()
 {
index 51337ebd909237b3bdfbd7331ec93c49fde0dc0c..079ebe2d04ef2f7cfa89169764620f46abedd939 100644 (file)
@@ -40,10 +40,14 @@ test02()
   VERIFY( f.is_open() );
 }
 
+using std::is_constructible_v;
+// PR libstdc++/83025
+static_assert(is_constructible_v<std::fstream, char*>);
+static_assert(is_constructible_v<std::fstream, char*, std::ios::openmode>);
+
 int
 main()
 {
   test01();
   test02();
-  return 0;
 }
index 8d0127be2b8ec580b1487969a15838cc1c1e9abf..297c8973ca1e7e2dd1279b0e20d21dcf8284224f 100644 (file)
@@ -24,7 +24,8 @@
 #include <filesystem>
 #include <testsuite_hooks.h>
 
-const std::filesystem::path filename = "ofstream_members-1.tst";
+char cstr[] = "filebuf_members-1.tst";
+const std::filesystem::path filename = cstr;
 
 void
 test01()
@@ -42,6 +43,14 @@ test02()
   VERIFY( f.is_open() );
 }
 
+void
+test03() // compile-only
+{
+  std::fstream f;
+  f.open(cstr);                                    // PR libstdc++/83025
+  f.open(cstr, std::ios::in|std::ios::out); // PR libstdc++/83025
+}
+
 int
 main()
 {
index a0de4ba55b2c3ee1ac9dfe042ad2532f6456ae33..4265149752b2d22161dc5bd40fc57e6a7a6eff44 100644 (file)
@@ -40,10 +40,14 @@ test02()
   VERIFY( f.is_open() );
 }
 
+using std::is_constructible_v;
+// PR libstdc++/83025
+static_assert(is_constructible_v<std::fstream, char*>);
+static_assert(is_constructible_v<std::fstream, char*, std::ios::openmode>);
+
 int
 main()
 {
   test01();
   test02();
-  return 0;
 }
index 192e0fe9e851f34a721c6ef69bcbb4f923e82b0e..49b8c1e4dc4ce0674cc9dd28129a16743ade67c7 100644 (file)
@@ -24,7 +24,8 @@
 #include <filesystem>
 #include <testsuite_hooks.h>
 
-const std::filesystem::path filename = "ifstream_members-1.tst";
+char cstr[] = "filebuf_members-1.tst";
+const std::filesystem::path filename = cstr;
 
 void
 test01()
@@ -42,6 +43,14 @@ test02()
   VERIFY( f.is_open() );
 }
 
+void
+test03() // compile-only
+{
+  std::ifstream f;
+  f.open(cstr);                      // PR libstdc++/83025
+  f.open(cstr, std::ios::in); // PR libstdc++/83025
+}
+
 int
 main()
 {
index c6b6b237dfd2e34ce14b6e3e7950c09d345a9f30..da88ff979c4d9e2019ab6ffb2a2a107cb7278b4d 100644 (file)
@@ -40,6 +40,11 @@ test02()
   VERIFY( f.is_open() );
 }
 
+using std::is_constructible_v;
+// PR libstdc++/83025
+static_assert(is_constructible_v<std::fstream, char*>);
+static_assert(is_constructible_v<std::fstream, char*, std::ios::openmode>);
+
 int
 main()
 {
index 38078c97ef75f7fdd95ed20b642102b3bbafc422..4bbace2c679ba6520871010ea36c01e56bab2b82 100644 (file)
@@ -24,7 +24,8 @@
 #include <filesystem>
 #include <testsuite_hooks.h>
 
-const std::filesystem::path filename = "ofstream_members-1.tst";
+char cstr[] = "filebuf_members-1.tst";
+const std::filesystem::path filename = cstr;
 
 void
 test01()
@@ -42,10 +43,17 @@ test02()
   VERIFY( f.is_open() );
 }
 
+void
+test03() // compile-only
+{
+  std::ofstream f;
+  f.open(cstr);                        // PR libstdc++/83025
+  f.open(cstr, std::ios::out); // PR libstdc++/83025
+}
+
 int
 main()
 {
   test01();
   test02();
-  return 0;
 }