mirror of git://gcc.gnu.org/git/gcc.git
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
This commit is contained in:
parent
610f66a3d1
commit
96e0367ead
|
|
@ -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>
|
2017-11-17 Marc Glisse <marc.glisse@inria.fr>
|
||||||
|
|
||||||
* include/bits/vector.tcc (vector::_M_realloc_insert): Cache old
|
* include/bits/vector.tcc (vector::_M_realloc_insert): Cache old
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,14 @@ namespace std _GLIBCXX_VISIBILITY(default)
|
||||||
{
|
{
|
||||||
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
_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
|
// [27.8.1.1] template class basic_filebuf
|
||||||
/**
|
/**
|
||||||
* @brief The actual work of input and output (for files).
|
* @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:
|
public:
|
||||||
// Constructors/destructor:
|
// Constructors/destructor:
|
||||||
/**
|
/**
|
||||||
|
|
@ -321,7 +323,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
* @return @c this on success, NULL on failure
|
* @return @c this on success, NULL on failure
|
||||||
*/
|
*/
|
||||||
template<typename _Path>
|
template<typename _Path>
|
||||||
_If_path<_Path, __filebuf_type*>
|
_If_fs_path<_Path, __filebuf_type*>
|
||||||
open(const _Path& __s, ios_base::openmode __mode)
|
open(const _Path& __s, ios_base::openmode __mode)
|
||||||
{ return open(__s.c_str(), __mode); }
|
{ return open(__s.c_str(), __mode); }
|
||||||
#endif // C++17
|
#endif // C++17
|
||||||
|
|
@ -540,8 +542,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
*
|
*
|
||||||
* @c ios_base::in is automatically included in @a __mode.
|
* @c ios_base::in is automatically included in @a __mode.
|
||||||
*/
|
*/
|
||||||
template<typename _Path, typename = _Require<
|
template<typename _Path, typename _Require = _If_fs_path<_Path>>
|
||||||
is_constructible<__filebuf_type, const _Path&, ios_base::openmode>>>
|
|
||||||
basic_ifstream(const _Path& __s,
|
basic_ifstream(const _Path& __s,
|
||||||
ios_base::openmode __mode = ios_base::in)
|
ios_base::openmode __mode = ios_base::in)
|
||||||
: basic_ifstream(__s.c_str(), __mode)
|
: 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.
|
* fails, @c failbit is set in the stream's error state.
|
||||||
*/
|
*/
|
||||||
template<typename _Path>
|
template<typename _Path>
|
||||||
auto
|
_If_fs_path<_Path, void>
|
||||||
open(const _Path& __s, ios_base::openmode __mode = ios_base::in)
|
open(const _Path& __s, ios_base::openmode __mode = ios_base::in)
|
||||||
-> decltype((void)_M_filebuf.open(__s, __mode))
|
|
||||||
{ open(__s.c_str(), __mode); }
|
{ open(__s.c_str(), __mode); }
|
||||||
#endif // C++17
|
#endif // C++17
|
||||||
#endif // C++11
|
#endif // C++11
|
||||||
|
|
@ -768,8 +768,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
*
|
*
|
||||||
* @c ios_base::out is automatically included in @a __mode.
|
* @c ios_base::out is automatically included in @a __mode.
|
||||||
*/
|
*/
|
||||||
template<typename _Path, typename = _Require<
|
template<typename _Path, typename _Require = _If_fs_path<_Path>>
|
||||||
is_constructible<__filebuf_type, const _Path&, ios_base::openmode>>>
|
|
||||||
basic_ofstream(const _Path& __s,
|
basic_ofstream(const _Path& __s,
|
||||||
ios_base::openmode __mode = ios_base::out)
|
ios_base::openmode __mode = ios_base::out)
|
||||||
: basic_ofstream(__s.c_str(), __mode)
|
: 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.
|
* function fails, @c failbit is set in the stream's error state.
|
||||||
*/
|
*/
|
||||||
template<typename _Path>
|
template<typename _Path>
|
||||||
auto
|
_If_fs_path<_Path, void>
|
||||||
open(const _Path& __s, ios_base::openmode __mode = ios_base::out)
|
open(const _Path& __s, ios_base::openmode __mode = ios_base::out)
|
||||||
-> decltype((void)_M_filebuf.open(__s, __mode))
|
|
||||||
{ open(__s.c_str(), __mode); }
|
{ open(__s.c_str(), __mode); }
|
||||||
#endif // C++17
|
#endif // C++17
|
||||||
#endif // C++11
|
#endif // C++11
|
||||||
|
|
@ -992,8 +990,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
* @param __s filesystem::path specifying the filename.
|
* @param __s filesystem::path specifying the filename.
|
||||||
* @param __mode Open file in specified mode (see std::ios_base).
|
* @param __mode Open file in specified mode (see std::ios_base).
|
||||||
*/
|
*/
|
||||||
template<typename _Path, typename = _Require<
|
template<typename _Path, typename _Require = _If_fs_path<_Path>>
|
||||||
is_constructible<__filebuf_type, const _Path&, ios_base::openmode>>>
|
|
||||||
basic_fstream(const _Path& __s,
|
basic_fstream(const _Path& __s,
|
||||||
ios_base::openmode __mode = ios_base::in | ios_base::out)
|
ios_base::openmode __mode = ios_base::in | ios_base::out)
|
||||||
: basic_fstream(__s.c_str(), __mode)
|
: 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.
|
* function fails, @c failbit is set in the stream's error state.
|
||||||
*/
|
*/
|
||||||
template<typename _Path>
|
template<typename _Path>
|
||||||
auto
|
_If_fs_path<_Path, void>
|
||||||
open(const _Path& __s,
|
open(const _Path& __s,
|
||||||
ios_base::openmode __mode = ios_base::in | ios_base::out)
|
ios_base::openmode __mode = ios_base::in | ios_base::out)
|
||||||
-> decltype((void)_M_filebuf.open(__s, __mode))
|
|
||||||
{ open(__s.c_str(), __mode); }
|
{ open(__s.c_str(), __mode); }
|
||||||
#endif // C++17
|
#endif // C++17
|
||||||
#endif // C++11
|
#endif // C++11
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <testsuite_hooks.h>
|
#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
|
void
|
||||||
test01()
|
test01()
|
||||||
|
|
@ -34,6 +35,13 @@ test01()
|
||||||
VERIFY( fb.is_open() );
|
VERIFY( fb.is_open() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
test02() // compile-only
|
||||||
|
{
|
||||||
|
std::filebuf fb;
|
||||||
|
fb.open(cstr, std::ios::in); // PR libstdc++/83025
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,14 @@ test02()
|
||||||
VERIFY( f.is_open() );
|
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
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
test01();
|
test01();
|
||||||
test02();
|
test02();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <testsuite_hooks.h>
|
#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
|
void
|
||||||
test01()
|
test01()
|
||||||
|
|
@ -42,6 +43,14 @@ test02()
|
||||||
VERIFY( f.is_open() );
|
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
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,14 @@ test02()
|
||||||
VERIFY( f.is_open() );
|
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
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
test01();
|
test01();
|
||||||
test02();
|
test02();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <testsuite_hooks.h>
|
#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
|
void
|
||||||
test01()
|
test01()
|
||||||
|
|
@ -42,6 +43,14 @@ test02()
|
||||||
VERIFY( f.is_open() );
|
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
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,11 @@ test02()
|
||||||
VERIFY( f.is_open() );
|
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
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <testsuite_hooks.h>
|
#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
|
void
|
||||||
test01()
|
test01()
|
||||||
|
|
@ -42,10 +43,17 @@ test02()
|
||||||
VERIFY( f.is_open() );
|
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
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
test01();
|
test01();
|
||||||
test02();
|
test02();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue