Add new std::basic_string constructor (LWG 2583)
* config/abi/pre/gnu.ver (GLIBCXX_3.4, GLIBCXX_3.4.21): Use more precise patterns for basic_string constructors. (GLIBCXX_3.4.23): Export new constructors. * doc/xml/manual/intro.xml: Document LWG 2583 status. * doc/html/*: Regenerate. * include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI] (basic_string(const basic_string&, size_type, const Alloc&)): Add new constructor for LWG 2583. (basic_string(const basic_string&, size_type, size_type)): Remove default argument. [!_GLIBCXX_USE_CXX11_ABI]: Likewise. * include/bits/basic_string.tcc [!_GLIBCXX_USE_CXX11_ABI]: Define it. * testsuite/21_strings/basic_string/cons/char/8.cc: New test. * testsuite/21_strings/basic_string/cons/wchar_t/8.cc: New test. From-SVN: r239773
This commit is contained in:
parent
83c7402aa5
commit
86bbf15b6b
8 changed files with 243 additions and 10 deletions
|
@ -1,3 +1,20 @@
|
|||
2016-08-26 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
* config/abi/pre/gnu.ver (GLIBCXX_3.4, GLIBCXX_3.4.21): Use more
|
||||
precise patterns for basic_string constructors.
|
||||
(GLIBCXX_3.4.23): Export new constructors.
|
||||
* doc/xml/manual/intro.xml: Document LWG 2583 status.
|
||||
* doc/html/*: Regenerate.
|
||||
* include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI]
|
||||
(basic_string(const basic_string&, size_type, const Alloc&)): Add
|
||||
new constructor for LWG 2583.
|
||||
(basic_string(const basic_string&, size_type, size_type)): Remove
|
||||
default argument.
|
||||
[!_GLIBCXX_USE_CXX11_ABI]: Likewise.
|
||||
* include/bits/basic_string.tcc [!_GLIBCXX_USE_CXX11_ABI]: Define it.
|
||||
* testsuite/21_strings/basic_string/cons/char/8.cc: New test.
|
||||
* testsuite/21_strings/basic_string/cons/wchar_t/8.cc: New test.
|
||||
|
||||
2016-08-24 Aditya Kumar <hiraditya@msn.com>
|
||||
|
||||
* include/bits/algorithmfwd.h: Remove trailing whitespace.
|
||||
|
|
|
@ -206,7 +206,14 @@ GLIBCXX_3.4 {
|
|||
# std::string
|
||||
# 'y' here and below represents 'unsigned long long'
|
||||
# where it is used for size_type on LLP64 platforms.
|
||||
_ZNSsC[12][EI][PRjmvyN]*;
|
||||
_ZNSsC[12]EPKc*;
|
||||
_ZNSsC[12]ERKSaIcE;
|
||||
_ZNSsC[12]ERKSs;
|
||||
# _ZNSsC[12]ERKSs[jmy]RKSaIcE;
|
||||
_ZNSsC[12]ERKSs[jmy][jmy]*;
|
||||
_ZNSsC[12]E[jmy]cRKSaIcE;
|
||||
_ZNSsC[12]Ev;
|
||||
_ZNSsC[12]I[PN]*;
|
||||
_ZNSsD*;
|
||||
_ZNSs[0-58-9]a*;
|
||||
_ZNSs5beginEv;
|
||||
|
@ -267,7 +274,13 @@ GLIBCXX_3.4 {
|
|||
_ZNKSs4copyEPc[jmy][jmy];
|
||||
|
||||
# std::wstring
|
||||
_ZNSbIwSt11char_traitsIwESaIwEEC[12][EI][PRjmvyN]*;
|
||||
_ZNSbIwSt11char_traitsIwESaIwEEC[12]EPKw*;
|
||||
_ZNSbIwSt11char_traitsIwESaIwEEC[12]ERKS[12]_;
|
||||
# _ZNSbIwSt11char_traitsIwESaIwEEC[12]ERKS2_mRKS1_;
|
||||
_ZNSbIwSt11char_traitsIwESaIwEEC[12]ERKS2_[jmy][jmy]*;
|
||||
_ZNSbIwSt11char_traitsIwESaIwEEC[12]E[jmy]wRKS1_;
|
||||
_ZNSbIwSt11char_traitsIwESaIwEEC[12]Ev;
|
||||
_ZNSbIwSt11char_traitsIwESaIwEEC[12]I[PN]*;
|
||||
_ZNSbIwSt11char_traitsIwESaIwEED*;
|
||||
_ZNSbIwSt11char_traitsIwESaIwEE[0-58-9]a*;
|
||||
_ZNSbIwSt11char_traitsIwESaIwEE5beginEv;
|
||||
|
@ -1683,7 +1696,17 @@ GLIBCXX_3.4.21 {
|
|||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE12_M*;
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE1[3-9]*;
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE[2-9]*;
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE[CDaip]*;
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]EOS4_*;
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]EPK*;
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]ERKS[34]_;
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]ERKS4_RKS3_;
|
||||
# _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]ERKS4_[jmy]RKS3_;
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]ERKS4_[jmy][jmy]*;
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]ESt16*;
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]E[jmy][cw]RKS3_;
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]I[PN]*;
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE[Daip]*;
|
||||
_ZNKSt7__cxx1112basic_string*;
|
||||
|
||||
# operator+ for ABI-tagged std::basic_string
|
||||
|
@ -1919,6 +1942,11 @@ GLIBCXX_3.4.23 {
|
|||
# basic_string<C, T, A>::_Alloc_hider::_Alloc_hider(C*, A&&)
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE12_Alloc_hiderC[12]EP[cw]OS3_;
|
||||
|
||||
# basic_string<C, T, A>::basic_string(const basic_string&, size_type, const A&)
|
||||
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]ERKS4_[jmy]RKS3_;
|
||||
_ZNSsC[12]ERKSs[jmy]RKSaIcE;
|
||||
_ZNSbIwSt11char_traitsIwESaIwEEC[12]ERKS2_mRKS1_;
|
||||
|
||||
} GLIBCXX_3.4.22;
|
||||
|
||||
# Symbols in the support library (libsupc++) have their own tag.
|
||||
|
|
|
@ -475,6 +475,10 @@
|
|||
<span class="emphasis"><em><code class="code">allocator_traits::max_size()</code> default behavior is incorrect
|
||||
</em></span>
|
||||
</span></dt><dd><p>Divide by the object type.
|
||||
</p></dd><dt><span class="term"><a class="link" href="../ext/lwg-defects.html#2583" target="_top">2583</a>:
|
||||
<span class="emphasis"><em>There is no way to supply an allocator for <code class="code"> basic_string(str, pos)</code>
|
||||
</em></span>
|
||||
</span></dt><dd><p>Add new constructor
|
||||
</p></dd><dt><span class="term"><a class="link" href="../ext/lwg-defects.html#2684" target="_top">2684</a>:
|
||||
<span class="emphasis"><em><code class="code">priority_queue</code> lacking comparator typedef
|
||||
</em></span>
|
||||
|
|
|
@ -1058,6 +1058,13 @@ requirements of the license of GCC.
|
|||
<listitem><para>Divide by the object type.
|
||||
</para></listitem></varlistentry>
|
||||
|
||||
<varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2583">2583</link>:
|
||||
<emphasis>There is no way to supply an allocator for <code> basic_string(str, pos)</code>
|
||||
</emphasis>
|
||||
</term>
|
||||
<listitem><para>Add new constructor
|
||||
</para></listitem></varlistentry>
|
||||
|
||||
<varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2684">2684</link>:
|
||||
<emphasis><code>priority_queue</code> lacking comparator typedef
|
||||
</emphasis>
|
||||
|
|
|
@ -417,16 +417,31 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
|
|||
_Alloc_traits::_S_select_on_copy(__str._M_get_allocator()))
|
||||
{ _M_construct(__str._M_data(), __str._M_data() + __str.length()); }
|
||||
|
||||
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
||||
// 2583. no way to supply an allocator for basic_string(str, pos)
|
||||
/**
|
||||
* @brief Construct string as copy of a substring.
|
||||
* @param __str Source string.
|
||||
* @param __pos Index of first character to copy from.
|
||||
* @param __n Number of characters to copy (default remainder).
|
||||
* @param __a Allocator to use.
|
||||
*/
|
||||
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
||||
// 2402. [this constructor] shouldn't use Allocator()
|
||||
basic_string(const basic_string& __str, size_type __pos,
|
||||
size_type __n = npos)
|
||||
const _Alloc& __a = _Alloc())
|
||||
: _M_dataplus(_M_local_data(), __a)
|
||||
{
|
||||
const _CharT* __start = __str._M_data()
|
||||
+ __str._M_check(__pos, "basic_string::basic_string");
|
||||
_M_construct(__start, __start + __str._M_limit(__pos, npos));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Construct string as copy of a substring.
|
||||
* @param __str Source string.
|
||||
* @param __pos Index of first character to copy from.
|
||||
* @param __n Number of characters to copy.
|
||||
*/
|
||||
basic_string(const basic_string& __str, size_type __pos,
|
||||
size_type __n)
|
||||
: _M_dataplus(_M_local_data())
|
||||
{
|
||||
const _CharT* __start = __str._M_data()
|
||||
|
@ -438,7 +453,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
|
|||
* @brief Construct string as copy of a substring.
|
||||
* @param __str Source string.
|
||||
* @param __pos Index of first character to copy from.
|
||||
* @param __n Number of characters to copy (default remainder).
|
||||
* @param __n Number of characters to copy.
|
||||
* @param __a Allocator to use.
|
||||
*/
|
||||
basic_string(const basic_string& __str, size_type __pos,
|
||||
|
@ -3305,14 +3320,26 @@ _GLIBCXX_END_NAMESPACE_CXX11
|
|||
* @param __str Source string.
|
||||
*/
|
||||
basic_string(const basic_string& __str);
|
||||
|
||||
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
||||
// 2583. no way to supply an allocator for basic_string(str, pos)
|
||||
/**
|
||||
* @brief Construct string as copy of a substring.
|
||||
* @param __str Source string.
|
||||
* @param __pos Index of first character to copy from.
|
||||
* @param __n Number of characters to copy (default remainder).
|
||||
* @param __a Allocator to use.
|
||||
*/
|
||||
basic_string(const basic_string& __str, size_type __pos,
|
||||
size_type __n = npos);
|
||||
const _Alloc& __a = _Alloc());
|
||||
|
||||
/**
|
||||
* @brief Construct string as copy of a substring.
|
||||
* @param __str Source string.
|
||||
* @param __pos Index of first character to copy from.
|
||||
* @param __n Number of characters to copy.
|
||||
*/
|
||||
basic_string(const basic_string& __str, size_type __pos,
|
||||
size_type __n);
|
||||
/**
|
||||
* @brief Construct string as copy of a substring.
|
||||
* @param __str Source string.
|
||||
|
|
|
@ -619,6 +619,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
: _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
|
||||
{ }
|
||||
|
||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||
basic_string<_CharT, _Traits, _Alloc>::
|
||||
basic_string(const basic_string& __str, size_type __pos, const _Alloc& __a)
|
||||
: _M_dataplus(_S_construct(__str._M_data()
|
||||
+ __str._M_check(__pos,
|
||||
"basic_string::basic_string"),
|
||||
__str._M_data() + __str._M_limit(__pos, npos)
|
||||
+ __pos, __a), __a)
|
||||
{ }
|
||||
|
||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||
basic_string<_CharT, _Traits, _Alloc>::
|
||||
basic_string(const basic_string& __str, size_type __pos, size_type __n)
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
// Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-do run { target c++11 } }
|
||||
|
||||
#include <string>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
template<typename... Args>
|
||||
std::size_t
|
||||
construct(Args&&... args)
|
||||
{
|
||||
return std::string( std::forward<Args>(args)... ).length();
|
||||
}
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
using string = std::string;
|
||||
using list = std::initializer_list<string::value_type>;
|
||||
|
||||
const std::string lvalue = "lvalue";
|
||||
std::allocator<char> alloc;
|
||||
|
||||
// test all valid combinations of arguments:
|
||||
VERIFY( construct( ) == 0 );
|
||||
VERIFY( construct( alloc ) == 0 );
|
||||
VERIFY( construct( lvalue ) == 6 );
|
||||
VERIFY( construct( string{"rvalue"} ) == 6 );
|
||||
VERIFY( construct( lvalue, 2 ) == 4 );
|
||||
VERIFY( construct( lvalue, 2, alloc ) == 4 );
|
||||
VERIFY( construct( lvalue, 2, 3 ) == 3 );
|
||||
VERIFY( construct( lvalue, 2, 3, alloc ) == 3 );
|
||||
VERIFY( construct( "C string", 4 ) == 4 );
|
||||
VERIFY( construct( "C string", 4, alloc ) == 4 );
|
||||
VERIFY( construct( "C string" ) == 8 );
|
||||
VERIFY( construct( "C string and alloc", alloc ) == 18 );
|
||||
VERIFY( construct( 5, ' ' ) == 5 );
|
||||
VERIFY( construct( 5, ' ', alloc ) == 5 );
|
||||
VERIFY( construct( lvalue.begin(), lvalue.end() ) == 6 );
|
||||
VERIFY( construct( lvalue.begin(), lvalue.end(), alloc ) == 6 );
|
||||
VERIFY( construct( list{ 'l' , 'i' , 's', 't' } ) == 4 );
|
||||
VERIFY( construct( list{ 'l', 'i', 's', 't' }, alloc ) == 4 );
|
||||
#if _GLIBCXX_USE_CXX11_ABI
|
||||
VERIFY( construct( lvalue, alloc ) == 6 );
|
||||
VERIFY( construct( string{"rvalue"}, alloc ) == 6 );
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
// Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-do run { target c++11 } }
|
||||
|
||||
#include <string>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
template<typename... Args>
|
||||
std::size_t
|
||||
construct(Args&&... args)
|
||||
{
|
||||
return std::wstring( std::forward<Args>(args)... ).length();
|
||||
}
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
using string = std::wstring;
|
||||
using list = std::initializer_list<string::value_type>;
|
||||
|
||||
const std::wstring lvalue = L"lvalue";
|
||||
std::allocator<char> alloc;
|
||||
|
||||
// test all valid combinations of arguments:
|
||||
VERIFY( construct( ) == 0 );
|
||||
VERIFY( construct( alloc ) == 0 );
|
||||
VERIFY( construct( lvalue ) == 6 );
|
||||
VERIFY( construct( string{L"rvalue"} ) == 6 );
|
||||
VERIFY( construct( lvalue, 2 ) == 4 );
|
||||
VERIFY( construct( lvalue, 2, alloc ) == 4 );
|
||||
VERIFY( construct( lvalue, 2, 3 ) == 3 );
|
||||
VERIFY( construct( lvalue, 2, 3, alloc ) == 3 );
|
||||
VERIFY( construct( L"C string", 4 ) == 4 );
|
||||
VERIFY( construct( L"C string", 4, alloc ) == 4 );
|
||||
VERIFY( construct( L"C string" ) == 8 );
|
||||
VERIFY( construct( L"C string and alloc", alloc ) == 18 );
|
||||
VERIFY( construct( 5, L' ' ) == 5 );
|
||||
VERIFY( construct( 5, L' ', alloc ) == 5 );
|
||||
VERIFY( construct( lvalue.begin(), lvalue.end() ) == 6 );
|
||||
VERIFY( construct( lvalue.begin(), lvalue.end(), alloc ) == 6 );
|
||||
VERIFY( construct( list{ L'l' , L'i' , L's', L't' } ) == 4 );
|
||||
VERIFY( construct( list{ L'l', L'i', L's', L't' }, alloc ) == 4 );
|
||||
#if _GLIBCXX_USE_CXX11_ABI
|
||||
VERIFY( construct( lvalue, alloc ) == 6 );
|
||||
VERIFY( construct( string{L"rvalue"}, alloc ) == 6 );
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
}
|
Loading…
Add table
Reference in a new issue