From: Jonathan Wakely Date: Fri, 17 Nov 2017 14:07:58 +0000 (+0000) Subject: PR libstdc++/83025 fix constraints for path overloads in X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=96e0367ead5d8dcac3bec2865582e76e2fbab190;p=gcc.git PR libstdc++/83025 fix constraints for path overloads in 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 3c9f3e7569a..3755ce6c53a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,25 @@ +2017-11-17 Jonathan Wakely + + 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 * 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 26176afccd0..503bdd61721 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().make_preferred().filename())> + using _If_fs_path = enable_if_t, _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().make_preferred().native())> - using _If_path = enable_if_t, _Result>; -#endif // C++17 - public: // Constructors/destructor: /** @@ -321,7 +323,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @return @c this on success, NULL on failure */ template - _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>> + template> 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 - 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>> + template> 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 - 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>> + template> 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 - 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 56fffde5f9b..51f0839394b 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 #include -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 51337ebd909..079ebe2d04e 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); +static_assert(is_constructible_v); + 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 8d0127be2b8..297c8973ca1 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 #include -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 a0de4ba55b2..4265149752b 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); +static_assert(is_constructible_v); + 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 192e0fe9e85..49b8c1e4dc4 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 #include -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 c6b6b237dfd..da88ff979c4 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); +static_assert(is_constructible_v); + 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 38078c97ef7..4bbace2c679 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 #include -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; }