mirror of git://gcc.gnu.org/git/gcc.git
P0935R0 Eradicating unnecessarily explicit default constructors
More pieces of P0935R0, making default constructors non-explicit. * include/backward/strstream (strstreambuf): Add non-explicit default constructor. * include/bits/locale_conv.h (wbuffer_convert, wstring_convert): Likewise. * include/bits/regex.h (match_results): Likewise. * testsuite/22_locale/conversions/buffer/1.cc: Test for non-explicit default constructor. * testsuite/22_locale/conversions/string/1.cc: Likewise. * testsuite/28_regex/match_results/ctors/char/default.cc: Likewise. * testsuite/28_regex/match_results/ctors/wchar_t/default.cc: Likewise. From-SVN: r261597
This commit is contained in:
parent
74755c6afc
commit
e9ecac306b
|
|
@ -1,5 +1,17 @@
|
||||||
2018-06-14 Jonathan Wakely <jwakely@redhat.com>
|
2018-06-14 Jonathan Wakely <jwakely@redhat.com>
|
||||||
|
|
||||||
|
P0935R0 Eradicating unnecessarily explicit default constructors
|
||||||
|
* include/backward/strstream (strstreambuf): Add non-explicit default
|
||||||
|
constructor.
|
||||||
|
* include/bits/locale_conv.h (wbuffer_convert, wstring_convert):
|
||||||
|
Likewise.
|
||||||
|
* include/bits/regex.h (match_results): Likewise.
|
||||||
|
* testsuite/22_locale/conversions/buffer/1.cc: Test for non-explicit
|
||||||
|
default constructor.
|
||||||
|
* testsuite/22_locale/conversions/string/1.cc: Likewise.
|
||||||
|
* testsuite/28_regex/match_results/ctors/char/default.cc: Likewise.
|
||||||
|
* testsuite/28_regex/match_results/ctors/wchar_t/default.cc: Likewise.
|
||||||
|
|
||||||
* include/std/tuple (__cpp_lib_tuple_element_t): Move feature test
|
* include/std/tuple (__cpp_lib_tuple_element_t): Move feature test
|
||||||
macro from <utility> and change type to long.
|
macro from <utility> and change type to long.
|
||||||
* include/std/utility (__cpp_lib_tuple_element_t): Remove.
|
* include/std/utility (__cpp_lib_tuple_element_t): Remove.
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor, destructor
|
// Constructor, destructor
|
||||||
|
#if __cplusplus >= 201103L
|
||||||
|
strstreambuf() : strstreambuf(0) { }
|
||||||
|
explicit strstreambuf(streamsize __initial_capacity);
|
||||||
|
#else
|
||||||
explicit strstreambuf(streamsize __initial_capacity = 0);
|
explicit strstreambuf(streamsize __initial_capacity = 0);
|
||||||
|
#endif
|
||||||
strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*));
|
strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*));
|
||||||
|
|
||||||
strstreambuf(char* __get, streamsize __n, char* __put = 0) throw ();
|
strstreambuf(char* __get, streamsize __n, char* __put = 0) throw ();
|
||||||
|
|
|
||||||
|
|
@ -174,14 +174,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
|
||||||
typedef typename _Codecvt::state_type state_type;
|
typedef typename _Codecvt::state_type state_type;
|
||||||
typedef typename wide_string::traits_type::int_type int_type;
|
typedef typename wide_string::traits_type::int_type int_type;
|
||||||
|
|
||||||
/** Default constructor.
|
/// Default constructor.
|
||||||
|
wstring_convert() : _M_cvt(new _Codecvt()) { }
|
||||||
|
|
||||||
|
/** Constructor.
|
||||||
*
|
*
|
||||||
* @param __pcvt The facet to use for conversions.
|
* @param __pcvt The facet to use for conversions.
|
||||||
*
|
*
|
||||||
* Takes ownership of @p __pcvt and will delete it in the destructor.
|
* Takes ownership of @p __pcvt and will delete it in the destructor.
|
||||||
*/
|
*/
|
||||||
explicit
|
explicit
|
||||||
wstring_convert(_Codecvt* __pcvt = new _Codecvt()) : _M_cvt(__pcvt)
|
wstring_convert(_Codecvt* __pcvt) : _M_cvt(__pcvt)
|
||||||
{
|
{
|
||||||
if (!_M_cvt)
|
if (!_M_cvt)
|
||||||
__throw_logic_error("wstring_convert");
|
__throw_logic_error("wstring_convert");
|
||||||
|
|
@ -325,7 +328,10 @@ _GLIBCXX_END_NAMESPACE_CXX11
|
||||||
public:
|
public:
|
||||||
typedef typename _Codecvt::state_type state_type;
|
typedef typename _Codecvt::state_type state_type;
|
||||||
|
|
||||||
/** Default constructor.
|
/// Default constructor.
|
||||||
|
wbuffer_convert() : wbuffer_convert(nullptr) { }
|
||||||
|
|
||||||
|
/** Constructor.
|
||||||
*
|
*
|
||||||
* @param __bytebuf The underlying byte stream buffer.
|
* @param __bytebuf The underlying byte stream buffer.
|
||||||
* @param __pcvt The facet to use for conversions.
|
* @param __pcvt The facet to use for conversions.
|
||||||
|
|
@ -334,7 +340,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
|
||||||
* Takes ownership of @p __pcvt and will delete it in the destructor.
|
* Takes ownership of @p __pcvt and will delete it in the destructor.
|
||||||
*/
|
*/
|
||||||
explicit
|
explicit
|
||||||
wbuffer_convert(streambuf* __bytebuf = 0, _Codecvt* __pcvt = new _Codecvt,
|
wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt = new _Codecvt,
|
||||||
state_type __state = state_type())
|
state_type __state = state_type())
|
||||||
: _M_buf(__bytebuf), _M_cvt(__pcvt), _M_state(__state)
|
: _M_buf(__bytebuf), _M_cvt(__pcvt), _M_state(__state)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1600,12 +1600,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a default %match_results container.
|
* @brief Constructs a default %match_results container.
|
||||||
* @post size() returns 0 and str() returns an empty string.
|
* @post size() returns 0 and str() returns an empty string.
|
||||||
|
* @{
|
||||||
*/
|
*/
|
||||||
|
match_results() : match_results(_Alloc()) { }
|
||||||
|
|
||||||
explicit
|
explicit
|
||||||
match_results(const _Alloc& __a = _Alloc()) noexcept
|
match_results(const _Alloc& __a) noexcept
|
||||||
: _Base_type(__a)
|
: _Base_type(__a)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
// @}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Copy constructs a %match_results.
|
* @brief Copy constructs a %match_results.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
#include <testsuite_common_types.h>
|
||||||
|
|
||||||
template<typename Elem>
|
template<typename Elem>
|
||||||
struct cvt : std::codecvt<Elem, char, std::mbstate_t> { };
|
struct cvt : std::codecvt<Elem, char, std::mbstate_t> { };
|
||||||
|
|
@ -42,6 +43,9 @@ void test01()
|
||||||
VERIFY( buf.rdbuf(&sbuf) == nullptr );
|
VERIFY( buf.rdbuf(&sbuf) == nullptr );
|
||||||
VERIFY( buf.rdbuf() == &sbuf );
|
VERIFY( buf.rdbuf() == &sbuf );
|
||||||
VERIFY( buf.rdbuf(nullptr) == &sbuf );
|
VERIFY( buf.rdbuf(nullptr) == &sbuf );
|
||||||
|
|
||||||
|
__gnu_test::implicitly_default_constructible test;
|
||||||
|
test.operator()<buf_conv<wchar_t>>(); // P0935R0
|
||||||
}
|
}
|
||||||
|
|
||||||
void test02()
|
void test02()
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
#include <testsuite_common_types.h>
|
||||||
|
|
||||||
template<typename Elem>
|
template<typename Elem>
|
||||||
struct cvt : std::codecvt<Elem, char, std::mbstate_t> { };
|
struct cvt : std::codecvt<Elem, char, std::mbstate_t> { };
|
||||||
|
|
@ -43,6 +44,9 @@ void test01()
|
||||||
string roundtrip = c.to_bytes(output);
|
string roundtrip = c.to_bytes(output);
|
||||||
VERIFY( input == roundtrip );
|
VERIFY( input == roundtrip );
|
||||||
VERIFY( c.converted() == roundtrip.length() );
|
VERIFY( c.converted() == roundtrip.length() );
|
||||||
|
|
||||||
|
__gnu_test::implicitly_default_constructible test;
|
||||||
|
test.operator()<sc>(); // P0935R0
|
||||||
}
|
}
|
||||||
|
|
||||||
void test02()
|
void test02()
|
||||||
|
|
@ -64,6 +68,9 @@ void test02()
|
||||||
VERIFY( c.to_bytes(output[0]) == input.substr(0, 1) );
|
VERIFY( c.to_bytes(output[0]) == input.substr(0, 1) );
|
||||||
VERIFY( c.to_bytes(output.c_str()) == input );
|
VERIFY( c.to_bytes(output.c_str()) == input );
|
||||||
VERIFY( c.to_bytes(output.data(), output.data()+output.size()) == input );
|
VERIFY( c.to_bytes(output.data(), output.data()+output.size()) == input );
|
||||||
|
|
||||||
|
__gnu_test::implicitly_default_constructible test;
|
||||||
|
test.operator()<wsc>(); // P0935R0
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,9 @@
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
#include <testsuite_common_types.h>
|
||||||
|
|
||||||
// Tests default constructor of the match_result class.
|
// Tests default constructor of the match_result class.
|
||||||
void test01()
|
void test01()
|
||||||
{
|
{
|
||||||
std::cmatch cm;
|
std::cmatch cm;
|
||||||
|
|
@ -43,10 +44,18 @@ void test02()
|
||||||
VERIFY( sm.begin() == sm.end() ); // PR libstdc++/83600
|
VERIFY( sm.begin() == sm.end() ); // PR libstdc++/83600
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test03()
|
||||||
|
{
|
||||||
|
// P0935R0
|
||||||
|
__gnu_test::implicitly_default_constructible test;
|
||||||
|
test.operator()<std::cmatch>();
|
||||||
|
test.operator()<std::smatch>();
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
test01();
|
test01();
|
||||||
test02();
|
test02();
|
||||||
return 0;
|
test03();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,9 @@
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
#include <testsuite_common_types.h>
|
||||||
|
|
||||||
// Tests default constructor of the match_result class.
|
// Tests default constructor of the match_result class.
|
||||||
void test01()
|
void test01()
|
||||||
{
|
{
|
||||||
std::wcmatch cm;
|
std::wcmatch cm;
|
||||||
|
|
@ -43,10 +44,18 @@ void test02()
|
||||||
VERIFY( sm.begin() == sm.end() ); // PR libstdc++/83600
|
VERIFY( sm.begin() == sm.end() ); // PR libstdc++/83600
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test03()
|
||||||
|
{
|
||||||
|
// P0935R0
|
||||||
|
__gnu_test::implicitly_default_constructible test;
|
||||||
|
test.operator()<std::wcmatch>();
|
||||||
|
test.operator()<std::wsmatch>();
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
test01();
|
test01();
|
||||||
test02();
|
test02();
|
||||||
return 0;
|
test03();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue