aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2017-11-17 14:07:58 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2017-11-17 14:07:58 +0000
commit96e0367ead5d8dcac3bec2865582e76e2fbab190 (patch)
tree7206a6f455f377e8e51d9d7466c82d36a3e08a50 /libstdc++-v3
parent610f66a3d14e56dee60cd542579ffbf14f803d80 (diff)
downloadgcc-96e0367ead5d8dcac3bec2865582e76e2fbab190.zip
gcc-96e0367ead5d8dcac3bec2865582e76e2fbab190.tar.gz
gcc-96e0367ead5d8dcac3bec2865582e76e2fbab190.tar.bz2
PR libstdc++/83025 fix constraints for path overloads in <fstream>
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
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog22
-rw-r--r--libstdc++-v3/include/std/fstream34
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/path.cc10
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/path.cc6
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_fstream/open/char/path.cc11
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/path.cc6
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/path.cc11
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/path.cc5
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/path.cc12
9 files changed, 91 insertions, 26 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 3c9f3e7..3755ce6 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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
diff --git a/libstdc++-v3/include/std/fstream b/libstdc++-v3/include/std/fstream
index 26176af..503bdd6 100644
--- a/libstdc++-v3/include/std/fstream
+++ b/libstdc++-v3/include/std/fstream
@@ -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
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/path.cc
index 56fffde..51f0839 100644
--- a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/path.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/path.cc
@@ -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()
{
diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/path.cc
index 51337eb..079ebe2 100644
--- a/libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/path.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/path.cc
@@ -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;
}
diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/open/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/open/char/path.cc
index 8d0127b..297c897 100644
--- a/libstdc++-v3/testsuite/27_io/basic_fstream/open/char/path.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_fstream/open/char/path.cc
@@ -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()
{
diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/path.cc
index a0de4ba..4265149 100644
--- a/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/path.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/path.cc
@@ -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;
}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/path.cc
index 192e0fe..49b8c1e 100644
--- a/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/path.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/path.cc
@@ -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()
{
diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/path.cc
index c6b6b23..da88ff9 100644
--- a/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/path.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/path.cc
@@ -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()
{
diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/path.cc
index 38078c9..4bbace2 100644
--- a/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/path.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/path.cc
@@ -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;
}